From 192b89a7b71bfcf8426fd9623e79cfcfe3ad0245 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Fri, 19 May 2023 11:53:50 +0200 Subject: [PATCH] Make companies employees type a number (#130) Make companies employees type a number to be consistent with api --- front/src/generated/graphql.tsx | 353 ++++++++++++++++-- .../__tests__/company.interface.test.ts | 4 +- .../interfaces/entities/company.interface.ts | 6 +- front/src/pages/companies/Companies.tsx | 2 +- .../companies/__tests__/__data__/mock-data.ts | 12 +- .../src/pages/companies/companies-columns.tsx | 12 +- front/src/services/api/companies/update.ts | 6 +- front/src/services/api/people/update.ts | 2 +- front/src/services/api/search/search.ts | 10 +- .../down.sql | 2 + .../up.sql | 2 + .../down.sql | 1 + .../up.sql | 1 + 13 files changed, 368 insertions(+), 45 deletions(-) create mode 100644 hasura/migrations/default/1684486726911_alter_table_public_companies_alter_column_employees/down.sql create mode 100644 hasura/migrations/default/1684486726911_alter_table_public_companies_alter_column_employees/up.sql create mode 100644 hasura/migrations/default/1684487555948_alter_table_public_companies_alter_column_employees/down.sql create mode 100644 hasura/migrations/default/1684487555948_alter_table_public_companies_alter_column_employees/up.sql diff --git a/front/src/generated/graphql.tsx b/front/src/generated/graphql.tsx index f76ac47f1..728d1d6a4 100644 --- a/front/src/generated/graphql.tsx +++ b/front/src/generated/graphql.tsx @@ -17,6 +17,7 @@ export type Scalars = { bytea: any; citext: any; jsonb: any; + numeric: any; timestamptz: any; uuid: any; }; @@ -1722,7 +1723,7 @@ export type Companies = { created_at: Scalars['timestamptz']; deleted_at?: Maybe; domain_name?: Maybe; - employees: Scalars['Int']; + employees?: Maybe; id: Scalars['uuid']; name?: Maybe; updated_at: Scalars['timestamptz']; @@ -1778,7 +1779,7 @@ export type Companies_Bool_Exp = { created_at?: InputMaybe; deleted_at?: InputMaybe; domain_name?: InputMaybe; - employees?: InputMaybe; + employees?: InputMaybe; id?: InputMaybe; name?: InputMaybe; updated_at?: InputMaybe; @@ -1794,7 +1795,7 @@ export enum Companies_Constraint { /** input type for incrementing numeric columns in table "companies" */ export type Companies_Inc_Input = { - employees?: InputMaybe; + employees?: InputMaybe; }; /** input type for inserting data into table "companies" */ @@ -1805,7 +1806,7 @@ export type Companies_Insert_Input = { created_at?: InputMaybe; deleted_at?: InputMaybe; domain_name?: InputMaybe; - employees?: InputMaybe; + employees?: InputMaybe; id?: InputMaybe; name?: InputMaybe; updated_at?: InputMaybe; @@ -1821,7 +1822,7 @@ export type Companies_Max_Fields = { created_at?: Maybe; deleted_at?: Maybe; domain_name?: Maybe; - employees?: Maybe; + employees?: Maybe; id?: Maybe; name?: Maybe; updated_at?: Maybe; @@ -1836,7 +1837,7 @@ export type Companies_Min_Fields = { created_at?: Maybe; deleted_at?: Maybe; domain_name?: Maybe; - employees?: Maybe; + employees?: Maybe; id?: Maybe; name?: Maybe; updated_at?: Maybe; @@ -1918,7 +1919,7 @@ export type Companies_Set_Input = { created_at?: InputMaybe; deleted_at?: InputMaybe; domain_name?: InputMaybe; - employees?: InputMaybe; + employees?: InputMaybe; id?: InputMaybe; name?: InputMaybe; updated_at?: InputMaybe; @@ -1958,7 +1959,7 @@ export type Companies_Stream_Cursor_Value_Input = { created_at?: InputMaybe; deleted_at?: InputMaybe; domain_name?: InputMaybe; - employees?: InputMaybe; + employees?: InputMaybe; id?: InputMaybe; name?: InputMaybe; updated_at?: InputMaybe; @@ -1968,7 +1969,7 @@ export type Companies_Stream_Cursor_Value_Input = { /** aggregate sum on columns */ export type Companies_Sum_Fields = { __typename?: 'companies_sum_fields'; - employees?: Maybe; + employees?: Maybe; }; /** update columns of table "companies" */ @@ -2807,6 +2808,19 @@ export type Mutation_RootUpdate_Workspaces_ManyArgs = { updates: Array; }; +/** Boolean expression to compare columns of type "numeric". All fields are combined with logical 'AND'. */ +export type Numeric_Comparison_Exp = { + _eq?: InputMaybe; + _gt?: InputMaybe; + _gte?: InputMaybe; + _in?: InputMaybe>; + _is_null?: InputMaybe; + _lt?: InputMaybe; + _lte?: InputMaybe; + _neq?: InputMaybe; + _nin?: InputMaybe>; +}; + /** column ordering options */ export enum Order_By { /** in ascending order, nulls last */ @@ -4999,25 +5013,49 @@ export type Workspaces_Updates = { export type GetCompaniesQueryVariables = Exact<{ orderBy?: InputMaybe | Companies_Order_By>; + where?: InputMaybe; }>; -export type GetCompaniesQuery = { __typename?: 'query_root', companies: Array<{ __typename?: 'companies', id: any, domain_name?: string | null, name?: string | null, created_at: any, address?: string | null, employees: number, account_owner?: { __typename?: 'users', id: any, email?: any | null, displayName: string } | null }> }; +export type GetCompaniesQuery = { __typename?: 'query_root', companies: Array<{ __typename?: 'companies', id: any, domain_name?: string | null, name?: string | null, created_at: any, address?: string | null, employees?: any | null, account_owner?: { __typename?: 'users', id: any, email?: any | null, displayName: string } | null }> }; export type UpdateCompanyMutationVariables = Exact<{ id?: InputMaybe; name?: InputMaybe; domain_name?: InputMaybe; account_owner_id?: InputMaybe; + created_at?: InputMaybe; address?: InputMaybe; - employees?: InputMaybe; + employees?: InputMaybe; }>; -export type UpdateCompanyMutation = { __typename?: 'mutation_root', update_companies?: { __typename?: 'companies_mutation_response', affected_rows: number, returning: Array<{ __typename?: 'companies', address?: string | null, created_at: any, domain_name?: string | null, employees: number, id: any, name?: string | null, account_owner?: { __typename?: 'users', id: any, email?: any | null, displayName: string } | null }> } | null }; +export type UpdateCompanyMutation = { __typename?: 'mutation_root', update_companies?: { __typename?: 'companies_mutation_response', affected_rows: number, returning: Array<{ __typename?: 'companies', address?: string | null, created_at: any, domain_name?: string | null, employees?: any | null, id: any, name?: string | null, account_owner?: { __typename?: 'users', id: any, email?: any | null, displayName: string } | null }> } | null }; + +export type InsertCompanyMutationVariables = Exact<{ + id?: InputMaybe; + name?: InputMaybe; + domain_name?: InputMaybe; + account_owner_id?: InputMaybe; + created_at?: InputMaybe; + address?: InputMaybe; + employees?: InputMaybe; +}>; + + +export type InsertCompanyMutation = { __typename?: 'mutation_root', insert_companies?: { __typename?: 'companies_mutation_response', affected_rows: number, returning: Array<{ __typename?: 'companies', address?: string | null, created_at: any, domain_name?: string | null, employees?: any | null, id: any, name?: string | null }> } | null }; + +export type DeleteCompaniesMutationVariables = Exact<{ + ids?: InputMaybe | Scalars['uuid']>; +}>; + + +export type DeleteCompaniesMutation = { __typename?: 'mutation_root', delete_companies?: { __typename?: 'companies_mutation_response', returning: Array<{ __typename?: 'companies', address?: string | null, created_at: any, domain_name?: string | null, employees?: any | null, id: any, name?: string | null }> } | null }; export type GetPeopleQueryVariables = Exact<{ orderBy?: InputMaybe | People_Order_By>; + where?: InputMaybe; + limit?: InputMaybe; }>; @@ -5031,15 +5069,44 @@ export type UpdatePeopleMutationVariables = Exact<{ city?: InputMaybe; company_id?: InputMaybe; email?: InputMaybe; + created_at?: InputMaybe; }>; -export type UpdatePeopleMutation = { __typename?: 'mutation_root', update_people?: { __typename?: 'people_mutation_response', returning: Array<{ __typename?: 'people', city?: string | null, email?: string | null, firstname?: string | null, id: any, lastname?: string | null, phone?: string | null, company?: { __typename?: 'companies', domain_name?: string | null, name?: string | null, id: any } | null }> } | null }; +export type UpdatePeopleMutation = { __typename?: 'mutation_root', update_people?: { __typename?: 'people_mutation_response', returning: Array<{ __typename?: 'people', city?: string | null, email?: string | null, firstname?: string | null, id: any, lastname?: string | null, phone?: string | null, created_at: any, company?: { __typename?: 'companies', domain_name?: string | null, name?: string | null, id: any } | null }> } | null }; + +export type InsertPersonMutationVariables = Exact<{ + id?: InputMaybe; + firstname?: InputMaybe; + lastname?: InputMaybe; + phone?: InputMaybe; + city?: InputMaybe; + company_id?: InputMaybe; + email?: InputMaybe; + created_at?: InputMaybe; +}>; + + +export type InsertPersonMutation = { __typename?: 'mutation_root', insert_people?: { __typename?: 'people_mutation_response', affected_rows: number, returning: Array<{ __typename?: 'people', city?: string | null, email?: string | null, firstname?: string | null, id: any, lastname?: string | null, phone?: string | null, created_at: any, company?: { __typename?: 'companies', domain_name?: string | null, name?: string | null, id: any } | null }> } | null }; + +export type DeletePeopleMutationVariables = Exact<{ + ids?: InputMaybe | Scalars['uuid']>; +}>; + + +export type DeletePeopleMutation = { __typename?: 'mutation_root', delete_people?: { __typename?: 'people_mutation_response', returning: Array<{ __typename?: 'people', city?: string | null, email?: string | null, firstname?: string | null, id: any, lastname?: string | null, phone?: string | null, created_at: any, company?: { __typename?: 'companies', domain_name?: string | null, name?: string | null, id: any } | null }> } | null }; + +export type GetCurrentUserQueryVariables = Exact<{ + uuid?: InputMaybe; +}>; + + +export type GetCurrentUserQuery = { __typename?: 'query_root', users: Array<{ __typename?: 'users', id: any, email?: any | null, displayName: string, workspace_member?: { __typename?: 'workspace_members', workspace: { __typename?: 'workspaces', id: any, domain_name: string, display_name: string, logo?: string | null } } | null }> }; export const GetCompaniesDocument = gql` - query GetCompanies($orderBy: [companies_order_by!]) { - companies(order_by: $orderBy) { + query GetCompanies($orderBy: [companies_order_by!], $where: companies_bool_exp) { + companies(order_by: $orderBy, where: $where) { id domain_name name @@ -5068,6 +5135,7 @@ export const GetCompaniesDocument = gql` * const { data, loading, error } = useGetCompaniesQuery({ * variables: { * orderBy: // value for 'orderBy' + * where: // value for 'where' * }, * }); */ @@ -5083,10 +5151,10 @@ export type GetCompaniesQueryHookResult = ReturnType; export type GetCompaniesQueryResult = Apollo.QueryResult; export const UpdateCompanyDocument = gql` - mutation UpdateCompany($id: uuid, $name: String, $domain_name: String, $account_owner_id: uuid, $address: String, $employees: Int) { + mutation UpdateCompany($id: uuid, $name: String, $domain_name: String, $account_owner_id: uuid, $created_at: timestamptz, $address: String, $employees: numeric) { update_companies( where: {id: {_eq: $id}} - _set: {account_owner_id: $account_owner_id, address: $address, domain_name: $domain_name, employees: $employees, name: $name} + _set: {account_owner_id: $account_owner_id, address: $address, domain_name: $domain_name, employees: $employees, name: $name, created_at: $created_at} ) { affected_rows returning { @@ -5124,6 +5192,7 @@ export type UpdateCompanyMutationFn = Apollo.MutationFunction; export type UpdateCompanyMutationResult = Apollo.MutationResult; export type UpdateCompanyMutationOptions = Apollo.BaseMutationOptions; +export const InsertCompanyDocument = gql` + mutation InsertCompany($id: uuid, $name: String, $domain_name: String, $account_owner_id: uuid, $created_at: timestamptz, $address: String, $employees: numeric) { + insert_companies( + objects: {id: $id, name: $name, domain_name: $domain_name, account_owner_id: $account_owner_id, created_at: $created_at, address: $address, employees: $employees} + ) { + affected_rows + returning { + address + created_at + domain_name + employees + id + name + } + } +} + `; +export type InsertCompanyMutationFn = Apollo.MutationFunction; + +/** + * __useInsertCompanyMutation__ + * + * To run a mutation, you first call `useInsertCompanyMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useInsertCompanyMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [insertCompanyMutation, { data, loading, error }] = useInsertCompanyMutation({ + * variables: { + * id: // value for 'id' + * name: // value for 'name' + * domain_name: // value for 'domain_name' + * account_owner_id: // value for 'account_owner_id' + * created_at: // value for 'created_at' + * address: // value for 'address' + * employees: // value for 'employees' + * }, + * }); + */ +export function useInsertCompanyMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(InsertCompanyDocument, options); + } +export type InsertCompanyMutationHookResult = ReturnType; +export type InsertCompanyMutationResult = Apollo.MutationResult; +export type InsertCompanyMutationOptions = Apollo.BaseMutationOptions; +export const DeleteCompaniesDocument = gql` + mutation DeleteCompanies($ids: [uuid!]) { + delete_companies(where: {id: {_in: $ids}}) { + returning { + address + created_at + domain_name + employees + id + name + } + } +} + `; +export type DeleteCompaniesMutationFn = Apollo.MutationFunction; + +/** + * __useDeleteCompaniesMutation__ + * + * To run a mutation, you first call `useDeleteCompaniesMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useDeleteCompaniesMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [deleteCompaniesMutation, { data, loading, error }] = useDeleteCompaniesMutation({ + * variables: { + * ids: // value for 'ids' + * }, + * }); + */ +export function useDeleteCompaniesMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(DeleteCompaniesDocument, options); + } +export type DeleteCompaniesMutationHookResult = ReturnType; +export type DeleteCompaniesMutationResult = Apollo.MutationResult; +export type DeleteCompaniesMutationOptions = Apollo.BaseMutationOptions; export const GetPeopleDocument = gql` - query GetPeople($orderBy: [people_order_by!]) { - people(order_by: $orderBy) { + query GetPeople($orderBy: [people_order_by!], $where: people_bool_exp, $limit: Int) { + people(order_by: $orderBy, where: $where, limit: $limit) { id phone email @@ -5168,6 +5326,8 @@ export const GetPeopleDocument = gql` * const { data, loading, error } = useGetPeopleQuery({ * variables: { * orderBy: // value for 'orderBy' + * where: // value for 'where' + * limit: // value for 'limit' * }, * }); */ @@ -5183,10 +5343,10 @@ export type GetPeopleQueryHookResult = ReturnType; export type GetPeopleLazyQueryHookResult = ReturnType; export type GetPeopleQueryResult = Apollo.QueryResult; export const UpdatePeopleDocument = gql` - mutation UpdatePeople($id: uuid, $firstname: String, $lastname: String, $phone: String, $city: String, $company_id: uuid, $email: String) { + mutation UpdatePeople($id: uuid, $firstname: String, $lastname: String, $phone: String, $city: String, $company_id: uuid, $email: String, $created_at: timestamptz) { update_people( where: {id: {_eq: $id}} - _set: {city: $city, company_id: $company_id, email: $email, firstname: $firstname, id: $id, lastname: $lastname, phone: $phone} + _set: {city: $city, company_id: $company_id, email: $email, firstname: $firstname, id: $id, lastname: $lastname, phone: $phone, created_at: $created_at} ) { returning { city @@ -5200,6 +5360,7 @@ export const UpdatePeopleDocument = gql` id lastname phone + created_at } } } @@ -5226,6 +5387,7 @@ export type UpdatePeopleMutationFn = Apollo.MutationFunction; export type UpdatePeopleMutationResult = Apollo.MutationResult; -export type UpdatePeopleMutationOptions = Apollo.BaseMutationOptions; \ No newline at end of file +export type UpdatePeopleMutationOptions = Apollo.BaseMutationOptions; +export const InsertPersonDocument = gql` + mutation InsertPerson($id: uuid, $firstname: String, $lastname: String, $phone: String, $city: String, $company_id: uuid, $email: String, $created_at: timestamptz) { + insert_people( + objects: {id: $id, firstname: $firstname, lastname: $lastname, phone: $phone, city: $city, company_id: $company_id, email: $email, created_at: $created_at} + ) { + affected_rows + returning { + city + company { + domain_name + name + id + } + email + firstname + id + lastname + phone + created_at + } + } +} + `; +export type InsertPersonMutationFn = Apollo.MutationFunction; + +/** + * __useInsertPersonMutation__ + * + * To run a mutation, you first call `useInsertPersonMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useInsertPersonMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [insertPersonMutation, { data, loading, error }] = useInsertPersonMutation({ + * variables: { + * id: // value for 'id' + * firstname: // value for 'firstname' + * lastname: // value for 'lastname' + * phone: // value for 'phone' + * city: // value for 'city' + * company_id: // value for 'company_id' + * email: // value for 'email' + * created_at: // value for 'created_at' + * }, + * }); + */ +export function useInsertPersonMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(InsertPersonDocument, options); + } +export type InsertPersonMutationHookResult = ReturnType; +export type InsertPersonMutationResult = Apollo.MutationResult; +export type InsertPersonMutationOptions = Apollo.BaseMutationOptions; +export const DeletePeopleDocument = gql` + mutation DeletePeople($ids: [uuid!]) { + delete_people(where: {id: {_in: $ids}}) { + returning { + city + company { + domain_name + name + id + } + email + firstname + id + lastname + phone + created_at + } + } +} + `; +export type DeletePeopleMutationFn = Apollo.MutationFunction; + +/** + * __useDeletePeopleMutation__ + * + * To run a mutation, you first call `useDeletePeopleMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useDeletePeopleMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [deletePeopleMutation, { data, loading, error }] = useDeletePeopleMutation({ + * variables: { + * ids: // value for 'ids' + * }, + * }); + */ +export function useDeletePeopleMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(DeletePeopleDocument, options); + } +export type DeletePeopleMutationHookResult = ReturnType; +export type DeletePeopleMutationResult = Apollo.MutationResult; +export type DeletePeopleMutationOptions = Apollo.BaseMutationOptions; +export const GetCurrentUserDocument = gql` + query GetCurrentUser($uuid: uuid) { + users(where: {id: {_eq: $uuid}}) { + id + email + displayName + workspace_member { + workspace { + id + domain_name + display_name + logo + } + } + } +} + `; + +/** + * __useGetCurrentUserQuery__ + * + * To run a query within a React component, call `useGetCurrentUserQuery` and pass it any options that fit your needs. + * When your component renders, `useGetCurrentUserQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useGetCurrentUserQuery({ + * variables: { + * uuid: // value for 'uuid' + * }, + * }); + */ +export function useGetCurrentUserQuery(baseOptions?: Apollo.QueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(GetCurrentUserDocument, options); + } +export function useGetCurrentUserLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(GetCurrentUserDocument, options); + } +export type GetCurrentUserQueryHookResult = ReturnType; +export type GetCurrentUserLazyQueryHookResult = ReturnType; +export type GetCurrentUserQueryResult = Apollo.QueryResult; \ No newline at end of file diff --git a/front/src/interfaces/entities/__tests__/company.interface.test.ts b/front/src/interfaces/entities/__tests__/company.interface.test.ts index cabead90b..6f7a2d20c 100644 --- a/front/src/interfaces/entities/__tests__/company.interface.test.ts +++ b/front/src/interfaces/entities/__tests__/company.interface.test.ts @@ -15,7 +15,7 @@ describe('Company mappers', () => { name: 'ACME', domain_name: 'exmaple.com', created_at: now.toUTCString(), - employees: '10', + employees: 10, address: '1 Infinite Loop, 95014 Cupertino, California, USA', account_owner: { id: '7af20dea-0412-4c4c-8b13-d6f0e6e09e87', @@ -61,7 +61,7 @@ describe('Company mappers', () => { id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', name: 'ACME', domainName: 'example.com', - employees: '10', + employees: 10, address: '1 Infinite Loop, 95014 Cupertino, California, USA', pipes: [], accountOwner: { diff --git a/front/src/interfaces/entities/company.interface.ts b/front/src/interfaces/entities/company.interface.ts index 12d4d932c..5225601b4 100644 --- a/front/src/interfaces/entities/company.interface.ts +++ b/front/src/interfaces/entities/company.interface.ts @@ -7,7 +7,7 @@ export type Company = { id: string; name?: string; domainName?: string; - employees?: string; + employees?: number | null; address?: string; creationDate?: Date; @@ -20,7 +20,7 @@ export type GraphqlQueryCompany = { id: string; name?: string; domain_name?: string; - employees?: string; + employees?: number | null; address?: string; created_at?: string; @@ -34,7 +34,7 @@ export type GraphqlMutationCompany = { id: string; name?: string; domain_name?: string; - employees?: string; + employees?: number | null; address?: string; created_at?: string; diff --git a/front/src/pages/companies/Companies.tsx b/front/src/pages/companies/Companies.tsx index a568d8f6d..e4f4987b6 100644 --- a/front/src/pages/companies/Companies.tsx +++ b/front/src/pages/companies/Companies.tsx @@ -65,7 +65,7 @@ function Companies() { id: uuidv4(), name: '', domainName: '', - employees: '0', + employees: null, address: '', pipes: [], creationDate: new Date(), diff --git a/front/src/pages/companies/__tests__/__data__/mock-data.ts b/front/src/pages/companies/__tests__/__data__/mock-data.ts index 45c85391e..18e1b9447 100644 --- a/front/src/pages/companies/__tests__/__data__/mock-data.ts +++ b/front/src/pages/companies/__tests__/__data__/mock-data.ts @@ -7,7 +7,7 @@ export const mockCompaniesData: Array = [ name: 'Airbnb', created_at: '2023-04-26T10:08:54.724515+00:00', address: '17 rue de clignancourt', - employees: '12', + employees: 12, account_owner: null, __typename: 'companies', }, @@ -17,7 +17,7 @@ export const mockCompaniesData: Array = [ name: 'Aircall', created_at: '2023-04-26T10:12:42.33625+00:00', address: '', - employees: '1', + employees: 1, account_owner: null, __typename: 'companies', }, @@ -27,7 +27,7 @@ export const mockCompaniesData: Array = [ name: 'Algolia', created_at: '2023-04-26T10:10:32.530184+00:00', address: '', - employees: '1', + employees: 1, account_owner: null, __typename: 'companies', }, @@ -37,7 +37,7 @@ export const mockCompaniesData: Array = [ name: 'Apple', created_at: '2023-03-21T06:30:25.39474+00:00', address: '', - employees: '10', + employees: 10, account_owner: null, __typename: 'companies', }, @@ -47,7 +47,7 @@ export const mockCompaniesData: Array = [ name: 'BeReal', created_at: '2023-04-26T10:13:29.712485+00:00', address: '10 rue de la Paix', - employees: '1', + employees: 1, account_owner: null, __typename: 'companies', }, @@ -57,7 +57,7 @@ export const mockCompaniesData: Array = [ name: 'Claap', created_at: '2023-04-26T10:09:25.656555+00:00', address: '', - employees: '1', + employees: 1, account_owner: null, __typename: 'companies', }, diff --git a/front/src/pages/companies/companies-columns.tsx b/front/src/pages/companies/companies-columns.tsx index 5794d0ddb..93ff8fb5a 100644 --- a/front/src/pages/companies/companies-columns.tsx +++ b/front/src/pages/companies/companies-columns.tsx @@ -75,11 +75,17 @@ export const useCompaniesColumns = () => { ), cell: (props) => ( { const company = props.row.original; - company.employees = value; - updateCompany(company); + + if (value === '') { + company.employees = null; + updateCompany(company); + } else if (!Number.isNaN(Number(value))) { + company.employees = Number(value); + updateCompany(company); + } }} /> ), diff --git a/front/src/services/api/companies/update.ts b/front/src/services/api/companies/update.ts index c7a269814..49013ddfb 100644 --- a/front/src/services/api/companies/update.ts +++ b/front/src/services/api/companies/update.ts @@ -13,7 +13,7 @@ export const UPDATE_COMPANY = gql` $account_owner_id: uuid $created_at: timestamptz $address: String - $employees: Int + $employees: numeric ) { update_companies( where: { id: { _eq: $id } } @@ -52,7 +52,7 @@ export const INSERT_COMPANY = gql` $account_owner_id: uuid $created_at: timestamptz $address: String - $employees: Int + $employees: numeric ) { insert_companies( objects: { @@ -79,7 +79,7 @@ export const INSERT_COMPANY = gql` `; export const DELETE_COMPANIES = gql` - mutation DeleteCompanies($ids: [uuid]) { + mutation DeleteCompanies($ids: [uuid!]) { delete_companies(where: { id: { _in: $ids } }) { returning { address diff --git a/front/src/services/api/people/update.ts b/front/src/services/api/people/update.ts index 33c3d77cb..8f3935d05 100644 --- a/front/src/services/api/people/update.ts +++ b/front/src/services/api/people/update.ts @@ -90,7 +90,7 @@ export const INSERT_PERSON = gql` `; export const DELETE_PEOPLE = gql` - mutation DeletePeople($ids: [uuid]) { + mutation DeletePeople($ids: [uuid!]) { delete_people(where: { id: { _in: $ids } }) { returning { city diff --git a/front/src/services/api/search/search.ts b/front/src/services/api/search/search.ts index 43b4b188b..8d3d79d55 100644 --- a/front/src/services/api/search/search.ts +++ b/front/src/services/api/search/search.ts @@ -4,7 +4,7 @@ import { SearchConfigType } from '../../../interfaces/search/interface'; import { AnyEntity } from '../../../interfaces/entities/generic.interface'; export const SEARCH_PEOPLE_QUERY = gql` - query SearchQuery($where: people_bool_exp, $limit: Int) { + query SearchPeopleQuery($where: people_bool_exp, $limit: Int) { searchResults: people(where: $where, limit: $limit) { id phone @@ -18,7 +18,7 @@ export const SEARCH_PEOPLE_QUERY = gql` `; export const SEARCH_USER_QUERY = gql` - query SearchQuery($where: users_bool_exp, $limit: Int) { + query SearchUserQuery($where: users_bool_exp, $limit: Int) { searchResults: users(where: $where, limit: $limit) { id email @@ -26,10 +26,12 @@ export const SEARCH_USER_QUERY = gql` } } `; - +// TODO: remove this query export const EMPTY_QUERY = gql` query EmptyQuery { - _ + users { + id + } } `; diff --git a/hasura/migrations/default/1684486726911_alter_table_public_companies_alter_column_employees/down.sql b/hasura/migrations/default/1684486726911_alter_table_public_companies_alter_column_employees/down.sql new file mode 100644 index 000000000..0b719974b --- /dev/null +++ b/hasura/migrations/default/1684486726911_alter_table_public_companies_alter_column_employees/down.sql @@ -0,0 +1,2 @@ +alter table "public"."companies" alter column "employees" set not null; +alter table "public"."companies" alter column "employees" set default '1'; diff --git a/hasura/migrations/default/1684486726911_alter_table_public_companies_alter_column_employees/up.sql b/hasura/migrations/default/1684486726911_alter_table_public_companies_alter_column_employees/up.sql new file mode 100644 index 000000000..7fa9a2bcc --- /dev/null +++ b/hasura/migrations/default/1684486726911_alter_table_public_companies_alter_column_employees/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE "public"."companies" ALTER COLUMN "employees" drop default; +alter table "public"."companies" alter column "employees" drop not null; diff --git a/hasura/migrations/default/1684487555948_alter_table_public_companies_alter_column_employees/down.sql b/hasura/migrations/default/1684487555948_alter_table_public_companies_alter_column_employees/down.sql new file mode 100644 index 000000000..ac7b197cc --- /dev/null +++ b/hasura/migrations/default/1684487555948_alter_table_public_companies_alter_column_employees/down.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."companies" ALTER COLUMN "employees" TYPE integer; diff --git a/hasura/migrations/default/1684487555948_alter_table_public_companies_alter_column_employees/up.sql b/hasura/migrations/default/1684487555948_alter_table_public_companies_alter_column_employees/up.sql new file mode 100644 index 000000000..f75910cb1 --- /dev/null +++ b/hasura/migrations/default/1684487555948_alter_table_public_companies_alter_column_employees/up.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."companies" ALTER COLUMN "employees" TYPE numeric;