Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-05-15 18:07:12 +07:00
commit 9f2357b81c
11 changed files with 1295 additions and 26 deletions

View file

@ -22,6 +22,21 @@ export class ProfileAvatarController extends Controller {
return new HttpSuccess(lists);
}
@Get("select/{profileId}/{id}")
public async selectAvatar(@Path() profileId: string, @Path() id: string) {
const result = await this.avatarRepository.findOneBy({ id: id });
if (!result) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const profile = await this.profileRepository.findOneBy({ id: profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
profile.avatar = result.avatar;
profile.avatarName = result.avatarName;
return new HttpSuccess();
}
@Post()
public async newAvatar(@Request() req: RequestWithUser, @Body() body: CreateProfileAvatar) {
const profile = await this.profileRepository.findOneBy({ id: body.profileId });

View file

@ -25,7 +25,7 @@ import {
UpdateProfileChildren,
} from "../entities/ProfileChildren";
@Route("api/v1/org/profile/children")
@Route("api/v1/org/profile/family/children")
@Tags("ProfileChildren")
@Security("bearerAuth")
export class ProfileChildrenController extends Controller {
@ -59,7 +59,6 @@ export class ProfileChildrenController extends Controller {
}
const data = new ProfileChildren();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
@ -68,9 +67,23 @@ export class ProfileChildrenController extends Controller {
};
Object.assign(data, { ...body, ...meta });
await this.childrenRepository.save(data);
if(data){
const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), {
profileChildrenId: data.id,
childrenCareer: data.childrenCareer,
childrenFirstName: data.childrenFirstName,
childrenLastName: data.childrenLastName,
childrenPrefix: data.childrenPrefix,
childrenLive: data.childrenLive,
childrenCitizenId: data.childrenCitizenId,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.childrenHistoryRepository.save(history);
}
return new HttpSuccess();
}
@ -81,17 +94,22 @@ export class ProfileChildrenController extends Controller {
@Path() childrenId: string,
) {
const record = await this.childrenRepository.findOneBy({ id: childrenId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileChildrenHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, body);
history.profileChildrenId = childrenId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
history.profileChildrenId = record.id;
history.childrenCareer = record.childrenCareer;
history.childrenFirstName = record.childrenFirstName;
history.childrenLastName = record.childrenLastName;
history.childrenPrefix = record.childrenPrefix;
history.childrenLive = record.childrenLive;
history.childrenCitizenId = record.childrenCitizenId;
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
await Promise.all([
this.childrenRepository.save(record),
this.childrenHistoryRepository.save(history),
@ -108,7 +126,7 @@ export class ProfileChildrenController extends Controller {
const result = await this.childrenRepository.delete({ id: childrenId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -27,7 +27,7 @@ import {
} from "../entities/ProfileChildren";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/profile-employee/children")
@Route("api/v1/org/profile-employee/family/children")
@Tags("ProfileChildren")
@Security("bearerAuth")
export class ProfileChildrenEmployeeController extends Controller {
@ -35,10 +35,10 @@ export class ProfileChildrenEmployeeController extends Controller {
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
@Get("{profileId}")
public async getChildren(@Path() profileId: string) {
@Get("{profileEmployeeId}")
public async getChildren(@Path() profileEmployeeId: string) {
const lists = await this.childrenRepository.find({
where: { profileEmployeeId: profileId },
where: { profileEmployeeId: profileEmployeeId },
});
return new HttpSuccess(lists);
}
@ -73,8 +73,23 @@ export class ProfileChildrenEmployeeController extends Controller {
};
Object.assign(data, { ...body, ...meta });
await this.childrenRepository.save(data);
if(data){
const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), {
profileChildrenId: data.id,
childrenCareer: data.childrenCareer,
childrenFirstName: data.childrenFirstName,
childrenLastName: data.childrenLastName,
childrenPrefix: data.childrenPrefix,
childrenLive: data.childrenLive,
childrenCitizenId: data.childrenCitizenId,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.childrenHistoryRepository.save(history);
}
return new HttpSuccess();
}
@ -86,15 +101,21 @@ export class ProfileChildrenEmployeeController extends Controller {
@Path() childrenId: string,
) {
const record = await this.childrenRepository.findOneBy({ id: childrenId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileChildrenHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, body);
history.profileChildrenId = childrenId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
history.profileChildrenId = record.id;
history.childrenCareer = record.childrenCareer;
history.childrenFirstName = record.childrenFirstName;
history.childrenLastName = record.childrenLastName;
history.childrenPrefix = record.childrenPrefix;
history.childrenLive = record.childrenLive;
history.childrenCitizenId = record.childrenCitizenId;
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
await Promise.all([
@ -113,7 +134,7 @@ export class ProfileChildrenEmployeeController extends Controller {
const result = await this.childrenRepository.delete({ id: childrenId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -0,0 +1,207 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { ProfileFamilyCouple, CreateProfileFamilyCouple, UpdateProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
@Route("api/v1/org/profile/family/couple")
@Tags("ProfileFamilyCouple")
@Security("bearerAuth")
export class ProfileFamilyCoupleController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple);
private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory);
@Get("{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [{
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
couple: true,
couplePrefix: "string",
coupleFirstName: "string",
coupleLastName: "string",
coupleLastNameOld: "string",
coupleCareer: "string",
coupleCitizenId: "string",
coupleLive: true,
relationship: "string",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}],
})
public async getFamilyCouple(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyCouple = await this.ProfileFamilyCouple.find({
select: [
"id", "couple", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld",
"coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileId",
],
where: { profileId },
});
return new HttpSuccess(familyCouple);
}
@Get("history/{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
createdAt: "2024-03-19T11:00:29.769Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
couple: true,
couplePrefix: "string",
coupleFirstName: "string",
coupleLastName: "string",
coupleLastNameOld: "string",
coupleCareer: "string",
coupleCitizenId: "string",
coupleLive: true,
relationship: "string",
profileFamilyCoupleId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
],
})
public async familyCoupleHistory(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyCouple = await this.ProfileFamilyCouple.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileId: profileId},
});
const mapData = familyCouple.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
couple: y.couple,
couplePrefix: y.couplePrefix,
coupleFirstName: y.coupleFirstName,
coupleLastName: y.coupleLastName,
coupleLastNameOld: y.coupleLastNameOld,
coupleCareer: y.coupleCareer,
coupleLive: y.coupleLive,
relationship: y.relationship,
profileFamilyCoupleId: y.profileFamilyCoupleId,
profileId: profileId,
}));
return new HttpSuccess(mapData);
}
@Post()
public async FamilyCouple(
@Request() req: RequestWithUser,
@Body() body: CreateProfileFamilyCouple,
) {
const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
if (!familyCouple) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyCouple.createdUserId = req.user.sub;
familyCouple.createdFullName = req.user.name;
familyCouple.lastUpdateUserId = req.user.sub;
familyCouple.lastUpdateFullName = req.user.name;
await this.ProfileFamilyCouple.save(familyCouple);
if (familyCouple) {
const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), {
profileFamilyCoupleId: familyCouple.id,
couple: familyCouple.couple,
couplePrefix: familyCouple.couplePrefix,
coupleFirstName: familyCouple.coupleFirstName,
coupleLastName: familyCouple.coupleLastName,
coupleLastNameOld: familyCouple.coupleLastNameOld,
coupleCareer: familyCouple.coupleCareer,
coupleLive: familyCouple.coupleLive,
relationship: familyCouple.relationship,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.ProfileFamilyCoupleHistory.save(history);
}
return new HttpSuccess(familyCouple.id);
}
@Patch("{profileId}")
public async editFamilyCouple(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileFamilyCouple,
@Path() profileId: string,
) {
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileId: profileId });
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...familyCouple, id: undefined });
Object.assign(familyCouple, body);
familyCouple.lastUpdateUserId = req.user.sub,
familyCouple.lastUpdateFullName = req.user.name;
history.profileFamilyCoupleId = familyCouple.id;
history.couple = familyCouple.couple,
history.couplePrefix = familyCouple.couplePrefix,
history.coupleFirstName = familyCouple.coupleFirstName,
history.coupleLastName = familyCouple.coupleLastName,
history.coupleLastNameOld = familyCouple.coupleLastNameOld,
history.coupleCareer = familyCouple.coupleCareer,
history.coupleLive = familyCouple.coupleLive,
history.relationship = familyCouple.relationship,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
await Promise.all([
this.ProfileFamilyCouple.save(familyCouple),
this.ProfileFamilyCoupleHistory.save(history),
]);
return new HttpSuccess();
}
}

View file

@ -0,0 +1,207 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { ProfileFamilyCouple, CreateProfileEmployeeFamilyCouple, UpdateProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
@Route("api/v1/org/profile-employee/family/couple")
@Tags("ProfileEmployeeFamilyCouple")
@Security("bearerAuth")
export class ProfileFamilyCoupleEmployeeController extends Controller {
private profileRepo = AppDataSource.getRepository(ProfileEmployee);
private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple);
private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory);
@Get("{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: {
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
couple: true,
couplePrefix: "string",
coupleFirstName: "string",
coupleLastName: "string",
coupleLastNameOld: "string",
coupleCareer: "string",
coupleCitizenId: "string",
coupleLive: true,
relationship: "string",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
},
})
public async getFamilyCouple(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyCouple = await this.ProfileFamilyCouple.findOne({
select: [
"id", "couple", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld",
"coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileEmployeeId",
],
where: { profileEmployeeId },
});
return new HttpSuccess(familyCouple);
}
@Get("history/{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
createdAt: "2024-03-19T11:00:29.769Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
couple: true,
couplePrefix: "string",
coupleFirstName: "string",
coupleLastName: "string",
coupleLastNameOld: "string",
coupleCareer: "string",
coupleCitizenId: "string",
coupleLive: true,
relationship: "string",
profileFamilyCoupleId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
],
})
public async familyCoupleHistory(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyCouple = await this.ProfileFamilyCouple.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profileEmployeeId},
});
const mapData = familyCouple.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
couple: y.couple,
couplePrefix: y.couplePrefix,
coupleFirstName: y.coupleFirstName,
coupleLastName: y.coupleLastName,
coupleLastNameOld: y.coupleLastNameOld,
coupleCareer: y.coupleCareer,
coupleLive: y.coupleLive,
relationship: y.relationship,
profileFamilyCoupleId: y.profileFamilyCoupleId,
profileEmployeeId: profileEmployeeId,
}));
return new HttpSuccess(mapData);
}
@Post()
public async FamilyCouple(
@Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyCouple,
) {
const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
if (!familyCouple) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyCouple.createdUserId = req.user.sub;
familyCouple.createdFullName = req.user.name;
familyCouple.lastUpdateUserId = req.user.sub;
familyCouple.lastUpdateFullName = req.user.name;
await this.ProfileFamilyCouple.save(familyCouple);
if (familyCouple) {
const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), {
profileFamilyCoupleId: familyCouple.id,
couple: familyCouple.couple,
couplePrefix: familyCouple.couplePrefix,
coupleFirstName: familyCouple.coupleFirstName,
coupleLastName: familyCouple.coupleLastName,
coupleLastNameOld: familyCouple.coupleLastNameOld,
coupleCareer: familyCouple.coupleCareer,
coupleLive: familyCouple.coupleLive,
relationship: familyCouple.relationship,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.ProfileFamilyCoupleHistory.save(history);
}
return new HttpSuccess(familyCouple.id);
}
@Patch("{profileEmployeeId}")
public async editFamilyCouple(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileFamilyCouple,
@Path() profileEmployeeId: string,
) {
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileEmployeeId: profileEmployeeId });
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...familyCouple, id: undefined });
Object.assign(familyCouple, body);
familyCouple.lastUpdateUserId = req.user.sub,
familyCouple.lastUpdateFullName = req.user.name;
history.profileFamilyCoupleId = familyCouple.id;
history.couple = familyCouple.couple,
history.couplePrefix = familyCouple.couplePrefix,
history.coupleFirstName = familyCouple.coupleFirstName,
history.coupleLastName = familyCouple.coupleLastName,
history.coupleLastNameOld = familyCouple.coupleLastNameOld,
history.coupleCareer = familyCouple.coupleCareer,
history.coupleLive = familyCouple.coupleLive,
history.relationship = familyCouple.relationship,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
await Promise.all([
this.ProfileFamilyCouple.save(familyCouple),
this.ProfileFamilyCoupleHistory.save(history),
]);
return new HttpSuccess();
}
}

View file

@ -0,0 +1,206 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { ProfileFamilyFather, CreateProfileFamilyFather, UpdateProfileFamilyFather } from "../entities/ProfileFamilyFather";
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
@Route("api/v1/org/profile/family/father")
@Tags("ProfileFamilyFather")
@Security("bearerAuth")
export class ProfileFamilyFatherController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather);
private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory);
@Get("{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: {
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
fatherPrefix: "string",
fatherFirstName: "string",
fatherLastName: "string",
fatherCareer: "string",
fatherCitizenId: "string",
fatherLive: true,
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
},
})
public async getFamilyFather(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyFather = await this.ProfileFamilyFather.findOne({
select: [
"id", "fatherPrefix", "fatherFirstName", "fatherLastName",
"fatherCareer", "fatherCitizenId", "fatherLive", "profileId",
],
where: { profileId },
});
return new HttpSuccess(familyFather);
}
@Get("history/{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
createdAt: "2024-03-19T11:00:29.769Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
fatherPrefix: "string",
fatherFirstName: "string",
fatherLastName: "string",
fatherCareer: "string",
fatherCitizenId: "string",
fatherLive: true,
profileFamilyFatherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
],
})
public async familyFatherHistory(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyFather = await this.ProfileFamilyFather.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileId: profileId},
});
const mapData = familyFather.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
fatherPrefix: y.fatherPrefix,
fatherFirstName: y.fatherFirstName,
fatherLastName: y.fatherLastName,
fatherCareer: y.fatherCareer,
fatherCitizenId: y.fatherCitizenId,
fatherLive: y.fatherLive,
profileFamilyFatherId: y.profileFamilyFatherId,
profileId: profileId,
}));
return new HttpSuccess(mapData);
}
@Post()
public async FamilyFather(
@Request() req: RequestWithUser,
@Body() body: CreateProfileFamilyFather,
) {
const familyFather = Object.assign(new ProfileFamilyFather(), body);
if (!familyFather) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyFather.createdUserId = req.user.sub;
familyFather.createdFullName = req.user.name;
familyFather.lastUpdateUserId = req.user.sub;
familyFather.lastUpdateFullName = req.user.name;
await this.ProfileFamilyFather.save(familyFather);
if (familyFather) {
const history: ProfileFamilyFatherHistory = Object.assign(new ProfileFamilyFatherHistory(), {
profileFamilyFatherId: familyFather.id,
fatherPrefix: familyFather.fatherPrefix,
fatherFirstName: familyFather.fatherFirstName,
fatherLastName: familyFather.fatherLastName,
fatherCareer: familyFather.fatherCareer,
fatherCitizenId: familyFather.fatherCitizenId,
fatherLive: familyFather.fatherLive,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.ProfileFamilyFatherHistory.save(history);
}
return new HttpSuccess(familyFather.id);
}
@Patch("{profileId}")
public async editFamilyFather(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileFamilyFather,
@Path() profileId: string,
) {
const familyFather = await this.ProfileFamilyFather.findOneBy({ profileId: profileId });
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...familyFather, id: undefined });
Object.assign(familyFather, body);
familyFather.lastUpdateUserId = req.user.sub,
familyFather.lastUpdateFullName = req.user.name;
history.profileFamilyFatherId = familyFather.id; //profileFamilyFatherId
history.fatherPrefix = familyFather.fatherPrefix,
history.fatherFirstName = familyFather.fatherFirstName,
history.fatherLastName = familyFather.fatherLastName,
history.fatherCareer = familyFather.fatherCareer,
history.fatherCitizenId = familyFather.fatherCitizenId,
history.fatherLive = familyFather.fatherLive,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
await Promise.all([
this.ProfileFamilyFather.save(familyFather),
this.ProfileFamilyFatherHistory.save(history),
]);
return new HttpSuccess();
}
// @Delete("{profileId}")
// public async deleteFamilyFather(@Path() profileId: string) {
// const result = await this.ProfileFamilyFather.delete({ profileId: profileId });
// if (result.affected == undefined || result.affected <= 0) {
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// }
// return new HttpSuccess();
// }
}

