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:
38
packages/twenty-chrome-extension/src/db/company.db.ts
Normal file
38
packages/twenty-chrome-extension/src/db/company.db.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user