Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
kittapath 2024-10-31 21:02:58 +07:00
commit 8b86a6120c
3 changed files with 253 additions and 1 deletions

View file

@ -3121,7 +3121,7 @@ export class CommandController extends Controller {
}[];
},
) {
const posMasters = await this.posMasterRepository.find({ where: { id: In(body.refIds) } });
const posMasters = await this.posMasterRepository.find({ where: { id: In(body.refIds.map(x => x.refId)) } });
const data = posMasters.map((_data) => ({
..._data,
statusReport: "PENDING",

View file

@ -14,6 +14,7 @@ import {
Get,
Query,
Example,
Patch,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
@ -25,6 +26,10 @@ import {
UpdateProfile,
ProfileHistory,
CreateProfileAllFields,
UpdateProfileReqEdit,
UpdateProfileFather,
UpdateProfileMother,
UpdateProfileCouple,
} from "../entities/Profile";
import { Any, Brackets, In, IsNull, Like, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
@ -65,6 +70,9 @@ import { PosMasterAct } from "../entities/PosMasterAct";
import axios from "axios";
import { OrgChild1 } from "../entities/OrgChild1";
import { viewCommanderDirector } from "../entities/view/viewCommanderDirector";
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
@Route("api/v1/org/profile")
@Tags("Profile")
@Security("bearerAuth")
@ -87,8 +95,11 @@ export class ProfileController extends Controller {
private subDistrict = AppDataSource.getRepository(SubDistrict);
private certificateRepository = AppDataSource.getRepository(ProfileCertificate);
private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple);
private profileFamilyCoupleHistoryRepo = AppDataSource.getRepository(ProfileFamilyCoupleHistory);
private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother);
private profileFamilyMotherHistoryRepo = AppDataSource.getRepository(ProfileFamilyMotherHistory);
private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather);
private profileFamilyFatherHistoryRepo = AppDataSource.getRepository(ProfileFamilyFatherHistory);
private trainingRepository = AppDataSource.getRepository(ProfileTraining);
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private educationRepository = AppDataSource.getRepository(ProfileEducation);
@ -2666,6 +2677,200 @@ export class ProfileController extends Controller {
return new HttpSuccess({ retireDate, age });
}
/**
* API
*
* @summary
*
* @param {string} id Id
*/
@Patch("request-edit/myprofile/{id}")
async updateProfileReEdit(
@Request() request: RequestWithUser,
@Path() id: string,
@Body() body: UpdateProfileReqEdit,
) {
const record = await this.profileRepo.findOneBy({ id });
const before = structuredClone(record);
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
Object.keys(body).forEach((key) => {
const typedKey = key as keyof UpdateProfileReqEdit; // บอก TypeScript ว่า key เป็นฟิลด์ของ UpdateProfileReqEdit
if (body[typedKey] === null || body[typedKey] === "") delete body[typedKey];
});
Object.assign(record, body);
record.createdUserId = request.user.sub;
record.createdFullName = request.user.name;
record.createdAt = new Date();
record.lastUpdateUserId = request.user.sub;
record.lastUpdateFullName = request.user.name;
record.lastUpdatedAt = new Date();
await this.profileHistoryRepo.save(
Object.assign(new ProfileHistory(), {
...record,
profileId: id,
id: undefined,
}),
);
await this.profileRepo.save(record);
// setLogDataDiff(request, { before, after: record });
if (record != null && record.keycloak != null) {
const result = await updateName(record.keycloak, record.firstName, record.lastName);
if (!result) {
throw new Error(result.errorMessage);
}
}
return new HttpSuccess();
}
/**
* API
*
* @summary
*
* @param {string} id Id
*/
@Patch("request-edit/father/{id}")
public async UpdateFamilyFather(
@Request() req: RequestWithUser,
@Path() id: string,
@Body() body: UpdateProfileFather,
) {
const profile = await this.profileRepo.findOneBy({ id:id });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lastestData = await this.profileFamilyFatherRepository.findOne({
where:{ profileId:id },
order:{ createdAt: "DESC" }
});
if (!lastestData) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูลดังกล่าว");
}
Object.keys(body).forEach((key) => {
const typedKey = key as keyof UpdateProfileFather; // บอก TypeScript ว่า key เป็นฟิลด์ของ UpdateProfileFather
if (body[typedKey] === null || body[typedKey] === "") delete body[typedKey];
});
Object.assign(lastestData, body);
lastestData.createdUserId = req.user.sub;
lastestData.createdFullName = req.user.name;
lastestData.lastUpdateUserId = req.user.sub;
lastestData.lastUpdateFullName = req.user.name;
lastestData.createdAt = new Date();
lastestData.lastUpdatedAt = new Date();
const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...lastestData, id: undefined });
await this.profileFamilyFatherRepository.save(lastestData, { data: req });
history.profileFamilyFatherId = lastestData.id;
await this.profileFamilyFatherHistoryRepo.save(history, { data: req });
return new HttpSuccess(lastestData.id);
}
/**
* API
*
* @summary
*
* @param {string} id Id
*/
@Patch("request-edit/mother/{id}")
public async UpdateFamilyMother(
@Request() req: RequestWithUser,
@Path() id: string,
@Body() body: UpdateProfileMother,
) {
const profile = await this.profileRepo.findOneBy({ id:id });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lastestData = await this.profileFamilyMotherRepository.findOne({
where:{ profileId:id },
order:{ createdAt: "DESC" }
});
if (!lastestData) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูลดังกล่าว");
}
Object.keys(body).forEach((key) => {
const typedKey = key as keyof UpdateProfileMother; // บอก TypeScript ว่า key เป็นฟิลด์ของ UpdateProfileMother
if (body[typedKey] === null || body[typedKey] === "") delete body[typedKey];
});
Object.assign(lastestData, body);
lastestData.createdUserId = req.user.sub;
lastestData.createdFullName = req.user.name;
lastestData.lastUpdateUserId = req.user.sub;
lastestData.lastUpdateFullName = req.user.name;
lastestData.createdAt = new Date();
lastestData.lastUpdatedAt = new Date();
const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...lastestData, id: undefined });
await this.profileFamilyMotherRepository.save(lastestData, { data: req });
history.profileFamilyMotherId = lastestData.id;
await this.profileFamilyMotherHistoryRepo.save(history, { data: req });
return new HttpSuccess(lastestData.id);
}
/**
* API
*
* @summary
*
* @param {string} id Id
*/
@Patch("request-edit/couple/{id}")
public async UpdateFamilyCouple(
@Request() req: RequestWithUser,
@Path() id: string,
@Body() body: UpdateProfileCouple,
) {
const profile = await this.profileRepo.findOneBy({ id:id });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const lastestData = await this.profileFamilyCoupleRepository.findOne({
where:{ profileId:id },
order:{ createdAt: "DESC" }
});
if (!lastestData) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูลดังกล่าว");
}
Object.keys(body).forEach((key) => {
const typedKey = key as keyof UpdateProfileCouple; // บอก TypeScript ว่า key เป็นฟิลด์ของ UpdateProfileCouple
if (body[typedKey] === null || body[typedKey] === "") delete body[typedKey];
});
Object.assign(lastestData, body);
lastestData.createdUserId = req.user.sub;
lastestData.createdFullName = req.user.name;
lastestData.lastUpdateUserId = req.user.sub;
lastestData.lastUpdateFullName = req.user.name;
lastestData.createdAt = new Date();
lastestData.lastUpdatedAt = new Date();
const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...lastestData, id: undefined });
await this.profileFamilyCoupleRepository.save(lastestData, { data: req });
history.profileFamilyCoupleId = lastestData.id;
await this.profileFamilyCoupleHistoryRepo.save(history, { data: req });
return new HttpSuccess(lastestData.id);
}
/**
* API
@ -2774,6 +2979,8 @@ export class ProfileController extends Controller {
return new HttpSuccess();
}
/**
* API
*

View file

@ -747,6 +747,51 @@ export type UpdateProfile = {
relationship?: string | null;
bloodGroup?: string | null;
};
export type UpdateProfileReqEdit = {
rank?: string | null;
prefix?: string | null;
firstName?: string | null;
lastName?: string | null;
birthDate?: Date | null;
ethnicity?: string | null;
telephoneNumber?: string | null;
nationality?: string | null;
religion?: string | null;
gender?: string | null;
relationship?: string | null;
bloodGroup?: string | null;
registrationAddress?: string | null;
registrationProvinceId?: string | null;
registrationDistrictId?: string | null;
registrationSubDistrictId?: string | null;
registrationZipCode?: string | null;
};
export type UpdateProfileFather = {
fatherPrefix?: string | null;
fatherFirstName?: string | null;
fatherLastName?: string | null;
fatherCareer?: string | null;
fatherLive?: boolean | null;
};
export type UpdateProfileMother = {
motherPrefix?: string | null;
motherFirstName?: string | null;
motherLastName?: string | null;
motherCareer?: string | null;
motherLive?: boolean | null;
};
export type UpdateProfileCouple = {
couplePrefix?: string | null;
coupleFirstName?: string | null;
coupleLastName?: string | null;
coupleLastNameOld?: string | null;
coupleCareer?: string | null;
coupleLive?: boolean | null;
relationship?: string | null;
};
export type UpdateProfileAddress = {
registrationAddress?: string | null;