refactor: shorten var name

This commit is contained in:
Methapon2001 2024-03-21 10:41:18 +07:00
parent ed7b15ebbe
commit 4b61617123

View file

@ -35,11 +35,11 @@ import { EmployeePosType } from "../entities/EmployeePosType";
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class ProfileEmployeeController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private posMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
private posTypeRepository = AppDataSource.getRepository(EmployeePosType);
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
private posMasterRepo = AppDataSource.getRepository(EmployeePosMaster);
private profileRepo = AppDataSource.getRepository(ProfileEmployee);
private posLevelRepo = AppDataSource.getRepository(EmployeePosLevel);
private posTypeRepo = AppDataSource.getRepository(EmployeePosType);
/**
* API
@ -53,7 +53,7 @@ export class ProfileEmployeeController extends Controller {
requestBody: CreateProfileEmployee,
@Request() request: { user: Record<string, any> },
) {
const _profile = await this.profileRepository.findOne({
const _profile = await this.profileRepo.findOne({
where: { citizenId: requestBody.citizenId },
});
if (_profile) {
@ -66,7 +66,7 @@ export class ProfileEmployeeController extends Controller {
requestBody.posLevelId = null;
}
if (requestBody.posLevelId) {
const checkPosLevel = await this.posLevelRepository.findOne({
const checkPosLevel = await this.posLevelRepo.findOne({
where: { id: requestBody.posLevelId },
});
if (!checkPosLevel) {
@ -78,7 +78,7 @@ export class ProfileEmployeeController extends Controller {
requestBody.posTypeId = null;
}
if (requestBody.posTypeId) {
const checkPosType = await this.posTypeRepository.findOne({
const checkPosType = await this.posTypeRepo.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkPosType) {
@ -86,7 +86,7 @@ export class ProfileEmployeeController extends Controller {
}
}
const checkCitizenId = await this.profileRepository.findOne({
const checkCitizenId = await this.profileRepo.findOne({
where: { citizenId: requestBody.citizenId },
});
@ -99,7 +99,7 @@ export class ProfileEmployeeController extends Controller {
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
await this.profileRepository.save(profile);
await this.profileRepo.save(profile);
return new HttpSuccess();
}
@ -117,12 +117,12 @@ export class ProfileEmployeeController extends Controller {
requestBody: CreateProfileEmployee,
@Request() request: { user: Record<string, any> },
) {
const profile = await this.profileRepository.findOne({ where: { id: id } });
const profile = await this.profileRepo.findOne({ where: { id: id } });
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
}
const _profile = await this.profileRepository.findOne({
const _profile = await this.profileRepo.findOne({
where: { id: Not(id), citizenId: requestBody.citizenId },
});
if (_profile) {
@ -136,7 +136,7 @@ export class ProfileEmployeeController extends Controller {
requestBody.posLevelId = null;
}
if (requestBody.posLevelId) {
const checkPosLevel = await this.posLevelRepository.findOne({
const checkPosLevel = await this.posLevelRepo.findOne({
where: { id: requestBody.posLevelId },
});
if (!checkPosLevel) {
@ -148,7 +148,7 @@ export class ProfileEmployeeController extends Controller {
requestBody.posTypeId = null;
}
if (requestBody.posTypeId) {
const checkPosType = await this.posTypeRepository.findOne({
const checkPosType = await this.posTypeRepo.findOne({
where: { id: requestBody.posTypeId },
});
if (!checkPosType) {
@ -156,7 +156,7 @@ export class ProfileEmployeeController extends Controller {
}
}
const checkCitizenId = await this.profileRepository.findOne({
const checkCitizenId = await this.profileRepo.findOne({
where: {
id: Not(id),
citizenId: requestBody.citizenId,
@ -169,8 +169,8 @@ export class ProfileEmployeeController extends Controller {
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
this.profileRepository.merge(profile, requestBody);
await this.profileRepository.save(profile);
this.profileRepo.merge(profile, requestBody);
await this.profileRepo.save(profile);
return new HttpSuccess();
}
@ -183,13 +183,13 @@ export class ProfileEmployeeController extends Controller {
*/
@Delete("{id}")
async deleteProfile(@Path() id: string) {
const delProfile = await this.profileRepository.findOne({
const delProfile = await this.profileRepo.findOne({
where: { id },
});
if (!delProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
}
await this.profileRepository.delete({ id: id });
await this.profileRepo.delete({ id: id });
return new HttpSuccess();
}
@ -202,7 +202,7 @@ export class ProfileEmployeeController extends Controller {
*/
@Get("{id}")
async detailProfile(@Path() id: string) {
const profile = await this.profileRepository.findOne({
const profile = await this.profileRepo.findOne({
where: { id },
select: [
"id",
@ -233,7 +233,7 @@ export class ProfileEmployeeController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
const [profile, total] = await this.profileRepository.findAndCount({
const [profile, total] = await this.profileRepo.findAndCount({
select: [
"id",
"prefix",
@ -302,7 +302,7 @@ export class ProfileEmployeeController extends Controller {
keyword?: string;
},
) {
const orgRevision = await this.orgRevisionRepository.findOne({
const orgRevision = await this.orgRevisionRepo.findOne({
where: {
orgRevisionIsDraft: true,
orgRevisionIsCurrent: false,
@ -312,7 +312,7 @@ export class ProfileEmployeeController extends Controller {
if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
}
const [profiles, total] = await this.profileRepository
const [profiles, total] = await this.profileRepo
.createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.next_holders", "next_holders")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
@ -412,7 +412,7 @@ export class ProfileEmployeeController extends Controller {
*/
@Get("keycloak/position")
async getProfileByKeycloak(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepository.findOne({
const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
});
@ -420,7 +420,7 @@ export class ProfileEmployeeController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
const orgRevisionPublish = await this.orgRevisionRepository
const orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
@ -533,28 +533,28 @@ export class ProfileEmployeeController extends Controller {
let findProfile: any;
switch (body.fieldName) {
case "idcard":
findProfile = await this.profileRepository.find({
findProfile = await this.profileRepo.find({
where: { citizenId: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"],
});
break;
case "firstname":
findProfile = await this.profileRepository.find({
findProfile = await this.profileRepo.find({
where: { firstName: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"],
});
break;
case "lastname":
findProfile = await this.profileRepository.find({
findProfile = await this.profileRepo.find({
where: { lastName: Like(`%${body.keyword}%`) },
relations: ["posType", "posLevel"],
});
break;
default:
findProfile = await this.profileRepository.find({
findProfile = await this.profileRepo.find({
relations: ["posType", "posLevel"],
});
break;
@ -593,17 +593,17 @@ export class ProfileEmployeeController extends Controller {
let commanderFullname_: any = {};
let commanderPosition_: any = {};
const findProfile = await this.profileRepository.findOne({
const findProfile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
});
const findRevision = await this.orgRevisionRepository.findOne({
const findRevision = await this.orgRevisionRepo.findOne({
where: {
orgRevisionIsCurrent: true,
},
});
const findPosMaster = await this.posMasterRepository.findOne({
const findPosMaster = await this.posMasterRepo.findOne({
where: {
current_holderId: findProfile?.id,
orgRevisionId: findRevision?.id,
@ -632,7 +632,7 @@ export class ProfileEmployeeController extends Controller {
condition = { orgRootId: childId, orgChild1Id: IsNull() };
}
const findCmd = await this.posMasterRepository.findOne({
const findCmd = await this.posMasterRepo.findOne({
where: {
current_holderId: Not(IsNull()) || Not(""),
orgRevisionId: findRevision?.id,
@ -775,7 +775,7 @@ export class ProfileEmployeeController extends Controller {
@Body()
requestBody: { citizenId: string },
) {
const profile = await this.profileRepository.findOne({
const profile = await this.profileRepo.findOne({
where: { id: Not(id), citizenId: requestBody.citizenId },
});
if (profile) {
@ -822,7 +822,7 @@ export class ProfileEmployeeController extends Controller {
.take(body.pageSize)
.getManyAndCount();
const orgRevisionActive = await this.orgRevisionRepository.findOne({
const orgRevisionActive = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
@ -912,7 +912,7 @@ export class ProfileEmployeeController extends Controller {
period: string;
},
) {
const findRevision = await this.orgRevisionRepository.findOne({
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
@ -1114,7 +1114,7 @@ export class ProfileEmployeeController extends Controller {
@Path() revisionId: string,
@Request() request: { user: Record<string, any> },
) {
const profile = await this.profileRepository.findOne({
const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
});