no message

This commit is contained in:
Kittapath 2024-06-25 10:21:30 +07:00
parent b11be3364f
commit 568d326797
6 changed files with 643 additions and 31 deletions

View file

@ -744,6 +744,9 @@ export class ProfileController extends Controller {
}
const profile: Profile = Object.assign(new Profile(), body);
const _null: any = null;
profile.dateRetire = body.birthDate == null ? _null : calculateRetireDate(body.birthDate);
profile.dateRetireLaw = body.birthDate == null ? _null : calculateRetireLaw(body.birthDate);
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
@ -2359,7 +2362,7 @@ export class ProfileController extends Controller {
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: root == null ? null : root.orgRevisionId,
org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName}`,
org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`,
};
}),
);
@ -2811,18 +2814,23 @@ export class ProfileController extends Controller {
if (_profile.child4Id != null) {
_profile.node = 4;
_profile.nodeId = _profile.child4Id;
_profile.nodeShortName = _profile.child4ShortName;
} else if (_profile.child3Id != null) {
_profile.node = 3;
_profile.nodeId = _profile.child3Id;
_profile.nodeShortName = _profile.child3ShortName;
} else if (_profile.child2Id != null) {
_profile.node = 2;
_profile.nodeId = _profile.child2Id;
_profile.nodeShortName = _profile.child2ShortName;
} else if (_profile.child1Id != null) {
_profile.node = 1;
_profile.nodeId = _profile.child1Id;
_profile.nodeShortName = _profile.child1ShortName;
} else if (_profile.rootId != null) {
_profile.node = 0;
_profile.nodeId = _profile.rootId;
_profile.nodeShortName = _profile.rootShortName;
}
return new HttpSuccess(_profile);
}
@ -3538,6 +3546,7 @@ export class ProfileController extends Controller {
keyword?: string;
},
) {
const isProbation: boolean = true;
const [findProfile, total] = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
@ -3551,12 +3560,24 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.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}%` })
.orWhere("posType.posTypeName LIKE :keyword", { keyword: `%${body.keyword}%` })
.where(`profile.prefix LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profile.firstName LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profile.lastName LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profile.position LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`posLevel.posLevelName LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`posType.posTypeName LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orderBy("profile.citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
@ -4275,12 +4296,12 @@ export class ProfileController extends Controller {
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const _null: any = null;
profile.isLeave = requestBody.isLeave;
if (profile.leaveReason != undefined && profile.leaveReason != null) {
if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) {
profile.leaveReason = requestBody.leaveReason;
} else {
profile.leaveReason = _null;
}
if (profile.dateLeave != undefined && profile.dateLeave != null) {
if (requestBody.dateLeave != undefined && requestBody.dateLeave != null) {
profile.dateLeave = requestBody.dateLeave;
} else {
profile.dateLeave = _null;
@ -4512,6 +4533,7 @@ export class ProfileController extends Controller {
select: ["id"],
});
if (citizen) return new HttpSuccess(citizen.id);
const _null: any = null;
const profile: Profile = Object.assign(new Profile(), body);
if (body && body.posLevelId) {
const findPosLevel = await this.posLevelRepo.findOne({
@ -4520,7 +4542,11 @@ export class ProfileController extends Controller {
});
if (findPosLevel) {
profile.posLevelId = findPosLevel.id;
} else {
profile.posLevelId = _null;
}
} else {
profile.posLevelId = _null;
}
if (body && body.posTypeId) {
const findPosType = await this.posTypeRepo.findOne({
@ -4529,17 +4555,25 @@ export class ProfileController extends Controller {
});
if (findPosType) {
profile.posTypeId = findPosType.id;
} else {
profile.posTypeId = _null;
}
} else {
profile.posTypeId = _null;
}
if (body && body.prefix) {
const findPrefix = await this.prefixRepo.findOne({
where: { name: body.prefix },
select: ["id", "name"],
});
if (findPrefix) {
profile.prefix = findPrefix.id;
}
}
// if (body && body.prefix) {
// const findPrefix = await this.prefixRepo.findOne({
// where: { name: body.prefix },
// select: ["id", "name"],
// });
// if (findPrefix) {
// profile.prefix = findPrefix.id;
// } else {
// profile.prefix = _null;
// }
// } else {
// profile.prefix = _null;
// }
//current
if (body && body.currentProvinceId) {
const findProvince = await this.provinceRepo.findOne({
@ -4548,7 +4582,11 @@ export class ProfileController extends Controller {
});
if (findProvince) {
profile.currentProvinceId = findProvince.id;
} else {
profile.currentProvinceId = _null;
}
} else {
profile.currentProvinceId = _null;
}
if (body && body.currentDistrictId) {
const findDistrict = await this.districtRepo.findOne({
@ -4557,7 +4595,11 @@ export class ProfileController extends Controller {
});
if (findDistrict) {
profile.currentDistrictId = findDistrict.id;
} else {
profile.currentDistrictId = _null;
}
} else {
profile.currentDistrictId = _null;
}
if (body && body.currentSubDistrictId) {
const findSubDistrict = await this.subDistrictRepo.findOne({
@ -4566,7 +4608,11 @@ export class ProfileController extends Controller {
});
if (findSubDistrict) {
profile.currentSubDistrictId = findSubDistrict.id;
} else {
profile.currentSubDistrictId = _null;
}
} else {
profile.currentSubDistrictId = _null;
}
//register
if (body && body.registrationProvinceId) {
@ -4576,7 +4622,11 @@ export class ProfileController extends Controller {
});
if (findProvince_regis) {
profile.registrationProvinceId = findProvince_regis.id;
} else {
profile.registrationProvinceId = _null;
}
} else {
profile.registrationProvinceId = _null;
}
if (body && body.registrationDistrictId) {
const findDistrict_regis = await this.districtRepo.findOne({
@ -4585,7 +4635,11 @@ export class ProfileController extends Controller {
});
if (findDistrict_regis) {
profile.registrationDistrictId = findDistrict_regis.id;
} else {
profile.registrationDistrictId = _null;
}
} else {
profile.registrationDistrictId = _null;
}
if (body && body.registrationSubDistrictId) {
const findSubDistrict_regis = await this.subDistrictRepo.findOne({
@ -4594,14 +4648,74 @@ export class ProfileController extends Controller {
});
if (findSubDistrict_regis) {
profile.registrationSubDistrictId = findSubDistrict_regis.id;
} else {
profile.registrationSubDistrictId = _null;
}
} else {
profile.registrationSubDistrictId = _null;
}
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
// return new HttpSuccess(profile);
await this.profileRepo.save(profile);
return new HttpSuccess(profile.id);
}
/**
*
* @summary (ADMIN)
*
*/
@Get("retireDate/mock")
async calRetireDate() {
const profile = await this.profileRepo.find({ relations: ["profileSalary"] });
const _null: any = null;
const profiles = profile.map((_data) => ({
..._data,
dateRetire: _data.birthDate == null ? _null : calculateRetireDate(_data.birthDate),
dateRetireLaw: _data.birthDate == null ? _null : calculateRetireLaw(_data.birthDate),
}));
await this.profileRepo.save(profiles);
return new HttpSuccess();
}
/**
*
* @summary (ADMIN)
*
*/
@Get("salarym/ock")
async calSalaryDate() {
const profile = await this.profileRepo.find();
const _null: any = null;
const profiles = await Promise.all(
profile.map(async (_data) => {
const salary = await this.salaryRepository.findOne({
where: {
profileId: _data.id,
},
order: { order: "DESC" },
});
const type = await this.posTypeRepo.findOne({
where: {
posTypeName: salary?.positionType ?? "",
},
});
const level = await this.posLevelRepo.findOne({
where: {
posLevelName: salary?.positionLevel ?? "",
},
});
return {
..._data,
position: salary?.position ?? _null,
posLevelId: level?.id ?? _null,
posTypeId: type?.id ?? _null,
};
}),
);
await this.profileRepo.save(profiles);
return new HttpSuccess("zxczx");
}
}