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

@ -26,6 +26,9 @@ import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Position } from "../entities/Position";
import { CreateInsignias, Insignia } from "../entities/Insignia";
import { InsigniaType } from "../entities/InsigniaType";
import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia";
@Route("api/v1/org/dotnet")
@Tags("Dotnet")
@ -39,7 +42,10 @@ export class OrganizationDotnetController extends Controller {
private orgRootRepo = AppDataSource.getRepository(OrgRoot);
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
private profileRepo = AppDataSource.getRepository(Profile);
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
private positionRepository = AppDataSource.getRepository(Position);
private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
/**
* 1. API Search Profile
@ -169,12 +175,16 @@ export class OrganizationDotnetController extends Controller {
posLevel: true,
posType: true,
profileSalary: true,
profileInsignias: true,
},
where: { keycloak: keycloakId },
order: {
profileSalary: {
date: "DESC",
},
profileInsignias: {
receiveDate: "DESC",
},
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -224,10 +234,247 @@ export class OrganizationDotnetController extends Controller {
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null,
profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null,
};
return new HttpSuccess(mapProfile);
}
/**
* 3. API Get Profile keycloak id
*
* @summary 3. API Get Profile keycloak id
*
* @param {string} citizenId Id keycloak
*/
@Get("citizenId/{citizenId}")
async GetProfileByCitizenIdAsync(@Path() citizenId: string) {
const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
posType: true,
profileSalary: true,
profileInsignias: true,
},
where: { citizenId: citizenId },
order: {
profileSalary: {
date: "DESC",
},
profileInsignias: {
receiveDate: "DESC",
},
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const mapProfile = {
id: profile.id,
avatar: profile.avatar,
avatarName: profile.avatarName,
rank: profile.rank,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
position: profile.position,
posLevelId: profile.posLevelId,
email: profile.email,
phone: profile.phone,
keycloak: profile.keycloak,
isProbation: profile.isProbation,
isLeave: profile.isLeave,
leaveReason: profile.leaveReason,
dateRetire: profile.dateRetire,
dateAppoint: profile.dateAppoint,
dateRetireLaw: profile.dateRetireLaw,
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
gender: profile.gender,
relationship: profile.relationship,
religion: profile.religion,
bloodGroup: profile.bloodGroup,
registrationAddress: profile.registrationAddress,
registrationProvinceId: profile.registrationProvinceId,
registrationDistrictId: profile.registrationDistrictId,
registrationSubDistrictId: profile.registrationSubDistrictId,
registrationZipCode: profile.registrationZipCode,
currentAddress: profile.currentAddress,
currentProvinceId: profile.currentProvinceId,
currentSubDistrictId: profile.currentSubDistrictId,
currentZipCode: profile.currentZipCode,
dutyTimeId: profile.dutyTimeId,
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null,
profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null,
};
return new HttpSuccess(mapProfile);
}
/**
* 3. API Get Profile keycloak id
*
* @summary 3. API Get Profile keycloak id
*
* @param {string} keycloakId Id keycloak
*/
@Get("root/officer/{rootId}")
async GetProfileByRootIdAsync(@Path() rootId: string) {
const profiles = await this.profileRepo.find({
relations: {
posLevel: true,
posType: true,
profileSalary: true,
profileInsignias: true,
},
where: { current_holders: { orgRootId: rootId } },
order: {
profileSalary: {
date: "DESC",
},
profileInsignias: {
receiveDate: "DESC",
},
},
});
// if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const mapProfile = profiles.map((profile) => ({
id: profile.id,
avatar: profile.avatar,
avatarName: profile.avatarName,
rank: profile.rank,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
position: profile.position,
posLevelId: profile.posLevelId,
email: profile.email,
phone: profile.phone,
keycloak: profile.keycloak,
isProbation: profile.isProbation,
isLeave: profile.isLeave,
leaveReason: profile.leaveReason,
dateRetire: profile.dateRetire,
dateAppoint: profile.dateAppoint,
dateRetireLaw: profile.dateRetireLaw,
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
gender: profile.gender,
relationship: profile.relationship,
religion: profile.religion,
bloodGroup: profile.bloodGroup,
registrationAddress: profile.registrationAddress,
registrationProvinceId: profile.registrationProvinceId,
registrationDistrictId: profile.registrationDistrictId,
registrationSubDistrictId: profile.registrationSubDistrictId,
registrationZipCode: profile.registrationZipCode,
currentAddress: profile.currentAddress,
currentProvinceId: profile.currentProvinceId,
currentSubDistrictId: profile.currentSubDistrictId,
currentZipCode: profile.currentZipCode,
dutyTimeId: profile.dutyTimeId,
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary,
profileInsignia: profile.profileInsignias,
}));
return new HttpSuccess(mapProfile);
}
/**
* 3. API Get Profile keycloak id
*
* @summary 3. API Get Profile keycloak id
*
* @param {string} keycloakId Id keycloak
*/
@Get("root/employee/{rootId}")
async GetProfileByRootIdEmpAsync(@Path() rootId: string) {
const profiles = await this.profileEmpRepo.find({
relations: {
posLevel: true,
posType: true,
profileSalarys: true,
profileInsignias: true,
},
where: { current_holders: { orgRootId: rootId } },
order: {
profileSalarys: {
date: "DESC",
},
profileInsignias: {
receiveDate: "DESC",
},
},
});
// if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const mapProfile = profiles.map((profile) => ({
id: profile.id,
avatar: profile.avatar,
avatarName: profile.avatarName,
rank: profile.rank,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
position: profile.position,
posLevelId: profile.posLevelId,
email: profile.email,
phone: profile.phone,
keycloak: profile.keycloak,
isProbation: profile.isProbation,
isLeave: profile.isLeave,
leaveReason: profile.leaveReason,
dateRetire: profile.dateRetire,
dateAppoint: profile.dateAppoint,
dateRetireLaw: profile.dateRetireLaw,
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
gender: profile.gender,
relationship: profile.relationship,
religion: profile.religion,
bloodGroup: profile.bloodGroup,
registrationAddress: profile.registrationAddress,
registrationProvinceId: profile.registrationProvinceId,
registrationDistrictId: profile.registrationDistrictId,
registrationSubDistrictId: profile.registrationSubDistrictId,
registrationZipCode: profile.registrationZipCode,
currentAddress: profile.currentAddress,
currentProvinceId: profile.currentProvinceId,
currentSubDistrictId: profile.currentSubDistrictId,
currentZipCode: profile.currentZipCode,
// dutyTimeId: profile.dutyTimeId,
// dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalarys,
profileInsignia: profile.profileInsignias,
}));
return new HttpSuccess(mapProfile);
}
/**
* 7.1 Get GetUserFullName
@ -506,4 +753,55 @@ export class OrganizationDotnetController extends Controller {
await this.profileRepo.save(profile);
return new HttpSuccess();
}
/**
* API
*
* @summary ORG_ - (ADMIN) #
*
*/
@Post("insignia/Dumb")
public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileInsignia) {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
// const insignia = await this.insigniaMetaRepo.findOne({
// where: { name: body.insigniaId },
// });
// const _null: any = null;
// if (body && body.insigniaId) {
// const findPosLevel = await this.insigniaMetaRepo.findOne({
// where: { name: body.insigniaId },
// select: ["id", "name"],
// });
// if (findPosLevel) {
// body.insigniaId = findPosLevel.id;
// } else {
// body.insigniaId = _null;
// }
// } else {
// body.insigniaId = _null;
// }
const data = new ProfileInsignia();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
};
Object.assign(data, { ...body, ...meta });
await this.insigniaRepo.save(data);
return new HttpSuccess();
}
}