|
@@ -121,10 +121,6 @@ class EntityManager {
|
|
|
|
|
|
|
|
const instance = repository.make(properties)
|
|
const instance = repository.make(properties)
|
|
|
|
|
|
|
|
- // Keep track of the model
|
|
|
|
|
- // TODO : attendre de voir si utile ou non
|
|
|
|
|
- // instance.setModel(model)
|
|
|
|
|
-
|
|
|
|
|
if (
|
|
if (
|
|
|
!Object.prototype.hasOwnProperty.call(properties, 'id') ||
|
|
!Object.prototype.hasOwnProperty.call(properties, 'id') ||
|
|
|
// @ts-expect-error Si la première condition passe, on sait que id existe
|
|
// @ts-expect-error Si la première condition passe, on sait que id existe
|
|
@@ -273,6 +269,8 @@ class EntityManager {
|
|
|
let url = UrlUtils.join('api', model.entity)
|
|
let url = UrlUtils.join('api', model.entity)
|
|
|
let response
|
|
let response
|
|
|
|
|
|
|
|
|
|
+ this.validateEntity(instance)
|
|
|
|
|
+
|
|
|
const data: AnyJson = HydraNormalizer.normalizeEntity(instance)
|
|
const data: AnyJson = HydraNormalizer.normalizeEntity(instance)
|
|
|
|
|
|
|
|
const headers = { profileHash: await this.makeProfileHash() }
|
|
const headers = { profileHash: await this.makeProfileHash() }
|
|
@@ -467,6 +465,29 @@ class EntityManager {
|
|
|
const mask = this._getProfileMask()
|
|
const mask = this._getProfileMask()
|
|
|
return await ObjectUtils.hash(mask)
|
|
return await ObjectUtils.hash(mask)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Validate the entity, and throw an error if it's not correctly defined.
|
|
|
|
|
+ * @param instance
|
|
|
|
|
+ * @protected
|
|
|
|
|
+ */
|
|
|
|
|
+ protected validateEntity(instance: unknown): void {
|
|
|
|
|
+ if (Object.prototype.hasOwnProperty.call(instance, 'id')) {
|
|
|
|
|
+ // @ts-expect-error At this point, we're sure there is an id property
|
|
|
|
|
+ const id = instance.id
|
|
|
|
|
+
|
|
|
|
|
+ if (
|
|
|
|
|
+ !(typeof id === 'number') &&
|
|
|
|
|
+ !(typeof id === 'string' && id.startsWith('tmp'))
|
|
|
|
|
+ ) {
|
|
|
|
|
+ // The id is a pinia orm Uid, the entity has been created using the `new` keyword (not supported for now)
|
|
|
|
|
+ throw new Error(
|
|
|
|
|
+ 'Definition error for the entity, did you use the entityManager.newInstance(...) method?\n' +
|
|
|
|
|
+ JSON.stringify(instance),
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default EntityManager
|
|
export default EntityManager
|