|
|
@@ -9,7 +9,7 @@ import {v4 as uuid4} from 'uuid'
|
|
|
import {AssociativeArray, Collection} from "~/types/data.d"
|
|
|
import models from "~/models/models";
|
|
|
import {useAccessProfileStore} from "~/stores/accessProfile"
|
|
|
-import _ from "lodash"
|
|
|
+import * as _ from "lodash-es"
|
|
|
|
|
|
/**
|
|
|
* Entity manager: make operations on the models defined with the Pinia-Orm library
|
|
|
@@ -118,10 +118,21 @@ class EntityManager {
|
|
|
*/
|
|
|
public save(model: typeof ApiResource, instance: ApiResource, permanent: boolean = false): ApiResource {
|
|
|
instance = this.cast(model, instance)
|
|
|
+ if (model === MyProfile) {
|
|
|
+ console.log(instance)
|
|
|
+ }
|
|
|
if (permanent) {
|
|
|
this.saveInitialState(model, instance)
|
|
|
}
|
|
|
- return this.getRepository(model).save(instance)
|
|
|
+
|
|
|
+ const repository = this.getRepository(model)
|
|
|
+ repository.save(instance)
|
|
|
+
|
|
|
+ instance = repository.find(instance.id) as ApiResource
|
|
|
+ if (model === MyProfile) {
|
|
|
+ console.log(instance)
|
|
|
+ }
|
|
|
+ return instance
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -161,6 +172,7 @@ class EntityManager {
|
|
|
|
|
|
// deserialize the response
|
|
|
const attributes = HydraDenormalizer.denormalize(response).data as object
|
|
|
+
|
|
|
return this.newInstance(model, attributes)
|
|
|
}
|
|
|
|
|
|
@@ -300,12 +312,21 @@ class EntityManager {
|
|
|
*
|
|
|
* Re-fetch the user profile and update the store
|
|
|
*/
|
|
|
- public async refreshProfile(accessId: number) {
|
|
|
- const profile = await this.fetch(MyProfile, accessId)
|
|
|
+ public async refreshProfile(accessId: number | null = null) {
|
|
|
+ const accessProfileStore = useAccessProfileStore()
|
|
|
+
|
|
|
+ if (accessId === null) {
|
|
|
+ accessId = accessProfileStore.currentAccessId
|
|
|
+ }
|
|
|
+
|
|
|
+ // Sans le flush, on observe un bug non-expliqué au rechargement de la page en mode dev : la fonction save
|
|
|
+ // du repo de MyProfile ne fonctionne pas quand le plugin init.server.ts re-fetch le profil
|
|
|
+ this.flush(MyProfile)
|
|
|
+
|
|
|
+ const profile = await this.fetch(MyProfile, accessId, true)
|
|
|
|
|
|
// On met à jour le store accessProfile
|
|
|
- const accessProfile = useAccessProfileStore()
|
|
|
- accessProfile.setProfile(profile)
|
|
|
+ accessProfileStore.setProfile(profile)
|
|
|
}
|
|
|
|
|
|
/**
|