Commit 274a3303 authored by nanahira's avatar nanahira

cond

parent fb3c9352
Pipeline #7299 passed with stages
in 1 minute and 26 seconds
......@@ -2,6 +2,7 @@ import { ConsoleLogger } from '@nestjs/common';
import { ClassConstructor } from 'class-transformer';
import {
DeleteResult,
FindConditions,
IsNull,
Not,
Repository,
......@@ -149,10 +150,20 @@ export class CrudBase<
}
}
async update(id: EntityId<T>, entPart: Partial<T>) {
async update(
id: EntityId<T>,
entPart: Partial<T>,
cond: FindConditions<T> = {},
) {
let result: UpdateResult;
try {
result = await this.repo.update(id, entPart);
result = await this.repo.update(
{
id,
...cond,
},
entPart,
);
} catch (e) {
this.error(
`Failed to update entity ID ${id} to ${JSON.stringify(
......@@ -167,12 +178,20 @@ export class CrudBase<
return new BlankReturnMessageDto(200, 'success');
}
async remove(id: EntityId<T>, hardDelete = false) {
async remove(
id: EntityId<T>,
hardDelete = false,
cond: FindConditions<T> = {},
) {
let result: UpdateResult | DeleteResult;
const searchCond = {
id,
...cond,
};
try {
result = await (hardDelete
? this.repo.delete(id)
: this.repo.softDelete(id));
? this.repo.delete(searchCond)
: this.repo.softDelete(searchCond));
} catch (e) {
this.error(`Failed to delete entity ID ${id}: ${e.toString()}`);
throw new BlankReturnMessageDto(500, 'internal error').toException();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment