remove try catch more
This commit is contained in:
parent
09cc93fdf8
commit
7531a9c582
9 changed files with 477 additions and 680 deletions
|
|
@ -67,10 +67,7 @@ export class ProfileController extends Controller {
|
|||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
if (!checkPosLevel) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลระดับตำแหน่งนี้"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,10 +79,7 @@ export class ProfileController extends Controller {
|
|||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
if (!checkPosType) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลประเภทตำแหน่งนี้"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,17 +94,13 @@ export class ProfileController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const profile = Object.assign(new Profile(), requestBody);
|
||||
profile.createdUserId = request.user.sub;
|
||||
profile.createdFullName = request.user.name;
|
||||
profile.lastUpdateUserId = request.user.sub;
|
||||
profile.lastUpdateFullName = request.user.name;
|
||||
await this.profileRepository.save(profile);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
const profile = Object.assign(new Profile(), requestBody);
|
||||
profile.createdUserId = request.user.sub;
|
||||
profile.createdFullName = request.user.name;
|
||||
profile.lastUpdateUserId = request.user.sub;
|
||||
profile.lastUpdateFullName = request.user.name;
|
||||
await this.profileRepository.save(profile);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -147,10 +137,7 @@ export class ProfileController extends Controller {
|
|||
where: { id: requestBody.posLevelId },
|
||||
});
|
||||
if (!checkPosLevel) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลระดับตำแหน่งนี้"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -162,10 +149,7 @@ export class ProfileController extends Controller {
|
|||
where: { id: requestBody.posTypeId },
|
||||
});
|
||||
if (!checkPosType) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลประเภทตำแหน่งนี้"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -183,15 +167,11 @@ export class ProfileController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
try {
|
||||
profile.lastUpdateUserId = request.user.sub;
|
||||
profile.lastUpdateFullName = request.user.name;
|
||||
this.profileRepository.merge(profile, requestBody);
|
||||
await this.profileRepository.save(profile);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
profile.lastUpdateUserId = request.user.sub;
|
||||
profile.lastUpdateFullName = request.user.name;
|
||||
this.profileRepository.merge(profile, requestBody);
|
||||
await this.profileRepository.save(profile);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -209,12 +189,8 @@ export class ProfileController extends Controller {
|
|||
if (!delProfile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
|
||||
}
|
||||
try {
|
||||
await this.profileRepository.delete({ id: id });
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
await this.profileRepository.delete({ id: id });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -242,11 +218,7 @@ export class ProfileController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(profile);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
return new HttpSuccess(profile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -334,108 +306,104 @@ export class ProfileController extends Controller {
|
|||
keyword?: string;
|
||||
},
|
||||
) {
|
||||
try {
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: {
|
||||
orgRevisionIsDraft: true,
|
||||
orgRevisionIsCurrent: false,
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: {
|
||||
orgRevisionIsDraft: true,
|
||||
orgRevisionIsCurrent: false,
|
||||
},
|
||||
relations: ["posMasters"],
|
||||
});
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
|
||||
}
|
||||
const [profiles, total] = await this.profileRepository
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.next_holders", "next_holders")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
.where(
|
||||
requestBody.position != null && requestBody.position != ""
|
||||
? "profile.position LIKE :position"
|
||||
: "1=1",
|
||||
{
|
||||
position: `%${requestBody.position}%`,
|
||||
},
|
||||
relations: ["posMasters"],
|
||||
});
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
|
||||
}
|
||||
const [profiles, total] = await this.profileRepository
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.next_holders", "next_holders")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
.where(
|
||||
requestBody.position != null && requestBody.position != ""
|
||||
? "profile.position LIKE :position"
|
||||
: "1=1",
|
||||
{
|
||||
position: `%${requestBody.position}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
requestBody.keyword != null && requestBody.keyword != ""
|
||||
? "profile.prefix LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${requestBody.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
requestBody.keyword != null && requestBody.keyword != ""
|
||||
? "profile.prefix LIKE :keyword"
|
||||
? "profile.firstName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${requestBody.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
requestBody.keyword != null && requestBody.keyword != ""
|
||||
? "profile.firstName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${requestBody.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
requestBody.keyword != null && requestBody.keyword != ""
|
||||
? "profile.lastName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${requestBody.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
requestBody.keyword != null && requestBody.keyword != ""
|
||||
? "profile.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${requestBody.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.andWhere(
|
||||
requestBody.posTypeId != null && requestBody.posTypeId != ""
|
||||
? "profile.posTypeId LIKE :posTypeId"
|
||||
: "1=1",
|
||||
{
|
||||
posTypeId: `%${requestBody.posTypeId}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
requestBody.posLevelId != null && requestBody.posLevelId != ""
|
||||
? "profile.posLevelId LIKE :posLevelId"
|
||||
: "1=1",
|
||||
{
|
||||
posLevelId: `%${requestBody.posLevelId}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where("next_holders.id IS NULL").orWhere("next_holders.id NOT IN (:...ids)", {
|
||||
ids: orgRevision.posMasters.map((x) => x.id),
|
||||
});
|
||||
}),
|
||||
)
|
||||
.skip((requestBody.page - 1) * requestBody.pageSize)
|
||||
.take(requestBody.pageSize)
|
||||
.getManyAndCount();
|
||||
.orWhere(
|
||||
requestBody.keyword != null && requestBody.keyword != ""
|
||||
? "profile.lastName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${requestBody.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
requestBody.keyword != null && requestBody.keyword != ""
|
||||
? "profile.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${requestBody.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.andWhere(
|
||||
requestBody.posTypeId != null && requestBody.posTypeId != ""
|
||||
? "profile.posTypeId LIKE :posTypeId"
|
||||
: "1=1",
|
||||
{
|
||||
posTypeId: `%${requestBody.posTypeId}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
requestBody.posLevelId != null && requestBody.posLevelId != ""
|
||||
? "profile.posLevelId LIKE :posLevelId"
|
||||
: "1=1",
|
||||
{
|
||||
posLevelId: `%${requestBody.posLevelId}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where("next_holders.id IS NULL").orWhere("next_holders.id NOT IN (:...ids)", {
|
||||
ids: orgRevision.posMasters.map((x) => x.id),
|
||||
});
|
||||
}),
|
||||
)
|
||||
.skip((requestBody.page - 1) * requestBody.pageSize)
|
||||
.take(requestBody.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const data = profiles.map((_data) => ({
|
||||
id: _data.id,
|
||||
prefix: _data.prefix,
|
||||
firstName: _data.firstName,
|
||||
lastName: _data.lastName,
|
||||
citizenId: _data.citizenId,
|
||||
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
|
||||
posType: _data.posType == null ? null : _data.posType.posTypeName,
|
||||
position: _data.position,
|
||||
}));
|
||||
const data = profiles.map((_data) => ({
|
||||
id: _data.id,
|
||||
prefix: _data.prefix,
|
||||
firstName: _data.firstName,
|
||||
lastName: _data.lastName,
|
||||
citizenId: _data.citizenId,
|
||||
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
|
||||
posType: _data.posType == null ? null : _data.posType.posTypeName,
|
||||
position: _data.position,
|
||||
}));
|
||||
|
||||
return new HttpSuccess({ data: data, total });
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
return new HttpSuccess({ data: data, total });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -547,11 +515,7 @@ export class ProfileController extends Controller {
|
|||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4
|
||||
.orgChild4Name,
|
||||
};
|
||||
try {
|
||||
return new HttpSuccess(_profile);
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
}
|
||||
return new HttpSuccess(_profile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -568,56 +532,52 @@ export class ProfileController extends Controller {
|
|||
keyword?: string;
|
||||
},
|
||||
) {
|
||||
try {
|
||||
let findProfile: any;
|
||||
switch (body.fieldName) {
|
||||
case "idcard":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { citizenId: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
let findProfile: any;
|
||||
switch (body.fieldName) {
|
||||
case "idcard":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { citizenId: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
|
||||
case "firstname":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { firstName: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
case "firstname":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { firstName: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
|
||||
case "lastname":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { lastName: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
case "lastname":
|
||||
findProfile = await this.profileRepository.find({
|
||||
where: { lastName: Like(`%${body.keyword}%`) },
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
findProfile = await this.profileRepository.find({
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
const mapDataProfile = await Promise.all(
|
||||
findProfile.map(async (item: Profile) => {
|
||||
return {
|
||||
id: item.id,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
idcard: item.citizenId,
|
||||
email: item.email,
|
||||
phone: item.phone,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess(mapDataProfile);
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
default:
|
||||
findProfile = await this.profileRepository.find({
|
||||
relations: ["posType", "posLevel"],
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
const mapDataProfile = await Promise.all(
|
||||
findProfile.map(async (item: Profile) => {
|
||||
return {
|
||||
id: item.id,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
idcard: item.citizenId,
|
||||
email: item.email,
|
||||
phone: item.phone,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess(mapDataProfile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -823,11 +783,7 @@ export class ProfileController extends Controller {
|
|||
if (profile) {
|
||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "เลขบัตรนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -845,100 +801,96 @@ export class ProfileController extends Controller {
|
|||
keyword?: string;
|
||||
},
|
||||
) {
|
||||
try {
|
||||
const [findProfile, total] = await AppDataSource.getRepository(Profile)
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
|
||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
.where("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
const [findProfile, total] = await AppDataSource.getRepository(Profile)
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
|
||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
.where("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` })
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const orgRevisionActive = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
const orgRevisionActive = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
|
||||
const mapDataProfile = await Promise.all(
|
||||
findProfile.map(async (item: Profile) => {
|
||||
return {
|
||||
id: item.id,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
idcard: item.citizenId,
|
||||
posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName,
|
||||
isProbation: item.isProbation,
|
||||
orgRootName:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot ==
|
||||
null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
|
||||
?.orgRootName == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgRoot?.orgRootName,
|
||||
orgChild1Name:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild1 == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1
|
||||
?.orgChild1Name == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild1?.orgChild1Name,
|
||||
orgChild2Name:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild2 == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2
|
||||
?.orgChild2Name == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild2?.orgChild2Name,
|
||||
orgChild3Name:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild3 == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3
|
||||
?.orgChild3Name == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild3?.orgChild3Name,
|
||||
orgChild4Name:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild4 == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4
|
||||
?.orgChild4Name == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild4?.orgChild4Name,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const mapDataProfile = await Promise.all(
|
||||
findProfile.map(async (item: Profile) => {
|
||||
return {
|
||||
id: item.id,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
idcard: item.citizenId,
|
||||
posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName,
|
||||
isProbation: item.isProbation,
|
||||
orgRootName:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot ==
|
||||
null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
|
||||
?.orgRootName == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
|
||||
?.orgRootName,
|
||||
orgChild1Name:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1 ==
|
||||
null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1
|
||||
?.orgChild1Name == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild1?.orgChild1Name,
|
||||
orgChild2Name:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2 ==
|
||||
null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2
|
||||
?.orgChild2Name == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild2?.orgChild2Name,
|
||||
orgChild3Name:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3 ==
|
||||
null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3
|
||||
?.orgChild3Name == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild3?.orgChild3Name,
|
||||
orgChild4Name:
|
||||
item.current_holders == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4 ==
|
||||
null ||
|
||||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4
|
||||
?.orgChild4Name == null
|
||||
? null
|
||||
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
|
||||
?.orgChild4?.orgChild4Name,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess({ data: mapDataProfile, total });
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
}
|
||||
return new HttpSuccess({ data: mapDataProfile, total });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -962,7 +914,7 @@ export class ProfileController extends Controller {
|
|||
if (!findRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
|
||||
|
||||
const [findPosMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
|
|
@ -990,55 +942,55 @@ export class ProfileController extends Controller {
|
|||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.firstName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.lastName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "posType.posTypeName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "posLevel.posLevelName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.firstName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.lastName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "posType.posTypeName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "posLevel.posLevelName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
|
|
@ -1047,8 +999,7 @@ export class ProfileController extends Controller {
|
|||
if (!findPosMaster) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster");
|
||||
}
|
||||
|
||||
|
||||
|
||||
const formattedData = findPosMaster.map((item) => {
|
||||
let orgShortName = "";
|
||||
|
||||
|
|
@ -1089,21 +1040,21 @@ export class ProfileController extends Controller {
|
|||
posMasterNoSuffix: item.posMasterNoSuffix,
|
||||
orgShortName: orgShortName,
|
||||
position: item.current_holder.position,
|
||||
posType: item.current_holder.posType.posTypeName,
|
||||
posLevel: item.current_holder.posLevel.posLevelName,
|
||||
posType: item.current_holder.posType.posTypeName,
|
||||
posLevel: item.current_holder.posLevel.posLevelName,
|
||||
posExecutive: posExecutive,
|
||||
amount: amount?amount:0,
|
||||
amount: amount ? amount : 0,
|
||||
// revisionId: item.orgRevisionId,
|
||||
rootId: item.orgRootId,
|
||||
root: item.orgRoot?.orgRootName?item.orgRoot.orgRootName:null,
|
||||
root: item.orgRoot?.orgRootName ? item.orgRoot.orgRootName : null,
|
||||
child1Id: item.orgChild1Id,
|
||||
child1: item.orgChild1?.orgChild1Name?item.orgChild1.orgChild1Name:null,
|
||||
child1: item.orgChild1?.orgChild1Name ? item.orgChild1.orgChild1Name : null,
|
||||
child2Id: item.orgChild2Id,
|
||||
child2: item.orgChild2?.orgChild2Name?item.orgChild2.orgChild2Name:null,
|
||||
child2: item.orgChild2?.orgChild2Name ? item.orgChild2.orgChild2Name : null,
|
||||
child3Id: item.orgChild3Id,
|
||||
child3: item.orgChild3?.orgChild3Name?item.orgChild3.orgChild3Name:null,
|
||||
child3: item.orgChild3?.orgChild3Name ? item.orgChild3.orgChild3Name : null,
|
||||
child4Id: item.orgChild4Id,
|
||||
child4: item.orgChild4?.orgChild4Name?item.orgChild4.orgChild4Name:null,
|
||||
child4: item.orgChild4?.orgChild4Name ? item.orgChild4.orgChild4Name : null,
|
||||
isResult: true,
|
||||
isDuration: false,
|
||||
isPunish: true,
|
||||
|
|
@ -1112,7 +1063,7 @@ export class ProfileController extends Controller {
|
|||
};
|
||||
});
|
||||
|
||||
return new HttpSuccess({data:formattedData,total:total});
|
||||
return new HttpSuccess({ data: formattedData, total: total });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1212,10 +1163,6 @@ export class ProfileController extends Controller {
|
|||
: profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4
|
||||
.orgChild4Name,
|
||||
};
|
||||
try {
|
||||
return new HttpSuccess(_profile);
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
}
|
||||
return new HttpSuccess(_profile);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue