crud emp myinfo

This commit is contained in:
AdisakKanthawilang 2024-05-14 10:29:05 +07:00
parent 2d582be2a1
commit ac82b6351f
10 changed files with 1050 additions and 2 deletions

View file

@ -0,0 +1,187 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { Profile } from "../entities/Profile";
import {
CreateProfileAbility,
CreateProfileAbilityEmployee,
ProfileAbility,
UpdateProfileAbility,
} from "../entities/ProfileAbility";
import { ProfileAbilityHistory } from "../entities/ProfileAbilityHistory";
import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/profile-employee/ability")
@Tags("ProfileAbilityEmployee")
@Security("bearerAuth")
export class ProfileAbilityEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility);
private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory);
@Get("{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "ad7d0955-7bcd-4ed0-911c-2edceba12579",
createdAt: "2024-03-12T21:37:35.037Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-12T21:37:35.037Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "test bar",
lastUpdateFullName: "test bar",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
remark: "ต้องส่งให้ทันก่อนวันที่ 15 มีนาคม",
detail: "-",
reference: "-",
dateStart: "2024-03-13T04:36:06.000Z",
dateEnd: "2024-03-13T04:36:06.000Z",
field: "ความมั่นคง",
},
],
})
public async detailProfileAbility(@Path() profileEmployeeId: string) {
const getProfileAbilityId = await this.profileAbilityRepo.findBy({ profileEmployeeId });
if (!getProfileAbilityId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAbilityId);
}
@Get("history/{abilityId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "1c92cd8a-e176-48af-ac00-c018fb4c9895",
createdAt: "2024-03-12T21:38:56.342Z",
createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-12T21:38:56.342Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "test bar",
remark: "ต้องส่งให้ทันก่อนวันที่ 15 มีนาคม",
detail: "ด่วน",
reference: "-",
dateStart: "2024-03-13T04:36:06.000Z",
dateEnd: "2024-03-13T04:36:06.000Z",
field: "ความมั่นคง",
profileAbilityId: "ad7d0955-7bcd-4ed0-911c-2edceba12579",
},
{
id: "2fb95768-cb62-40a3-9540-5a561d640959",
createdAt: "2024-03-12T21:39:06.094Z",
createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-12T21:39:06.094Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "test bar",
remark: "ต้องส่งให้ทันก่อนวันที่ 15 มีนาคม",
detail: "ด่วนมากสุด",
reference: "-",
dateStart: "2024-03-13T04:36:06.000Z",
dateEnd: "2024-03-13T04:36:06.000Z",
field: "ความมั่นคง",
profileAbilityId: "ad7d0955-7bcd-4ed0-911c-2edceba12579",
},
],
})
public async getProfileAbilityHistory(@Path() abilityId: string) {
const record = await this.profileAbilityHistoryRepo.findBy({
profileAbilityId: abilityId,
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileAbility(
@Request() req: RequestWithUser,
@Body() body: CreateProfileAbilityEmployee,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const data = new ProfileAbility();
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.profileAbilityRepo.save(data);
return new HttpSuccess();
}
@Patch("{abilityId}")
public async editProfileAbility(
@Body() requestBody: UpdateProfileAbility,
@Request() req: RequestWithUser,
@Path() abilityId: string,
) {
const record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileAbilityHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, requestBody);
history.profileAbilityId = abilityId;
history.lastUpdateFullName = req.user.name;
record.lastUpdateFullName = req.user.name;
await Promise.all([
this.profileAbilityRepo.save(record),
this.profileAbilityHistoryRepo.save(history),
]);
return new HttpSuccess();
}
@Delete("{abilityId}")
public async deleteProfileAbility(@Path() abilityId: string) {
await this.profileAbilityHistoryRepo.delete({
profileAbilityId: abilityId,
});
const result = await this.profileAbilityRepo.delete({ id: abilityId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -0,0 +1,174 @@
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 { ProfileChangeNameHistory } from "../entities/ProfileChangeNameHistory";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import {
CreateProfileChangeName,
CreateProfileChangeNameEmployee,
ProfileChangeName,
UpdateProfileChangeName,
} from "../entities/ProfileChangeName";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/profile-employee/changeName")
@Tags("ProfileChangeNameEmployee")
@Security("bearerAuth")
export class ProfileChangeNameEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private changeNameRepository = AppDataSource.getRepository(ProfileChangeName);
private changeNameHistoryRepository = AppDataSource.getRepository(ProfileChangeNameHistory);
@Get("{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
prefix: "string",
firstName: "string",
lastName: "string",
status: "string",
},
],
})
public async getChangeName(@Path() profileEmployeeId: string) {
const lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profileEmployeeId },
select: ["id", "prefix", "firstName", "lastName", "status"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("history/{changeNameId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
prefix: "string",
firstName: "string",
lastName: "string",
status: "string",
createdFullName: "string",
createdAt: "string",
},
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
prefix: "string",
firstName: "string",
lastName: "string",
status: "string",
createdFullName: "string",
createdAt: "string",
},
],
})
public async changeNameHistory(@Path() changeNameId: string) {
const record = await this.changeNameHistoryRepository.find({
where: { profileChangeNameId: changeNameId },
select: [
"id",
"prefix",
"firstName",
"lastName",
"status",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@Post()
public async newChangeName(
@Request() req: RequestWithUser,
@Body() body: CreateProfileChangeNameEmployee,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const data = new ProfileChangeName();
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.changeNameRepository.save(data);
return new HttpSuccess(data.id);
}
@Patch("{changeNameId}")
public async editChangeName(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileChangeName,
@Path() changeNameId: string,
) {
const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileChangeNameHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, body);
history.profileChangeNameId = changeNameId;
record.lastUpdateFullName = req.user.name;
history.lastUpdateFullName = req.user.name;
await Promise.all([
this.changeNameRepository.save(record),
this.changeNameHistoryRepository.save(history),
]);
return new HttpSuccess();
}
@Delete("{changeNameId}")
public async deleteTraning(@Path() changeNameId: string) {
await this.changeNameHistoryRepository.delete({
profileChangeNameId: changeNameId,
});
const result = await this.changeNameRepository.delete({ id: changeNameId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -0,0 +1,235 @@
import {
Controller,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
SuccessResponse,
Response,
Get,
Query,
Patch,
Example,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import {
ProfileEducation,
CreateProfileEducation,
UpdateProfileEducation,
CreateProfileEducationEmployee,
} from "../entities/ProfileEducation";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { AppDataSource } from "../database/data-source";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/profile-employee/educations")
@Tags("ProfileEducationsEmployee")
@Security("bearerAuth")
export class ProfileEducationsEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory);
@Get("{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "f6c693b4-1a9b-4fbe-95c5-ed4da50d35b6",
createdAt: "2024-03-12T20:26:42.621Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-12T20:33:09.000Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "test bar",
lastUpdateFullName: "test bar",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
isActive: true,
country: "string",
degree: "ปวส",
duration: "-",
durationYear: 0,
field: "ชางเทคนิค ชั้นสูง",
finishDate: "2024-03-13T03:23:31.000Z",
fundName: "-",
gpa: "3.64",
institute: "เทคโนเชียงใหม่",
other: "string",
startDate: "2024-03-13T03:23:31.000Z",
endDate: "2024-03-13T03:23:31.000Z",
educationLevel: "ปวส",
educationLevelId: "string",
positionPath: "string",
positionPathId: "string",
note: "string",
isDate: true,
isEducation: true,
},
],
})
public async detailProfileEducation(@Path() profileEmployeeId: string) {
const getProfileEducation = await this.profileEducationRepo.findBy({ profileEmployeeId });
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileEducation);
}
@Get("history/{educationId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "294aa117-6ce7-4c23-b5bd-fe1f12932c4a",
createdAt: "2024-03-12T20:29:45.251Z",
createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-12T20:29:45.251Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "test bar",
isActive: true,
country: "string",
degree: "ปวส",
duration: "-",
durationYear: 0,
field: "ชางเทคนิค",
finishDate: "2024-03-13T03:23:31.000Z",
fundName: "-",
gpa: "3.64",
institute: "เทคโนเชียงใหม่",
other: "string",
startDate: "2024-03-13T03:23:31.000Z",
endDate: "2024-03-13T03:23:31.000Z",
educationLevel: "ปวส",
educationLevelId: "string",
positionPath: "string",
positionPathId: "string",
note: "string",
isDate: true,
isEducation: true,
profileEducationId: "f6c693b4-1a9b-4fbe-95c5-ed4da50d35b6",
},
{
id: "2f00bd59-be3e-46d8-92a2-c4700baabf12",
createdAt: "2024-03-12T20:33:09.128Z",
createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-12T20:33:09.128Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "test bar",
isActive: true,
country: "string",
degree: "ปวส",
duration: "-",
durationYear: 0,
field: "ชางเทคนิค ชั้นสูง",
finishDate: "2024-03-13T03:23:31.000Z",
fundName: "-",
gpa: "3.64",
institute: "เทคโนเชียงใหม่",
other: "string",
startDate: "2024-03-13T03:23:31.000Z",
endDate: "2024-03-13T03:23:31.000Z",
educationLevel: "ปวส",
educationLevelId: "string",
positionPath: "string",
positionPathId: "string",
note: "string",
isDate: true,
isEducation: true,
profileEducationId: "f6c693b4-1a9b-4fbe-95c5-ed4da50d35b6",
},
],
})
public async getProfileEducationHistory(@Path() educationId: string) {
const record = await this.profileEducationHistoryRepo.findBy({
profileEducationId: educationId,
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Post()
public async newProfileEducation(
@Request() req: RequestWithUser,
@Body() body: CreateProfileEducationEmployee,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const data = new ProfileEducation();
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.profileEducationRepo.save(data);
return new HttpSuccess();
}
@Patch("{educationId}")
public async editProfileEducation(
@Body() requestBody: UpdateProfileEducation,
@Request() req: RequestWithUser,
@Path() educationId: string,
) {
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileEducationHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, requestBody);
history.profileEducationId = educationId;
history.lastUpdateFullName = req.user.name;
record.lastUpdateFullName = req.user.name;
await Promise.all([
this.profileEducationRepo.save(record),
this.profileEducationHistoryRepo.save(history),
]);
return new HttpSuccess();
}
@Delete("{educationId}")
public async deleteProfileEducation(@Path() educationId: string) {
await this.profileEducationHistoryRepo.delete({
profileEducationId: educationId,
});
const result = await this.profileEducationRepo.delete({ id: educationId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -0,0 +1,367 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import {
CreateChildren,
CreateProfileFamily,
CreateProfileFamilyEmployee,
ProfileChildren,
ProfileChildrenHistory,
ProfileFamilyHistory,
UpdateProfileFamily,
} from "../entities/ProfileFamily";
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 { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/profile-employee/family")
@Tags("ProfileFamilyHistoryEmployee")
@Security("bearerAuth")
export class ProfileFamilyHistoryEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private familyHistoryRepo = AppDataSource.getRepository(ProfileFamilyHistory);
private childrenRepo = AppDataSource.getRepository(ProfileChildren);
private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory);
@Get("{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,
fatherPrefix: "string",
fatherFirstName: "string",
fatherLastName: "string",
fatherCareer: "string",
fatherCitizenId: "string",
fatherLive: true,
motherPrefix: "string",
motherFirstName: "string",
motherLastName: "string",
motherCareer: "string",
motherCitizenId: "string",
motherLive: true,
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
children: [
{
id: "9717f95a-cd20-4edb-a8b9-443c1dd99f90",
createdAt: "2024-03-19T11:00:29.785Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T11:00:29.785Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
childrenCareer: "string",
childrenFirstName: "string",
childrenLastName: "string",
childrenPrefix: "string",
childrenLive: "string",
childrenCitizenId: "string",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
},
],
},
})
public async getFamilyHistory(@Path() profileEmployeeId: string) {
const family = await this.familyHistoryRepo.find({
take: 1,
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId },
});
const children = await this.childrenRepo.find({
order: { createdAt: "ASC" },
where: { profileEmployeeId },
});
return new HttpSuccess(
family.length > 0
? {
...family[0],
children,
}
: null,
);
}
@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,
fatherPrefix: "string",
fatherFirstName: "string",
fatherLastName: "string",
fatherCareer: "string",
fatherCitizenId: "string",
fatherLive: true,
motherPrefix: "string",
motherFirstName: "string",
motherLastName: "string",
motherCareer: "string",
motherCitizenId: "string",
motherLive: true,
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
children: [
{
id: "980835f8-d766-4b6b-b7dc-1726db889352",
createdAt: "2024-03-19T12:42:11.437Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T12:42:11.437Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
childrenCareer: "hey",
childrenFirstName: "hey",
childrenLastName: "hey",
childrenPrefix: "hey",
childrenLive: "hey",
childrenCitizenId: "hey",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileFamilyHistoryId: "6207ae29-05ef-4abb-9a37-a887265d671e",
profileChildrenId: "222db098-3f08-4d0b-ac58-7914fa41032b",
},
{
id: "cd539e67-3f34-4b8c-a9da-b7eb193fa0b4",
createdAt: "2024-03-19T12:42:11.438Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-19T12:42:11.438Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
childrenCareer: "ay",
childrenFirstName: "ay",
childrenLastName: "ay",
childrenPrefix: "ay",
childrenLive: "ay",
childrenCitizenId: "ay",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileFamilyHistoryId: "6207ae29-05ef-4abb-9a37-a887265d671e",
profileChildrenId: "d0495491-9e9f-4d2e-bc3b-c2833955fa12",
},
],
},
{
id: "60bbf8d1-f674-4d88-b3fb-b5603e408319",
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: "yeah",
coupleCitizenId: "yeah",
coupleLive: true,
fatherPrefix: "yeah",
fatherFirstName: "haaa",
fatherLastName: "yeah",
fatherCareer: "haaa",
fatherCitizenId: "yeah",
fatherLive: true,
motherPrefix: "string",
motherFirstName: "string",
motherLastName: "string",
motherCareer: "string",
motherCitizenId: "string",
motherLive: true,
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
children: [],
},
],
})
public async familyHistory(@Path() profileEmployeeId: string) {
const family = await this.familyHistoryRepo.find({
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId },
});
family.shift();
const record = await Promise.all(
family.map(async (v) => ({
...v,
children: await this.childrenHistoryRepo.find({
order: { createdAt: "ASC" },
where: { profileFamilyHistoryId: v.id },
}),
})),
);
return new HttpSuccess(record);
}
@Post()
public async newFamilyHistory(
@Request() req: RequestWithUser,
@Body() body: CreateProfileFamilyEmployee,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const dataFamily = new ProfileFamilyHistory();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
};
const { children, ...family } = body;
Object.assign(dataFamily, { ...family, ...meta });
await this.familyHistoryRepo.save(dataFamily);
const profileEmployeeId = dataFamily.profileEmployeeId;
await Promise.all(
children.map(async (v) => {
const dataChildren = new ProfileChildrenHistory();
Object.assign(dataChildren, { ...v, profileEmployeeId, ...meta });
await this.childrenRepo.save(dataChildren);
}),
);
return new HttpSuccess();
}
@Patch("{profileEmployeeId}")
public async editFamilyHistory(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileFamily,
@Path() profileEmployeeId: string,
) {
const familyRecord = (
await this.familyHistoryRepo.find({
take: 1,
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId },
})
)[0];
if (!familyRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const childrenRecord = await this.childrenRepo.findBy({
profileEmployeeId: familyRecord.profileEmployeeId,
});
const historyData = new ProfileFamilyHistory();
const { children, ...family } = body;
Object.assign(historyData, { ...familyRecord, ...family, id: undefined });
historyData.lastUpdateFullName = req.user.name;
historyData.lastUpdateFullName = req.user.name;
const newChild: CreateChildren[] = [];
for (let child of children) {
newChild.push(
Object.assign(new ProfileChildren(), {
...child,
profileEmployeeId,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
id: !childrenRecord.find((v) => v.id === child.id) ? undefined : child.id,
}),
);
}
await Promise.all([
this.familyHistoryRepo.save({ ...historyData, lastUpdatedAt: undefined }),
...newChild.map(async (v) => {
return await this.childrenRepo.save(v);
}),
...childrenRecord.map(async (v) => {
if (!children.find((x) => x.id === v.id)) {
return await this.childrenRepo.delete({ id: v.id });
}
}),
...childrenRecord.map(async (v) => {
if (children.find((x) => x.id === v.id)) {
return await this.childrenHistoryRepo.save(
this.childrenHistoryRepo.create({
...v,
profileFamilyHistoryId: familyRecord.id,
profileChildrenId: v.id,
id: undefined,
}),
);
}
}),
]);
return new HttpSuccess();
}
@Delete("{profileEmployeeId}")
public async deleteFamilyHistory(@Path() profileEmployeeId: string) {
const result = await this.familyHistoryRepo.delete({ id: profileEmployeeId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess();
}
}

View file

@ -16,7 +16,7 @@ import { ProfileAbility } from "./ProfileAbility";
import { ProfileDuty } from "./ProfileDuty";
import { ProfileNopaid } from "./ProfileNopaid";
import { ProfileOther } from "./ProfileOther";
import { ProfileFamilyHistory } from "./ProfileFamily";
import { ProfileChildren, ProfileFamilyHistory } from "./ProfileFamily";
import { ProfileGovernment } from "./ProfileGovernment";
import { Province } from "./Province";
import { SubDistrict } from "./SubDistrict";
@ -297,6 +297,9 @@ export class Profile extends EntityBase {
@OneToMany(() => ProfileFamilyHistory, (profileFamily) => profileFamily.profile)
profileFamily: ProfileFamilyHistory[];
@OneToMany(() => ProfileChildren, (profileChildren) => profileChildren.profile)
profileChildren: ProfileChildren[];
@OneToMany(() => ProfileGovernment, (profileGovernment) => profileGovernment.profile)
profileGovernment: ProfileGovernment[];

View file

@ -95,6 +95,16 @@ export class CreateProfileAbility {
field: string | null;
}
export class CreateProfileAbilityEmployee {
profileEmployeeId: string | null;
remark: string | null;
detail: string | null;
reference: string | null;
dateStart: Date | null;
dateEnd: Date | null;
field: string | null;
}
export type UpdateProfileAbility = {
remark?: string | null;
detail?: string | null;

View file

@ -92,6 +92,16 @@ export class CreateProfileChangeName {
documentId: string | null;
}
export class CreateProfileChangeNameEmployee {
profileEmployeeId: string | null;
prefixId: string | null;
prefix: string | null;
firstName: string | null;
lastName: string | null;
status: string | null;
documentId: string | null;
}
export type UpdateProfileChangeName = {
prefixId?: string | null;
prefix?: string | null;

View file

@ -206,6 +206,29 @@ export class CreateProfileEducation {
note: string | null;
}
export class CreateProfileEducationEmployee {
profileEmployeeId: string | null;
country: string | null;
degree: string | null;
duration: string | null;
durationYear: number;
field: string | null;
finishDate: Date | null;
fundName: string | null;
gpa: string | null;
institute: string | null;
other: string | null;
startDate: Date | null;
endDate: Date | null;
educationLevel: string | null;
educationLevelId: string | null;
positionPath: string | null;
positionPathId: string | null;
isDate: boolean | null;
isEducation: boolean | null;
note: string | null;
}
export type UpdateProfileEducation = {
country?: string | null;
degree?: string | null;

View file

@ -15,7 +15,7 @@ import { ProfileDuty } from "./ProfileDuty";
import { ProfileNopaid } from "./ProfileNopaid";
import { ProfileDiscipline } from "./ProfileDiscipline";
import { ProfileChangeName } from "./ProfileChangeName";
import { ProfileFamilyHistory } from "./ProfileFamily";
import { ProfileChildren, ProfileFamilyHistory } from "./ProfileFamily";
import { ProfileEducation } from "./ProfileEducation";
import { ProfileAbility } from "./ProfileAbility";
@Entity("profileEmployee")
@ -242,6 +242,9 @@ export class ProfileEmployee extends EntityBase {
@OneToMany(() => ProfileFamilyHistory, (v) => v.profileEmployee)
profileFamilys: ProfileFamilyHistory[];
@OneToMany(() => ProfileChildren, (v) => v.profileEmployee)
profileChildrens: ProfileChildren[];
@OneToMany(() => ProfileEducation, (v) => v.profileEmployee)
profileEducations: ProfileEducation[];

View file

@ -229,11 +229,23 @@ export class ProfileChildren extends EntityBase {
})
profileId: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง ProfileEmployee",
default: null,
})
profileEmployeeId: string;
@ManyToOne(() => Profile, (v) => v.profileFamily, { onDelete: "CASCADE" })
profile: Profile;
@OneToMany(() => ProfileChildrenHistory, (v) => v.profileChildren)
histories: Profile;
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileChildrens)
@JoinColumn({ name: "profileEmployeeId" })
profileEmployee: ProfileEmployee;
}
@Entity("profileChildrenHistory")
@ -306,6 +318,30 @@ export type CreateProfileFamily = {
profileId: string;
children: CreateChildren[];
};
export type CreateProfileFamilyEmployee = {
couple: boolean | null;
couplePrefix: string | null;
coupleFirstName: string | null;
coupleLastName: string | null;
coupleLastNameOld: string | null;
coupleCareer: string | null;
coupleCitizenId: string | null;
coupleLive: boolean | null;
fatherPrefix: string | null;
fatherFirstName: string | null;
fatherLastName: string | null;
fatherCareer: string | null;
fatherCitizenId: string | null;
fatherLive: boolean | null;
motherPrefix: string | null;
motherFirstName: string | null;
motherLastName: string | null;
motherCareer: string | null;
motherCitizenId: string | null;
motherLive: boolean | null;
profileEmployeeId: string | null;
children: CreateChildren[];
};
export type UpdateProfileFamily = {
couple?: boolean | null;