Files
twenty/front/src/interfaces/company.interface.ts
Charles Bochet bc49815ff0 Make all fields optional on entities (#121)
* Make all fields optional on entities

* Rewrite tests

* Add test on TableHeader Cancel button
2023-05-17 14:50:49 +02:00

73 lines
1.6 KiB
TypeScript

import { Pipe } from 'stream';
import { GraphqlQueryUser, User, mapToUser } from './user.interface';
import { GraphqlQueryPipe } from './pipe.interface';
export type Company = {
id: string;
name?: string;
domainName?: string;
employees?: string;
address?: string;
creationDate?: Date;
pipes?: Pipe[];
accountOwner?: User | null;
};
export type GraphqlQueryCompany = {
id: string;
name?: string;
domain_name?: string;
employees?: string;
address?: string;
created_at?: string;
account_owner?: GraphqlQueryUser | null;
pipes?: GraphqlQueryPipe[] | null;
__typename: string;
};
export type GraphqlMutationCompany = {
id: string;
name?: string;
domain_name?: string;
employees?: string;
address?: string;
created_at?: string;
account_owner_id?: string;
__typename: string;
};
export const mapToCompany = (company: GraphqlQueryCompany): Company => ({
id: company.id,
employees: company.employees,
name: company.name,
address: company.address,
domainName: company.domain_name,
creationDate: company.created_at ? new Date(company.created_at) : undefined,
accountOwner: company.account_owner
? mapToUser(company.account_owner)
: company.account_owner,
pipes: [],
});
export const mapToGqlCompany = (company: Company): GraphqlMutationCompany => ({
id: company.id,
name: company.name,
domain_name: company.domainName,
address: company.address,
employees: company.employees,
created_at: company.creationDate
? company.creationDate.toUTCString()
: undefined,
account_owner_id: company.accountOwner?.id,
__typename: 'companies',
});