Make all fields optional on entities (#121)

* Make all fields optional on entities

* Rewrite tests

* Add test on TableHeader Cancel button
This commit is contained in:
Charles Bochet
2023-05-17 14:50:49 +02:00
committed by GitHub
parent 2facb383a2
commit bc49815ff0
31 changed files with 541 additions and 419 deletions

View File

@ -1,64 +1,77 @@
import { Company, GraphqlQueryCompany, mapCompany } from './company.interface';
import {
Company,
GraphqlQueryCompany,
mapToCompany,
} from './company.interface';
import { Pipe } from './pipe.interface';
export type Person = {
id: string;
firstname: string;
lastname: string;
picture?: string;
email: string;
company: Company | null;
phone: string;
creationDate: Date;
pipe: Pipe | null;
city: 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 = {
city: string;
company: GraphqlQueryCompany | null;
created_at: string;
email: string;
firstname: string;
id: string;
lastname: string;
phone: string;
firstname?: string;
lastname?: string;
city?: string;
email?: string;
phone?: string;
created_at?: string;
company?: GraphqlQueryCompany | null;
__typename: string;
};
export type GraphqlMutationPerson = {
city: string;
company_id?: string;
created_at: string;
email: string;
firstname: string;
id: string;
lastname: string;
phone: string;
firstname?: string;
lastname?: string;
email?: string;
phone?: string;
city?: string;
created_at?: string;
company_id?: string;
__typename: string;
};
export const mapPerson = (person: GraphqlQueryPerson): Person => ({
export const mapToPerson = (person: GraphqlQueryPerson): Person => ({
id: person.id,
firstname: person.firstname,
lastname: person.lastname,
email: person.email,
phone: person.phone,
city: person.city,
firstname: person.firstname,
lastname: person.lastname,
creationDate: new Date(person.created_at),
pipe: {
name: 'coucou',
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
icon: '💰',
},
company: person.company ? mapCompany(person.company) : null,
creationDate: person.created_at ? new Date(person.created_at) : undefined,
company: person.company ? mapToCompany(person.company) : null,
});
export const mapGqlPerson = (person: Person): GraphqlMutationPerson => ({
...(person as Omit<Person, 'company'>),
export const mapToGqlPerson = (person: Person): GraphqlMutationPerson => ({
id: person.id,
firstname: person.firstname,
lastname: person.lastname,
created_at: person.creationDate.toUTCString(),
email: person.email,
phone: person.phone,
city: person.city,
created_at: person.creationDate
? person.creationDate.toUTCString()
: undefined,
company_id: person.company?.id,
__typename: 'People',
__typename: 'people',
});