♻️ back: repository remove returns success now and file path alternative

This commit is contained in:
Eric Doughty-Papassideris
2025-02-28 00:54:35 +01:00
committed by Anton Shepilov
parent 8efcb2546c
commit c4d45412fd
4 changed files with 9 additions and 7 deletions
@@ -291,7 +291,7 @@ export class MongoConnector extends AbstractConnector<MongoConnectionOptions> {
});
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;
}
public async remove(entity: EntityType, entityType?: EntityType): Promise<this> {
public async remove(entity: EntityType, entityType?: EntityType): Promise<boolean> {
if (entityType) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
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.");
}
await this.connector.remove([entity]);
const result = await this.connector.remove([entity]);
localEventBus.publish("database:entities:removed", {
entities: [entity],
} as DatabaseEntitiesRemovedEvent);
return this;
return result[0];
}
}
@@ -149,8 +149,8 @@ export default class Repository<EntityType> {
await Promise.all(entities.map(entity => this.manager.persist(entity)));
}
async remove(entity: EntityType, _context?: ExecutionContext): Promise<void> {
await this.manager.remove(entity);
async remove(entity: EntityType, _context?: ExecutionContext): Promise<boolean> {
return this.manager.remove(entity);
}
//Avoid using this except when no choice
@@ -478,7 +478,9 @@ export class FileServiceImpl {
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}/${
entity.user_id || "anonymous"
}/${entity.id}`;