fixing \n field organization
This commit is contained in:
parent
5e827d4060
commit
a38adb9598
1 changed files with 37 additions and 103 deletions
|
|
@ -27,7 +27,7 @@ import { Brackets } from "typeorm";
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
@Response(
|
@Response(
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
)
|
)
|
||||||
export class PersonalController extends Controller {
|
export class PersonalController extends Controller {
|
||||||
private personalRepository = AppDataSource.getRepository(Personal);
|
private personalRepository = AppDataSource.getRepository(Personal);
|
||||||
|
|
@ -40,10 +40,7 @@ export class PersonalController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("add")
|
@Post("add")
|
||||||
async AddPersonal(
|
async AddPersonal(@Body() requestBody: PostPersonal, @Request() request: RequestWithUser) {
|
||||||
@Body() requestBody: PostPersonal,
|
|
||||||
@Request() request: RequestWithUser
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
||||||
|
|
||||||
|
|
@ -53,31 +50,19 @@ export class PersonalController extends Controller {
|
||||||
if (checkPersonal > 0) {
|
if (checkPersonal > 0) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatusCode.BAD_REQUEST,
|
HttpStatusCode.BAD_REQUEST,
|
||||||
"ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว"
|
"ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let organization = await (requestBody.orgChild4Name
|
let organization = await (requestBody.orgChild4Name ? requestBody.orgChild4Name + "\n" : "");
|
||||||
? requestBody.orgChild4Name + " "
|
organization += await (requestBody.orgChild3Name ? requestBody.orgChild3Name + "\n" : "");
|
||||||
: "");
|
organization += await (requestBody.orgChild2Name ? requestBody.orgChild2Name + "\n" : "");
|
||||||
organization += await (requestBody.orgChild3Name
|
organization += await (requestBody.orgChild1Name ? requestBody.orgChild1Name + "\n" : "");
|
||||||
? requestBody.orgChild3Name + " "
|
organization += await (requestBody.orgRootName ? requestBody.orgRootName : "");
|
||||||
: "");
|
|
||||||
organization += await (requestBody.orgChild2Name
|
|
||||||
? requestBody.orgChild2Name + " "
|
|
||||||
: "");
|
|
||||||
organization += await (requestBody.orgChild1Name
|
|
||||||
? requestBody.orgChild1Name + " "
|
|
||||||
: "");
|
|
||||||
organization += await (requestBody.orgRootName
|
|
||||||
? requestBody.orgRootName
|
|
||||||
: "");
|
|
||||||
|
|
||||||
const personalData = Object.assign(new Personal());
|
const personalData = Object.assign(new Personal());
|
||||||
personalData.personal_id = requestBody.id;
|
personalData.personal_id = requestBody.id;
|
||||||
personalData.order_number = requestBody.order_number
|
personalData.order_number = requestBody.order_number ? requestBody.order_number : "";
|
||||||
? requestBody.order_number
|
|
||||||
: "";
|
|
||||||
personalData.probation_status = 1;
|
personalData.probation_status = 1;
|
||||||
personalData.createdUserId = request.user.sub;
|
personalData.createdUserId = request.user.sub;
|
||||||
personalData.createdFullName = request.user.name;
|
personalData.createdFullName = request.user.name;
|
||||||
|
|
@ -89,12 +74,8 @@ export class PersonalController extends Controller {
|
||||||
personalData.firstName = requestBody.firstName;
|
personalData.firstName = requestBody.firstName;
|
||||||
personalData.lastName = requestBody.lastName;
|
personalData.lastName = requestBody.lastName;
|
||||||
personalData.isProbation = requestBody.isProbation ? 1 : 0;
|
personalData.isProbation = requestBody.isProbation ? 1 : 0;
|
||||||
personalData.positionLevelName = requestBody.posLevelName
|
personalData.positionLevelName = requestBody.posLevelName ? requestBody.posLevelName : "";
|
||||||
? requestBody.posLevelName
|
personalData.positionName = requestBody.position ? requestBody.position : "";
|
||||||
: "";
|
|
||||||
personalData.positionName = requestBody.position
|
|
||||||
? requestBody.position
|
|
||||||
: "";
|
|
||||||
personalData.positionLineName = requestBody.posLineName;
|
personalData.positionLineName = requestBody.posLineName;
|
||||||
personalData.positionTypeName = requestBody.posTypeName;
|
personalData.positionTypeName = requestBody.posTypeName;
|
||||||
personalData.posNo = requestBody.posNo ? requestBody.posNo : "";
|
personalData.posNo = requestBody.posNo ? requestBody.posNo : "";
|
||||||
|
|
@ -139,57 +120,34 @@ export class PersonalController extends Controller {
|
||||||
@Query() keyword: string = "",
|
@Query() keyword: string = "",
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Request() request: RequestWithUser
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
await new permission().PermissionList(request, "SYS_PROBATION");
|
await new permission().PermissionList(request, "SYS_PROBATION");
|
||||||
const _data = await new permission().PermissionOrgList(
|
const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION");
|
||||||
request,
|
|
||||||
"SYS_PROBATION"
|
|
||||||
);
|
|
||||||
|
|
||||||
const conditions: any = {};
|
const conditions: any = {};
|
||||||
if (status) {
|
if (status) {
|
||||||
conditions.probation_status = status;
|
conditions.probation_status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (_data.root != undefined && _data.root != null && _data.root[0] != null) {
|
||||||
_data.root != undefined &&
|
|
||||||
_data.root != null &&
|
|
||||||
_data.root[0] != null
|
|
||||||
) {
|
|
||||||
conditions.root = _data.root;
|
conditions.root = _data.root;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) {
|
||||||
_data.child1 != undefined &&
|
|
||||||
_data.child1 != null &&
|
|
||||||
_data.child1[0] != null
|
|
||||||
) {
|
|
||||||
conditions.child1 = _data.child1;
|
conditions.child1 = _data.child1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) {
|
||||||
_data.child2 != undefined &&
|
|
||||||
_data.child2 != null &&
|
|
||||||
_data.child2[0] != null
|
|
||||||
) {
|
|
||||||
conditions.child2 = _data.child2;
|
conditions.child2 = _data.child2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) {
|
||||||
_data.child3 != undefined &&
|
|
||||||
_data.child3 != null &&
|
|
||||||
_data.child3[0] != null
|
|
||||||
) {
|
|
||||||
conditions.child3 = _data.child3;
|
conditions.child3 = _data.child3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) {
|
||||||
_data.child4 != undefined &&
|
|
||||||
_data.child4 != null &&
|
|
||||||
_data.child4[0] != null
|
|
||||||
) {
|
|
||||||
conditions.child4 = _data.child4;
|
conditions.child4 = _data.child4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,33 +164,21 @@ export class PersonalController extends Controller {
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
keyword: `%${searchKeyword}%`,
|
keyword: `%${searchKeyword}%`,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
qb.orWhere(
|
qb.orWhere(searchKeyword ? `positionName like '%${keyword}%'` : "1=1", {
|
||||||
searchKeyword ? `positionName like '%${keyword}%'` : "1=1",
|
keyword: `%${searchKeyword}%`,
|
||||||
{
|
});
|
||||||
keyword: `%${searchKeyword}%`,
|
qb.orWhere(searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1", {
|
||||||
}
|
keyword: `%${searchKeyword}%`,
|
||||||
);
|
});
|
||||||
qb.orWhere(
|
qb.orWhere(searchKeyword ? `organization like '%${keyword}%'` : "1=1", {
|
||||||
searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1",
|
keyword: `%${searchKeyword}%`,
|
||||||
{
|
});
|
||||||
keyword: `%${searchKeyword}%`,
|
qb.orWhere(searchKeyword ? `order_number like '%${keyword}%'` : "1=1", {
|
||||||
}
|
keyword: `%${searchKeyword}%`,
|
||||||
);
|
});
|
||||||
qb.orWhere(
|
}),
|
||||||
searchKeyword ? `organization like '%${keyword}%'` : "1=1",
|
|
||||||
{
|
|
||||||
keyword: `%${searchKeyword}%`,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
qb.orWhere(
|
|
||||||
searchKeyword ? `order_number like '%${keyword}%'` : "1=1",
|
|
||||||
{
|
|
||||||
keyword: `%${searchKeyword}%`,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
.orderBy("updatedAt", "DESC")
|
.orderBy("updatedAt", "DESC")
|
||||||
.skip((page - 1) * pageSize)
|
.skip((page - 1) * pageSize)
|
||||||
|
|
@ -240,10 +186,7 @@ export class PersonalController extends Controller {
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
||||||
if (!lists) {
|
if (!lists) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้");
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
||||||
"ไม่สามารถแสดงข้อมูลได้"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let result: any = [];
|
let result: any = [];
|
||||||
|
|
@ -256,8 +199,7 @@ export class PersonalController extends Controller {
|
||||||
await result.push({
|
await result.push({
|
||||||
personal_id: lists[i].personal_id,
|
personal_id: lists[i].personal_id,
|
||||||
ordering: i + 1,
|
ordering: i + 1,
|
||||||
name:
|
name: lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
|
||||||
lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
|
|
||||||
prefixName: lists[i].prefixName,
|
prefixName: lists[i].prefixName,
|
||||||
firstName: lists[i].firstName,
|
firstName: lists[i].firstName,
|
||||||
lastName: lists[i].lastName,
|
lastName: lists[i].lastName,
|
||||||
|
|
@ -313,18 +255,10 @@ export class PersonalController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("")
|
@Get("")
|
||||||
async GetPersonal(
|
async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) {
|
||||||
@Request() request: RequestWithUser,
|
|
||||||
@Query() personal_id: string
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
let _workflow = await new permission().Workflow(
|
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION");
|
||||||
request,
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
personal_id,
|
|
||||||
"SYS_PROBATION"
|
|
||||||
);
|
|
||||||
if (_workflow == false)
|
|
||||||
await new permission().PermissionGet(request, "SYS_PROBATION");
|
|
||||||
const person = await this.personalRepository.findOne({
|
const person = await this.personalRepository.findOne({
|
||||||
where: { personal_id: personal_id },
|
where: { personal_id: personal_id },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue