From ec781942e4ed00e6bd5fab4508ed8939096ec3b3 Mon Sep 17 00:00:00 2001 From: Nils Brinckmann <nils.brinckmann@gfz-potsdam.de> Date: Thu, 11 Mar 2021 12:56:39 +0100 Subject: [PATCH] Adding & removing contacts for platforms --- services/sms/PlatformApi.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/services/sms/PlatformApi.ts b/services/sms/PlatformApi.ts index 772404765..df258d048 100644 --- a/services/sms/PlatformApi.ts +++ b/services/sms/PlatformApi.ts @@ -32,11 +32,14 @@ import { AxiosInstance, Method } from 'axios' import { Attachment } from '@/models/Attachment' +import { Contact } from '@/models/Contact' import { Platform } from '@/models/Platform' import { PlatformType } from '@/models/PlatformType' import { Manufacturer } from '@/models/Manufacturer' import { Status } from '@/models/Status' +import { ContactSerializer } from '@/serializers/jsonapi/ContactSerializer' + import { PlatformSerializer, platformWithMetaToPlatformByThrowingErrorOnMissing, @@ -105,6 +108,16 @@ export class PlatformApi { return new PlatformSearchBuilder(this.axiosApi, this.serializer) } + findRelatedContacts (platformId: string): Promise<Contact[]> { + const url = platformId + '/contacts' + const params = { + 'page[size]': 10000 + } + return this.axiosApi.get(url, { params }).then((rawServerResponse) => { + return new ContactSerializer().convertJsonApiObjectListToModelList(rawServerResponse.data) + }) + } + findRelatedDeviceAttachments (deviceId: string): Promise<Attachment[]> { const url = deviceId + '/device-attachments' const params = { @@ -114,6 +127,26 @@ export class PlatformApi { return new PlatformAttachmentSerializer().convertJsonApiObjectListToModelList(rawServerResponse.data) }) } + + removeContact (platformId: string, contactId: string): Promise<void> { + const url = platformId + '/relationships/contacts' + const params = { + data: [{ + type: 'contact', + id: contactId + }] + } + return this.axiosApi.delete(url, { data: params }) + } + + addContact (platformId: string, contactId: string): Promise<void> { + const url = platformId + '/relationships/contacts' + const data = [{ + type: 'contact', + id: contactId + }] + return this.axiosApi.post(url, { data }) + } } export class PlatformSearchBuilder { -- GitLab