Skip to content
Snippets Groups Projects
Verified Commit 70ef0f0f authored by Kotyba Alhaj Taha's avatar Kotyba Alhaj Taha
Browse files

Platform make include related object optional

parent 141d7ab2
No related branches found
No related tags found
2 merge requests!92Feature restructure frontend platforms,!82Restructure frontend
......@@ -64,7 +64,10 @@ export default class PlatformPage extends Vue {
mounted () {
this.initializeAppBar()
this.$api.platforms.findById(this.platformId).then((platform) => {
this.$api.platforms.findById(this.platformId,{
includeContacts: false,
includePlatformAttachments: false
}).then((platform) => {
this.platform = platform
this.isLoading = false
}).catch((_error) => {
......
......@@ -207,3 +207,7 @@ export const platformWithMetaToPlatformByAddingDummyObjects = (platformWithMeta:
return platform
}
export const platformWithMetaToDeviceThrowingNoErrorOnMissing = (platformWithMeta: { missing: { contacts: { ids: any[] } }; platform: Platform }): Platform => {
const platform = platformWithMeta.platform
return platform
}
......@@ -42,7 +42,7 @@ import { ContactSerializer } from '@/serializers/jsonapi/ContactSerializer'
import {
PlatformSerializer,
platformWithMetaToPlatformByThrowingErrorOnMissing,
platformWithMetaToDeviceThrowingNoErrorOnMissing,
platformWithMetaToPlatformByAddingDummyObjects
} from '@/serializers/jsonapi/PlatformSerializer'
import { PlatformAttachmentSerializer } from '@/serializers/jsonapi/PlatformAttachmentSerializer'
......@@ -53,6 +53,11 @@ import {
IPaginationLoader, FilteredPaginationedLoader
} from '@/utils/PaginatedLoader'
interface IncludedRelationships {
includeContacts?: boolean
includePlatformAttachments?: boolean
}
export class PlatformApi {
private axiosApi: AxiosInstance
private serializer: PlatformSerializer
......@@ -62,16 +67,25 @@ export class PlatformApi {
this.serializer = new PlatformSerializer()
}
findById (id: string): Promise<Platform> {
findById (id: string, includes: IncludedRelationships): Promise<Platform> {
const listIncludedRelationships: string[] = []
if (includes.includeContacts) {
listIncludedRelationships.push('contacts')
}
if (includes.includePlatformAttachments) {
listIncludedRelationships.push('platform_attachments')
}
const include = listIncludedRelationships.join(',')
return this.axiosApi.get(id, {
params: {
include: 'contacts,platform_attachments'
include
}
}).then((rawResponse) => {
const rawData = rawResponse.data
// As we ask the api to include all the contacts, we want to have them here
// if they are missing => throw an error
return platformWithMetaToPlatformByThrowingErrorOnMissing(this.serializer.convertJsonApiObjectToModel(rawData))
return platformWithMetaToDeviceThrowingNoErrorOnMissing(this.serializer.convertJsonApiObjectToModel(rawData))
})
}
......@@ -100,7 +114,7 @@ export class PlatformApi {
data
}
}).then((serverAnswer) => {
return this.findById(serverAnswer.data.data.id)
return this.findById(serverAnswer.data.data.id, {})
})
}
......
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