Commit 6bae51cd authored by nanahira's avatar nanahira

fix

parent b575540d
Pipeline #7077 passed with stages
in 57 seconds
import { ConsoleLogger } from '@nestjs/common';
import { ClassConstructor } from 'class-transformer';
import { Repository, SelectQueryBuilder } from 'typeorm';
import { Repository, SelectQueryBuilder, UpdateResult } from 'typeorm';
import {
BlankReturnMessageDto,
ReturnMessageDto,
......@@ -141,15 +141,9 @@ export class CrudBase<
}
async update(id: EntityId<T>, entPart: Partial<T>) {
let result: UpdateResult;
try {
const result = await this.repo.update({ id, isDeleted: false }, entPart);
if (!result.affected) {
throw new BlankReturnMessageDto(
404,
`ID ${id} not found.`,
).toException();
}
return new BlankReturnMessageDto(200, 'success');
result = await this.repo.update({ id, isDeleted: false }, entPart);
} catch (e) {
this.error(
`Failed to create entity ID ${id} to ${JSON.stringify(
......@@ -158,6 +152,10 @@ export class CrudBase<
);
throw new BlankReturnMessageDto(500, 'internal error').toException();
}
if (!result.affected) {
throw new BlankReturnMessageDto(404, `ID ${id} not found.`).toException();
}
return new BlankReturnMessageDto(200, 'success');
}
async remove(id: EntityId<T>) {
......
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