remove try catch

This commit is contained in:
AdisakKanthawilang 2024-02-28 10:36:44 +07:00
parent a7fb4e87b3
commit 439e1ffaa4
3 changed files with 67 additions and 110 deletions

View file

@ -50,17 +50,13 @@ export class EducationLevelController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
const educationLevel = Object.assign(new EducationLevel(), requestBody);
educationLevel.createdUserId = request.user.sub;
educationLevel.createdFullName = request.user.name;
educationLevel.lastUpdateUserId = request.user.sub;
educationLevel.lastUpdateFullName = request.user.name;
await this.educationLevelRepository.save(educationLevel);
return new HttpSuccess();
} catch (error) {
return error;
}
const educationLevel = Object.assign(new EducationLevel(), requestBody);
educationLevel.createdUserId = request.user.sub;
educationLevel.createdFullName = request.user.name;
educationLevel.lastUpdateUserId = request.user.sub;
educationLevel.lastUpdateFullName = request.user.name;
await this.educationLevelRepository.save(educationLevel);
return new HttpSuccess();
}
/**
@ -90,15 +86,11 @@ export class EducationLevelController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
educationLevel.lastUpdateUserId = request.user.sub;
educationLevel.lastUpdateFullName = request.user.name;
this.educationLevelRepository.merge(educationLevel, requestBody);
await this.educationLevelRepository.save(educationLevel);
return new HttpSuccess();
} catch (error) {
return error;
}
educationLevel.lastUpdateUserId = request.user.sub;
educationLevel.lastUpdateFullName = request.user.name;
this.educationLevelRepository.merge(educationLevel, requestBody);
await this.educationLevelRepository.save(educationLevel);
return new HttpSuccess();
}
/**
@ -116,12 +108,8 @@ export class EducationLevelController extends Controller {
if (!delEducationLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
}
try {
await this.educationLevelRepository.delete({ id: id });
return new HttpSuccess();
} catch (error) {
return error;
}
await this.educationLevelRepository.delete({ id: id });
return new HttpSuccess();
}
/**
@ -135,16 +123,20 @@ export class EducationLevelController extends Controller {
async detailEducationLevel(@Path() id: string) {
const educationLevel = await this.educationLevelRepository.findOne({
where: { id },
select: ["id", "name", "rank", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
select: [
"id",
"name",
"rank",
"createdAt",
"lastUpdatedAt",
"createdFullName",
"lastUpdateFullName",
],
});
if (!educationLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
try {
return new HttpSuccess(educationLevel);
} catch (error) {
return error;
}
return new HttpSuccess(educationLevel);
}
/**
@ -156,17 +148,21 @@ export class EducationLevelController extends Controller {
@Get()
async listEducationLevel() {
const educationLevel = await this.educationLevelRepository.find({
select: ["id", "name","rank", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
select: [
"id",
"name",
"rank",
"createdAt",
"lastUpdatedAt",
"createdFullName",
"lastUpdateFullName",
],
order: { createdAt: "ASC" },
});
if (!educationLevel) {
return new HttpSuccess([]);
}
try {
return new HttpSuccess(educationLevel);
} catch (error) {
return error;
}
return new HttpSuccess(educationLevel);
}
}