Skip to content
Snippets Groups Projects
Commit ec781942 authored by Nils Brinckmann's avatar Nils Brinckmann
Browse files

Adding & removing contacts for platforms

parent f0c47704
No related branches found
No related tags found
2 merge requests!90Draft: restructure frontend properties 2,!82Restructure frontend
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment