Skip to content

Commit f0fbd68

Browse files
authored
fix(base-service): filter out deleted items on delete (#433)
1 parent 5adc0df commit f0fbd68

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/core/BaseService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export class BaseService<E extends BaseModel> {
428428
return manager.findOneOrFail(this.entityClass, result.id);
429429
}
430430

431-
async delete<W extends any>(
431+
async delete<W extends object>(
432432
where: W,
433433
userId: string,
434434
options?: BaseOptions
@@ -440,7 +440,12 @@ export class BaseService<E extends BaseModel> {
440440
deletedById: userId
441441
};
442442

443-
const found = await manager.findOneOrFail<E>(this.entityClass, where as any);
443+
const whereNotDeleted = {
444+
...where,
445+
deletedAt: null
446+
};
447+
448+
const found = await manager.findOneOrFail<E>(this.entityClass, whereNotDeleted as any);
444449
const idData = ({ id: found.id } as any) as DeepPartial<E>;
445450
const entity = manager.merge<E>(this.entityClass, new this.entityClass(), data as any, idData);
446451

0 commit comments

Comments
 (0)