Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-10-03 15:58:52 +07:00
commit c0b14fe189
12 changed files with 383 additions and 87 deletions

View file

@ -30,6 +30,8 @@ import { CommandSalary } from "../entities/CommandSalary";
import { CommandRecive } from "../entities/CommandRecive";
import HttpStatus from "../interfaces/http-status";
import Extension from "../interfaces/extension";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import CallAPI from "../interfaces/call-api";
@Route("api/v1/org/command")
@Tags("Command")
@ -47,6 +49,7 @@ export class CommandController extends Controller {
private commandSalaryRepository = AppDataSource.getRepository(CommandSalary);
private commandReciveRepository = AppDataSource.getRepository(CommandRecive);
private profileRepository = AppDataSource.getRepository(Profile);
private profileEmployeeRepository = AppDataSource.getRepository(ProfileEmployee);
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
/**
@ -276,7 +279,7 @@ export class CommandController extends Controller {
prefix: x.prefix,
firstName: x.firstName,
lastName: x.lastName,
profileId: x.profileId,
// profileId: x.profileId,
order: x.order,
remarkVertical: x.remarkVertical,
remarkHorizontal: x.remarkHorizontal,
@ -828,9 +831,9 @@ export class CommandController extends Controller {
}
/**
* API
* API
*
* @summary API
* @summary API
*
* @param {string} id Id
*/
@ -841,7 +844,10 @@ export class CommandController extends Controller {
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
const command = await this.commandRepository.findOne({ where: { id: id } });
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
@ -858,7 +864,28 @@ export class CommandController extends Controller {
) {
command.status = "WAITING";
} else {
command.status = "REPORTED";
const path = this.commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path + "/excecute", {
refIds: command.commandRecives
.filter((x) => x.refId != null)
.map((x) => ({
refId: x.refId,
commandAffectDate: command.commandAffectDate,
commandNo: command.commandNo,
commandYear: command.commandYear,
templateDoc: command.positionDetail,
amount: x.amount,
positionSalaryAmount: x.positionSalaryAmount,
mouthSalaryAmount: x.mouthSalaryAmount,
})),
})
.then(async (res) => {
command.status = "REPORTED";
})
.catch((e) => {});
}
command.lastUpdateUserId = request.user.sub;
command.lastUpdateFullName = request.user.name;
@ -875,7 +902,7 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab4/cover/{id}")
async GetByIdTab4Cover(@Path() id: string) {
async GetByIdTab4Cover(@Path() id: string, @Request() request: RequestWithUser) {
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType"],
@ -918,38 +945,234 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab4/attachment/{id}")
async GetByIdTab4Attachment(@Path() id: string) {
async GetByIdTab4Attachment(@Path() id: string, @Request() request: RequestWithUser) {
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType"],
relations: ["commandType", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
const _command = {
issue: "...................................",
commandNo: command.commandNo,
commandYear: command.commandYear,
commandTitle: command.issue,
detailHeader: command.detailHeader,
detailBody: command.detailBody,
detailFooter: command.detailFooter,
commandDate:
command.commandAffectDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandAffectDate)),
commandExcecuteDate:
command.commandExcecuteDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandExcecuteDate)),
name: "...................................",
position: "...................................",
};
let _command: any = [];
const path = this.commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path + "/attachment", {
refIds: command.commandRecives.map((x) => x.refId),
})
.then(async (res) => {
console.log(res);
_command = res;
})
.catch(() => {});
return new HttpSuccess({
template: command.commandType.fileAttachment,
reportName: "xlsx-report",
data: _command,
});
}
/**
* API body
*
* @summary API body
*
*/
@Post("person")
async PostPerson(
@Body()
requestBody: {
commandTypeId?: string | null;
commandNo?: string | null;
commandYear?: number | null;
commandId?: string | null;
persons: {
refId: string;
citizenId: string;
prefix: string;
firstName: string;
lastName: string;
}[];
},
@Request() request: RequestWithUser,
) {
let command = new Command();
let commandCode = null;
if (
requestBody.commandId != undefined &&
requestBody.commandId != null &&
requestBody.commandId != ""
) {
const _command = await this.commandRepository.findOne({
where: { id: requestBody.commandId },
relations: ["commandRecives", "commandType"],
order: {
commandRecives: {
order: "DESC",
},
},
});
if (!_command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบคำสั่งนี้ในระบบ");
}
commandCode = _command.commandType.code;
command = _command;
} else {
command = Object.assign(new Command(), requestBody);
if (!requestBody.commandTypeId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่ง");
}
const commandType = await this.commandTypeRepository.findOne({
where: { id: requestBody.commandTypeId },
});
if (!commandType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
}
commandCode = commandType.code;
command.detailHeader = commandType.detailHeader;
command.detailBody = commandType.detailBody;
command.detailFooter = commandType.detailFooter;
command.isAttachment = commandType.isAttachment;
command.status = "NEW";
command.issue = commandType.name;
command.createdUserId = request.user.sub;
command.createdFullName = request.user.name;
command.createdAt = new Date();
command.lastUpdateUserId = request.user.sub;
command.lastUpdateFullName = request.user.name;
command.lastUpdatedAt = new Date();
await this.commandRepository.save(command);
}
const path = this.commandTypePath(commandCode);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path, {
refIds: requestBody.persons.map((x) => x.refId),
})
.then(async (res) => {
let order =
command.commandRecives == null || command.commandRecives.length <= 0
? 0
: command.commandRecives[0].order;
await Promise.all(
requestBody.persons.map(async (item) => {
const _commandRecive = await this.commandReciveRepository.findOne({
where: {
commandId: command.id,
refId: item.refId,
},
});
if (_commandRecive) return;
order = order + 1;
let commandRecive = new CommandRecive();
commandRecive = Object.assign(new CommandRecive(), item);
commandRecive.order = order;
commandRecive.commandId = command.id;
commandRecive.createdUserId = request.user.sub;
commandRecive.createdFullName = request.user.name;
commandRecive.createdAt = new Date();
commandRecive.lastUpdateUserId = request.user.sub;
commandRecive.lastUpdateFullName = request.user.name;
commandRecive.lastUpdatedAt = new Date();
await this.commandReciveRepository.save(commandRecive);
}),
);
})
.catch(() => {});
return new HttpSuccess(command.id);
}
commandTypePath(commandCode: string) {
switch (commandCode) {
case "C-PM-01":
return "/placement/recruit/report";
case "C-PM-02":
return "/placement/candidate/report";
case "C-PM-03":
return "/placement/appoint/report";
case "C-PM-04":
return "/placement/move/report";
case "C-PM-05":
return "/placement/appointment/appoint/report";
case "C-PM-06":
return "/placement/appointment/slip/report";
case "C-PM-07":
return "/placement/appointment/move/report";
case "C-PM-08":
return "/retirement/other/appoint/report";
case "C-PM-09":
return "/retirement/other/out/report";
case "C-PM-10":
return "/xxxxxx";
case "C-PM-11":
return "/order/command11/report";
case "C-PM-12":
return "/order/command12/report";
case "C-PM-13":
return "/placement/transfer/command/report";
case "C-PM-14":
return "/placement/Receive/command/report";
case "C-PM-15":
return "/placement/officer/command/report";
case "C-PM-16":
return "/placement/repatriation/command/report";
case "C-PM-17":
return "/retirement/resign/command/report";
case "C-PM-18":
return "/retirement/out/command/report";
case "C-PM-19":
return "/order/command19/report";
case "C-PM-20":
return "/order/command20/report";
case "C-PM-21":
return "/order/command21/report";
case "C-PM-22":
return "/placement/appointment/employee-appoint/report";
case "C-PM-23":
return "/retirement/resign/employee/report";
case "C-PM-24":
return "/placement/appointment/employee-move/report";
case "C-PM-25":
return "/order/command25/report";
case "C-PM-26":
return "/order/command26/report";
case "C-PM-27":
return "/order/command27/report";
case "C-PM-28":
return "/order/command28/report";
case "C-PM-29":
return "/order/command29/report";
case "C-PM-30":
return "/order/command30/report";
case "C-PM-31":
return "/order/command31/report";
case "C-PM-32":
return "/order/command32/report";
case "C-PM-33":
return "/order/command33/report";
case "C-PM-34":
return "/order/command34/report";
case "C-PM-35":
return "/order/command35/report";
case "C-PM-36":
return "/order/command36/report";
case "C-PM-37":
return "/order/command37/report";
case "C-PM-38":
return "/order/command38/report";
case "C-PM-39":
return "/placement/slip/report";
case "C-PM-40":
return "/order/command40/report";
case "C-PM-41":
return "/retirement/resign/leave-cancel/report";
default:
return null;
}
}
}

