export default class CommonResourceService<T extends Resource> {
- serverApi: AxiosInstance;
- resourceType: string;
-
static mapResponseKeys = (response: any): Promise<any> =>
CommonResourceService.mapKeys(_.camelCase)(response.data)
}
}
+ protected serverApi: AxiosInstance;
+ protected resourceType: string;
+
constructor(serverApi: AxiosInstance, resourceType: string) {
this.serverApi = serverApi;
- this.resourceType = "/" + resourceType;
+ this.resourceType = '/' + resourceType + '/';
}
create() {
delete(uuid: string): Promise<T> {
return this.serverApi
- .delete(this.resourceType + "/" + uuid)
+ .delete(this.resourceType + uuid)
.then(CommonResourceService.mapResponseKeys);
}
get(uuid: string) {
return this.serverApi
- .get<T>(this.resourceType + "/" + uuid)
+ .get<T>(this.resourceType + uuid)
.then(CommonResourceService.mapResponseKeys);
}
order: order ? order.get() : undefined
};
return this.serverApi
- .get(this.resourceType + `/${uuid}/contents`, {
+ .get(this.resourceType + `${uuid}/contents/`, {
params: CommonResourceService.mapKeys(_.snakeCase)(params)
})
.then(CommonResourceService.mapResponseKeys);