Files
twenty/front/src/interfaces/person.interface.ts
Anders Borch d4b1b2f661 Companies table (#79)
* Add columns to companies:
* account_owner_id
* employees
* address

Add foreign key constraint companies_account_owner_id_fkey
to auth.users.id

* Add select permissions to:
* account_owner_id
* employees
* address

Add relationship between companies and auth.users.

* Update Companies interface to include:
* account_owner_id
* employees
* address

Opportunity is expected to be replace by actual opportunity in a separate PR.

* Add GetCompanies query

* Add initial companies table

* Update test to use mock apollo provider

* Update to match changed company column names

* Add company interface mapping tests

* Test entire object

* Add test for companies being rendered in table.

* Add test for sorting reduce.

* Fix prettier errors
2023-04-27 12:46:43 +02:00

74 lines
1.6 KiB
TypeScript

import { Company } from './company.interface';
import { Pipe } from './pipe.interface';
export type Person = {
id: string;
fullName: string;
picture?: string;
email: string;
company: Omit<
Company,
'employees' | 'address' | 'opportunities' | 'accountOwner' | 'creationDate'
>;
phone: string;
creationDate: Date;
pipe: Pipe;
city: string;
countryCode: string;
};
export type GraphqlQueryPerson = {
city: string;
company: {
__typename: string;
id: string;
name: string;
domain_name: string;
};
created_at: string;
email: string;
firstname: string;
id: string;
lastname: string;
phone: string;
__typename: string;
};
export type GraphqlMutationPerson = {
city: string;
company_id?: string;
created_at: string;
email: string;
firstname: string;
id: string;
lastname: string;
phone: string;
__typename: string;
};
export const mapPerson = (person: GraphqlQueryPerson): Person => ({
fullName: `${person.firstname} ${person.lastname}`,
creationDate: new Date(person.created_at),
pipe: {
name: 'coucou',
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
icon: '💰',
},
...person,
company: {
id: person.company.id,
name: person.company.name,
domain_name: person.company.domain_name,
},
countryCode: 'FR',
});
export const mapGqlPerson = (person: Person): GraphqlMutationPerson => ({
firstname: person.fullName.split(' ').shift() || '',
lastname: person.fullName.split(' ').slice(1).join(' '),
created_at: person.creationDate.toUTCString(),
company_id: person.company.id,
...(person as Omit<Person, 'company'>),
__typename: 'People',
});