fix: employee code

This commit is contained in:
puriphat 2024-06-14 06:19:15 +00:00
parent d97b1260cf
commit d8a6565abe
4 changed files with 28 additions and 28 deletions

View file

@ -51,7 +51,7 @@ export class EmployeeCheckupController extends Controller {
throw new HttpError(
HttpStatus.NOT_FOUND,
"Employee checkup cannot be found.",
"data_not_found",
"employeeCheckupNotFound",
);
}
return record;
@ -72,13 +72,13 @@ export class EmployeeCheckupController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Province cannot be found.",
"missing_or_invalid_parameter",
"provinceNotFound",
);
if (!employee)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Employee cannot be found.",
"missing_or_invalid_parameter",
"employeeNotFound",
);
}
@ -116,13 +116,13 @@ export class EmployeeCheckupController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Province cannot be found.",
"missing_or_invalid_parameter",
"provinceNotFound",
);
if (!employee)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Employee cannot be found.",
"missing_or_invalid_parameter",
"employeeNotFound",
);
}
@ -132,7 +132,7 @@ export class EmployeeCheckupController extends Controller {
throw new HttpError(
HttpStatus.NOT_FOUND,
"Employee checkup cannot be found.",
"data_not_found",
"employeeCheckupNotFound",
);
}
@ -160,7 +160,7 @@ export class EmployeeCheckupController extends Controller {
throw new HttpError(
HttpStatus.NOT_FOUND,
"Employee checkup cannot be found.",
"data_not_found",
"employeeCheckupNotFound",
);
}

View file

@ -295,7 +295,7 @@ export class EmployeeController extends Controller {
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Employee cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Employee cannot be found.", "employeeNotFound");
}
return record;
@ -316,25 +316,25 @@ export class EmployeeController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Province cannot be found.",
"missing_or_invalid_parameter",
"relationProvinceNotFound",
);
if (body.districtId !== district?.id)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"District cannot be found.",
"missing_or_invalid_parameter",
"relationDistrictNotFound",
);
if (body.subDistrictId !== subDistrict?.id)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Sub-district cannot be found.",
"missing_or_invalid_parameter",
"relationSubDistrictNotFound",
);
if (!customerBranch)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Customer Branch cannot be found.",
"missing_or_invalid_parameter",
"relationCustomerBranchNotFound",
);
const {
@ -362,7 +362,7 @@ export class EmployeeController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some province cannot be found.",
"missing_or_invalid_parameter",
"someProvinceNotFound",
);
}
}
@ -476,28 +476,28 @@ export class EmployeeController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Province cannot be found.",
"missing_or_invalid_parameter",
"relationProvinceNotFound",
);
if (body.districtId && !district)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"District cannot be found.",
"missing_or_invalid_parameter",
"relationDistrictNotFound",
);
if (body.subDistrictId && !subDistrict)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Sub-district cannot be found.",
"missing_or_invalid_parameter",
"relationSubDistrictNotFound",
);
if (body.customerBranchId && !customerBranch)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Customer cannot be found.",
"missing_or_invalid_parameter",
"relationCustomerNotFound",
);
if (!employee) {
throw new HttpError(HttpStatus.NOT_FOUND, "Employee cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Employee cannot be found.", "employeeNotFound");
}
const {
@ -524,7 +524,7 @@ export class EmployeeController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Some province cannot be found.",
"missing_or_invalid_parameter",
"someProvinceNotFound",
);
}
}
@ -652,14 +652,14 @@ export class EmployeeController extends Controller {
const record = await prisma.employee.findFirst({ where: { id: employeeId } });
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Employee cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Employee cannot be found.", "employeeNotFound");
}
if (record.status !== Status.CREATED) {
throw new HttpError(
HttpStatus.FORBIDDEN,
"Employee is in used.",
"missing_or_invalid_parameter",
"employeeInUsed",
);
}

View file

@ -54,7 +54,7 @@ export class EmployeeOtherInfo extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Employee cannot be found.",
"missing_or_invalid_parameter",
"employeeBadReq",
);
const record = await prisma.employeeOtherInfo.create({
@ -82,7 +82,7 @@ export class EmployeeOtherInfo extends Controller {
throw new HttpError(
HttpStatus.NOT_FOUND,
"Employee other info cannot be found.",
"data_not_found",
"employeeOtherNotFound",
);
}
@ -106,7 +106,7 @@ export class EmployeeOtherInfo extends Controller {
throw new HttpError(
HttpStatus.NOT_FOUND,
"Employee other info cannot be found.",
"data_not_found",
"employeeOtherNotFound",
);
}

View file

@ -46,7 +46,7 @@ export class EmployeeWorkController extends Controller {
where: { id: workId, employeeId },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "employeeWorkNotFound");
}
return record;
}
@ -61,7 +61,7 @@ export class EmployeeWorkController extends Controller {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Employee cannot be found.",
"missing_or_invalid_parameter",
"employeeBadReq",
);
const record = await prisma.employeeWork.create({
@ -86,7 +86,7 @@ export class EmployeeWorkController extends Controller {
@Body() body: EmployeeWorkPayload,
) {
if (!(await prisma.employeeWork.findUnique({ where: { id: workId, employeeId } }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "employeeWorkNotFound");
}
const record = await prisma.employeeWork.update({
@ -104,7 +104,7 @@ export class EmployeeWorkController extends Controller {
const record = await prisma.employeeWork.findFirst({ where: { id: workId, employeeId } });
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "data_not_found");
throw new HttpError(HttpStatus.NOT_FOUND, "Employee work cannot be found.", "employeeWorkNotFound");
}
return await prisma.employeeWork.delete({ where: { id: workId, employeeId } });