แก้ path call api

This commit is contained in:
Kittapath 2024-08-07 17:49:28 +07:00
parent c7920c2657
commit 372e6d8973
3 changed files with 102 additions and 104 deletions

View file

@ -4,14 +4,12 @@ import {
Post, Post,
Put, Put,
Delete, Delete,
Patch,
Route, Route,
Security, Security,
Tags, Tags,
Body, Body,
Path, Path,
Request, Request,
Example,
SuccessResponse, SuccessResponse,
Response, Response,
Query, Query,
@ -20,18 +18,18 @@ import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { Equal, ILike, In, IsNull, Like, Not, Brackets, MoreThan } from "typeorm"; import { In, Not, Brackets } from "typeorm";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { import {
ChangePosition, ChangePosition,
CreateChangePosition, CreateChangePosition,
UpdateChangePosition UpdateChangePosition,
} from "../entities/ChangePosition"; } from "../entities/ChangePosition";
import { import {
ProfileChangePosition, ProfileChangePosition,
CreateProfileChangePosition, CreateProfileChangePosition,
UpdateProfileChangePosition, UpdateProfileChangePosition,
SelectProfileChangePosition SelectProfileChangePosition,
} from "../entities/ProfileChangePosition"; } from "../entities/ProfileChangePosition";
import { OrgRoot } from "../entities/OrgRoot"; import { OrgRoot } from "../entities/OrgRoot";
import { OrgChild1 } from "../entities/OrgChild1"; import { OrgChild1 } from "../entities/OrgChild1";
@ -70,7 +68,7 @@ export class ChangePositionController extends Controller {
const _changePosition = await this.changePositionRepository.findOne({ const _changePosition = await this.changePositionRepository.findOne({
where: { name: body.name }, where: { name: body.name },
}); });
if(_changePosition){ if (_changePosition) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว",
@ -79,9 +77,9 @@ export class ChangePositionController extends Controller {
const changePosition = new ChangePosition(); const changePosition = new ChangePosition();
Object.assign(changePosition, body); Object.assign(changePosition, body);
changePosition.date = new Date, (changePosition.date = new Date()),
changePosition.status = "WAITTING", (changePosition.status = "WAITTING"),
changePosition.createdUserId = request.user.sub; (changePosition.createdUserId = request.user.sub);
changePosition.createdFullName = request.user.name; changePosition.createdFullName = request.user.name;
changePosition.lastUpdateUserId = request.user.sub; changePosition.lastUpdateUserId = request.user.sub;
changePosition.lastUpdateFullName = request.user.name; changePosition.lastUpdateFullName = request.user.name;
@ -126,17 +124,17 @@ export class ChangePositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateChangePosition, @Body() body: UpdateChangePosition,
) { ) {
const changePosition = await this.changePositionRepository.findOneBy({ id }); const changePosition = await this.changePositionRepository.findOneBy({ id });
if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); if (!changePosition)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
const checkDuplicate = await this.changePositionRepository.find({ const checkDuplicate = await this.changePositionRepository.find({
where: { where: {
id: Not(id), id: Not(id),
name: body.name name: body.name,
}, },
}); });
if(checkDuplicate.length > 0){ if (checkDuplicate.length > 0) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว",
@ -168,7 +166,7 @@ export class ChangePositionController extends Controller {
searchKeyword searchKeyword
? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword" ? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword"
: "1=1", : "1=1",
{ keyword: `%${searchKeyword}%` } { keyword: `%${searchKeyword}%` },
) )
.orderBy("changePosition.date", "ASC") .orderBy("changePosition.date", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
@ -190,9 +188,9 @@ export class ChangePositionController extends Controller {
relations: ["profileChangePosition"], relations: ["profileChangePosition"],
where: { where: {
profileChangePosition: { profileChangePosition: {
status: "PENDING" status: "PENDING",
} },
} },
}); });
return new HttpSuccess(profiles); return new HttpSuccess(profiles);
} }
@ -205,12 +203,11 @@ export class ChangePositionController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("{id}") @Get("{id}")
async GetChangePositionById( @Path() id: string ) { async GetChangePositionById(@Path() id: string) {
const data = await this.changePositionRepository.findOne({ const data = await this.changePositionRepository.findOne({
relations: ["profileChangePosition"], relations: ["profileChangePosition"],
where: { id: id }} where: { id: id },
); });
if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
return new HttpSuccess(data); return new HttpSuccess(data);
} }
@ -229,18 +226,19 @@ export class ChangePositionController extends Controller {
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
const changePosition = await this.changePositionRepository.findOneBy({ id: changePositionId }); const changePosition = await this.changePositionRepository.findOneBy({ id: changePositionId });
if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); if (!changePosition)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
const profileChangePositions: ProfileChangePosition[] = []; const profileChangePositions: ProfileChangePosition[] = [];
const profiles = new ProfileChangePosition(); const profiles = new ProfileChangePosition();
for (const data of body.profiles) { for (const data of body.profiles) {
Object.assign(profiles, data); Object.assign(profiles, data);
let positionOld = data.positionOld ? `${data.positionOld}` : ""; let positionOld = data.positionOld ? `${data.positionOld}` : "";
let rootOld = data.rootOld ? data.positionOld ? `/${data.rootOld}` : `${data.rootOld}` : ""; let rootOld = data.rootOld ? (data.positionOld ? `/${data.rootOld}` : `${data.rootOld}`) : "";
profiles.changePositionId = changePositionId; profiles.changePositionId = changePositionId;
profiles.organizationPositionOld = `${positionOld}${rootOld}`, (profiles.organizationPositionOld = `${positionOld}${rootOld}`),
profiles.status = "WAITTING", (profiles.status = "WAITTING"),
profiles.createdUserId = request.user.sub; (profiles.createdUserId = request.user.sub);
profiles.createdFullName = request.user.name; profiles.createdFullName = request.user.name;
profiles.lastUpdateUserId = request.user.sub; profiles.lastUpdateUserId = request.user.sub;
profiles.lastUpdateFullName = request.user.name; profiles.lastUpdateFullName = request.user.name;
@ -279,7 +277,6 @@ export class ChangePositionController extends Controller {
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query() searchKeyword: string = "", @Query() searchKeyword: string = "",
) { ) {
const [profileChangePosition, total] = await AppDataSource.getRepository(ProfileChangePosition) const [profileChangePosition, total] = await AppDataSource.getRepository(ProfileChangePosition)
.createQueryBuilder("profileChangePosition") .createQueryBuilder("profileChangePosition")
@ -341,7 +338,7 @@ export class ChangePositionController extends Controller {
{ {
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}, },
) );
}), }),
) )
.orderBy("profileChangePosition.createdAt", "ASC") .orderBy("profileChangePosition.createdAt", "ASC")
@ -360,13 +357,15 @@ export class ChangePositionController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("profile/{id}") @Get("profile/{id}")
async GetProfileChangePositionById( async GetProfileChangePositionById(@Path() id: string) {
@Path() id: string
) {
const profileChangePos = await this.profileChangePositionRepository.findOne({ const profileChangePos = await this.profileChangePositionRepository.findOne({
where: { id: id } where: { id: id },
}); });
if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง"); if (!profileChangePos)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง",
);
return new HttpSuccess(profileChangePos); return new HttpSuccess(profileChangePos);
} }
@ -383,9 +382,12 @@ export class ChangePositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateProfileChangePosition, @Body() body: UpdateProfileChangePosition,
) { ) {
const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id }); const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id });
if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้"); if (!profileChangePos)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้",
);
profileChangePos.lastUpdateUserId = request.user.sub; profileChangePos.lastUpdateUserId = request.user.sub;
profileChangePos.lastUpdateFullName = request.user.name; profileChangePos.lastUpdateFullName = request.user.name;
@ -395,7 +397,7 @@ export class ChangePositionController extends Controller {
profileChangePos.positionLevelOld = body.positionLevelOld; profileChangePos.positionLevelOld = body.positionLevelOld;
profileChangePos.organizationPositionOld = body.organizationPositionOld; profileChangePos.organizationPositionOld = body.organizationPositionOld;
profileChangePos.amountOld = body.amountOld; profileChangePos.amountOld = body.amountOld;
profileChangePos.reason = body.reason? String(body.reason) : ""; profileChangePos.reason = body.reason ? String(body.reason) : "";
profileChangePos.dateCurrent = body.dateCurrent; profileChangePos.dateCurrent = body.dateCurrent;
await this.profileChangePositionRepository.save(profileChangePos); await this.profileChangePositionRepository.save(profileChangePos);
return new HttpSuccess(); return new HttpSuccess();
@ -414,9 +416,12 @@ export class ChangePositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: SelectProfileChangePosition, @Body() body: SelectProfileChangePosition,
) { ) {
const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id }); const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id });
if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้"); if (!profileChangePos)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้",
);
switch (body.node) { switch (body.node) {
case 0: { case 0: {
@ -507,18 +512,18 @@ export class ChangePositionController extends Controller {
profileChangePos.lastUpdateUserId = request.user.sub; profileChangePos.lastUpdateUserId = request.user.sub;
profileChangePos.lastUpdateFullName = request.user.name; profileChangePos.lastUpdateFullName = request.user.name;
profileChangePos.node = body.node; profileChangePos.node = body.node;
profileChangePos.nodeId = body.nodeId; profileChangePos.nodeId = body.nodeId;
profileChangePos.orgRevisionId = body.orgRevisionId; profileChangePos.orgRevisionId = body.orgRevisionId;
profileChangePos.posmasterId = body.posmasterId; profileChangePos.posmasterId = body.posmasterId;
profileChangePos.posMasterNo = body.posMasterNo; profileChangePos.posMasterNo = body.posMasterNo;
profileChangePos.positionId = body.positionId; profileChangePos.positionId = body.positionId;
profileChangePos.position = body.position; profileChangePos.position = body.position;
profileChangePos.positionField = body.positionField; profileChangePos.positionField = body.positionField;
profileChangePos.posTypeId = String(body.posTypeId); profileChangePos.posTypeId = String(body.posTypeId);
profileChangePos.posTypeName = body.posTypeName; profileChangePos.posTypeName = body.posTypeName;
profileChangePos.posLevelId = String(body.posLevelId); profileChangePos.posLevelId = String(body.posLevelId);
profileChangePos.posLevelName = body.posLevelName; profileChangePos.posLevelName = body.posLevelName;
profileChangePos.status = "PENDING"; profileChangePos.status = "PENDING";
await this.profileChangePositionRepository.save(profileChangePos); await this.profileChangePositionRepository.save(profileChangePos);
return new HttpSuccess(); return new HttpSuccess();
@ -534,24 +539,24 @@ export class ChangePositionController extends Controller {
async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) { async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) {
const profilechangePositions = await this.changePositionRepository.find({ const profilechangePositions = await this.changePositionRepository.find({
relations: ["profileChangePosition"], relations: ["profileChangePosition"],
where: { id: In(requestBody.id) } where: { id: In(requestBody.id) },
}); });
for (const item of profilechangePositions) { for (const item of profilechangePositions) {
item.status = "REPORT"; item.status = "REPORT";
item.lastUpdateUserId = request.user.sub; item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name; item.lastUpdateFullName = request.user.name;
if (item.profileChangePosition) { if (item.profileChangePosition) {
for (const profile of item.profileChangePosition) { for (const profile of item.profileChangePosition) {
profile.status = "REPORT"; profile.status = "REPORT";
profile.lastUpdateUserId = request.user.sub; profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name; profile.lastUpdateFullName = request.user.name;
await this.profileChangePositionRepository.save(profile); await this.profileChangePositionRepository.save(profile);
}
} }
await this.changePositionRepository.save(item);
} }
return new HttpSuccess(); await this.changePositionRepository.save(item);
}
return new HttpSuccess();
} }
/** /**
@ -573,11 +578,11 @@ export class ChangePositionController extends Controller {
await Promise.all( await Promise.all(
body.result.map(async (v) => { body.result.map(async (v) => {
const profile = await this.profileChangePositionRepository.findOne({ const profile = await this.profileChangePositionRepository.findOne({
where: { id: v.id } where: { id: v.id },
}); });
if (profile != null) { if (profile != null) {
await new CallAPI() await new CallAPI()
.PostData(request, "org/profile/salary", { .PostData(request, "/org/profile/salary", {
profileId: profile.id, profileId: profile.id,
date: new Date(), date: new Date(),
}) })

View file

@ -3,23 +3,19 @@ import {
Get, Get,
Post, Post,
Put, Put,
Delete,
Patch,
Route, Route,
Security, Security,
Tags, Tags,
Body, Body,
Path, Path,
Request, Request,
Example,
SuccessResponse, SuccessResponse,
Response, Response,
Query,
} from "tsoa"; } from "tsoa";
import { CreateOrgRevision, OrgRevision } from "../entities/OrgRevision"; import { CreateOrgRevision, OrgRevision } from "../entities/OrgRevision";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1"; import { OrgChild1 } from "../entities/OrgChild1";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import { In, IsNull, Not } from "typeorm"; import { In, IsNull, Not } from "typeorm";
@ -29,7 +25,6 @@ import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4"; import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { log } from "console";
import CallAPI from "../interfaces/call-api"; import CallAPI from "../interfaces/call-api";
import { ProfileSalary } from "../entities/ProfileSalary"; import { ProfileSalary } from "../entities/ProfileSalary";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
@ -1680,7 +1675,7 @@ export class OrganizationController extends Controller {
: item != null && item?.orgRoot != null : item != null && item?.orgRoot != null
? `${item.orgRoot.orgRootShortName}${item.posMasterNo}` ? `${item.orgRoot.orgRootShortName}${item.posMasterNo}`
: null; : null;
await new CallAPI().PostData(request, "org/profile/salary", { await new CallAPI().PostData(request, "/org/profile/salary", {
profileId: item.next_holderId, profileId: item.next_holderId,
date: new Date(), date: new Date(),
amount: profileSalary?.amount ?? null, amount: profileSalary?.amount ?? null,

View file

@ -37,7 +37,6 @@ import {
import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosType } from "../entities/EmployeePosType";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Position } from "../entities/Position";
import { Province } from "../entities/Province"; import { Province } from "../entities/Province";
import { District } from "../entities/District"; import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict"; import { SubDistrict } from "../entities/SubDistrict";
@ -63,7 +62,6 @@ import {
} from "../entities/ProfileEmployeeEmployment"; } from "../entities/ProfileEmployeeEmployment";
import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory"; import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory";
import CallAPI from "../interfaces/call-api"; import CallAPI from "../interfaces/call-api";
import e from "cors";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileInsignia } from "../entities/ProfileInsignia";
import { ProfileLeave } from "../entities/ProfileLeave"; import { ProfileLeave } from "../entities/ProfileLeave";
@ -3131,7 +3129,7 @@ export class ProfileEmployeeController extends Controller {
}); });
if (profile != null) { if (profile != null) {
await new CallAPI() await new CallAPI()
.PostData(request, "org/profile-employee/salary", { .PostData(request, "/org/profile-employee/salary", {
profileEmployeeId: profile.id, profileEmployeeId: profile.id,
date: new Date(), date: new Date(),
amount: v.amount, amount: v.amount,
@ -3148,9 +3146,9 @@ export class ProfileEmployeeController extends Controller {
profile.statusTemp = "DONE"; profile.statusTemp = "DONE";
profile.employeeClass = "PERM"; profile.employeeClass = "PERM";
await this.profileRepo.save(profile); await this.profileRepo.save(profile);
}); })
await new CallAPI() await new CallAPI()
.PostData(request, "org/employee/pos/report/current", { .PostData(request, "/org/employee/pos/report/current", {
posmasterId: profile.posmasterIdTemp, posmasterId: profile.posmasterIdTemp,
positionId: profile.positionIdTemp, positionId: profile.positionIdTemp,
profileId: profile.id, profileId: profile.id,