View file

@ -0,0 +1,196 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { ProfileFamilyFather, CreateProfileEmployeeFamilyFather, UpdateProfileFamilyFather } from "../entities/ProfileFamilyFather";
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
@Route("api/v1/org/profile-employee/family/father")
@Tags("ProfileEmployeeFamilyFather")
@Security("bearerAuth")
export class ProfileFamilyFatherEmployeeController extends Controller {
private profileRepo = AppDataSource.getRepository(ProfileEmployee);
private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather);
private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory);
@Get("{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: {
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
fatherPrefix: "string",
fatherFirstName: "string",
fatherLastName: "string",
fatherCareer: "string",
fatherCitizenId: "string",
fatherLive: true,
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
},
})
public async getFamilyFather(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyFather = await this.ProfileFamilyFather.findOne({
select: [
"id", "fatherPrefix", "fatherFirstName", "fatherLastName",
"fatherCareer", "fatherCitizenId", "fatherLive", "profileEmployeeId",
],
where: { profileEmployeeId },
});
return new HttpSuccess(familyFather);
}
@Get("history/{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
createdAt: "2024-03-19T11:00:29.769Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
fatherPrefix: "string",
fatherFirstName: "string",
fatherLastName: "string",
fatherCareer: "string",
fatherCitizenId: "string",
fatherLive: true,
profileFamilyFatherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
],
})
public async familyFatherHistory(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyFather = await this.ProfileFamilyFather.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profileEmployeeId},
});
const mapData = familyFather.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
fatherPrefix: y.fatherPrefix,
fatherFirstName: y.fatherFirstName,
fatherLastName: y.fatherLastName,
fatherCareer: y.fatherCareer,
fatherCitizenId: y.fatherCitizenId,
fatherLive: y.fatherLive,
profileFamilyFatherId: y.profileFamilyFatherId,
profileEmployeeId: profileEmployeeId,
}));
return new HttpSuccess(mapData);
}
@Post()
public async FamilyFather(
@Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyFather,
) {
const familyFather = Object.assign(new ProfileFamilyFather(), body);
if (!familyFather) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyFather.createdUserId = req.user.sub;
familyFather.createdFullName = req.user.name;
familyFather.lastUpdateUserId = req.user.sub;
familyFather.lastUpdateFullName = req.user.name;
await this.ProfileFamilyFather.save(familyFather);
if (familyFather) {
const history: ProfileFamilyFatherHistory = Object.assign(new ProfileFamilyFatherHistory(), {
profileFamilyFatherId: familyFather.id,
fatherPrefix: familyFather.fatherPrefix,
fatherFirstName: familyFather.fatherFirstName,
fatherLastName: familyFather.fatherLastName,
fatherCareer: familyFather.fatherCareer,
fatherCitizenId: familyFather.fatherCitizenId,
fatherLive: familyFather.fatherLive,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.ProfileFamilyFatherHistory.save(history);
}
return new HttpSuccess(familyFather.id);
}
@Patch("{profileEmployeeId}")
public async editFamilyFather(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileFamilyFather,
@Path() profileEmployeeId: string,
) {
const familyFather = await this.ProfileFamilyFather.findOneBy({ profileEmployeeId: profileEmployeeId });
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...familyFather, id: undefined });
Object.assign(familyFather, body);
familyFather.lastUpdateUserId = req.user.sub,
familyFather.lastUpdateFullName = req.user.name;
history.profileFamilyFatherId = familyFather.id;
history.fatherPrefix = familyFather.fatherPrefix,
history.fatherFirstName = familyFather.fatherFirstName,
history.fatherLastName = familyFather.fatherLastName,
history.fatherCareer = familyFather.fatherCareer,
history.fatherCitizenId = familyFather.fatherCitizenId,
history.fatherLive = familyFather.fatherLive,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
await Promise.all([
this.ProfileFamilyFather.save(familyFather),
this.ProfileFamilyFatherHistory.save(history),
]);
return new HttpSuccess();
}
}

View file

@ -0,0 +1,196 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { ProfileFamilyMother, CreateProfileFamilyMother, UpdateProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
@Route("api/v1/org/profile/family/mother")
@Tags("ProfileFamilyMother")
@Security("bearerAuth")
export class ProfileFamilyMotherController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother);
private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory);
@Get("{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: {
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
motherPrefix: "string",
motherFirstName: "string",
motherLastName: "string",
motherCareer: "string",
motherCitizenId: "string",
motherLive: true,
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
},
})
public async getFamilyMother(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyMother = await this.ProfileFamilyMother.findOne({
select: [
"id", "motherPrefix", "motherFirstName", "motherLastName",
"motherCareer", "motherCitizenId", "motherLive", "profileId",
],
where: { profileId },
});
return new HttpSuccess(familyMother);
}
@Get("history/{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
createdAt: "2024-03-19T11:00:29.769Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
motherPrefix: "string",
motherFirstName: "string",
motherLastName: "string",
motherCareer: "string",
motherCitizenId: "string",
motherLive: true,
profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
],
})
public async familyMotherHistory(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyMother = await this.ProfileFamilyMother.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileId: profileId},
});
const mapData = familyMother.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
motherPrefix: y.motherPrefix,
motherFirstName: y.motherFirstName,
motherLastName: y.motherLastName,
motherCareer: y.motherCareer,
motherCitizenId: y.motherCitizenId,
motherLive: y.motherLive,
profileFamilyMotherId: y.profileFamilyMotherId,
profileId: profileId,
}));
return new HttpSuccess(mapData);
}
@Post()
public async FamilyMother(
@Request() req: RequestWithUser,
@Body() body: CreateProfileFamilyMother,
) {
const familyMother = Object.assign(new ProfileFamilyMother(), body);
if (!familyMother) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name;
familyMother.lastUpdateUserId = req.user.sub;
familyMother.lastUpdateFullName = req.user.name;
await this.ProfileFamilyMother.save(familyMother);
if (familyMother) {
const history: ProfileFamilyMotherHistory = Object.assign(new ProfileFamilyMotherHistory(), {
profileFamilyMotherId: familyMother.id,
motherPrefix: familyMother.motherPrefix,
motherFirstName: familyMother.motherFirstName,
motherLastName: familyMother.motherLastName,
motherCareer: familyMother.motherCareer,
motherCitizenId: familyMother.motherCitizenId,
motherLive: familyMother.motherLive,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.ProfileFamilyMotherHistory.save(history);
}
return new HttpSuccess(familyMother.id);
}
@Patch("{profileId}")
public async editFamilyMother(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileFamilyMother,
@Path() profileId: string,
) {
const familyMother = await this.ProfileFamilyMother.findOneBy({ profileId: profileId });
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...familyMother, id: undefined });
Object.assign(familyMother, body);
familyMother.lastUpdateUserId = req.user.sub,
familyMother.lastUpdateFullName = req.user.name;
history.profileFamilyMotherId = familyMother.id;
history.motherPrefix = familyMother.motherPrefix,
history.motherFirstName = familyMother.motherFirstName,
history.motherLastName = familyMother.motherLastName,
history.motherCareer = familyMother.motherCareer,
history.motherCitizenId = familyMother.motherCitizenId,
history.motherLive = familyMother.motherLive,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
await Promise.all([
this.ProfileFamilyMother.save(familyMother),
this.ProfileFamilyMotherHistory.save(history),
]);
return new HttpSuccess();
}
}

View file

@ -0,0 +1,196 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { ProfileFamilyMother, CreateProfileEmployeeFamilyMother, UpdateProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
@Route("api/v1/org/profile-employee/family/mother")
@Tags("ProfileEmployeeFamilyMother")
@Security("bearerAuth")
export class ProfileFamilyMotherEmployeeController extends Controller {
private profileRepo = AppDataSource.getRepository(ProfileEmployee);
private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother);
private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory);
@Get("{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: {
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
motherPrefix: "string",
motherFirstName: "string",
motherLastName: "string",
motherCareer: "string",
motherCitizenId: "string",
motherLive: true,
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
},
})
public async getFamilyMother(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyMother = await this.ProfileFamilyMother.findOne({
select: [
"id", "motherPrefix", "motherFirstName", "motherLastName",
"motherCareer", "motherCitizenId", "motherLive", "profileEmployeeId",
],
where: { profileEmployeeId },
});
return new HttpSuccess(familyMother);
}
@Get("history/{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
createdAt: "2024-03-19T11:00:29.769Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T11:00:29.769Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
motherPrefix: "string",
motherFirstName: "string",
motherLastName: "string",
motherCareer: "string",
motherCitizenId: "string",
motherLive: true,
profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
],
})
public async familyMotherHistory(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyMother = await this.ProfileFamilyMother.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profileEmployeeId},
});
const mapData = familyMother.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
motherPrefix: y.motherPrefix,
motherFirstName: y.motherFirstName,
motherLastName: y.motherLastName,
motherCareer: y.motherCareer,
motherCitizenId: y.motherCitizenId,
motherLive: y.motherLive,
profileFamilyMotherId: y.profileFamilyMotherId,
profileEmployeeId: profileEmployeeId,
}));
return new HttpSuccess(mapData);
}
@Post()
public async FamilyMother(
@Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyMother,
) {
const familyMother = Object.assign(new ProfileFamilyMother(), body);
if (!familyMother) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name;
familyMother.lastUpdateUserId = req.user.sub;
familyMother.lastUpdateFullName = req.user.name;
await this.ProfileFamilyMother.save(familyMother);
if (familyMother) {
const history: ProfileFamilyMotherHistory = Object.assign(new ProfileFamilyMotherHistory(), {
profileFamilyMotherId: familyMother.id,
motherPrefix: familyMother.motherPrefix,
motherFirstName: familyMother.motherFirstName,
motherLastName: familyMother.motherLastName,
motherCareer: familyMother.motherCareer,
motherCitizenId: familyMother.motherCitizenId,
motherLive: familyMother.motherLive,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.ProfileFamilyMotherHistory.save(history);
}
return new HttpSuccess(familyMother.id);
}
@Patch("{profileEmployeeId}")
public async editFamilyMother(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileFamilyMother,
@Path() profileEmployeeId: string,
) {
const familyMother = await this.ProfileFamilyMother.findOneBy({ profileEmployeeId: profileEmployeeId });
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...familyMother, id: undefined });
Object.assign(familyMother, body);
familyMother.lastUpdateUserId = req.user.sub,
familyMother.lastUpdateFullName = req.user.name;
history.profileFamilyMotherId = familyMother.id;
history.motherPrefix = familyMother.motherPrefix,
history.motherFirstName = familyMother.motherFirstName,
history.motherLastName = familyMother.motherLastName,
history.motherCareer = familyMother.motherCareer,
history.motherCitizenId = familyMother.motherCitizenId,
history.motherLive = familyMother.motherLive,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
await Promise.all([
this.ProfileFamilyMother.save(familyMother),
this.ProfileFamilyMotherHistory.save(history),
]);
return new HttpSuccess();
}
}