# Introduction Avoid having multiple `isDefined` definition across our pacakges Also avoid importing `isDefined` from `twenty-ui` which exposes a huge barrel for a such little util function ## In a nutshell Removed own `isDefined.ts` definition from `twenty-ui` `twenty-front` and `twenty-server` to move it to `twenty-shared`. Updated imports for each packages, and added explicit dependencies to `twenty-shared` if not already in place Related PR https://github.com/twentyhq/twenty/pull/9941
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { isDefined } from 'twenty-shared';
|
|
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 (isDefined(data?.companies.edges)) {
|
|
return data.companies.edges.length > 0
|
|
? isDefined(data.companies.edges[0].node)
|
|
? data.companies.edges[0].node
|
|
: null
|
|
: null;
|
|
}
|
|
return null;
|
|
};
|
|
|
|
export const createCompany = async (
|
|
company: CompanyInput,
|
|
): Promise<string | null> => {
|
|
const data = await callMutation<CreateCompanyResponse>(CREATE_COMPANY, {
|
|
input: company,
|
|
});
|
|
if (isDefined(data)) {
|
|
return data.createCompany.id;
|
|
}
|
|
return null;
|
|
};
|