mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
fix the favorites api (#2129)
- fix the crash related to remapping entities
This commit is contained in:
parent
c4454e3392
commit
b1e627eedc
@ -23,17 +23,18 @@ import { UserPreferencesService } from './user-preferences.service';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FavoritesApiService {
|
export class FavoritesApiService {
|
||||||
private remapFavoritesData(data: any = {}): NodePaging {
|
static remapFavoritesData(data: any = {}): NodePaging {
|
||||||
const list = (data.list || {});
|
const list = (data.list || {});
|
||||||
const pagination = (list.pagination || {});
|
const pagination = (list.pagination || {});
|
||||||
const entries: any[] = this.remapFavoriteEntries(list.entries || []);
|
const entries: any[] = FavoritesApiService
|
||||||
|
.remapFavoriteEntries(list.entries || []);
|
||||||
|
|
||||||
return <NodePaging> {
|
return <NodePaging> {
|
||||||
list: { entries, pagination }
|
list: { entries, pagination }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private remapEntry({ entry }: any): any {
|
static remapEntry({ entry }: any): any {
|
||||||
entry.createdAt = new Date(entry.createdAt);
|
entry.createdAt = new Date(entry.createdAt);
|
||||||
entry.modifiedAt = new Date(entry.modifiedAt);
|
entry.modifiedAt = new Date(entry.modifiedAt);
|
||||||
|
|
||||||
@ -45,13 +46,13 @@ export class FavoritesApiService {
|
|||||||
return { entry };
|
return { entry };
|
||||||
}
|
}
|
||||||
|
|
||||||
private remapFavoriteEntries(entries: any[]) {
|
static remapFavoriteEntries(entries: any[]) {
|
||||||
return entries
|
return entries
|
||||||
.map(({ entry: { target }}: any) => ({
|
.map(({ entry: { target }}: any) => ({
|
||||||
entry: target.file || target.folder
|
entry: target.file || target.folder
|
||||||
}))
|
}))
|
||||||
.filter(({ entry }) => (!!entry))
|
.filter(({ entry }) => (!!entry))
|
||||||
.map(this.remapEntry);
|
.map(FavoritesApiService.remapEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -74,7 +75,7 @@ export class FavoritesApiService {
|
|||||||
const queryOptions = Object.assign(defaultOptions, options);
|
const queryOptions = Object.assign(defaultOptions, options);
|
||||||
const promise = favoritesApi
|
const promise = favoritesApi
|
||||||
.getFavorites(personId, queryOptions)
|
.getFavorites(personId, queryOptions)
|
||||||
.then(this.remapFavoritesData);
|
.then(FavoritesApiService.remapFavoritesData);
|
||||||
|
|
||||||
return Observable
|
return Observable
|
||||||
.fromPromise(promise)
|
.fromPromise(promise)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user