|
|
@@ -8,6 +8,7 @@ import ApiResource from '~/models/ApiResource'
|
|
|
import type { AnyJson, AssociativeArray, Collection } from '~/types/data.d'
|
|
|
import models from '~/models/models'
|
|
|
import HydraNormalizer from '~/services/data/normalizer/hydraNormalizer'
|
|
|
+import ObjectUtils from '~/services/utils/objectUtils'
|
|
|
|
|
|
/**
|
|
|
* Entity manager: make operations on the models defined with the Pinia-Orm library
|
|
|
@@ -30,12 +31,16 @@ class EntityManager {
|
|
|
*/
|
|
|
protected _getRepo: (model: typeof ApiResource) => Repository<ApiResource>
|
|
|
|
|
|
+ protected _getProfileMask: () => object
|
|
|
+
|
|
|
public constructor(
|
|
|
apiRequestService: ApiRequestService,
|
|
|
getRepo: (model: typeof ApiResource) => Repository<ApiResource>,
|
|
|
+ getProfileMask: () => object,
|
|
|
) {
|
|
|
this.apiRequestService = apiRequestService
|
|
|
this._getRepo = getRepo
|
|
|
+ this._getProfileMask = getProfileMask
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -241,12 +246,14 @@ class EntityManager {
|
|
|
|
|
|
const data: AnyJson = HydraNormalizer.normalizeEntity(instance)
|
|
|
|
|
|
+ const headers = { profileHash: await this.makeProfileHash() }
|
|
|
+
|
|
|
if (!instance.isNew()) {
|
|
|
url = UrlUtils.join(url, String(instance.id))
|
|
|
- response = await this.apiRequestService.put(url, data)
|
|
|
+ response = await this.apiRequestService.put(url, data, null, headers)
|
|
|
} else {
|
|
|
delete data.id
|
|
|
- response = await this.apiRequestService.post(url, data)
|
|
|
+ response = await this.apiRequestService.post(url, data, null, headers)
|
|
|
}
|
|
|
|
|
|
const hydraResponse = HydraNormalizer.denormalize(response, model)
|
|
|
@@ -426,6 +433,11 @@ class EntityManager {
|
|
|
repository.destroy(tempInstanceId)
|
|
|
repository.destroy(this.CLONE_PREFIX + tempInstanceId)
|
|
|
}
|
|
|
+
|
|
|
+ protected async makeProfileHash(): Promise<string> {
|
|
|
+ const mask = this._getProfileMask()
|
|
|
+ return await ObjectUtils.hash(mask)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export default EntityManager
|