♻️ back: repository remove returns success now and file path alternative
This commit is contained in:
committed by
Anton Shepilov
parent
8efcb2546c
commit
c4d45412fd
+1
-1
@@ -291,7 +291,7 @@ export class MongoConnector extends AbstractConnector<MongoConnectionOptions> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Promise.all(promises).then(results => {
|
Promise.all(promises).then(results => {
|
||||||
resolve(results.map(result => result.acknowledged));
|
resolve(results.map(result => result.acknowledged && result.deletedCount == 1));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export default class EntityManager<EntityType extends Record<string, any>> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async remove(entity: EntityType, entityType?: EntityType): Promise<this> {
|
public async remove(entity: EntityType, entityType?: EntityType): Promise<boolean> {
|
||||||
if (entityType) {
|
if (entityType) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
entity = _.merge(new (entityType as any)(), entity);
|
entity = _.merge(new (entityType as any)(), entity);
|
||||||
@@ -79,12 +79,12 @@ export default class EntityManager<EntityType extends Record<string, any>> {
|
|||||||
throw Error("Cannot remove this object: it is not an entity.");
|
throw Error("Cannot remove this object: it is not an entity.");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.connector.remove([entity]);
|
const result = await this.connector.remove([entity]);
|
||||||
|
|
||||||
localEventBus.publish("database:entities:removed", {
|
localEventBus.publish("database:entities:removed", {
|
||||||
entities: [entity],
|
entities: [entity],
|
||||||
} as DatabaseEntitiesRemovedEvent);
|
} as DatabaseEntitiesRemovedEvent);
|
||||||
|
|
||||||
return this;
|
return result[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -149,8 +149,8 @@ export default class Repository<EntityType> {
|
|||||||
await Promise.all(entities.map(entity => this.manager.persist(entity)));
|
await Promise.all(entities.map(entity => this.manager.persist(entity)));
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(entity: EntityType, _context?: ExecutionContext): Promise<void> {
|
async remove(entity: EntityType, _context?: ExecutionContext): Promise<boolean> {
|
||||||
await this.manager.remove(entity);
|
return this.manager.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Avoid using this except when no choice
|
//Avoid using this except when no choice
|
||||||
|
|||||||
@@ -478,7 +478,9 @@ export class FileServiceImpl {
|
|||||||
return this.algorithm;
|
return this.algorithm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const getFilePath = (entity: File): string => {
|
export const getFilePath = (
|
||||||
|
entity: File | { company_id: string; user_id?: string; id: string },
|
||||||
|
): string => {
|
||||||
return `${gr.platformServices.storage.getHomeDir()}/files/${entity.company_id}/${
|
return `${gr.platformServices.storage.getHomeDir()}/files/${entity.company_id}/${
|
||||||
entity.user_id || "anonymous"
|
entity.user_id || "anonymous"
|
||||||
}/${entity.id}`;
|
}/${entity.id}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user