View file

@ -621,7 +621,8 @@ export class OrganizationController extends Controller {
// let attrOwnership = null;
if (
orgRevision.orgRevisionIsDraft == true &&
orgRevision.orgRevisionIsCurrent == false
orgRevision.orgRevisionIsCurrent == false &&
request.user.role.includes("SUPER_ADMIN")
// attrOwnership == false
) {
const profile = await this.profileRepo.findOne({
@ -4786,7 +4787,10 @@ export class OrganizationController extends Controller {
child3: null,
child4: null,
};
if (orgRevision.orgRevisionIsDraft == true && orgRevision.orgRevisionIsCurrent == false) {
if (
(orgRevision.orgRevisionIsDraft == true && orgRevision.orgRevisionIsCurrent == false) ||
system != "SYS_ORG"
) {
_data = await new permission().PermissionOrgList(request, system.trim().toUpperCase());
}
const orgRootData = await AppDataSource.getRepository(OrgRoot)

View file

@ -48,9 +48,9 @@ export class PermissionOrgController extends Controller {
*/
@Get()
async GetActiveRootIdAdmin(@Request() request: RequestWithUser) {
if (!request.user.role.includes("SUPER_ADMIN")) {
throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
}
// if (!request.user.role.includes("SUPER_ADMIN")) {
// throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
// }
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true },
});
@ -76,9 +76,9 @@ export class PermissionOrgController extends Controller {
searchField?: "fullName" | "position" | "posNo" | "postype" | "poslevel",
@Query() searchKeyword: string = "",
) {
if (!request.user.role.includes("SUPER_ADMIN")) {
throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
}
// if (!request.user.role.includes("SUPER_ADMIN")) {
// throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
// }
let queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
if (searchField == "postype") {
@ -233,9 +233,9 @@ export class PermissionOrgController extends Controller {
searchKeyword: string;
},
) {
if (!request.user.role.includes("SUPER_ADMIN")) {
throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
}
// if (!request.user.role.includes("SUPER_ADMIN")) {
// throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
// }
let profiles: any = [];
if (requestBody.id != null) {
const _permissionOrg = await this.orgRootRepository.findOne({
@ -423,9 +423,9 @@ export class PermissionOrgController extends Controller {
@Request() request: RequestWithUser,
@Body() requestBody: { nodeId: string; personId: string },
) {
if (!request.user.role.includes("SUPER_ADMIN")) {
throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
}
// if (!request.user.role.includes("SUPER_ADMIN")) {
// throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
// }
const orgRoot = await this.orgRootRepository.findOne({
where: { id: requestBody.nodeId },
});
@ -472,9 +472,9 @@ export class PermissionOrgController extends Controller {
*/
@Delete("{id}")
async Delete(@Request() request: RequestWithUser, @Path() id: string) {
if (!request.user.role.includes("SUPER_ADMIN")) {
throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
}
// if (!request.user.role.includes("SUPER_ADMIN")) {
// throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
// }
// const orgRoot = await this.orgRootRepository.findOne({
// where: { id: nodeId },
// relations: ["permissionOrgRoots"],

View file

@ -840,9 +840,13 @@ export class PositionController extends Controller {
}
let _null: any = null;
posMaster.isDirector = requestBody.isDirector;
posMaster.isStaff = requestBody.isStaff == null || requestBody.isStaff == undefined ? _null : requestBody.isStaff;
posMaster.isStaff =
requestBody.isStaff == null || requestBody.isStaff == undefined ? _null : requestBody.isStaff;
// posMaster.isOfficer = requestBody.isOfficer;
posMaster.positionSign = requestBody.positionSign == null || requestBody.positionSign == undefined ? _null : requestBody.positionSign;
posMaster.positionSign =
requestBody.positionSign == null || requestBody.positionSign == undefined
? _null
: requestBody.positionSign;
posMaster.posMasterNo = requestBody.posMasterNo;
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
@ -1101,6 +1105,7 @@ export class PositionController extends Controller {
revisionId: string;
type: number;
isAll: boolean;
isBlank: boolean;
page: number;
pageSize: number;
keyword?: string;
@ -1127,6 +1132,9 @@ export class PositionController extends Controller {
searchShortName = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
} else {
}
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.type === 1) {
typeCondition = {
orgChild1Id: body.id,
@ -1138,6 +1146,9 @@ export class PositionController extends Controller {
searchShortName = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
} else {
}
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.type === 2) {
typeCondition = {
orgChild2Id: body.id,
@ -1149,6 +1160,9 @@ export class PositionController extends Controller {
searchShortName = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
} else {
}
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.type === 3) {
typeCondition = {
orgChild3Id: body.id,
@ -1160,11 +1174,17 @@ export class PositionController extends Controller {
searchShortName = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
} else {
}
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
} else if (body.type === 4) {
typeCondition = {
orgChild4Id: body.id,
};
searchShortName = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
if (body.isBlank == true) {
typeCondition.current_holderId = IsNull();
}
}
let findPosition: any;
let masterId = new Array();

View file

@ -3478,7 +3478,6 @@ export class ProfileEmployeeController extends Controller {
body: {
result: {
id: string;
personId: string;
templateDoc: string;
amount: Double | null;
positionSalaryAmount: Double | null;

View file

@ -3179,7 +3179,6 @@ export class ProfileEmployeeTempController extends Controller {
body: {
result: {
id: string;
personId: string;
templateDoc: string;
amount: Double | null;
positionSalaryAmount: Double | null;