remove try catch
This commit is contained in:
parent
a7fb4e87b3
commit
439e1ffaa4
3 changed files with 67 additions and 110 deletions
|
|
@ -50,17 +50,13 @@ export class BloodGroupController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
|
||||||
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
|
bloodGroup.createdUserId = request.user.sub;
|
||||||
bloodGroup.createdUserId = request.user.sub;
|
bloodGroup.createdFullName = request.user.name;
|
||||||
bloodGroup.createdFullName = request.user.name;
|
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||||
bloodGroup.lastUpdateUserId = request.user.sub;
|
bloodGroup.lastUpdateFullName = request.user.name;
|
||||||
bloodGroup.lastUpdateFullName = request.user.name;
|
await this.bloodGroupRepository.save(bloodGroup);
|
||||||
await this.bloodGroupRepository.save(bloodGroup);
|
return new HttpSuccess();
|
||||||
return new HttpSuccess();
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -90,15 +86,11 @@ export class BloodGroupController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||||
bloodGroup.lastUpdateUserId = request.user.sub;
|
bloodGroup.lastUpdateFullName = request.user.name;
|
||||||
bloodGroup.lastUpdateFullName = request.user.name;
|
this.bloodGroupRepository.merge(bloodGroup, requestBody);
|
||||||
this.bloodGroupRepository.merge(bloodGroup, requestBody);
|
await this.bloodGroupRepository.save(bloodGroup);
|
||||||
await this.bloodGroupRepository.save(bloodGroup);
|
return new HttpSuccess();
|
||||||
return new HttpSuccess();
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -116,12 +108,9 @@ export class BloodGroupController extends Controller {
|
||||||
if (!delBloodGroup) {
|
if (!delBloodGroup) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
await this.bloodGroupRepository.delete({ id: id });
|
await this.bloodGroupRepository.delete({ id: id });
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -140,11 +129,7 @@ export class BloodGroupController extends Controller {
|
||||||
if (!bloodGroup) {
|
if (!bloodGroup) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
}
|
||||||
try {
|
return new HttpSuccess(bloodGroup);
|
||||||
return new HttpSuccess(bloodGroup);
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -163,10 +148,6 @@ export class BloodGroupController extends Controller {
|
||||||
if (!bloodGroup) {
|
if (!bloodGroup) {
|
||||||
return new HttpSuccess([]);
|
return new HttpSuccess([]);
|
||||||
}
|
}
|
||||||
try {
|
return new HttpSuccess(bloodGroup);
|
||||||
return new HttpSuccess(bloodGroup);
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,17 +50,13 @@ export class EducationLevelController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const educationLevel = Object.assign(new EducationLevel(), requestBody);
|
||||||
const educationLevel = Object.assign(new EducationLevel(), requestBody);
|
educationLevel.createdUserId = request.user.sub;
|
||||||
educationLevel.createdUserId = request.user.sub;
|
educationLevel.createdFullName = request.user.name;
|
||||||
educationLevel.createdFullName = request.user.name;
|
educationLevel.lastUpdateUserId = request.user.sub;
|
||||||
educationLevel.lastUpdateUserId = request.user.sub;
|
educationLevel.lastUpdateFullName = request.user.name;
|
||||||
educationLevel.lastUpdateFullName = request.user.name;
|
await this.educationLevelRepository.save(educationLevel);
|
||||||
await this.educationLevelRepository.save(educationLevel);
|
return new HttpSuccess();
|
||||||
return new HttpSuccess();
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -90,15 +86,11 @@ export class EducationLevelController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
educationLevel.lastUpdateUserId = request.user.sub;
|
||||||
educationLevel.lastUpdateUserId = request.user.sub;
|
educationLevel.lastUpdateFullName = request.user.name;
|
||||||
educationLevel.lastUpdateFullName = request.user.name;
|
this.educationLevelRepository.merge(educationLevel, requestBody);
|
||||||
this.educationLevelRepository.merge(educationLevel, requestBody);
|
await this.educationLevelRepository.save(educationLevel);
|
||||||
await this.educationLevelRepository.save(educationLevel);
|
return new HttpSuccess();
|
||||||
return new HttpSuccess();
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -116,12 +108,8 @@ export class EducationLevelController extends Controller {
|
||||||
if (!delEducationLevel) {
|
if (!delEducationLevel) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||||
}
|
}
|
||||||
try {
|
await this.educationLevelRepository.delete({ id: id });
|
||||||
await this.educationLevelRepository.delete({ id: id });
|
return new HttpSuccess();
|
||||||
return new HttpSuccess();
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -135,16 +123,20 @@ export class EducationLevelController extends Controller {
|
||||||
async detailEducationLevel(@Path() id: string) {
|
async detailEducationLevel(@Path() id: string) {
|
||||||
const educationLevel = await this.educationLevelRepository.findOne({
|
const educationLevel = await this.educationLevelRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
select: ["id", "name", "rank", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
select: [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"rank",
|
||||||
|
"createdAt",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
"createdFullName",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
],
|
||||||
});
|
});
|
||||||
if (!educationLevel) {
|
if (!educationLevel) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
}
|
||||||
try {
|
return new HttpSuccess(educationLevel);
|
||||||
return new HttpSuccess(educationLevel);
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -156,17 +148,21 @@ export class EducationLevelController extends Controller {
|
||||||
@Get()
|
@Get()
|
||||||
async listEducationLevel() {
|
async listEducationLevel() {
|
||||||
const educationLevel = await this.educationLevelRepository.find({
|
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" },
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!educationLevel) {
|
if (!educationLevel) {
|
||||||
return new HttpSuccess([]);
|
return new HttpSuccess([]);
|
||||||
}
|
}
|
||||||
try {
|
return new HttpSuccess(educationLevel);
|
||||||
return new HttpSuccess(educationLevel);
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,7 @@ export class GenderController extends Controller {
|
||||||
if (!_gender) {
|
if (!_gender) {
|
||||||
return new HttpSuccess([]);
|
return new HttpSuccess([]);
|
||||||
}
|
}
|
||||||
try {
|
return new HttpSuccess(_gender);
|
||||||
return new HttpSuccess(_gender);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -71,11 +66,8 @@ export class GenderController extends Controller {
|
||||||
if (!_gender) {
|
if (!_gender) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
return new HttpSuccess(_gender);
|
return new HttpSuccess(_gender);
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -103,16 +95,12 @@ export class GenderController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
_gender.createdUserId = request.user.sub;
|
||||||
_gender.createdUserId = request.user.sub;
|
_gender.createdFullName = request.user.name;
|
||||||
_gender.createdFullName = request.user.name;
|
_gender.lastUpdateUserId = request.user.sub;
|
||||||
_gender.lastUpdateUserId = request.user.sub;
|
_gender.lastUpdateFullName = request.user.name;
|
||||||
_gender.lastUpdateFullName = request.user.name;
|
await this.genderRepository.save(_gender);
|
||||||
await this.genderRepository.save(_gender);
|
return new HttpSuccess();
|
||||||
return new HttpSuccess();
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -140,15 +128,11 @@ export class GenderController extends Controller {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
_gender.lastUpdateUserId = request.user.sub;
|
||||||
_gender.lastUpdateUserId = request.user.sub;
|
_gender.lastUpdateFullName = request.user.name;
|
||||||
_gender.lastUpdateFullName = request.user.name;
|
this.genderRepository.merge(_gender, requestBody);
|
||||||
this.genderRepository.merge(_gender, requestBody);
|
await this.genderRepository.save(_gender);
|
||||||
await this.genderRepository.save(_gender);
|
return new HttpSuccess();
|
||||||
return new HttpSuccess();
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -166,11 +150,7 @@ export class GenderController extends Controller {
|
||||||
if (!_delGender) {
|
if (!_delGender) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + id);
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + id);
|
||||||
}
|
}
|
||||||
try {
|
await this.genderRepository.delete(_delGender.id);
|
||||||
await this.genderRepository.delete(_delGender.id);
|
return new HttpSuccess();
|
||||||
return new HttpSuccess();
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue