Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
59cefbeec5
7 changed files with 283 additions and 10 deletions
|
|
@ -70,6 +70,37 @@ export class ProfileChangeNameController extends Controller {
|
||||||
return new HttpSuccess(lists);
|
return new HttpSuccess(lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @summary ประวัติแก้ไขชื่อ by keycloak
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("history/user")
|
||||||
|
public async changeNameHistoryUser(@Request() request: RequestWithUser) {
|
||||||
|
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
const record = await this.changeNameHistoryRepository.find({
|
||||||
|
where: {
|
||||||
|
histories: {
|
||||||
|
profileId: profile.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"prefix",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"status",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
],
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("history/{changeNameId}")
|
@Get("history/{changeNameId}")
|
||||||
@Example({
|
@Example({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,37 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
||||||
return new HttpSuccess(lists);
|
return new HttpSuccess(lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @summary ประวัติแก้ไขชื่อ by keycloak
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("history/user")
|
||||||
|
public async changeNameHistoryUser(@Request() request: RequestWithUser) {
|
||||||
|
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
const record = await this.changeNameHistoryRepository.find({
|
||||||
|
where: {
|
||||||
|
histories: {
|
||||||
|
profileEmployeeId: profile.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"prefix",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"status",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
],
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("history/{changeNameId}")
|
@Get("history/{changeNameId}")
|
||||||
@Example({
|
@Example({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|
@ -146,7 +177,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
||||||
profile.lastName = body.lastName ?? profile.lastName;
|
profile.lastName = body.lastName ?? profile.lastName;
|
||||||
profile.prefix = body.prefix ?? profile.prefix;
|
profile.prefix = body.prefix ?? profile.prefix;
|
||||||
await this.profileEmployeeRepo.save(profile);
|
await this.profileEmployeeRepo.save(profile);
|
||||||
|
|
||||||
return new HttpSuccess(data.id);
|
return new HttpSuccess(data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,17 +205,17 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const chkLastRecord = await this.changeNameRepository.findOne({
|
const chkLastRecord = await this.changeNameRepository.findOne({
|
||||||
where:{
|
where: {
|
||||||
profileEmployeeId: record.profileEmployeeId
|
profileEmployeeId: record.profileEmployeeId,
|
||||||
},
|
},
|
||||||
order:{
|
order: {
|
||||||
createdAt: "DESC"
|
createdAt: "DESC",
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
const profile = await this.profileEmployeeRepo.findOneBy({ id: record.profileEmployeeId });
|
const profile = await this.profileEmployeeRepo.findOneBy({ id: record.profileEmployeeId });
|
||||||
|
|
||||||
if (profile && chkLastRecord.id === record.id) {
|
if (profile && chkLastRecord.id === record.id) {
|
||||||
profile.firstName = body.firstName ?? profile.firstName;
|
profile.firstName = body.firstName ?? profile.firstName;
|
||||||
profile.lastName = body.lastName ?? profile.lastName;
|
profile.lastName = body.lastName ?? profile.lastName;
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,39 @@ export class ProfileDisciplineController extends Controller {
|
||||||
return new HttpSuccess(lists);
|
return new HttpSuccess(lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @summary ประวัติแก้ไขข้อมูลวินัย by keycloak
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("history/user")
|
||||||
|
public async disciplineHistoryUser(@Request() request: RequestWithUser) {
|
||||||
|
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
const record = await this.disciplineHistoryRepository.find({
|
||||||
|
where: {
|
||||||
|
histories: {
|
||||||
|
profileId: profile.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"date",
|
||||||
|
"level",
|
||||||
|
"detail",
|
||||||
|
"unStigma",
|
||||||
|
"refCommandNo",
|
||||||
|
"refCommandDate",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
],
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("history/{disciplineId}")
|
@Get("history/{disciplineId}")
|
||||||
@Example({
|
@Example({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,39 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
||||||
return new HttpSuccess(lists);
|
return new HttpSuccess(lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @summary ประวัติแก้ไขข้อมูลวินัย by keycloak
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("history/user")
|
||||||
|
public async disciplineHistoryUser(@Request() request: RequestWithUser) {
|
||||||
|
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
const record = await this.disciplineHistoryRepository.find({
|
||||||
|
where: {
|
||||||
|
histories: {
|
||||||
|
profileEmployeeId: profile.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"date",
|
||||||
|
"level",
|
||||||
|
"detail",
|
||||||
|
"unStigma",
|
||||||
|
"refCommandNo",
|
||||||
|
"refCommandDate",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
],
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("history/{disciplineId}")
|
@Get("history/{disciplineId}")
|
||||||
public async disciplineHistory(@Path() disciplineId: string) {
|
public async disciplineHistory(@Path() disciplineId: string) {
|
||||||
const record = await this.disciplineHistoryRepository.find({
|
const record = await this.disciplineHistoryRepository.find({
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,40 @@ export class ProfileDutyController extends Controller {
|
||||||
return new HttpSuccess(lists);
|
return new HttpSuccess(lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @summary ประวัติแก้ไขตำแหน่งหน้าที่ by keycloak
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("history/user")
|
||||||
|
public async dutyHistoryUser(@Request() request: RequestWithUser) {
|
||||||
|
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
const record = await this.dutyHistoryRepository.find({
|
||||||
|
where: {
|
||||||
|
histories: {
|
||||||
|
profileId: profile.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"dateStart",
|
||||||
|
"dateEnd",
|
||||||
|
"reference",
|
||||||
|
"detail",
|
||||||
|
"refCommandNo",
|
||||||
|
"refCommandDate",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
],
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("history/{dutyId}")
|
@Get("history/{dutyId}")
|
||||||
@Example({
|
@Example({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
|
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
|
||||||
|
|
||||||
@Route("api/v1/org/profile-employee/duty")
|
@Route("api/v1/org/profile-employee/duty")
|
||||||
@Tags("ProfileDuty")
|
@Tags("ProfileEmployeeDuty")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
export class ProfileDutyEmployeeController extends Controller {
|
export class ProfileDutyEmployeeController extends Controller {
|
||||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
|
@ -67,6 +67,40 @@ export class ProfileDutyEmployeeController extends Controller {
|
||||||
return new HttpSuccess(lists);
|
return new HttpSuccess(lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @summary ประวัติแก้ไขตำแหน่งหน้าที่ by keycloak
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("history/user")
|
||||||
|
public async dutyHistoryUser(@Request() request: RequestWithUser) {
|
||||||
|
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
const record = await this.dutyHistoryRepository.find({
|
||||||
|
where: {
|
||||||
|
histories: {
|
||||||
|
profileEmployeeId: profile.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"dateStart",
|
||||||
|
"dateEnd",
|
||||||
|
"reference",
|
||||||
|
"detail",
|
||||||
|
"refCommandNo",
|
||||||
|
"refCommandDate",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
],
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("history/{dutyId}")
|
@Get("history/{dutyId}")
|
||||||
public async dutyHistory(@Path() dutyId: string) {
|
public async dutyHistory(@Path() dutyId: string) {
|
||||||
const record = await this.dutyHistoryRepository.find({
|
const record = await this.dutyHistoryRepository.find({
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { Profile } from "../entities/Profile";
|
import { Profile } from "../entities/Profile";
|
||||||
import { LeaveType } from "../entities/LeaveType";
|
import { LeaveType } from "../entities/LeaveType";
|
||||||
|
import { Brackets } from "typeorm";
|
||||||
|
|
||||||
@Route("api/v1/org/profile/leave")
|
@Route("api/v1/org/profile/leave")
|
||||||
@Tags("ProfileLeave")
|
@Tags("ProfileLeave")
|
||||||
|
|
@ -36,6 +37,82 @@ export class ProfileLeaveController extends Controller {
|
||||||
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
|
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
|
||||||
private leaveTypeRepository = AppDataSource.getRepository(LeaveType);
|
private leaveTypeRepository = AppDataSource.getRepository(LeaveType);
|
||||||
|
|
||||||
|
@Post("search")
|
||||||
|
public async searchProfile(
|
||||||
|
@Body()
|
||||||
|
body: {
|
||||||
|
citizenId?: string | null;
|
||||||
|
firstName?: string | null;
|
||||||
|
lastName?: string | null;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const profileRepository = AppDataSource.getRepository(Profile);
|
||||||
|
const queryBuilder = profileRepository
|
||||||
|
.createQueryBuilder("profile")
|
||||||
|
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||||
|
.leftJoinAndSelect("profile.posType", "posType");
|
||||||
|
|
||||||
|
if (body.citizenId || body.firstName || body.lastName) {
|
||||||
|
queryBuilder.where(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
if (body.citizenId) {
|
||||||
|
qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
|
||||||
|
}
|
||||||
|
if (body.firstName) {
|
||||||
|
qb.orWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` });
|
||||||
|
}
|
||||||
|
if (body.lastName) {
|
||||||
|
qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const profiles = await queryBuilder.getMany();
|
||||||
|
|
||||||
|
if (!profiles.length) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูลโปรไฟล์");
|
||||||
|
}
|
||||||
|
|
||||||
|
const formattedProfiles = profiles.map((profile) => ({
|
||||||
|
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,
|
||||||
|
posLevelName: profile.posLevel.posLevelName,
|
||||||
|
posTypeId: profile.posTypeId,
|
||||||
|
posTypeName: profile.posType.posTypeName,
|
||||||
|
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,
|
||||||
|
ethnicity: profile.ethnicity,
|
||||||
|
telephoneNumber: profile.telephoneNumber,
|
||||||
|
nationality: profile.nationality,
|
||||||
|
gender: profile.gender,
|
||||||
|
relationship: profile.relationship,
|
||||||
|
religion: profile.religion,
|
||||||
|
bloodGroup: profile.bloodGroup,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return new HttpSuccess(formattedProfiles);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("user")
|
@Get("user")
|
||||||
public async getLeaveUser(@Request() request: { user: Record<string, any> }) {
|
public async getLeaveUser(@Request() request: { user: Record<string, any> }) {
|
||||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue