fixing exception error
This commit is contained in:
parent
1c9f276cfb
commit
6585520af7
5 changed files with 1343 additions and 1085 deletions
|
|
@ -46,36 +46,45 @@ export class DirectorController {
|
|||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
await new permission().PermissionList(request, "SYS_EVA_INFO");
|
||||
const directors = await AppDataSource.getRepository(Director)
|
||||
.createQueryBuilder("director")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != null && keyword != ""
|
||||
? "CONCAT(director.prefix, director.firstName, ' ', director.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
})
|
||||
.orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
})
|
||||
.orWhere(keyword != null && keyword != "" ? "director.phone LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("director.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
try {
|
||||
await new permission().PermissionList(request, "SYS_EVA_INFO");
|
||||
const directors = await AppDataSource.getRepository(Director)
|
||||
.createQueryBuilder("director")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != null && keyword != ""
|
||||
? "CONCAT(director.prefix, director.firstName, ' ', director.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
})
|
||||
.orWhere(keyword != null && keyword != "" ? "director.phone LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("director.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
|
||||
return new HttpSuccess(directors);
|
||||
return new HttpSuccess(directors);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("admin")
|
||||
|
|
@ -85,34 +94,43 @@ export class DirectorController {
|
|||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const directors = await AppDataSource.getRepository(Director)
|
||||
.createQueryBuilder("director")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != null && keyword != ""
|
||||
? "CONCAT(director.prefix, director.firstName, ' ', director.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
})
|
||||
.orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
})
|
||||
.orWhere(keyword != null && keyword != "" ? "director.phone LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("director.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
return new HttpSuccess(directors);
|
||||
try {
|
||||
const directors = await AppDataSource.getRepository(Director)
|
||||
.createQueryBuilder("director")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != null && keyword != ""
|
||||
? "CONCAT(director.prefix, director.firstName, ' ', director.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
})
|
||||
.orWhere(keyword != null && keyword != "" ? "director.phone LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("director.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
return new HttpSuccess(directors);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,13 +141,19 @@ export class DirectorController {
|
|||
*/
|
||||
@Get("{id}")
|
||||
async one(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO");
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO");
|
||||
const director = await this.directorRepository.findOne({ where: { id } });
|
||||
if (!director) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
try {
|
||||
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO");
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO");
|
||||
const director = await this.directorRepository.findOne({ where: { id } });
|
||||
if (!director) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
return new HttpSuccess(director);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
return new HttpSuccess(director);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,27 +164,33 @@ export class DirectorController {
|
|||
*/
|
||||
@Post()
|
||||
async save(@Body() requestBody: CreateDirector, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionCreate(request, "SYS_EVA_INFO");
|
||||
let directorDup = await this.directorRepository.findOne({
|
||||
where: { firstName: requestBody.firstName, lastName: requestBody.lastName },
|
||||
});
|
||||
if (directorDup != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกรรมการนี้มีอยู่ในระบบแล้ว");
|
||||
try {
|
||||
await new permission().PermissionCreate(request, "SYS_EVA_INFO");
|
||||
let directorDup = await this.directorRepository.findOne({
|
||||
where: { firstName: requestBody.firstName, lastName: requestBody.lastName },
|
||||
});
|
||||
if (directorDup != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกรรมการนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const director = Object.assign(new Director(), requestBody);
|
||||
director.createdUserId = request.user.sub;
|
||||
director.createdFullName = request.user.name;
|
||||
director.createdAt = new Date();
|
||||
director.lastUpdateUserId = request.user.sub;
|
||||
director.lastUpdateFullName = request.user.name;
|
||||
director.lastUpdatedAt = new Date();
|
||||
|
||||
const before = null;
|
||||
|
||||
await this.directorRepository.save(director, { data: request });
|
||||
setLogDataDiff(request, { before, after: director });
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
const director = Object.assign(new Director(), requestBody);
|
||||
director.createdUserId = request.user.sub;
|
||||
director.createdFullName = request.user.name;
|
||||
director.createdAt = new Date();
|
||||
director.lastUpdateUserId = request.user.sub;
|
||||
director.lastUpdateFullName = request.user.name;
|
||||
director.lastUpdatedAt = new Date();
|
||||
|
||||
const before = null;
|
||||
|
||||
await this.directorRepository.save(director, { data: request });
|
||||
setLogDataDiff(request, { before, after: director });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -171,25 +201,31 @@ export class DirectorController {
|
|||
*/
|
||||
@Put("{id}")
|
||||
async update(@Path() id: string, @Body() u: CreateDirector, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
|
||||
let directorDup = await this.directorRepository.findOne({
|
||||
where: { firstName: u.firstName, lastName: u.lastName, id: Not(id) },
|
||||
});
|
||||
if (directorDup != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกรรมการนี้มีอยู่ในระบบแล้ว");
|
||||
try {
|
||||
await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
|
||||
let directorDup = await this.directorRepository.findOne({
|
||||
where: { firstName: u.firstName, lastName: u.lastName, id: Not(id) },
|
||||
});
|
||||
if (directorDup != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกรรมการนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
let director = await this.directorRepository.findOneBy({ id });
|
||||
if (!director) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
const before = structuredClone(directorDup);
|
||||
director.lastUpdateUserId = request.user.sub;
|
||||
director.lastUpdateFullName = request.user.name;
|
||||
director.lastUpdatedAt = new Date();
|
||||
this.directorRepository.merge(director, u);
|
||||
await this.directorRepository.save(director, { data: request });
|
||||
setLogDataDiff(request, { before, after: director });
|
||||
return new HttpSuccess();
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
let director = await this.directorRepository.findOneBy({ id });
|
||||
if (!director) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
const before = structuredClone(directorDup);
|
||||
director.lastUpdateUserId = request.user.sub;
|
||||
director.lastUpdateFullName = request.user.name;
|
||||
director.lastUpdatedAt = new Date();
|
||||
this.directorRepository.merge(director, u);
|
||||
await this.directorRepository.save(director, { data: request });
|
||||
setLogDataDiff(request, { before, after: director });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -200,12 +236,18 @@ export class DirectorController {
|
|||
*/
|
||||
@Delete("{id}")
|
||||
async remove(id: string, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionDelete(request, "SYS_EVA_INFO");
|
||||
let director = await this.directorRepository.findOneBy({ id });
|
||||
if (!director) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
try {
|
||||
await new permission().PermissionDelete(request, "SYS_EVA_INFO");
|
||||
let director = await this.directorRepository.findOneBy({ id });
|
||||
if (!director) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
await this.directorRepository.remove(director, { data: request });
|
||||
return new HttpSuccess();
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
await this.directorRepository.remove(director, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import {
|
|||
} from "../services/storage";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Evaluation } from "../entities/Evaluation";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
||||
@Route("api/v1/evaluation/document")
|
||||
@Tags("document")
|
||||
|
|
@ -58,9 +60,15 @@ export class DocumentController extends Controller {
|
|||
},
|
||||
])
|
||||
public async getFile(@Path() volume: string, @Path() id: string) {
|
||||
const list = await listFile(["ระบบประเมิน", volume, id]);
|
||||
if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
return list;
|
||||
try {
|
||||
const list = await listFile(["ระบบประเมิน", volume, id]);
|
||||
if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
return list;
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -97,9 +105,15 @@ export class DocumentController extends Controller {
|
|||
downloadUrl: "https://.../...", // Presigned Download URL 7 Days Exp
|
||||
})
|
||||
public async getFileDownload(@Path() id: string, @Path() volume: string, @Path() file: string) {
|
||||
const data = await downloadFile(["ระบบประเมิน", volume, id], file);
|
||||
if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
return data;
|
||||
try {
|
||||
const data = await downloadFile(["ระบบประเมิน", volume, id], file);
|
||||
if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
return data;
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -194,64 +208,73 @@ export class DocumentController extends Controller {
|
|||
replace?: boolean;
|
||||
},
|
||||
) {
|
||||
const path = ["ระบบประเมิน", volume];
|
||||
try {
|
||||
const path = ["ระบบประเมิน", volume];
|
||||
|
||||
if (!(await createFolder(path, id, true))) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
if (!(await createFolder(path, id, true))) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
}
|
||||
|
||||
const list = await listFile(["ระบบประเมิน", volume, id]);
|
||||
|
||||
if (!list || !Array.isArray(list)) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
}
|
||||
|
||||
let used: string[] = [];
|
||||
|
||||
const evaluation = AppDataSource.getRepository(Evaluation);
|
||||
|
||||
let author = await evaluation.findOne({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
let fileList = !body.replace
|
||||
? body.fileList.map(({ fileName, ...props }) => {
|
||||
const dotIndex = fileName.lastIndexOf(".");
|
||||
const originalName =
|
||||
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(0, dotIndex) : fileName;
|
||||
const extension =
|
||||
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : "";
|
||||
|
||||
let i = 1;
|
||||
while (
|
||||
list.findIndex((v) => v.fileName === fileName) !== -1 ||
|
||||
used.includes(fileName)
|
||||
) {
|
||||
fileName = `${originalName} (${i++})`;
|
||||
if (dotIndex !== -1) fileName += extension;
|
||||
}
|
||||
if (author) {
|
||||
props.author = `${author.prefix}${author.fullName}`;
|
||||
} else {
|
||||
props.author = "ไม่พบข้อมูล";
|
||||
}
|
||||
|
||||
used.push(fileName);
|
||||
return { fileName: fileName, ...props };
|
||||
})
|
||||
: body.fileList;
|
||||
|
||||
const map = fileList.map(async ({ fileName, ...props }) => [
|
||||
fileName,
|
||||
await createFile([...path, id], fileName, props),
|
||||
]);
|
||||
|
||||
const result = await Promise.all(map).catch((e) =>
|
||||
console.error(`Storage Service Error: ${e}`),
|
||||
);
|
||||
|
||||
if (!result || result.some((v) => !v[1])) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
|
||||
}
|
||||
|
||||
return Object.fromEntries(result);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
|
||||
const list = await listFile(["ระบบประเมิน", volume, id]);
|
||||
|
||||
if (!list || !Array.isArray(list)) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
}
|
||||
|
||||
let used: string[] = [];
|
||||
|
||||
const evaluation = AppDataSource.getRepository(Evaluation);
|
||||
|
||||
let author = await evaluation.findOne({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
let fileList = !body.replace
|
||||
? body.fileList.map(({ fileName, ...props }) => {
|
||||
const dotIndex = fileName.lastIndexOf(".");
|
||||
const originalName =
|
||||
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(0, dotIndex) : fileName;
|
||||
const extension =
|
||||
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : "";
|
||||
|
||||
let i = 1;
|
||||
while (list.findIndex((v) => v.fileName === fileName) !== -1 || used.includes(fileName)) {
|
||||
fileName = `${originalName} (${i++})`;
|
||||
if (dotIndex !== -1) fileName += extension;
|
||||
}
|
||||
if(author){
|
||||
props.author = `${author.prefix}${author.fullName}`;
|
||||
}else{
|
||||
props.author = "ไม่พบข้อมูล";
|
||||
}
|
||||
|
||||
used.push(fileName);
|
||||
return { fileName: fileName, ...props };
|
||||
})
|
||||
: body.fileList;
|
||||
|
||||
const map = fileList.map(async ({ fileName, ...props }) => [
|
||||
fileName,
|
||||
await createFile([...path, id], fileName, props),
|
||||
]);
|
||||
|
||||
const result = await Promise.all(map).catch((e) =>
|
||||
console.error(`Storage Service Error: ${e}`),
|
||||
);
|
||||
|
||||
if (!result || result.some((v) => !v[1])) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
|
||||
}
|
||||
|
||||
return Object.fromEntries(result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -276,13 +299,19 @@ export class DocumentController extends Controller {
|
|||
metadata?: { [key: string]: unknown };
|
||||
},
|
||||
) {
|
||||
const props = body;
|
||||
const result = await updateFile(["ระบบประเมิน", volume, id], file, props);
|
||||
try {
|
||||
const props = body;
|
||||
const result = await updateFile(["ระบบประเมิน", volume, id], file, props);
|
||||
|
||||
if (!result) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
|
||||
if (!result) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
|
||||
}
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -293,12 +322,18 @@ export class DocumentController extends Controller {
|
|||
*/
|
||||
@Delete("{volume}/{id}")
|
||||
public async deleteFolder(@Path() volume: string, @Path() id: string) {
|
||||
const result = await deleteFolder(["ระบบประเมิน", volume], id);
|
||||
try {
|
||||
const result = await deleteFolder(["ระบบประเมิน", volume], id);
|
||||
|
||||
if (!result) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
|
||||
if (!result) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
|
||||
}
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -310,11 +345,17 @@ export class DocumentController extends Controller {
|
|||
*/
|
||||
@Delete("{volume}/{id}/{file}")
|
||||
public async deleteFile(@Path() volume: string, @Path() id: string, @Path() file: string) {
|
||||
const result = await deleteFile(["ระบบประเมิน", volume, id], file);
|
||||
try {
|
||||
const result = await deleteFile(["ระบบประเมิน", volume, id], file);
|
||||
|
||||
if (!result) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
|
||||
if (!result) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
|
||||
}
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -47,23 +47,29 @@ export class MeetingController {
|
|||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
await new permission().PermissionList(request, "SYS_EVA_INFO");
|
||||
const meetings = await AppDataSource.getRepository(Meeting)
|
||||
.createQueryBuilder("meeting")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(keyword != null && keyword != "" ? "meeting.title LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
}).orWhere(keyword != null && keyword != "" ? "meeting.round LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("meeting.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
return new HttpSuccess(meetings);
|
||||
try {
|
||||
await new permission().PermissionList(request, "SYS_EVA_INFO");
|
||||
const meetings = await AppDataSource.getRepository(Meeting)
|
||||
.createQueryBuilder("meeting")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(keyword != null && keyword != "" ? "meeting.title LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
}).orWhere(keyword != null && keyword != "" ? "meeting.round LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("meeting.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
return new HttpSuccess(meetings);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("admin")
|
||||
|
|
@ -73,22 +79,28 @@ export class MeetingController {
|
|||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const meetings = await AppDataSource.getRepository(Meeting)
|
||||
.createQueryBuilder("meeting")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(keyword != null && keyword != "" ? "meeting.title LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
}).orWhere(keyword != null && keyword != "" ? "meeting.round LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("meeting.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
return new HttpSuccess(meetings);
|
||||
try {
|
||||
const meetings = await AppDataSource.getRepository(Meeting)
|
||||
.createQueryBuilder("meeting")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(keyword != null && keyword != "" ? "meeting.title LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
}).orWhere(keyword != null && keyword != "" ? "meeting.round LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("meeting.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
return new HttpSuccess(meetings);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -99,13 +111,19 @@ export class MeetingController {
|
|||
*/
|
||||
@Get("{id}")
|
||||
async one(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO");
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO");
|
||||
const meeting = await this.meetingRepository.findOne({ where: { id } });
|
||||
if (!meeting) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
try {
|
||||
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO");
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO");
|
||||
const meeting = await this.meetingRepository.findOne({ where: { id } });
|
||||
if (!meeting) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
return new HttpSuccess(meeting);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
return new HttpSuccess(meeting);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -116,20 +134,26 @@ export class MeetingController {
|
|||
*/
|
||||
@Post()
|
||||
async save(@Body() requestBody: CreateMeeting, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionCreate(request, "SYS_EVA_INFO");
|
||||
const meeting = Object.assign(new Meeting(), requestBody);
|
||||
meeting.createdUserId = request.user.sub;
|
||||
meeting.createdFullName = request.user.name;
|
||||
meeting.createdAt = new Date();
|
||||
meeting.lastUpdateUserId = request.user.sub;
|
||||
meeting.lastUpdateFullName = request.user.name;
|
||||
meeting.lastUpdatedAt = new Date();
|
||||
const before = null;
|
||||
try {
|
||||
await new permission().PermissionCreate(request, "SYS_EVA_INFO");
|
||||
const meeting = Object.assign(new Meeting(), requestBody);
|
||||
meeting.createdUserId = request.user.sub;
|
||||
meeting.createdFullName = request.user.name;
|
||||
meeting.createdAt = new Date();
|
||||
meeting.lastUpdateUserId = request.user.sub;
|
||||
meeting.lastUpdateFullName = request.user.name;
|
||||
meeting.lastUpdatedAt = new Date();
|
||||
const before = null;
|
||||
|
||||
await this.meetingRepository.save(meeting, { data: request });
|
||||
setLogDataDiff(request, { before, after: meeting });
|
||||
await this.meetingRepository.save(meeting, { data: request });
|
||||
setLogDataDiff(request, { before, after: meeting });
|
||||
|
||||
return new HttpSuccess();
|
||||
return new HttpSuccess();
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,20 +164,26 @@ export class MeetingController {
|
|||
*/
|
||||
@Put("{id}")
|
||||
async update(@Path() id: string, @Body() u: CreateMeeting, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
|
||||
let meeting = await this.meetingRepository.findOneBy({ id });
|
||||
if (!meeting) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
const before = structuredClone(meeting);
|
||||
meeting.lastUpdateUserId = request.user.sub;
|
||||
meeting.lastUpdateFullName = request.user.name;
|
||||
meeting.lastUpdatedAt = new Date();
|
||||
this.meetingRepository.merge(meeting, u);
|
||||
await this.meetingRepository.save(meeting, { data: request });
|
||||
setLogDataDiff(request, { before, after: meeting });
|
||||
try {
|
||||
await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
|
||||
let meeting = await this.meetingRepository.findOneBy({ id });
|
||||
if (!meeting) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
const before = structuredClone(meeting);
|
||||
meeting.lastUpdateUserId = request.user.sub;
|
||||
meeting.lastUpdateFullName = request.user.name;
|
||||
meeting.lastUpdatedAt = new Date();
|
||||
this.meetingRepository.merge(meeting, u);
|
||||
await this.meetingRepository.save(meeting, { data: request });
|
||||
setLogDataDiff(request, { before, after: meeting });
|
||||
|
||||
return new HttpSuccess();
|
||||
return new HttpSuccess();
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,12 +194,18 @@ export class MeetingController {
|
|||
*/
|
||||
@Delete("{id}")
|
||||
async remove(id: string, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionDelete(request, "SYS_EVA_INFO");
|
||||
let meeting = await this.meetingRepository.findOneBy({ id });
|
||||
if (!meeting) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
try {
|
||||
await new permission().PermissionDelete(request, "SYS_EVA_INFO");
|
||||
let meeting = await this.meetingRepository.findOneBy({ id });
|
||||
if (!meeting) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
await this.meetingRepository.remove(meeting, { data: request });
|
||||
return new HttpSuccess();
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
await this.meetingRepository.remove(meeting, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,70 +58,90 @@ export class ReoportController {
|
|||
*
|
||||
*/
|
||||
@Get()
|
||||
async sumaryEvaluationReport(@Query("year") year?: string, @Query("rootid") rootId?: string, @Query("nameOrg") nameOrg?: string) {
|
||||
|
||||
const yearInAD = year?year:null;
|
||||
const yearInBE = yearInAD ? (parseInt(yearInAD) - 543).toString() : null;
|
||||
async sumaryEvaluationReport(
|
||||
@Query("year") year?: string,
|
||||
@Query("rootid") rootId?: string,
|
||||
@Query("nameOrg") nameOrg?: string,
|
||||
) {
|
||||
try {
|
||||
const yearInAD = year ? year : null;
|
||||
const yearInBE = yearInAD ? (parseInt(yearInAD) - 543).toString() : null;
|
||||
|
||||
let evaluation = [];
|
||||
evaluation = await AppDataSource.getRepository(Evaluation)
|
||||
.createQueryBuilder("evaluation")
|
||||
.where('evaluation.evaluationResult NOT IN (:...evaluationResults)', { evaluationResults: ['PENDING'] })
|
||||
.andWhere( yearInBE && yearInBE != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInBE })
|
||||
.andWhere('evaluation.orgRootId = :rootId',{ rootId: rootId })
|
||||
.andWhere('evaluation.step = :step', { step: 'DONE' })
|
||||
.getMany();
|
||||
|
||||
const groupedData = evaluation.reduce((acc:any, item) => {
|
||||
const key = item.root;
|
||||
if (!acc[key]) {
|
||||
acc[key] = {
|
||||
agency: item.root && item.root != "" ? item.root: "-",
|
||||
submitter: 0,
|
||||
passCount: 0,
|
||||
notPassCount: 0,
|
||||
};
|
||||
}
|
||||
if (item.evaluationResult === 'PASS') {
|
||||
acc[key].passCount++;
|
||||
} else if (item.evaluationResult === 'NOTPASS') {
|
||||
acc[key].notPassCount++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
let evaluation = [];
|
||||
evaluation = await AppDataSource.getRepository(Evaluation)
|
||||
.createQueryBuilder("evaluation")
|
||||
.where("evaluation.evaluationResult NOT IN (:...evaluationResults)", {
|
||||
evaluationResults: ["PENDING"],
|
||||
})
|
||||
.andWhere(yearInBE && yearInBE != null ? "YEAR(createdAt) = :year" : "1=1", {
|
||||
year: yearInBE,
|
||||
})
|
||||
.andWhere("evaluation.orgRootId = :rootId", { rootId: rootId })
|
||||
.andWhere("evaluation.step = :step", { step: "DONE" })
|
||||
.getMany();
|
||||
|
||||
const result = Object.values(groupedData).map((item: any) => ({
|
||||
...item ,
|
||||
submitter: Extension.ToThaiNumber((item.passCount + item.notPassCount).toString()),
|
||||
passCount: Extension.ToThaiNumber(item.passCount.toString()),
|
||||
notPassCount: Extension.ToThaiNumber(item.notPassCount.toString()),
|
||||
}));
|
||||
const groupedData = evaluation.reduce((acc: any, item) => {
|
||||
const key = item.root;
|
||||
if (!acc[key]) {
|
||||
acc[key] = {
|
||||
agency: item.root && item.root != "" ? item.root : "-",
|
||||
submitter: 0,
|
||||
passCount: 0,
|
||||
notPassCount: 0,
|
||||
};
|
||||
}
|
||||
if (item.evaluationResult === "PASS") {
|
||||
acc[key].passCount++;
|
||||
} else if (item.evaluationResult === "NOTPASS") {
|
||||
acc[key].notPassCount++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const submitter = Object.values(groupedData).reduce((acc: number, item: any) => {
|
||||
return acc + item.passCount + item.notPassCount;
|
||||
}, 0);
|
||||
|
||||
const sumPass = Object.values(groupedData).reduce((acc: number, item: any) => {
|
||||
return acc + item.passCount;
|
||||
}, 0);
|
||||
|
||||
const sumNotPass = Object.values(groupedData).reduce((acc: number, item: any) => {
|
||||
return acc + item.notPassCount;
|
||||
}, 0);
|
||||
const result = Object.values(groupedData).map((item: any) => ({
|
||||
...item,
|
||||
submitter: Extension.ToThaiNumber((item.passCount + item.notPassCount).toString()),
|
||||
passCount: Extension.ToThaiNumber(item.passCount.toString()),
|
||||
notPassCount: Extension.ToThaiNumber(item.notPassCount.toString()),
|
||||
}));
|
||||
|
||||
return new HttpSuccess({
|
||||
template: "summary-evaluation",
|
||||
reportName: "xlsx-report",
|
||||
data: {
|
||||
year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()),
|
||||
date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())),
|
||||
mainAgency: rootId && result.length > 0?result[0].agency: rootId && result.length === 0 ? '':'หน่วยงานทั้งหมด',
|
||||
list: result,
|
||||
total: Extension.ToThaiNumber(submitter.toString()),
|
||||
sumPass: Extension.ToThaiNumber(sumPass.toString()),
|
||||
sumNotPass: Extension.ToThaiNumber(sumNotPass.toString()),
|
||||
},
|
||||
});
|
||||
const submitter = Object.values(groupedData).reduce((acc: number, item: any) => {
|
||||
return acc + item.passCount + item.notPassCount;
|
||||
}, 0);
|
||||
|
||||
const sumPass = Object.values(groupedData).reduce((acc: number, item: any) => {
|
||||
return acc + item.passCount;
|
||||
}, 0);
|
||||
|
||||
const sumNotPass = Object.values(groupedData).reduce((acc: number, item: any) => {
|
||||
return acc + item.notPassCount;
|
||||
}, 0);
|
||||
|
||||
return new HttpSuccess({
|
||||
template: "summary-evaluation",
|
||||
reportName: "xlsx-report",
|
||||
data: {
|
||||
year: year
|
||||
? Extension.ToThaiNumber(year.toString())
|
||||
: Extension.ToThaiNumber(new Date().getFullYear().toString()),
|
||||
date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())),
|
||||
mainAgency:
|
||||
rootId && result.length > 0
|
||||
? result[0].agency
|
||||
: rootId && result.length === 0
|
||||
? ""
|
||||
: "หน่วยงานทั้งหมด",
|
||||
list: result,
|
||||
total: Extension.ToThaiNumber(submitter.toString()),
|
||||
sumPass: Extension.ToThaiNumber(sumPass.toString()),
|
||||
sumNotPass: Extension.ToThaiNumber(sumNotPass.toString()),
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,310 +153,318 @@ export class ReoportController {
|
|||
*/
|
||||
@Get("check-spec-report/{id}")
|
||||
async checkSpecGetReport(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
const evaluation = await AppDataSource.getRepository(Evaluation)
|
||||
.createQueryBuilder("evaluation")
|
||||
.leftJoin("evaluation.education", "education")
|
||||
.leftJoin("evaluation.certificate", "certificate")
|
||||
.leftJoin("evaluation.salaries", "salaries")
|
||||
.leftJoin("evaluation.training", "training")
|
||||
.leftJoin("evaluation.assessment", "assessment")
|
||||
.where("evaluation.id = :id", { id })
|
||||
.select([
|
||||
"evaluation.id",
|
||||
"evaluation.userId",
|
||||
"evaluation.subject",
|
||||
"evaluation.isEducationalQft",
|
||||
"evaluation.isGovermantServiceHtr",
|
||||
"evaluation.isOperatingExp",
|
||||
"evaluation.isMinPeriodOfTenure",
|
||||
"evaluation.isHaveSpecificQft",
|
||||
"evaluation.isHaveProLicense",
|
||||
"evaluation.isHaveMinPeriodOrHoldPos",
|
||||
"evaluation.type",
|
||||
"evaluation.prefix",
|
||||
"evaluation.fullName",
|
||||
"evaluation.position",
|
||||
"evaluation.posNo",
|
||||
"evaluation.oc",
|
||||
"evaluation.salary",
|
||||
"evaluation.positionLevel",
|
||||
"evaluation.birthDate",
|
||||
"evaluation.govAge",
|
||||
"evaluation.experience",
|
||||
try {
|
||||
const evaluation = await AppDataSource.getRepository(Evaluation)
|
||||
.createQueryBuilder("evaluation")
|
||||
.leftJoin("evaluation.education", "education")
|
||||
.leftJoin("evaluation.certificate", "certificate")
|
||||
.leftJoin("evaluation.salaries", "salaries")
|
||||
.leftJoin("evaluation.training", "training")
|
||||
.leftJoin("evaluation.assessment", "assessment")
|
||||
.where("evaluation.id = :id", { id })
|
||||
.select([
|
||||
"evaluation.id",
|
||||
"evaluation.userId",
|
||||
"evaluation.subject",
|
||||
"evaluation.isEducationalQft",
|
||||
"evaluation.isGovermantServiceHtr",
|
||||
"evaluation.isOperatingExp",
|
||||
"evaluation.isMinPeriodOfTenure",
|
||||
"evaluation.isHaveSpecificQft",
|
||||
"evaluation.isHaveProLicense",
|
||||
"evaluation.isHaveMinPeriodOrHoldPos",
|
||||
"evaluation.type",
|
||||
"evaluation.prefix",
|
||||
"evaluation.fullName",
|
||||
"evaluation.position",
|
||||
"evaluation.posNo",
|
||||
"evaluation.oc",
|
||||
"evaluation.salary",
|
||||
"evaluation.positionLevel",
|
||||
"evaluation.birthDate",
|
||||
"evaluation.govAge",
|
||||
"evaluation.experience",
|
||||
|
||||
"education.educationLevel",
|
||||
"education.institute",
|
||||
"education.isDate",
|
||||
"education.startDate",
|
||||
"education.endDate",
|
||||
"education.finishDate",
|
||||
"education.isEducation",
|
||||
"education.degree",
|
||||
"education.field",
|
||||
"education.fundName",
|
||||
"education.gpa",
|
||||
"education.country",
|
||||
"education.other",
|
||||
"education.duration",
|
||||
"education.durationYear",
|
||||
"education.educationLevel",
|
||||
"education.institute",
|
||||
"education.isDate",
|
||||
"education.startDate",
|
||||
"education.endDate",
|
||||
"education.finishDate",
|
||||
"education.isEducation",
|
||||
"education.degree",
|
||||
"education.field",
|
||||
"education.fundName",
|
||||
"education.gpa",
|
||||
"education.country",
|
||||
"education.other",
|
||||
"education.duration",
|
||||
"education.durationYear",
|
||||
|
||||
"certificate.certificateType",
|
||||
"certificate.issuer",
|
||||
"certificate.certificateNo",
|
||||
"certificate.issueDate",
|
||||
"certificate.expireDate",
|
||||
"certificate.certificateType",
|
||||
"certificate.issuer",
|
||||
"certificate.certificateNo",
|
||||
"certificate.issueDate",
|
||||
"certificate.expireDate",
|
||||
|
||||
"salaries.date",
|
||||
"salaries.amount",
|
||||
"salaries.positionSalaryAmount",
|
||||
"salaries.mouthSalaryAmount",
|
||||
"salaries.position",
|
||||
"salaries.posNo",
|
||||
"salaries.salaryClass",
|
||||
"salaries.salaryRef",
|
||||
"salaries.refCommandNo",
|
||||
"salaries.refCommandDate",
|
||||
"salaries.salaryStatus",
|
||||
"salaries.date",
|
||||
"salaries.amount",
|
||||
"salaries.positionSalaryAmount",
|
||||
"salaries.mouthSalaryAmount",
|
||||
"salaries.position",
|
||||
"salaries.posNo",
|
||||
"salaries.salaryClass",
|
||||
"salaries.salaryRef",
|
||||
"salaries.refCommandNo",
|
||||
"salaries.refCommandDate",
|
||||
"salaries.salaryStatus",
|
||||
|
||||
"training.name",
|
||||
"training.topic",
|
||||
"training.startDate",
|
||||
"training.endDate",
|
||||
"training.yearly",
|
||||
"training.place",
|
||||
"training.duration",
|
||||
"training.department",
|
||||
"training.numberOrder",
|
||||
"training.dateOrder",
|
||||
"training.name",
|
||||
"training.topic",
|
||||
"training.startDate",
|
||||
"training.endDate",
|
||||
"training.yearly",
|
||||
"training.place",
|
||||
"training.duration",
|
||||
"training.department",
|
||||
"training.numberOrder",
|
||||
"training.dateOrder",
|
||||
|
||||
"assessment.date",
|
||||
"assessment.point1Total",
|
||||
"assessment.point1",
|
||||
"assessment.point2Total",
|
||||
"assessment.point2",
|
||||
"assessment.pointSumTotal",
|
||||
"assessment.pointSum",
|
||||
])
|
||||
.getOne();
|
||||
"assessment.date",
|
||||
"assessment.point1Total",
|
||||
"assessment.point1",
|
||||
"assessment.point2Total",
|
||||
"assessment.point2",
|
||||
"assessment.pointSumTotal",
|
||||
"assessment.pointSum",
|
||||
])
|
||||
.getOne();
|
||||
|
||||
if (!evaluation) {
|
||||
return "ไม่พบข้อมูล";
|
||||
}
|
||||
let root: any;
|
||||
let dateStart: any;
|
||||
let dateRetireLaw: any;
|
||||
let org: any;
|
||||
let commanderFullname: any;
|
||||
let commanderPosition: any;
|
||||
let commanderRootName: any;
|
||||
let commanderOrg: any;
|
||||
let commanderAboveFullname: any;
|
||||
let commanderAbovePosition: any;
|
||||
let commanderAboveRootName: any;
|
||||
let commanderAboveOrg: any;
|
||||
if (!evaluation.userId) {
|
||||
return "ไม่พบข้อมูลผู้ขอประเมิน";
|
||||
}
|
||||
await new CallAPI()
|
||||
.GetData(request, `/org/profile/keycloak/commander/${evaluation.userId}`)
|
||||
.then(async (x) => {
|
||||
(root = x.root),
|
||||
(dateStart = x.dateStart),
|
||||
(dateRetireLaw = x.dateRetireLaw),
|
||||
(org = x.org),
|
||||
(commanderFullname = x.commanderFullname),
|
||||
(commanderPosition = x.commanderPosition),
|
||||
(commanderRootName = x.commanderRootName),
|
||||
(commanderOrg = x.commanderOrg),
|
||||
(commanderAboveFullname = x.commanderAboveFullname),
|
||||
(commanderAbovePosition = x.commanderAbovePosition),
|
||||
(commanderAboveRootName = x.commanderAboveRootName),
|
||||
(commanderAboveOrg = x.commanderAboveOrg);
|
||||
})
|
||||
.catch();
|
||||
const evaluationOld = await this.evaluationRepository.find({
|
||||
where: {
|
||||
id: Not(id),
|
||||
userId: evaluation.userId,
|
||||
step: "DONE",
|
||||
},
|
||||
});
|
||||
let subjectOld =
|
||||
evaluationOld.length > 0 ? evaluationOld.map((x) => x.subject).join(", ") : "ไม่มี";
|
||||
let thaiYear: number = new Date().getFullYear() + 543;
|
||||
let years = {
|
||||
lastTwoYear: Extension.ToThaiNumber((thaiYear - 2).toString()),
|
||||
lastOneYear: Extension.ToThaiNumber((thaiYear - 1).toString()),
|
||||
currentYear: Extension.ToThaiNumber(thaiYear.toString()),
|
||||
};
|
||||
const dataEvaluation = {
|
||||
isEducationalQft: evaluation.isEducationalQft,
|
||||
isGovermantServiceHtr: evaluation.isGovermantServiceHtr,
|
||||
isOperatingExp: evaluation.isOperatingExp,
|
||||
isMinPeriodOfTenure: evaluation.isMinPeriodOfTenure,
|
||||
isHaveSpecificQft: evaluation.isHaveSpecificQft,
|
||||
isHaveProLicense: evaluation.isHaveProLicense,
|
||||
isHaveMinPeriodOrHoldPos: evaluation.isHaveMinPeriodOrHoldPos,
|
||||
type: evaluation.type,
|
||||
prefix: evaluation.prefix,
|
||||
fullName: evaluation.fullName ? `${evaluation.fullName}` : "-",
|
||||
position: evaluation.position ? evaluation.position : "-",
|
||||
posNo: evaluation.posNo ? Extension.ToThaiNumber(evaluation.posNo) : "-",
|
||||
oc: evaluation.oc ? evaluation.oc : "-",
|
||||
org: org ? org : "-", //สังกัด
|
||||
root: root ? root : "-", //หน่วยงาน
|
||||
salary: evaluation.salary ? Extension.ToThaiNumber(evaluation.salary) : "-",
|
||||
positionLevel: evaluation.positionLevel ? evaluation.positionLevel : "-",
|
||||
birthDate:
|
||||
evaluation.birthDate != null && evaluation.birthDate != ""
|
||||
? Extension.ToThaiNumber(
|
||||
Extension.ToThaiShortDate_noPrefix(new Date(evaluation.birthDate)),
|
||||
)
|
||||
if (!evaluation) {
|
||||
return "ไม่พบข้อมูล";
|
||||
}
|
||||
let root: any;
|
||||
let dateStart: any;
|
||||
let dateRetireLaw: any;
|
||||
let org: any;
|
||||
let commanderFullname: any;
|
||||
let commanderPosition: any;
|
||||
let commanderRootName: any;
|
||||
let commanderOrg: any;
|
||||
let commanderAboveFullname: any;
|
||||
let commanderAbovePosition: any;
|
||||
let commanderAboveRootName: any;
|
||||
let commanderAboveOrg: any;
|
||||
if (!evaluation.userId) {
|
||||
return "ไม่พบข้อมูลผู้ขอประเมิน";
|
||||
}
|
||||
await new CallAPI()
|
||||
.GetData(request, `/org/profile/keycloak/commander/${evaluation.userId}`)
|
||||
.then(async (x) => {
|
||||
(root = x.root),
|
||||
(dateStart = x.dateStart),
|
||||
(dateRetireLaw = x.dateRetireLaw),
|
||||
(org = x.org),
|
||||
(commanderFullname = x.commanderFullname),
|
||||
(commanderPosition = x.commanderPosition),
|
||||
(commanderRootName = x.commanderRootName),
|
||||
(commanderOrg = x.commanderOrg),
|
||||
(commanderAboveFullname = x.commanderAboveFullname),
|
||||
(commanderAbovePosition = x.commanderAbovePosition),
|
||||
(commanderAboveRootName = x.commanderAboveRootName),
|
||||
(commanderAboveOrg = x.commanderAboveOrg);
|
||||
})
|
||||
.catch();
|
||||
const evaluationOld = await this.evaluationRepository.find({
|
||||
where: {
|
||||
id: Not(id),
|
||||
userId: evaluation.userId,
|
||||
step: "DONE",
|
||||
},
|
||||
});
|
||||
let subjectOld =
|
||||
evaluationOld.length > 0 ? evaluationOld.map((x) => x.subject).join(", ") : "ไม่มี";
|
||||
let thaiYear: number = new Date().getFullYear() + 543;
|
||||
let years = {
|
||||
lastTwoYear: Extension.ToThaiNumber((thaiYear - 2).toString()),
|
||||
lastOneYear: Extension.ToThaiNumber((thaiYear - 1).toString()),
|
||||
currentYear: Extension.ToThaiNumber(thaiYear.toString()),
|
||||
};
|
||||
const dataEvaluation = {
|
||||
isEducationalQft: evaluation.isEducationalQft,
|
||||
isGovermantServiceHtr: evaluation.isGovermantServiceHtr,
|
||||
isOperatingExp: evaluation.isOperatingExp,
|
||||
isMinPeriodOfTenure: evaluation.isMinPeriodOfTenure,
|
||||
isHaveSpecificQft: evaluation.isHaveSpecificQft,
|
||||
isHaveProLicense: evaluation.isHaveProLicense,
|
||||
isHaveMinPeriodOrHoldPos: evaluation.isHaveMinPeriodOrHoldPos,
|
||||
type: evaluation.type,
|
||||
prefix: evaluation.prefix,
|
||||
fullName: evaluation.fullName ? `${evaluation.fullName}` : "-",
|
||||
position: evaluation.position ? evaluation.position : "-",
|
||||
posNo: evaluation.posNo ? Extension.ToThaiNumber(evaluation.posNo) : "-",
|
||||
oc: evaluation.oc ? evaluation.oc : "-",
|
||||
org: org ? org : "-", //สังกัด
|
||||
root: root ? root : "-", //หน่วยงาน
|
||||
salary: evaluation.salary ? Extension.ToThaiNumber(evaluation.salary) : "-",
|
||||
positionLevel: evaluation.positionLevel ? evaluation.positionLevel : "-",
|
||||
birthDate:
|
||||
evaluation.birthDate != null && evaluation.birthDate != ""
|
||||
? Extension.ToThaiNumber(
|
||||
Extension.ToThaiShortDate_noPrefix(new Date(evaluation.birthDate)),
|
||||
)
|
||||
: "-",
|
||||
govAge: evaluation.govAge != null ? Extension.ToThaiNumber(evaluation.govAge) : "-",
|
||||
experience: evaluation.experience ? evaluation.experience : "-",
|
||||
dateStart: dateStart
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date(dateStart)))
|
||||
: "-",
|
||||
govAge: evaluation.govAge != null ? Extension.ToThaiNumber(evaluation.govAge) : "-",
|
||||
experience: evaluation.experience ? evaluation.experience : "-",
|
||||
dateStart: dateStart
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date(dateStart)))
|
||||
: "-",
|
||||
dateRetireLaw: dateRetireLaw
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date(dateRetireLaw)))
|
||||
: "-",
|
||||
subject: evaluation.subject != null ? evaluation.subject : "-",
|
||||
subjectOld: subjectOld,
|
||||
educations:
|
||||
evaluation.education.length > 0
|
||||
? evaluation.education.map((education) => ({
|
||||
educationLevel: education.educationLevel
|
||||
? Extension.ToThaiNumber(education.educationLevel)
|
||||
: "-",
|
||||
institute: education.institute ? Extension.ToThaiNumber(education.institute) : "-",
|
||||
finishYear: education.finishDate
|
||||
? Extension.ToThaiNumber(
|
||||
Extension.ToThaiYear(education.finishDate.getFullYear()).toString(),
|
||||
)
|
||||
: "-",
|
||||
isDate: education.isDate,
|
||||
startDate: education.startDate,
|
||||
endDate: education.endDate,
|
||||
finishDate: education.finishDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate(education.finishDate).toString())
|
||||
: "-",
|
||||
isEducation: education.isEducation,
|
||||
degree: education.degree ? Extension.ToThaiNumber(education.degree) : "-",
|
||||
field: education.field ? Extension.ToThaiNumber(education.field) : "-",
|
||||
fundName: education.fundName,
|
||||
gpa: education.gpa,
|
||||
country: education.country,
|
||||
other: education.other,
|
||||
duration: education.duration,
|
||||
durationYear: education.durationYear,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
educationLevel: "-",
|
||||
institute: "-",
|
||||
finishYear: "-",
|
||||
finishDate: "-",
|
||||
degree: "-",
|
||||
field: "-",
|
||||
},
|
||||
],
|
||||
certificates:
|
||||
evaluation.certificate.length > 0
|
||||
? evaluation.certificate.map((certificate) => ({
|
||||
certificateType: certificate.certificateType
|
||||
? Extension.ToThaiNumber(certificate.certificateType)
|
||||
: "-",
|
||||
issuer: certificate.issuer ? Extension.ToThaiNumber(certificate.issuer) : "-",
|
||||
certificateNo: certificate.certificateNo
|
||||
? Extension.ToThaiNumber(certificate.certificateNo)
|
||||
: "-",
|
||||
issueDate: certificate.issueDate,
|
||||
expireDate: certificate.expireDate,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
certificateType: "-",
|
||||
issuer: "-",
|
||||
certificateNo: "-",
|
||||
issueDate: "-",
|
||||
expireDate: "-",
|
||||
},
|
||||
],
|
||||
salaries:
|
||||
evaluation.salaries.length > 0
|
||||
? evaluation.salaries.map((salaries) => ({
|
||||
date: salaries.date
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(salaries.date))
|
||||
: "-",
|
||||
amount: salaries.amount
|
||||
? Extension.ToThaiNumber(salaries.amount.toLocaleString())
|
||||
: "-",
|
||||
position: salaries.position ? Extension.ToThaiNumber(salaries.position) : "-",
|
||||
positionSalaryAmount: salaries.positionSalaryAmount,
|
||||
mouthSalaryAmount: salaries.mouthSalaryAmount,
|
||||
posNo: salaries.posNo,
|
||||
salaryClass: salaries.salaryClass,
|
||||
salaryRef: salaries.salaryRef,
|
||||
refCommandNo: salaries.refCommandNo,
|
||||
refCommandDate: salaries.refCommandDate,
|
||||
salaryStatus: salaries.salaryStatus,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
date: "-",
|
||||
amount: "-",
|
||||
position: "-",
|
||||
},
|
||||
],
|
||||
trainings:
|
||||
evaluation.training.length > 0
|
||||
? evaluation.training.map((training) => ({
|
||||
name: training.name ? Extension.ToThaiNumber(training.name) : "-",
|
||||
topic: training.topic ? Extension.ToThaiNumber(training.topic) : "-",
|
||||
startDate: training.startDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(training.startDate))
|
||||
: "-",
|
||||
endDate: training.endDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(training.endDate))
|
||||
: "-",
|
||||
yearly: training.yearly ? Extension.ToThaiNumber(training.yearly.toString()) : "-",
|
||||
place: training.place,
|
||||
duration: training.duration,
|
||||
department: training.department,
|
||||
numberOrder: training.numberOrder,
|
||||
dateOrder: training.dateOrder,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
name: "-",
|
||||
topic: "-",
|
||||
yearly: "-",
|
||||
},
|
||||
],
|
||||
assessments: evaluation.assessment.map((assessment) => ({
|
||||
date: assessment.date,
|
||||
point1Total: assessment.point1Total,
|
||||
point1: assessment.point1,
|
||||
point2Total: assessment.point2Total,
|
||||
point2: assessment.point2,
|
||||
pointSumTotal: assessment.pointSumTotal,
|
||||
pointSum: assessment.pointSum,
|
||||
})),
|
||||
commanderFullname: commanderFullname ? commanderFullname : "-",
|
||||
commanderPosition: commanderPosition ? commanderPosition : "-",
|
||||
commanderRootName: commanderRootName ? commanderRootName : "-",
|
||||
commanderOrg: commanderOrg ? commanderOrg : "-",
|
||||
commanderAboveFullname: commanderAboveFullname ? commanderAboveFullname : "-",
|
||||
commanderAbovePosition: commanderAbovePosition ? commanderAbovePosition : "-",
|
||||
commanderAboveRootName: commanderAboveRootName ? commanderAboveRootName : "-",
|
||||
commanderAboveOrg: commanderAboveOrg ? commanderAboveOrg : "-",
|
||||
years: years,
|
||||
};
|
||||
dateRetireLaw: dateRetireLaw
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date(dateRetireLaw)))
|
||||
: "-",
|
||||
subject: evaluation.subject != null ? evaluation.subject : "-",
|
||||
subjectOld: subjectOld,
|
||||
educations:
|
||||
evaluation.education.length > 0
|
||||
? evaluation.education.map((education) => ({
|
||||
educationLevel: education.educationLevel
|
||||
? Extension.ToThaiNumber(education.educationLevel)
|
||||
: "-",
|
||||
institute: education.institute ? Extension.ToThaiNumber(education.institute) : "-",
|
||||
finishYear: education.finishDate
|
||||
? Extension.ToThaiNumber(
|
||||
Extension.ToThaiYear(education.finishDate.getFullYear()).toString(),
|
||||
)
|
||||
: "-",
|
||||
isDate: education.isDate,
|
||||
startDate: education.startDate,
|
||||
endDate: education.endDate,
|
||||
finishDate: education.finishDate
|
||||
? Extension.ToThaiNumber(
|
||||
Extension.ToThaiShortDate(education.finishDate).toString(),
|
||||
)
|
||||
: "-",
|
||||
isEducation: education.isEducation,
|
||||
degree: education.degree ? Extension.ToThaiNumber(education.degree) : "-",
|
||||
field: education.field ? Extension.ToThaiNumber(education.field) : "-",
|
||||
fundName: education.fundName,
|
||||
gpa: education.gpa,
|
||||
country: education.country,
|
||||
other: education.other,
|
||||
duration: education.duration,
|
||||
durationYear: education.durationYear,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
educationLevel: "-",
|
||||
institute: "-",
|
||||
finishYear: "-",
|
||||
finishDate: "-",
|
||||
degree: "-",
|
||||
field: "-",
|
||||
},
|
||||
],
|
||||
certificates:
|
||||
evaluation.certificate.length > 0
|
||||
? evaluation.certificate.map((certificate) => ({
|
||||
certificateType: certificate.certificateType
|
||||
? Extension.ToThaiNumber(certificate.certificateType)
|
||||
: "-",
|
||||
issuer: certificate.issuer ? Extension.ToThaiNumber(certificate.issuer) : "-",
|
||||
certificateNo: certificate.certificateNo
|
||||
? Extension.ToThaiNumber(certificate.certificateNo)
|
||||
: "-",
|
||||
issueDate: certificate.issueDate,
|
||||
expireDate: certificate.expireDate,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
certificateType: "-",
|
||||
issuer: "-",
|
||||
certificateNo: "-",
|
||||
issueDate: "-",
|
||||
expireDate: "-",
|
||||
},
|
||||
],
|
||||
salaries:
|
||||
evaluation.salaries.length > 0
|
||||
? evaluation.salaries.map((salaries) => ({
|
||||
date: salaries.date
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(salaries.date))
|
||||
: "-",
|
||||
amount: salaries.amount
|
||||
? Extension.ToThaiNumber(salaries.amount.toLocaleString())
|
||||
: "-",
|
||||
position: salaries.position ? Extension.ToThaiNumber(salaries.position) : "-",
|
||||
positionSalaryAmount: salaries.positionSalaryAmount,
|
||||
mouthSalaryAmount: salaries.mouthSalaryAmount,
|
||||
posNo: salaries.posNo,
|
||||
salaryClass: salaries.salaryClass,
|
||||
salaryRef: salaries.salaryRef,
|
||||
refCommandNo: salaries.refCommandNo,
|
||||
refCommandDate: salaries.refCommandDate,
|
||||
salaryStatus: salaries.salaryStatus,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
date: "-",
|
||||
amount: "-",
|
||||
position: "-",
|
||||
},
|
||||
],
|
||||
trainings:
|
||||
evaluation.training.length > 0
|
||||
? evaluation.training.map((training) => ({
|
||||
name: training.name ? Extension.ToThaiNumber(training.name) : "-",
|
||||
topic: training.topic ? Extension.ToThaiNumber(training.topic) : "-",
|
||||
startDate: training.startDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(training.startDate))
|
||||
: "-",
|
||||
endDate: training.endDate
|
||||
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(training.endDate))
|
||||
: "-",
|
||||
yearly: training.yearly ? Extension.ToThaiNumber(training.yearly.toString()) : "-",
|
||||
place: training.place,
|
||||
duration: training.duration,
|
||||
department: training.department,
|
||||
numberOrder: training.numberOrder,
|
||||
dateOrder: training.dateOrder,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
name: "-",
|
||||
topic: "-",
|
||||
yearly: "-",
|
||||
},
|
||||
],
|
||||
assessments: evaluation.assessment.map((assessment) => ({
|
||||
date: assessment.date,
|
||||
point1Total: assessment.point1Total,
|
||||
point1: assessment.point1,
|
||||
point2Total: assessment.point2Total,
|
||||
point2: assessment.point2,
|
||||
pointSumTotal: assessment.pointSumTotal,
|
||||
pointSum: assessment.pointSum,
|
||||
})),
|
||||
commanderFullname: commanderFullname ? commanderFullname : "-",
|
||||
commanderPosition: commanderPosition ? commanderPosition : "-",
|
||||
commanderRootName: commanderRootName ? commanderRootName : "-",
|
||||
commanderOrg: commanderOrg ? commanderOrg : "-",
|
||||
commanderAboveFullname: commanderAboveFullname ? commanderAboveFullname : "-",
|
||||
commanderAbovePosition: commanderAbovePosition ? commanderAbovePosition : "-",
|
||||
commanderAboveRootName: commanderAboveRootName ? commanderAboveRootName : "-",
|
||||
commanderAboveOrg: commanderAboveOrg ? commanderAboveOrg : "-",
|
||||
years: years,
|
||||
};
|
||||
|
||||
if (!dataEvaluation) {
|
||||
return "ไม่พบข้อมูล";
|
||||
if (!dataEvaluation) {
|
||||
return "ไม่พบข้อมูล";
|
||||
}
|
||||
return new HttpSuccess(dataEvaluation);
|
||||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
}
|
||||
return new HttpSuccess(dataEvaluation);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue