tell if files were replaced or not
This commit is contained in:
parent
4e55bf79f3
commit
cec7a03362
@ -10,7 +10,8 @@ export abstract class EntitiesMapService<E extends Entity<I>, I> {
|
||||
private readonly _entityChanged$ = new Subject<E>();
|
||||
private readonly _entityDeleted$ = new Subject<E>();
|
||||
|
||||
protected constructor(@Inject('ENTITY_PRIMARY_KEY') protected readonly _primaryKey: string) {}
|
||||
protected constructor(@Inject('ENTITY_PRIMARY_KEY') protected readonly _primaryKey: string) {
|
||||
}
|
||||
|
||||
get empty(): boolean {
|
||||
return this._map.size === 0;
|
||||
@ -73,6 +74,7 @@ export abstract class EntitiesMapService<E extends Entity<I>, I> {
|
||||
}
|
||||
|
||||
replace(entities: E[]) {
|
||||
/** Return true if files were replaced or false if not **/
|
||||
const key = this._pluckPrimaryKey(entities[0]);
|
||||
const entityIds = entities.map(entity => entity.id);
|
||||
const existingEntities = this.get(key).filter(entity => entityIds.includes(entity.id));
|
||||
@ -80,10 +82,14 @@ export abstract class EntitiesMapService<E extends Entity<I>, I> {
|
||||
const old = existingEntities.find(e => e.id === entity.id);
|
||||
return !old || !entity.isEqual(old);
|
||||
});
|
||||
|
||||
if (newEntities.length) {
|
||||
const all = this.get(key).filter(e => !newEntities.map(entity => entity.id).includes(e.id));
|
||||
this.set(key, [...all, ...newEntities]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Validate()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user