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 BloodGroupController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
bloodGroup.createdUserId = request.user.sub;
bloodGroup.createdFullName = request.user.name;
bloodGroup.lastUpdateUserId = request.user.sub;
bloodGroup.lastUpdateFullName = request.user.name;
await this.bloodGroupRepository.save(bloodGroup);
return new HttpSuccess();
} catch (error) {
return error;
}
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
bloodGroup.createdUserId = request.user.sub;
bloodGroup.createdFullName = request.user.name;
bloodGroup.lastUpdateUserId = request.user.sub;
bloodGroup.lastUpdateFullName = request.user.name;
await this.bloodGroupRepository.save(bloodGroup);
return new HttpSuccess();
}
/**
@ -90,15 +86,11 @@ export class BloodGroupController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
bloodGroup.lastUpdateUserId = request.user.sub;
bloodGroup.lastUpdateFullName = request.user.name;
this.bloodGroupRepository.merge(bloodGroup, requestBody);
await this.bloodGroupRepository.save(bloodGroup);
return new HttpSuccess();
} catch (error) {
return error;
}
bloodGroup.lastUpdateUserId = request.user.sub;
bloodGroup.lastUpdateFullName = request.user.name;
this.bloodGroupRepository.merge(bloodGroup, requestBody);
await this.bloodGroupRepository.save(bloodGroup);
return new HttpSuccess();
}
/**
@ -116,12 +108,9 @@ export class BloodGroupController extends Controller {
if (!delBloodGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
}
try {
await this.bloodGroupRepository.delete({ id: id });
return new HttpSuccess();
} catch (error) {
return error;
}
await this.bloodGroupRepository.delete({ id: id });
return new HttpSuccess();
}
/**
@ -140,11 +129,7 @@ export class BloodGroupController extends Controller {
if (!bloodGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
try {
return new HttpSuccess(bloodGroup);
} catch (error) {
return error;
}
return new HttpSuccess(bloodGroup);
}
/**
@ -163,10 +148,6 @@ export class BloodGroupController extends Controller {
if (!bloodGroup) {
return new HttpSuccess([]);
}
try {
return new HttpSuccess(bloodGroup);
} catch (error) {
return error;
}
return new HttpSuccess(bloodGroup);
}
}

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);
}
}

View file

@ -47,12 +47,7 @@ export class GenderController extends Controller {
if (!_gender) {
return new HttpSuccess([]);
}
try {
return new HttpSuccess(_gender);
} catch (error) {
console.log(error);
return error;
}
return new HttpSuccess(_gender);
}
/**
@ -71,11 +66,8 @@ export class GenderController extends Controller {
if (!_gender) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
try {
return new HttpSuccess(_gender);
} catch (error) {
return error;
}
return new HttpSuccess(_gender);
}
/**
@ -103,16 +95,12 @@ export class GenderController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
_gender.createdUserId = request.user.sub;
_gender.createdFullName = request.user.name;
_gender.lastUpdateUserId = request.user.sub;
_gender.lastUpdateFullName = request.user.name;
await this.genderRepository.save(_gender);
return new HttpSuccess();
} catch (error) {
return error;
}
_gender.createdUserId = request.user.sub;
_gender.createdFullName = request.user.name;
_gender.lastUpdateUserId = request.user.sub;
_gender.lastUpdateFullName = request.user.name;
await this.genderRepository.save(_gender);
return new HttpSuccess();
}
/**
@ -140,15 +128,11 @@ export class GenderController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
_gender.lastUpdateUserId = request.user.sub;
_gender.lastUpdateFullName = request.user.name;
this.genderRepository.merge(_gender, requestBody);
await this.genderRepository.save(_gender);
return new HttpSuccess();
} catch (error) {
return error;
}
_gender.lastUpdateUserId = request.user.sub;
_gender.lastUpdateFullName = request.user.name;
this.genderRepository.merge(_gender, requestBody);
await this.genderRepository.save(_gender);
return new HttpSuccess();
}
/**
@ -166,11 +150,7 @@ export class GenderController extends Controller {
if (!_delGender) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + id);
}
try {
await this.genderRepository.delete(_delGender.id);
return new HttpSuccess();
} catch (error) {
return error;
}
await this.genderRepository.delete(_delGender.id);
return new HttpSuccess();
}
}