Merge branch 'adiDev' into develop

# Conflicts:
#	src/controllers/ProfileController.ts
This commit is contained in:
AdisakKanthawilang 2024-02-08 15:43:32 +07:00
commit fa36abfe85

View file

@ -21,6 +21,8 @@ import { Profile, CreateProfile, UpdateProfile } from "../entities/Profile";
import { Brackets, In, IsNull, Like, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { PosMaster } from "../entities/PosMaster";
import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType";
@Route("api/v1/org/profile")
@Tags("Profile")
@ -34,6 +36,8 @@ export class ProfileController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private profileRepository = AppDataSource.getRepository(Profile);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
private posTypeRepository = AppDataSource.getRepository(PosType);
/**
* API
@ -47,6 +51,30 @@ export class ProfileController extends Controller {
requestBody: CreateProfile,
@Request() request: { user: Record<string, any> },
) {
if (requestBody.posLevelId) {
const checkPosLevel = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
if (!checkPosLevel) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลใน PosLevel จากไอดีนี้ : " + requestBody.posLevelId,
);
}
}
if (requestBody.posTypeId) {
const checkPosType = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkPosType) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลใน PosType จากไอดีนี้ : " + requestBody.posTypeId,
);
}
}
try {
const profile = Object.assign(new Profile(), requestBody);
profile.createdUserId = request.user.sub;
@ -79,6 +107,30 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
if (requestBody.posLevelId) {
const checkPosLevel = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
if (!checkPosLevel) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลใน PosLevel จากไอดีนี้ : " + requestBody.posLevelId,
);
}
}
if (requestBody.posTypeId) {
const checkPosType = await this.posTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkPosType) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลใน PosType จากไอดีนี้ : " + requestBody.posTypeId,
);
}
}
try {
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;