|
@@ -178,28 +178,24 @@ class EntityManager {
|
|
|
id: number,
|
|
id: number,
|
|
|
forceRefresh: boolean = false,
|
|
forceRefresh: boolean = false,
|
|
|
): Promise<ApiResource> {
|
|
): Promise<ApiResource> {
|
|
|
- try {
|
|
|
|
|
- // If the model instance is already in the store and forceRefresh is false, return the object in store
|
|
|
|
|
- if (!forceRefresh) {
|
|
|
|
|
- // TODO: est-ce qu'il y a vraiment des situations où on appellera cette méthode sans le forceRefresh?
|
|
|
|
|
- const item = this.find(model, id)
|
|
|
|
|
- if (item && typeof item !== 'undefined') {
|
|
|
|
|
- return item
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // If the model instance is already in the store and forceRefresh is false, return the object in store
|
|
|
|
|
+ if (!forceRefresh) {
|
|
|
|
|
+ // TODO: est-ce qu'il y a vraiment des situations où on appellera cette méthode sans le forceRefresh?
|
|
|
|
|
+ const item = this.find(model, id)
|
|
|
|
|
+ if (item && typeof item !== 'undefined') {
|
|
|
|
|
+ return item
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Else, get the object from the API
|
|
|
|
|
- const url = UrlUtils.join('api', model.entity, String(id))
|
|
|
|
|
- const response = await this.apiRequestService.get(url)
|
|
|
|
|
|
|
+ // Else, get the object from the API
|
|
|
|
|
+ const url = UrlUtils.join('api', model.entity, String(id))
|
|
|
|
|
+ const response = await this.apiRequestService.get(url)
|
|
|
|
|
|
|
|
- // deserialize the response
|
|
|
|
|
- const attributes = HydraNormalizer.denormalize(response, model)
|
|
|
|
|
- .data as object
|
|
|
|
|
|
|
+ // deserialize the response
|
|
|
|
|
+ const attributes = HydraNormalizer.denormalize(response, model)
|
|
|
|
|
+ .data as object
|
|
|
|
|
|
|
|
- return this.newInstance(model, attributes)
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- console.error(e)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return this.newInstance(model, attributes)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|