Files
twenty_crm/front/src/interfaces/person.interface.ts
Sammy Teillet baca6150f5 Sammy/t 240 frontend filtering search is refactored (#122)
* refactor: use AnyEntity instead of any

* refactor: remove any and brand company type

* refactor: add typename for user and people

* bugfix: await company to be created before displaying it

* feature: await deletion before removing the lines

* refactor: remove default tyep for filters

* refactor: remove default type AnyEntity

* refactor: remove USers from filterable types

* refactor: do not depend on Filter types in Table

* Add tests

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2023-05-17 21:49:34 +02:00

80 lines
1.6 KiB
TypeScript

import {
Company,
GraphqlQueryCompany,
mapToCompany,
} from './company.interface';
import { Pipe } from './pipe.interface';
export type Person = {
__typename: 'people';
id: string;
firstname?: string;
lastname?: string;
picture?: string | null;
email?: string;
phone?: string;
city?: string;
creationDate?: Date;
company?: Company | null;
pipes?: Pipe[] | null;
};
export type GraphqlQueryPerson = {
id: string;
firstname?: string;
lastname?: string;
city?: string;
email?: string;
phone?: string;
created_at?: string;
company?: GraphqlQueryCompany | null;
__typename: string;
};
export type GraphqlMutationPerson = {
id: string;
firstname?: string;
lastname?: string;
email?: string;
phone?: string;
city?: string;
created_at?: string;
company_id?: string;
__typename: 'people';
};
export const mapToPerson = (person: GraphqlQueryPerson): Person => ({
__typename: 'people',
id: person.id,
firstname: person.firstname,
lastname: person.lastname,
email: person.email,
phone: person.phone,
city: person.city,
creationDate: person.created_at ? new Date(person.created_at) : undefined,
company: person.company ? mapToCompany(person.company) : null,
});
export const mapToGqlPerson = (person: Person): GraphqlMutationPerson => ({
id: person.id,
firstname: person.firstname,
lastname: person.lastname,
email: person.email,
phone: person.phone,
city: person.city,
created_at: person.creationDate
? person.creationDate.toUTCString()
: undefined,
company_id: person.company?.id,
__typename: 'people',
});