From 38132749c2a9ba190e14afd41d9caafce3b4789c Mon Sep 17 00:00:00 2001 From: Anders Borch Date: Mon, 24 Apr 2023 21:39:09 +0200 Subject: [PATCH] Add updatePerson function --- front/src/services/people/index.ts | 1 + front/src/services/people/update.ts | 50 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 front/src/services/people/update.ts diff --git a/front/src/services/people/index.ts b/front/src/services/people/index.ts index c7396734d3..18c6c2f7dd 100644 --- a/front/src/services/people/index.ts +++ b/front/src/services/people/index.ts @@ -1 +1,2 @@ export * from './select'; +export * from './update'; diff --git a/front/src/services/people/update.ts b/front/src/services/people/update.ts new file mode 100644 index 0000000000..81bfb95f99 --- /dev/null +++ b/front/src/services/people/update.ts @@ -0,0 +1,50 @@ +import { gql } from '@apollo/client'; +import { Person, mapGqlPerson } from '../../interfaces/person.interface'; +import { apiClient } from '../../apollo'; + +const UPDATE_PERSON = gql` + mutation UpdatePeople( + $id: Int + $firstname: String + $lastname: String + $phone: String + $city: String + $company_id: Int + $email: String + ) { + update_people( + where: { id: { _eq: $id } } + _set: { + city: $city + company_id: $company_id + email: $email + firstname: $firstname + id: $id + lastname: $lastname + phone: $phone + } + ) { + returning { + city + company { + company_domain + company_name + id + } + email + firstname + id + lastname + phone + } + } + } +`; + +export async function updatePerson(person: Person) { + const result = await apiClient.mutate({ + mutation: UPDATE_PERSON, + variables: mapGqlPerson(person), + }); + return result; +}