feat: check if company/person saved (chrome-extension) (#4280)

* add twenty icon

* rest api calls for company

* check if company exists

* refacto

* person/company saved call

* gql codegen init

* type defs

* build fix

* DB calls with gql codegen and apollo integration
This commit is contained in:
Aditya Pimpalkar
2024-03-26 13:37:36 +00:00
committed by GitHub
parent c54acb35b6
commit 5c5dcf5cb5
20 changed files with 6107 additions and 241 deletions

View File

@ -0,0 +1,38 @@
import {
CompanyInput,
CreateCompanyResponse,
FindCompanyResponse,
} from '~/db/types/company.types';
import { Company, CompanyFilterInput } from '~/generated/graphql';
import { CREATE_COMPANY } from '~/graphql/company/mutations';
import { FIND_COMPANY } from '~/graphql/company/queries';
import { callMutation, callQuery } from '../utils/requestDb';
export const fetchCompany = async (
companyfilerInput: CompanyFilterInput,
): Promise<Company | null> => {
const data = await callQuery<FindCompanyResponse>(FIND_COMPANY, {
filter: {
...companyfilerInput,
},
});
if (data?.companies.edges) {
return data?.companies.edges.length > 0
? data?.companies.edges[0].node
: null;
}
return null;
};
export const createCompany = async (
company: CompanyInput,
): Promise<string | null> => {
const data = await callMutation<CreateCompanyResponse>(CREATE_COMPANY, {
input: company,
});
if (data) {
return data.createCompany.id;
}
return null;
};

View File

@ -0,0 +1,36 @@
import {
CreatePersonResponse,
FindPersonResponse,
PersonInput,
} from '~/db/types/person.types';
import { Person, PersonFilterInput } from '~/generated/graphql';
import { CREATE_PERSON } from '~/graphql/person/mutations';
import { FIND_PERSON } from '~/graphql/person/queries';
import { callMutation, callQuery } from '../utils/requestDb';
export const fetchPerson = async (
personFilterData: PersonFilterInput,
): Promise<Person | null> => {
const data = await callQuery<FindPersonResponse>(FIND_PERSON, {
filter: {
...personFilterData,
},
});
if (data?.people.edges) {
return data?.people.edges.length > 0 ? data?.people.edges[0].node : null;
}
return null;
};
export const createPerson = async (
person: PersonInput,
): Promise<string | null> => {
const data = await callMutation<CreatePersonResponse>(CREATE_PERSON, {
input: person,
});
if (data?.createPerson) {
return data.createPerson.id;
}
return null;
};

View File

@ -0,0 +1,10 @@
import { Company, CompanyConnection } from '~/generated/graphql';
export type CompanyInput = Pick<
Company,
'name' | 'domainName' | 'address' | 'employees' | 'linkedinLink'
>;
export type FindCompanyResponse = {
companies: Pick<CompanyConnection, 'edges'>;
};
export type CreateCompanyResponse = { createCompany: { id: string } };

View File

@ -0,0 +1,8 @@
import { Person, PersonConnection } from '~/generated/graphql';
export type PersonInput = Pick<
Person,
'name' | 'city' | 'avatarUrl' | 'jobTitle' | 'linkedinLink'
>;
export type FindPersonResponse = { people: Pick<PersonConnection, 'edges'> };
export type CreatePersonResponse = { createPerson: { id: string } };