sort ตำแหน่งลูกจ้าง
This commit is contained in:
parent
2972d6ef5e
commit
222a2a5b6b
4 changed files with 71 additions and 22 deletions
|
|
@ -14,7 +14,7 @@ import {
|
|||
Get,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import { Not } from "typeorm"
|
||||
import { Not } from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -54,6 +54,27 @@ export class PosExecutiveController extends Controller {
|
|||
}
|
||||
|
||||
const posExecutive = Object.assign(new PosExecutive(), requestBody);
|
||||
if (requestBody.posExecutivePriority == null) {
|
||||
const checkPriority = await this.posExecutiveRepository.findOne({
|
||||
order: { posExecutivePriority: "DESC" },
|
||||
});
|
||||
if (checkPriority == null) {
|
||||
posExecutive.posExecutivePriority = 1;
|
||||
} else {
|
||||
posExecutive.posExecutivePriority = checkPriority.posExecutivePriority + 1;
|
||||
}
|
||||
} else {
|
||||
posExecutive.posExecutivePriority = requestBody.posExecutivePriority;
|
||||
}
|
||||
const _checkPriority = await this.posExecutiveRepository.findOne({
|
||||
where: {
|
||||
posExecutivePriority: posExecutive.posExecutivePriority,
|
||||
},
|
||||
});
|
||||
|
||||
if (_checkPriority) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
posExecutive.createdUserId = request.user.sub;
|
||||
posExecutive.createdFullName = request.user.name;
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
|
|
@ -84,17 +105,40 @@ export class PosExecutiveController extends Controller {
|
|||
const checkName = await this.posExecutiveRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posExecutiveName: requestBody.posExecutiveName
|
||||
posExecutiveName: requestBody.posExecutiveName,
|
||||
},
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
if (requestBody.posExecutivePriority == null) {
|
||||
const checkPriority = await this.posExecutiveRepository.findOne({
|
||||
order: { posExecutivePriority: "DESC" },
|
||||
});
|
||||
if (checkPriority == null) {
|
||||
posExecutive.posExecutivePriority = 1;
|
||||
} else {
|
||||
posExecutive.posExecutivePriority = checkPriority.posExecutivePriority + 1;
|
||||
}
|
||||
} else {
|
||||
posExecutive.posExecutivePriority = requestBody.posExecutivePriority;
|
||||
}
|
||||
const _checkPriority = await this.posExecutiveRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posExecutivePriority: posExecutive.posExecutivePriority,
|
||||
},
|
||||
});
|
||||
|
||||
if (_checkPriority) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
posExecutive.posExecutiveName = requestBody.posExecutiveName;
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
posExecutive.lastUpdateFullName = request.user.name;
|
||||
this.posExecutiveRepository.merge(posExecutive, requestBody);
|
||||
// this.posExecutiveRepository.merge(posExecutive, requestBody);
|
||||
await this.posExecutiveRepository.save(posExecutive);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue