แก้ path อนุมัติเงินเดือน

This commit is contained in:
Kittapath 2024-03-15 09:21:56 +07:00
parent c22dd4ecf2
commit 2529d7d43f

View file

@ -4,18 +4,16 @@ import {
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Body,
Path,
Request,
Example,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { DeepPartial, In, IsNull, Not, Between, MoreThan, Like, Brackets } from "typeorm";
import { In, Not, MoreThan, Brackets } from "typeorm";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
@ -28,7 +26,6 @@ import { PosLevel } from "../entities/PosLevel";
import { Salarys } from "../entities/Salarys";
import { SalaryRanks } from "../entities/SalaryRanks";
import CallAPI from "../interfaces/call-api";
import { Int32 } from "typeorm/browser";
@Route("api/v1/salary/period")
@Tags("Salary")
@ -1966,19 +1963,23 @@ export class SalaryPeriodController extends Controller {
* API
*
*
* @param {string} orgId Guid, *Id
* @param {string} periodId Guid, *Id
* @param {string} rootId Guid, *Id
*/
@Get("officer/approve/{orgId}")
async OfficerApprove(@Path() orgId: string) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
@Get("officer/approve/{periodId}/{rootId}")
async OfficerApprove(@Path() periodId: string, rootId: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: periodId },
relations: ["salaryOrgs"],
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "PENDING")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
salaryOrg.status = "WAITHEAD1";
await this.salaryOrgRepository.save(salaryOrg);
if (!salaryPeriod)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
await Promise.all(
salaryPeriod.salaryOrgs.map(async (x) => {
x.status = "WAITHEAD1";
await this.salaryPeriodRepository.save(salaryPeriod);
}),
);
return new HttpSuccess();
}
@ -1987,18 +1988,25 @@ export class SalaryPeriodController extends Controller {
*
*
* @param {string} orgId Guid, *Id
* @param {string} rootId Guid, *Id
*/
@Get("head/approve/{orgId}")
async HeadApprove(@Path() orgId: string) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
@Get("head/approve/{periodId}/{rootId}")
async HeadApprove(@Path() periodId: string, rootId: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: periodId },
relations: ["salaryOrgs"],
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "WAITHEAD1")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
if (!salaryPeriod)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
salaryOrg.status = "WAITOWNER1";
await this.salaryOrgRepository.save(salaryOrg);
await Promise.all(
salaryPeriod.salaryOrgs
.filter((x) => x.rootId == rootId)
.map(async (x) => {
x.status = "WAITOWNER1";
await this.salaryPeriodRepository.save(salaryPeriod);
}),
);
return new HttpSuccess();
}
@ -2007,18 +2015,25 @@ export class SalaryPeriodController extends Controller {
*
*
* @param {string} orgId Guid, *Id
* @param {string} rootId Guid, *Id
*/
@Get("owner/approve/{orgId}")
async OwnerApprove(@Path() orgId: string) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
@Get("owner/approve/{periodId}/{rootId}")
async OwnerApprove(@Path() periodId: string, rootId: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: periodId },
relations: ["salaryOrgs"],
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "WAITOWNER1")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
if (!salaryPeriod)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
salaryOrg.status = "REPORT";
await this.salaryOrgRepository.save(salaryOrg);
await Promise.all(
salaryPeriod.salaryOrgs
.filter((x) => x.rootId == rootId)
.map(async (x) => {
x.status = "REPORT";
await this.salaryPeriodRepository.save(salaryPeriod);
}),
);
return new HttpSuccess();
}
@ -2027,25 +2042,33 @@ export class SalaryPeriodController extends Controller {
*
*
* @param {string} orgId Guid, *Id
* @param {string} rootId Guid, *Id
*/
@Put("owner/comment/{orgId}")
@Put("owner/comment/{periodId}/{rootId}")
async WaitOwnerApprove(
@Path() orgId: string,
@Path() periodId: string,
rootId: string,
@Body()
body: {
titleRecommend: string;
},
) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: periodId },
relations: ["salaryOrgs"],
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "WAITOWNER1")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
if (!salaryPeriod)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
salaryOrg.status = "WAITHEAD2";
salaryOrg.ownerRecommend = body.titleRecommend;
await this.salaryOrgRepository.save(salaryOrg);
await Promise.all(
salaryPeriod.salaryOrgs
.filter((x) => x.rootId == rootId)
.map(async (x) => {
x.status = "WAITHEAD2";
x.ownerRecommend = body.titleRecommend;
await this.salaryPeriodRepository.save(salaryPeriod);
}),
);
return new HttpSuccess();
}
@ -2054,25 +2077,33 @@ export class SalaryPeriodController extends Controller {
*
*
* @param {string} orgId Guid, *Id
* @param {string} rootId Guid, *Id
*/
@Put("head/comment/{orgId}")
@Put("head/comment/{periodId}/{rootId}")
async WaitHeadApprove(
@Path() orgId: string,
@Path() periodId: string,
rootId: string,
@Body()
body: {
titleRecommend: string;
},
) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: orgId },
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: periodId },
relations: ["salaryOrgs"],
});
if (!salaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
if (salaryOrg.status != "WAITOFFICER2")
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ยังไม่ไม่สามารถอนุมัติได้");
if (!salaryPeriod)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
salaryOrg.status = "REPORT";
salaryOrg.headRecommend = body.titleRecommend;
await this.salaryOrgRepository.save(salaryOrg);
await Promise.all(
salaryPeriod.salaryOrgs
.filter((x) => x.rootId == rootId)
.map(async (x) => {
x.status = "REPORT";
x.ownerRecommend = body.titleRecommend;
await this.salaryPeriodRepository.save(salaryPeriod);
}),
);
return new HttpSuccess();
}
}