แก้api ลูกจ้างประจำ
This commit is contained in:
parent
ab138c2e04
commit
23e5d4f7fe
44 changed files with 7960 additions and 79 deletions
|
|
@ -81,7 +81,6 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
return new HttpSuccess(getProfileAbilityId);
|
||||
}
|
||||
|
||||
|
||||
@Get("history/{abilityId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
|
|
@ -136,7 +135,7 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileAbilityEmployee,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -167,7 +166,7 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Path() abilityId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
|
@ -190,7 +189,7 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
|
||||
@Delete("{abilityId}")
|
||||
public async deleteProfileAbility(@Path() abilityId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.profileAbilityHistoryRepo.delete({
|
||||
profileAbilityId: abilityId,
|
||||
});
|
||||
|
|
|
|||
205
src/controllers/ProfileAbilityEmployeeTempController.ts
Normal file
205
src/controllers/ProfileAbilityEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
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";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/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("user")
|
||||
public async detailProfileAbilityUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const getProfileAbilityId = await this.profileAbilityRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
if (!getProfileAbilityId) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileAbilityId);
|
||||
}
|
||||
|
||||
@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,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
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, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -99,12 +99,12 @@ export class ProfileAddressEmployeeController extends Controller {
|
|||
*/
|
||||
@Get("history/user")
|
||||
public async getProfileAddressHistoryUser(@Request() request: RequestWithUser) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.profileAddressHistoryRepo.find({
|
||||
where: { profileEmployeeId: profile.id},
|
||||
where: { profileEmployeeId: profile.id },
|
||||
relations: {
|
||||
registrationProvince: true,
|
||||
registrationDistrict: true,
|
||||
|
|
@ -183,7 +183,7 @@ export class ProfileAddressEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Path() profileId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
|
|
|||
206
src/controllers/ProfileAddressEmployeeTempController.ts
Normal file
206
src/controllers/ProfileAddressEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
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 { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile, ProfileAddressHistory, UpdateProfileAddress } from "../entities/Profile";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Province } from "../entities/Province";
|
||||
import { District } from "../entities/District";
|
||||
import { SubDistrict } from "../entities/SubDistrict";
|
||||
import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/address")
|
||||
@Tags("ProfileAddressEmployee")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileAddressEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory);
|
||||
|
||||
@Get("user")
|
||||
public async detailProfileAddressUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const getProfileAddress = await this.profileEmployeeRepo.findOne({
|
||||
where: { id: profile.id },
|
||||
select: [
|
||||
"id",
|
||||
"registrationAddress",
|
||||
"registrationProvinceId",
|
||||
"registrationDistrictId",
|
||||
"registrationSubDistrictId",
|
||||
"registrationZipCode",
|
||||
"currentAddress",
|
||||
"currentProvinceId",
|
||||
"currentDistrictId",
|
||||
"currentSubDistrictId",
|
||||
"currentZipCode",
|
||||
],
|
||||
});
|
||||
if (!getProfileAddress) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ข้อมูลที่อยู่
|
||||
*
|
||||
*/
|
||||
@Get("{profileEmployeeId}")
|
||||
public async detailProfileAddress(@Path() profileEmployeeId: string) {
|
||||
const getProfileAddress = await this.profileEmployeeRepo.findOne({
|
||||
where: { id: profileEmployeeId },
|
||||
select: [
|
||||
"id",
|
||||
"registrationAddress",
|
||||
"registrationProvinceId",
|
||||
"registrationDistrictId",
|
||||
"registrationSubDistrictId",
|
||||
"registrationZipCode",
|
||||
"currentAddress",
|
||||
"currentProvinceId",
|
||||
"currentDistrictId",
|
||||
"currentSubDistrictId",
|
||||
"currentZipCode",
|
||||
],
|
||||
});
|
||||
if (!getProfileAddress) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขที่อยู่ by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async getProfileAddressHistoryUser(@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.profileAddressHistoryRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
relations: {
|
||||
registrationProvince: true,
|
||||
registrationDistrict: true,
|
||||
registrationSubDistrict: true,
|
||||
currentProvince: true,
|
||||
currentDistrict: true,
|
||||
currentSubDistrict: true,
|
||||
},
|
||||
select: [
|
||||
"registrationAddress",
|
||||
"registrationProvinceId",
|
||||
"registrationDistrictId",
|
||||
"registrationSubDistrictId",
|
||||
"registrationZipCode",
|
||||
"currentAddress",
|
||||
"currentProvinceId",
|
||||
"currentDistrictId",
|
||||
"currentSubDistrictId",
|
||||
"currentZipCode",
|
||||
"lastUpdateFullName",
|
||||
"lastUpdatedAt",
|
||||
],
|
||||
});
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขที่อยู่
|
||||
*
|
||||
*/
|
||||
@Get("history/{profileId}")
|
||||
public async getProfileAddressHistory(@Path() profileId: string) {
|
||||
const record = await this.profileAddressHistoryRepo.find({
|
||||
where: { profileEmployeeId: profileId },
|
||||
relations: {
|
||||
registrationProvince: true,
|
||||
registrationDistrict: true,
|
||||
registrationSubDistrict: true,
|
||||
currentProvince: true,
|
||||
currentDistrict: true,
|
||||
currentSubDistrict: true,
|
||||
},
|
||||
select: [
|
||||
"registrationAddress",
|
||||
"registrationProvinceId",
|
||||
"registrationDistrictId",
|
||||
"registrationSubDistrictId",
|
||||
"registrationZipCode",
|
||||
"currentAddress",
|
||||
"currentProvinceId",
|
||||
"currentDistrictId",
|
||||
"currentSubDistrictId",
|
||||
"currentZipCode",
|
||||
"lastUpdateFullName",
|
||||
"lastUpdatedAt",
|
||||
],
|
||||
});
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary แก้ไขที่อยู่
|
||||
*
|
||||
*/
|
||||
@Patch("{profileId}")
|
||||
public async editProfileAddress(
|
||||
@Body() requestBody: UpdateProfileAddressEmployee,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() profileId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileAddressHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
|
||||
history.profileEmployeeId = profileId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileEmployeeRepo.save(record),
|
||||
this.profileAddressHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeAssessment,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Path() assessmentId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
|
@ -199,8 +199,11 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@Delete("{assessmentId}")
|
||||
public async deleteProfileAssessment(@Path() assessmentId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
public async deleteProfileAssessment(
|
||||
@Path() assessmentId: string,
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.profileAssessmentsHistoryRepository.delete({
|
||||
profileAssessmentId: assessmentId,
|
||||
});
|
||||
|
|
|
|||
218
src/controllers/ProfileAssessmentsEmployeeTempController.ts
Normal file
218
src/controllers/ProfileAssessmentsEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
Patch,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateProfileEmployeeAssessment,
|
||||
ProfileAssessment,
|
||||
UpdateProfileAssessment,
|
||||
} from "../entities/ProfileAssessment";
|
||||
import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/assessments")
|
||||
@Tags("ProfileEmployeeAssessments")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileAssessmentsEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
|
||||
private profileAssessmentsHistoryRepository =
|
||||
AppDataSource.getRepository(ProfileAssessmentHistory);
|
||||
|
||||
@Get("user")
|
||||
public async detailProfileAssessmentsUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const getProfileAssessments = await this.profileAssessmentsRepository.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
if (!getProfileAssessments) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileAssessments);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||
createdAt: "2024-03-12T20:56:45.986Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T20:56:45.986Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "test bar",
|
||||
lastUpdateFullName: "test bar",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
name: "สาวิตรี ศรีสมัย",
|
||||
date: "2024-03-13T03:55:42.000Z",
|
||||
point1: 0,
|
||||
point1Total: 0,
|
||||
point2: 0,
|
||||
point2Total: 0,
|
||||
pointSum: 0,
|
||||
pointSumTotal: 0,
|
||||
},
|
||||
],
|
||||
})
|
||||
public async detailProfileAssessments(@Path() profileEmployeeId: string) {
|
||||
const getProfileAssessments = await this.profileAssessmentsRepository.findBy({
|
||||
profileEmployeeId,
|
||||
});
|
||||
if (!getProfileAssessments) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileAssessments);
|
||||
}
|
||||
|
||||
@Get("history/{assessmentId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "47b3e370-be05-4469-a34f-e4a04747f54e",
|
||||
createdAt: "2024-03-12T20:59:39.774Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T20:59:39.774Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "test bar",
|
||||
name: "สาวิตรี ศรีสมัย",
|
||||
date: "2024-03-13T03:55:42.000Z",
|
||||
point1: 0,
|
||||
point1Total: 0,
|
||||
point2: 100,
|
||||
point2Total: 100,
|
||||
pointSum: 100,
|
||||
pointSumTotal: 100,
|
||||
profileAssessmentId: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||
},
|
||||
{
|
||||
id: "ecff89b1-9bef-49a9-83f5-8be3cecb8ca7",
|
||||
createdAt: "2024-03-12T20:58:19.450Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T20:58:19.450Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "test bar",
|
||||
name: "สาวิตรี ศรีสมัย",
|
||||
date: "2024-03-13T03:55:42.000Z",
|
||||
point1: 50,
|
||||
point1Total: 50,
|
||||
point2: 100,
|
||||
point2Total: 100,
|
||||
pointSum: 150,
|
||||
pointSumTotal: 150,
|
||||
profileAssessmentId: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getProfileAssessmentsHistory(@Path() assessmentId: string) {
|
||||
const record = await this.profileAssessmentsHistoryRepository.findBy({
|
||||
profileAssessmentId: assessmentId,
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async profileAssessment(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeAssessment,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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 ProfileAssessment();
|
||||
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.profileAssessmentsRepository.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{assessmentId}")
|
||||
public async editProfileAssessment(
|
||||
@Body() requestBody: UpdateProfileAssessment,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() assessmentId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, requestBody);
|
||||
|
||||
history.profileAssessmentId = assessmentId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(record),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
]);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{assessmentId}")
|
||||
public async deleteProfileAssessment(
|
||||
@Path() assessmentId: string,
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.profileAssessmentsHistoryRepository.delete({
|
||||
profileAssessmentId: assessmentId,
|
||||
});
|
||||
|
||||
const result = await this.profileAssessmentsRepository.delete({ id: assessmentId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ export class ProfileAvatarEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeAvatar,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: body.profileEmployeeId },
|
||||
});
|
||||
|
|
@ -106,7 +106,7 @@ export class ProfileAvatarEmployeeController extends Controller {
|
|||
|
||||
@Delete("{avatarId}")
|
||||
public async deleteAvatarEmployee(@Path() avatarId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
const result = await this.avatarRepository.delete({ id: avatarId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
|
|
|
|||
118
src/controllers/ProfileAvatarEmployeeTempController.ts
Normal file
118
src/controllers/ProfileAvatarEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
import { Body, Controller, Delete, Get, 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 { CreateProfileEmployeeAvatar, ProfileAvatar } from "../entities/ProfileAvatar";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/avatar")
|
||||
@Tags("ProfileAvatar")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileAvatarEmployeeController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
private avatarRepository = AppDataSource.getRepository(ProfileAvatar);
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
public async getAvatarEmployee(@Path() profileEmployeeId: string) {
|
||||
const lists = await this.avatarRepository.find({
|
||||
where: { profileEmployeeId },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("select/{profileEmployeeId}/{id}")
|
||||
public async selectAvatarEmployee(@Path() profileEmployeeId: 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.findOne({
|
||||
where: { id: profileEmployeeId },
|
||||
relations: ["profileAvatars"],
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await Promise.all(
|
||||
profile.profileAvatars.map(async (item: any) => {
|
||||
item.isActive = false;
|
||||
await this.avatarRepository.save(item);
|
||||
}),
|
||||
);
|
||||
result.isActive = true;
|
||||
profile.avatar = result.avatar;
|
||||
profile.avatarName = result.avatarName;
|
||||
await this.avatarRepository.save(result);
|
||||
await this.profileRepository.save(profile);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newAvatarEmployee(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeAvatar,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { id: body.profileEmployeeId },
|
||||
});
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileAvatar();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
const _profile = await this.profileRepository.findOne({
|
||||
where: { id: body.profileEmployeeId },
|
||||
relations: ["profileAvatars"],
|
||||
});
|
||||
|
||||
if (!_profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await Promise.all(
|
||||
_profile.profileAvatars.map(async (item: any) => {
|
||||
item.isActive = false;
|
||||
await this.avatarRepository.save(item);
|
||||
}),
|
||||
);
|
||||
|
||||
await this.avatarRepository.save(data);
|
||||
let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}`;
|
||||
let fileName = `profile-${data.id}`;
|
||||
|
||||
data.isActive = true;
|
||||
data.avatar = avatar;
|
||||
data.avatarName = fileName;
|
||||
await this.avatarRepository.save(data);
|
||||
profile.avatar = avatar;
|
||||
profile.avatarName = fileName;
|
||||
await this.profileRepository.save(profile);
|
||||
|
||||
return new HttpSuccess({ avatar: avatar, avatarName: fileName });
|
||||
}
|
||||
|
||||
@Delete("{avatarId}")
|
||||
public async deleteAvatarEmployee(@Path() avatarId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
const result = await this.avatarRepository.delete({ id: avatarId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeCertificate,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileCertificate,
|
||||
@Path() certificateId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -177,7 +177,7 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
|
||||
@Delete("{certificateId}")
|
||||
public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.certificateHistoryRepo.delete({
|
||||
profileCertificateId: certificateId,
|
||||
});
|
||||
|
|
|
|||
195
src/controllers/ProfileCertificateEmployeeTempController.ts
Normal file
195
src/controllers/ProfileCertificateEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateProfileEmployeeCertificate,
|
||||
ProfileCertificate,
|
||||
UpdateProfileCertificate,
|
||||
} from "../entities/ProfileCertificate";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/certificate")
|
||||
@Tags("ProfileEmployeeCertificate")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileCertificateEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
|
||||
private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getCertificateUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.certificateRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70",
|
||||
createdAt: "2024-03-12T03:02:27.532Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T03:02:27.532Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
expireDate: "2024-03-12T10:01:48.000Z",
|
||||
issueDate: "2024-03-12T10:01:48.000Z",
|
||||
certificateNo: "string",
|
||||
certificateType: "string",
|
||||
issuer: "string",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getCertificate(@Path() profileEmployeeId: string) {
|
||||
const record = await this.certificateRepo.findBy({ profileEmployeeId });
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{certificateId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "c0ecf986-b290-44ca-b45e-f4448cdd34dd",
|
||||
createdAt: "2024-03-12T03:03:30.169Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T03:03:30.169Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
expireDate: "2024-03-12T10:03:05.000Z",
|
||||
issueDate: "2024-03-12T10:03:05.000Z",
|
||||
certificateNo: "no",
|
||||
certificateType: "type",
|
||||
issuer: "issuer",
|
||||
profileCertificateId: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70",
|
||||
},
|
||||
{
|
||||
id: "dc4c2800-5fc5-4ec3-b19a-c4a27beac35f",
|
||||
createdAt: "2024-03-12T03:02:27.583Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T03:02:27.583Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
expireDate: "2024-03-12T10:01:48.000Z",
|
||||
issueDate: "2024-03-12T10:01:48.000Z",
|
||||
certificateNo: "string",
|
||||
certificateType: "string",
|
||||
issuer: "string",
|
||||
profileCertificateId: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async certificateHistory(@Path() certificateId: string) {
|
||||
const record = await this.certificateHistoryRepo.findBy({
|
||||
profileCertificateId: certificateId,
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newCertificate(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeCertificate,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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 ProfileCertificate();
|
||||
|
||||
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.certificateRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{certificateId}")
|
||||
public async editCertificate(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileCertificate,
|
||||
@Path() certificateId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileCertificateId = certificateId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(record),
|
||||
this.certificateHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{certificateId}")
|
||||
public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.certificateHistoryRepo.delete({
|
||||
profileCertificateId: certificateId,
|
||||
});
|
||||
|
||||
const certificateResult = await this.certificateRepo.delete({
|
||||
id: certificateId,
|
||||
});
|
||||
|
||||
if (certificateResult.affected == undefined || certificateResult.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -119,7 +119,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileChangeNameEmployee,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileChangeName,
|
||||
@Path() changeNameId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -199,7 +199,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
|
||||
@Delete("{changeNameId}")
|
||||
public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.changeNameHistoryRepository.delete({
|
||||
profileChangeNameId: changeNameId,
|
||||
});
|
||||
|
|
|
|||
215
src/controllers/ProfileChangeNameEmployeeTempController.ts
Normal file
215
src/controllers/ProfileChangeNameEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
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";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/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("user")
|
||||
public async getChangeNameUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const lists = await this.changeNameRepository.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
select: ["id", "prefix", "firstName", "lastName", "status"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@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,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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);
|
||||
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
profile.prefix = body.prefix ?? profile.prefix;
|
||||
await this.profileEmployeeRepo.save(profile);
|
||||
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
@Patch("{changeNameId}")
|
||||
public async editChangeName(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileChangeName,
|
||||
@Path() changeNameId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
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),
|
||||
]);
|
||||
|
||||
const chkLastRecord = await this.changeNameRepository.findOne({
|
||||
where: {
|
||||
profileEmployeeId: record.profileEmployeeId,
|
||||
},
|
||||
order: {
|
||||
createdAt: "DESC",
|
||||
},
|
||||
});
|
||||
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ id: record.profileEmployeeId });
|
||||
|
||||
if (profile && chkLastRecord.id === record.id) {
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
profile.prefix = body.prefix ?? profile.prefix;
|
||||
await this.profileEmployeeRepo.save(profile);
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{changeNameId}")
|
||||
public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileChildrenEmployee,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
|
|
@ -89,7 +89,7 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
Object.assign(data, { ...body, ...meta });
|
||||
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
|
||||
await this.childrenRepository.save(data);
|
||||
if(data){
|
||||
if (data) {
|
||||
const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), {
|
||||
profileChildrenId: data.id,
|
||||
childrenCareer: data.childrenCareer,
|
||||
|
|
@ -115,7 +115,7 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileChildren,
|
||||
@Path() childrenId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
|
@ -129,11 +129,10 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
history.childrenCareer = record.childrenCareer;
|
||||
history.childrenFirstName = record.childrenFirstName;
|
||||
history.childrenLastName = record.childrenLastName;
|
||||
history.childrenPrefix = record.childrenPrefix;
|
||||
history.childrenPrefix = record.childrenPrefix;
|
||||
history.childrenLive = record.childrenLive;
|
||||
history.childrenCitizenId = record.childrenCitizenId;
|
||||
history.lastUpdateUserId = req.user.sub,
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
(history.lastUpdateUserId = req.user.sub), (history.lastUpdateFullName = req.user.name);
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
|
|
@ -145,7 +144,7 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
|
||||
@Delete("{childrenId}")
|
||||
public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.childrenHistoryRepository.delete({
|
||||
profileChildrenId: childrenId,
|
||||
});
|
||||
|
|
|
|||
160
src/controllers/ProfileChildrenEmployeeTempController.ts
Normal file
160
src/controllers/ProfileChildrenEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
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 { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import {
|
||||
CreateProfileChildren,
|
||||
CreateProfileChildrenEmployee,
|
||||
ProfileChildren,
|
||||
UpdateProfileChildren,
|
||||
} from "../entities/ProfileChildren";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/family/children")
|
||||
@Tags("ProfileChildren")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileChildrenEmployeeController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
|
||||
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getChildrenUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const lists = await this.childrenRepository.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
public async getChildren(@Path() profileEmployeeId: string) {
|
||||
const lists = await this.childrenRepository.find({
|
||||
where: { profileEmployeeId: profileEmployeeId },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("history/{childrenId}")
|
||||
public async childrenHistory(@Path() childrenId: string) {
|
||||
const record = await this.childrenHistoryRepository.find({
|
||||
where: { profileChildrenId: childrenId },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newChildren(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileChildrenEmployee,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileChildren();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
|
||||
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();
|
||||
}
|
||||
|
||||
@Patch("{childrenId}")
|
||||
public async editChildren(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileChildren,
|
||||
@Path() childrenId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
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);
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId));
|
||||
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),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{childrenId}")
|
||||
public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.childrenHistoryRepository.delete({
|
||||
profileChildrenId: childrenId,
|
||||
});
|
||||
|
||||
const result = await this.childrenRepository.delete({ id: childrenId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeDiscipline,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileDiscipline,
|
||||
@Path() disciplineId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -171,7 +171,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
|
||||
@Delete("{disciplineId}")
|
||||
public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.disciplineHistoryRepository.delete({
|
||||
profileDisciplineId: disciplineId,
|
||||
});
|
||||
|
|
|
|||
187
src/controllers/ProfileDisciplineEmployeeTempController.ts
Normal file
187
src/controllers/ProfileDisciplineEmployeeTempController.ts
Normal 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 HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import {
|
||||
CreateProfileEmployeeDiscipline,
|
||||
ProfileDiscipline,
|
||||
UpdateProfileDiscipline,
|
||||
} from "../entities/ProfileDiscipline";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/discipline")
|
||||
@Tags("ProfileDisciplineEmployee")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileDisciplineEmployeeController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
|
||||
private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getDisciplineUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const lists = await this.disciplineRepository.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
select: [
|
||||
"id",
|
||||
"date",
|
||||
"level",
|
||||
"detail",
|
||||
"unStigma",
|
||||
"refCommandNo",
|
||||
"refCommandDate",
|
||||
"lastUpdateFullName",
|
||||
"lastUpdatedAt",
|
||||
],
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||
date: "2024-03-12T10:09:47.000Z",
|
||||
level: "string",
|
||||
detail: "string",
|
||||
unStigma: "string",
|
||||
refCommandNo: "string",
|
||||
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getDiscipline(@Path() profileId: string) {
|
||||
const lists = await this.disciplineRepository.find({
|
||||
where: { profileEmployeeId: profileId },
|
||||
select: [
|
||||
"id",
|
||||
"date",
|
||||
"level",
|
||||
"detail",
|
||||
"unStigma",
|
||||
"refCommandNo",
|
||||
"refCommandDate",
|
||||
"lastUpdateFullName",
|
||||
"lastUpdatedAt",
|
||||
],
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("history/{disciplineId}")
|
||||
public async disciplineHistory(@Path() disciplineId: string) {
|
||||
const record = await this.disciplineHistoryRepository.find({
|
||||
where: { profileDisciplineId: disciplineId },
|
||||
select: [
|
||||
"id",
|
||||
"date",
|
||||
"level",
|
||||
"detail",
|
||||
"unStigma",
|
||||
"refCommandNo",
|
||||
"refCommandDate",
|
||||
"lastUpdateFullName",
|
||||
"lastUpdatedAt",
|
||||
],
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newDiscipline(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeDiscipline,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileDiscipline();
|
||||
|
||||
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.disciplineRepository.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{disciplineId}")
|
||||
public async editDiscipline(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileDiscipline,
|
||||
@Path() disciplineId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileDisciplineHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileDisciplineId = disciplineId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(record),
|
||||
this.disciplineHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{disciplineId}")
|
||||
public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.disciplineHistoryRepository.delete({
|
||||
profileDisciplineId: disciplineId,
|
||||
});
|
||||
|
||||
const result = await this.disciplineRepository.delete({ id: disciplineId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
|
||||
@Post()
|
||||
public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeDuty) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileDuty,
|
||||
@Path() dutyId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.dutyRepository.findOneBy({ id: dutyId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -142,7 +142,7 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
|
||||
@Delete("{dutyId}")
|
||||
public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.dutyHistoryRepository.delete({
|
||||
profileDutyId: dutyId,
|
||||
});
|
||||
|
|
|
|||
158
src/controllers/ProfileDutyEmployeeTempController.ts
Normal file
158
src/controllers/ProfileDutyEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
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 { ProfileDutyHistory } from "../entities/ProfileDutyHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/duty")
|
||||
@Tags("ProfileEmployeeDuty")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileDutyEmployeeController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
private dutyRepository = AppDataSource.getRepository(ProfileDuty);
|
||||
private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getDutyUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const lists = await this.dutyRepository.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
select: [
|
||||
"id",
|
||||
"dateStart",
|
||||
"dateEnd",
|
||||
"reference",
|
||||
"detail",
|
||||
"refCommandNo",
|
||||
"refCommandDate",
|
||||
],
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
public async getDuty(@Path() profileId: string) {
|
||||
const lists = await this.dutyRepository.find({
|
||||
where: { profileEmployeeId: profileId },
|
||||
select: [
|
||||
"id",
|
||||
"dateStart",
|
||||
"dateEnd",
|
||||
"reference",
|
||||
"detail",
|
||||
"refCommandNo",
|
||||
"refCommandDate",
|
||||
],
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("history/{dutyId}")
|
||||
public async dutyHistory(@Path() dutyId: string) {
|
||||
const record = await this.dutyHistoryRepository.find({
|
||||
where: { profileDutyId: dutyId },
|
||||
select: [
|
||||
"id",
|
||||
"dateStart",
|
||||
"dateEnd",
|
||||
"reference",
|
||||
"detail",
|
||||
"refCommandNo",
|
||||
"refCommandDate",
|
||||
"lastUpdateFullName",
|
||||
"lastUpdatedAt",
|
||||
],
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeDuty) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileDuty();
|
||||
|
||||
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.dutyRepository.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{dutyId}")
|
||||
public async editDuty(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileDuty,
|
||||
@Path() dutyId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.dutyRepository.findOneBy({ id: dutyId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileDutyHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileDutyId = dutyId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{dutyId}")
|
||||
public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.dutyHistoryRepository.delete({
|
||||
profileDutyId: dutyId,
|
||||
});
|
||||
|
||||
const result = await this.dutyRepository.delete({ id: dutyId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
}
|
||||
return new HttpSuccess(getProfileEducation);
|
||||
}
|
||||
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
|
|
@ -93,8 +93,8 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
})
|
||||
public async detailProfileEducation(@Path() profileEmployeeId: string) {
|
||||
const getProfileEducation = await this.profileEducationRepo.find({
|
||||
where: { profileEmployeeId: profileEmployeeId}
|
||||
});
|
||||
where: { profileEmployeeId: profileEmployeeId },
|
||||
});
|
||||
if (!getProfileEducation) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
|
@ -183,7 +183,7 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEducationEmployee,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Path() educationId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
|
@ -236,8 +236,11 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@Delete("{educationId}")
|
||||
public async deleteProfileEducation(@Path() educationId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
public async deleteProfileEducation(
|
||||
@Path() educationId: string,
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.profileEducationHistoryRepo.delete({
|
||||
profileEducationId: educationId,
|
||||
});
|
||||
|
|
|
|||
256
src/controllers/ProfileEducationsEmployeeTempController.ts
Normal file
256
src/controllers/ProfileEducationsEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
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";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/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("user")
|
||||
public async detailProfileEducationUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const getProfileEducation = await this.profileEducationRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
if (!getProfileEducation) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileEducation);
|
||||
}
|
||||
|
||||
@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.find({
|
||||
where: { profileEmployeeId: 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,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
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,
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -576,7 +576,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
*/
|
||||
@Post()
|
||||
async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionCreate(request,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(request, "SYS_REGISTRY_EMP");
|
||||
if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) {
|
||||
throw new HttpError(
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
|
|
@ -629,7 +629,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body() body: UpdateProfileEmployee,
|
||||
) {
|
||||
await new permission().PermissionUpdate(request,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(request, "SYS_REGISTRY_EMP");
|
||||
const exists =
|
||||
!!body.citizenId &&
|
||||
(await this.profileRepo.findOne({
|
||||
|
|
@ -692,8 +692,8 @@ export class ProfileEmployeeController extends Controller {
|
|||
* @param {string} id Id ทะเบียนประวัติ
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteProfile(@Path() id: string, @Request() request: RequestWithUser,) {
|
||||
await new permission().PermissionDelete(request,"SYS_REGISTRY_EMP");
|
||||
async deleteProfile(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionDelete(request, "SYS_REGISTRY_EMP");
|
||||
const result = await this.profileRepo.findOne({ where: { id: id } });
|
||||
if (!result) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
|
|||
3487
src/controllers/ProfileEmployeeTempController.ts
Normal file
3487
src/controllers/ProfileEmployeeTempController.ts
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -18,7 +18,11 @@ 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 {
|
||||
ProfileFamilyCouple,
|
||||
CreateProfileEmployeeFamilyCouple,
|
||||
UpdateProfileFamilyCouple,
|
||||
} from "../entities/ProfileFamilyCouple";
|
||||
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
|
|
@ -216,7 +220,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeFamilyCouple,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
|
||||
if (!familyCouple) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -263,7 +267,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileFamilyCouple,
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const familyCouple = await this.ProfileFamilyCouple.findOneBy({
|
||||
profileEmployeeId: profileEmployeeId,
|
||||
});
|
||||
|
|
|
|||
301
src/controllers/ProfileFamilyCoupleEmployeeTempController.ts
Normal file
301
src/controllers/ProfileFamilyCoupleEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
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";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/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("user")
|
||||
public async getFamilyCoupleUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const familyCouple = await this.ProfileFamilyCouple.findOne({
|
||||
select: [
|
||||
"id",
|
||||
"couplePrefix",
|
||||
"coupleFirstName",
|
||||
"coupleLastName",
|
||||
"coupleLastNameOld",
|
||||
"coupleCareer",
|
||||
"coupleCitizenId",
|
||||
"coupleLive",
|
||||
"relationship",
|
||||
"profileId",
|
||||
],
|
||||
where: { profileEmployeeId: profile.id },
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
return new HttpSuccess(familyCouple);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: {
|
||||
id: "6207ae29-05ef-4abb-9a37-a887265d671e",
|
||||
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",
|
||||
"couplePrefix",
|
||||
"coupleFirstName",
|
||||
"coupleLastName",
|
||||
"coupleLastNameOld",
|
||||
"coupleCareer",
|
||||
"coupleCitizenId",
|
||||
"coupleLive",
|
||||
"relationship",
|
||||
"profileEmployeeId",
|
||||
],
|
||||
where: { profileEmployeeId },
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
return new HttpSuccess(familyCouple);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขครอบครัว by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async familyCoupleHistoryUser(@Request() request: RequestWithUser) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const familyCouple = await this.ProfileFamilyCouple.find({
|
||||
relations: ["histories"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: {
|
||||
profileEmployeeId: profile.id,
|
||||
},
|
||||
});
|
||||
|
||||
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,
|
||||
couplePrefix: y.couplePrefix,
|
||||
coupleFirstName: y.coupleFirstName,
|
||||
coupleLastName: y.coupleLastName,
|
||||
coupleLastNameOld: y.coupleLastNameOld,
|
||||
coupleCareer: y.coupleCareer,
|
||||
coupleCitizenId: y.coupleCitizenId,
|
||||
coupleLive: y.coupleLive,
|
||||
relationship: y.relationship,
|
||||
profileFamilyCoupleId: y.profileFamilyCoupleId,
|
||||
profileEmployeeId: profile.id,
|
||||
}));
|
||||
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
||||
@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: "สาวิตรี ศรีสมัย",
|
||||
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,
|
||||
couplePrefix: y.couplePrefix,
|
||||
coupleFirstName: y.coupleFirstName,
|
||||
coupleLastName: y.coupleLastName,
|
||||
coupleLastNameOld: y.coupleLastNameOld,
|
||||
coupleCareer: y.coupleCareer,
|
||||
coupleCitizenId: y.coupleCitizenId,
|
||||
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,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
|
||||
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) {
|
||||
profile.relationship = familyCouple.relationship; //update profileEmployee.relationship
|
||||
const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), {
|
||||
profileFamilyCoupleId: familyCouple.id,
|
||||
couplePrefix: familyCouple.couplePrefix,
|
||||
coupleFirstName: familyCouple.coupleFirstName,
|
||||
coupleLastName: familyCouple.coupleLastName,
|
||||
coupleLastNameOld: familyCouple.coupleLastNameOld,
|
||||
coupleCareer: familyCouple.coupleCareer,
|
||||
coupleCitizenId: familyCouple.coupleCitizenId,
|
||||
coupleLive: familyCouple.coupleLive,
|
||||
relationship: familyCouple.relationship,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
});
|
||||
await Promise.all([
|
||||
this.profileRepo.save(profile),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
]);
|
||||
}
|
||||
return new HttpSuccess(familyCouple.id);
|
||||
}
|
||||
|
||||
@Patch("{profileEmployeeId}")
|
||||
public async editFamilyCouple(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileFamilyCouple,
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
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);
|
||||
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
|
||||
history.profileFamilyCoupleId = familyCouple.id;
|
||||
(history.couplePrefix = familyCouple.couplePrefix),
|
||||
(history.coupleFirstName = familyCouple.coupleFirstName),
|
||||
(history.coupleLastName = familyCouple.coupleLastName),
|
||||
(history.coupleLastNameOld = familyCouple.coupleLastNameOld),
|
||||
(history.coupleCareer = familyCouple.coupleCareer),
|
||||
(history.coupleCitizenId = familyCouple.coupleCitizenId),
|
||||
(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();
|
||||
}
|
||||
}
|
||||
|
|
@ -206,7 +206,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeFamilyFather,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
const familyFather = Object.assign(new ProfileFamilyFather(), body);
|
||||
if (!familyFather) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -247,7 +247,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileFamilyFather,
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const familyFather = await this.ProfileFamilyFather.findOneBy({
|
||||
profileEmployeeId: profileEmployeeId,
|
||||
});
|
||||
|
|
|
|||
279
src/controllers/ProfileFamilyFatherEmployeeTempController.ts
Normal file
279
src/controllers/ProfileFamilyFatherEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
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";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/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("user")
|
||||
public async getFamilyFatherUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
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: { profileEmployeeId: profile.id },
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
return new HttpSuccess(familyFather);
|
||||
}
|
||||
|
||||
@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 },
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
return new HttpSuccess(familyFather);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขครอบครัว by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async familyFatherHistoryUser(@Request() request: RequestWithUser) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const familyFather = await this.ProfileFamilyFather.find({
|
||||
relations: ["histories"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
|
||||
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: profile.id,
|
||||
}));
|
||||
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
||||
@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,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
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,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
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);
|
||||
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,11 @@ 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 {
|
||||
ProfileFamilyMother,
|
||||
CreateProfileEmployeeFamilyMother,
|
||||
UpdateProfileFamilyMother,
|
||||
} from "../entities/ProfileFamilyMother";
|
||||
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
|
|
@ -202,7 +206,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeFamilyMother,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
const familyMother = Object.assign(new ProfileFamilyMother(), body);
|
||||
if (!familyMother) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -243,7 +247,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileFamilyMother,
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const familyMother = await this.ProfileFamilyMother.findOneBy({
|
||||
profileEmployeeId: profileEmployeeId,
|
||||
});
|
||||
|
|
|
|||
279
src/controllers/ProfileFamilyMotherEmployeeTempController.ts
Normal file
279
src/controllers/ProfileFamilyMotherEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
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";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/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("user")
|
||||
public async getFamilyMotherUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
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: { profileEmployeeId: profile.id },
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
return new HttpSuccess(familyMother);
|
||||
}
|
||||
|
||||
@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 },
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
});
|
||||
|
||||
return new HttpSuccess(familyMother);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขครอบครัว by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async familyMotherHistoryUser(@Request() request: RequestWithUser) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const familyMother = await this.ProfileFamilyMother.find({
|
||||
relations: ["histories"],
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
|
||||
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: profile.id,
|
||||
}));
|
||||
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
||||
@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,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
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,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
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);
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileGovernment,
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.profileEmployeeRepo.findOne({
|
||||
where: { id: profileEmployeeId },
|
||||
});
|
||||
|
|
|
|||
323
src/controllers/ProfileGovernmentEmployeeTempController.ts
Normal file
323
src/controllers/ProfileGovernmentEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Delete,
|
||||
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 {
|
||||
CreateProfileEmployeeGovernment,
|
||||
ProfileGovernment,
|
||||
UpdateProfileGovernment,
|
||||
} from "../entities/ProfileGovernment";
|
||||
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
import { calculateAge, calculateRetireDate } from "../interfaces/utils";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/government")
|
||||
@Tags("ProfileEmployeeGovernment")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileGovernmentEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private govRepo = AppDataSource.getRepository(ProfileGovernment);
|
||||
private positionRepo = AppDataSource.getRepository(EmployeePosition);
|
||||
private posMasterRepo = AppDataSource.getRepository(EmployeePosMaster);
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ข้อมูลราชการ
|
||||
*
|
||||
*/
|
||||
@Get("user")
|
||||
public async getGovHistoryUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.profileEmployeeRepo.findOne({
|
||||
where: { id: profile.id },
|
||||
relations: {
|
||||
posType: true,
|
||||
posLevel: true,
|
||||
},
|
||||
});
|
||||
const posMaster = await this.posMasterRepo.findOne({
|
||||
where: {
|
||||
orgRevision: {
|
||||
orgRevisionIsCurrent: true,
|
||||
orgRevisionIsDraft: false,
|
||||
},
|
||||
current_holderId: profile.id,
|
||||
},
|
||||
order: { createdAt: "DESC" },
|
||||
relations: {
|
||||
orgRoot: true,
|
||||
orgChild1: true,
|
||||
orgChild2: true,
|
||||
orgChild3: true,
|
||||
orgChild4: true,
|
||||
},
|
||||
});
|
||||
// const position = await this.positionRepo.findOne({
|
||||
// where: {
|
||||
// positionIsSelected: true,
|
||||
// posMaster: {
|
||||
// orgRevision: {
|
||||
// orgRevisionIsCurrent: true,
|
||||
// orgRevisionIsDraft: false,
|
||||
// },
|
||||
// current_holderId: profile.id,
|
||||
// },
|
||||
// },
|
||||
// order: { createdAt: "DESC" },
|
||||
// });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const fullNameParts = [
|
||||
posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name,
|
||||
posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name,
|
||||
posMaster == null || posMaster.orgChild2 == null ? null : posMaster.orgChild2.orgChild2Name,
|
||||
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
|
||||
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
|
||||
];
|
||||
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
|
||||
let orgShortName = "";
|
||||
if (posMaster != null) {
|
||||
if (posMaster.orgChild1Id === null) {
|
||||
orgShortName = posMaster.orgRoot?.orgRootShortName;
|
||||
} else if (posMaster.orgChild2Id === null) {
|
||||
orgShortName = posMaster.orgChild1?.orgChild1ShortName;
|
||||
} else if (posMaster.orgChild3Id === null) {
|
||||
orgShortName = posMaster.orgChild2?.orgChild2ShortName;
|
||||
} else if (posMaster.orgChild4Id === null) {
|
||||
orgShortName = posMaster.orgChild3?.orgChild3ShortName;
|
||||
} else {
|
||||
orgShortName = posMaster.orgChild4?.orgChild4ShortName;
|
||||
}
|
||||
}
|
||||
const data = {
|
||||
org: org, //สังกัด
|
||||
position: record.position, //ตำแหน่ง
|
||||
posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ
|
||||
posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง
|
||||
posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท
|
||||
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate),
|
||||
dateRetireLaw: record.dateRetireLaw ?? null,
|
||||
govAge: record.dateStart == null ? null : calculateAge(record.dateStart),
|
||||
dateAppoint: record.dateAppoint,
|
||||
dateStart: record.dateStart,
|
||||
govAgeAbsent: record.govAgeAbsent,
|
||||
govAgePlus: record.govAgePlus,
|
||||
reasonSameDate: record.reasonSameDate,
|
||||
};
|
||||
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ข้อมูลราชการ
|
||||
*
|
||||
*/
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({})
|
||||
public async getGovHistory(@Path() profileEmployeeId: string) {
|
||||
const record = await this.profileEmployeeRepo.findOne({
|
||||
where: { id: profileEmployeeId },
|
||||
relations: {
|
||||
posType: true,
|
||||
posLevel: true,
|
||||
},
|
||||
});
|
||||
const posMaster = await this.posMasterRepo.findOne({
|
||||
where: {
|
||||
orgRevision: {
|
||||
orgRevisionIsCurrent: true,
|
||||
orgRevisionIsDraft: false,
|
||||
},
|
||||
current_holderId: profileEmployeeId,
|
||||
},
|
||||
order: { createdAt: "DESC" },
|
||||
relations: {
|
||||
orgRoot: true,
|
||||
orgChild1: true,
|
||||
orgChild2: true,
|
||||
orgChild3: true,
|
||||
orgChild4: true,
|
||||
},
|
||||
});
|
||||
const position = await this.positionRepo.findOne({
|
||||
where: {
|
||||
positionIsSelected: true,
|
||||
posMaster: {
|
||||
orgRevision: {
|
||||
orgRevisionIsCurrent: true,
|
||||
orgRevisionIsDraft: false,
|
||||
},
|
||||
current_holderId: profileEmployeeId,
|
||||
},
|
||||
},
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const fullNameParts = [
|
||||
posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name,
|
||||
posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name,
|
||||
posMaster == null || posMaster.orgChild2 == null ? null : posMaster.orgChild2.orgChild2Name,
|
||||
posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name,
|
||||
posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName,
|
||||
];
|
||||
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
|
||||
let orgShortName = "";
|
||||
if (posMaster != null) {
|
||||
if (posMaster.orgChild1Id === null) {
|
||||
orgShortName = posMaster.orgRoot?.orgRootShortName;
|
||||
} else if (posMaster.orgChild2Id === null) {
|
||||
orgShortName = posMaster.orgChild1?.orgChild1ShortName;
|
||||
} else if (posMaster.orgChild3Id === null) {
|
||||
orgShortName = posMaster.orgChild2?.orgChild2ShortName;
|
||||
} else if (posMaster.orgChild4Id === null) {
|
||||
orgShortName = posMaster.orgChild3?.orgChild3ShortName;
|
||||
} else {
|
||||
orgShortName = posMaster.orgChild4?.orgChild4ShortName;
|
||||
}
|
||||
}
|
||||
const data = {
|
||||
org: org, //สังกัด
|
||||
position: record.position, //ตำแหน่ง
|
||||
posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ
|
||||
posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง
|
||||
posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท
|
||||
dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), //วันเกษียณ
|
||||
dateAppoint: record.dateAppoint, //วันที่สั่งบรรจุ
|
||||
dateStart: record.dateStart, //วันที่เริ่มปฎิบัติงานราชการ
|
||||
reasonSameDate: record.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน
|
||||
dateRetire: record.dateRetire ?? null, //วันครบเกษียณอายุ
|
||||
govAge: record.dateStart == null ? null : calculateAge(record.dateStart), //อายุราชการ
|
||||
govAgeAbsent: record.govAgeAbsent ?? null, // ขาดราชการ
|
||||
govAgePlus: record.govAgePlus, // อายุราชการเกื้อกูล
|
||||
dateRetireLaw: record.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย
|
||||
};
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติข้อมูลราชการ by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async govHistoryUser(@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.govRepo.find({
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติข้อมูลราชการ
|
||||
*
|
||||
*/
|
||||
@Get("history/{profileEmployeeId}")
|
||||
@Example({})
|
||||
public async govHistory(@Path() profileEmployeeId: string) {
|
||||
const record = await this.govRepo.find({
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileEmployeeId: profileEmployeeId },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @summary เพิ่มข้อมูลราชการ
|
||||
// *
|
||||
// */
|
||||
// @Post()
|
||||
// public async newGov(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeGovernment) {
|
||||
// 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 ProfileGovernment();
|
||||
// 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.govRepo.save(data);
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary แก้ไขข้อมูลราชการ
|
||||
*
|
||||
*/
|
||||
@Patch("{profileEmployeeId}")
|
||||
public async editGov(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileGovernment,
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.profileEmployeeRepo.findOne({
|
||||
where: { id: profileEmployeeId },
|
||||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const historyData = new ProfileGovernment();
|
||||
|
||||
Object.assign(historyData, { ...record, ...body, id: undefined });
|
||||
Object.assign(record, body);
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
historyData.profileEmployeeId = profileEmployeeId;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
historyData.lastUpdateFullName = req.user.name;
|
||||
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(historyData)]);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @summary ลบข้อมูลราชการ
|
||||
// *
|
||||
// */
|
||||
// @Delete("{profileEmployeeId}")
|
||||
// public async deleteGov(@Path() profileEmployeeId: string) {
|
||||
// const result = await this.govRepo.delete({ profileEmployeeId: profileEmployeeId });
|
||||
// if (result.affected == undefined || result.affected <= 0) {
|
||||
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
// return new HttpSuccess();
|
||||
// }
|
||||
}
|
||||
|
|
@ -13,7 +13,11 @@ import {
|
|||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { CreateProfileEmployeeHonor, ProfileHonor, UpdateProfileHonor } from "../entities/ProfileHonor";
|
||||
import {
|
||||
CreateProfileEmployeeHonor,
|
||||
ProfileHonor,
|
||||
UpdateProfileHonor,
|
||||
} from "../entities/ProfileHonor";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
|
|
@ -138,7 +142,7 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
|
||||
@Post()
|
||||
public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -171,7 +175,7 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileHonor,
|
||||
@Path() honorId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.honorRepo.findOneBy({ id: honorId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -191,7 +195,7 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
|
||||
@Delete("{honorId}")
|
||||
public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.honorHistoryRepo.delete({
|
||||
profileHonorId: honorId,
|
||||
});
|
||||
|
|
|
|||
211
src/controllers/ProfileHonorEmployeeTempController.ts
Normal file
211
src/controllers/ProfileHonorEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateProfileEmployeeHonor,
|
||||
ProfileHonor,
|
||||
UpdateProfileHonor,
|
||||
} from "../entities/ProfileHonor";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/honor")
|
||||
@Tags("ProfileEmployeeHonor")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileHonorEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private honorRepo = AppDataSource.getRepository(ProfileHonor);
|
||||
private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getHonorUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.honorRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||
createdAt: "2024-03-12T03:10:05.594Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T03:10:05.594Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
detail: "string",
|
||||
issueDate: "2024-03-12T10:09:47.000Z",
|
||||
issuer: "string",
|
||||
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||
refCommandNo: "string",
|
||||
isDate: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getHonor(@Path() profileEmployeeId: string) {
|
||||
const record = await this.honorRepo.findBy({ profileEmployeeId });
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary ประวัติแก้ไขเกียรติประวัติ by keycloak
|
||||
*
|
||||
*/
|
||||
@Get("history/user")
|
||||
public async honorHistoryUser(@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.honorHistoryRepo.find({
|
||||
where: {
|
||||
histories: {
|
||||
profileEmployeeId: profile.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{honorId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "3bedb365-4a41-4df5-8f47-b6e143221d2c",
|
||||
createdAt: "2024-03-12T03:11:01.395Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T03:11:01.395Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
detail: "detail",
|
||||
issueDate: "2024-03-12T10:10:31.000Z",
|
||||
issuer: "issuer",
|
||||
refCommandDate: "2024-03-12T10:10:31.000Z",
|
||||
refCommandNo: "refCommandNo",
|
||||
isDate: true,
|
||||
profileHonorId: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||
},
|
||||
{
|
||||
id: "ba0e2f82-014e-46c6-8b82-a7c28eb5325f",
|
||||
createdAt: "2024-03-12T03:10:05.657Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T03:10:05.657Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
detail: "string",
|
||||
issueDate: "2024-03-12T10:09:47.000Z",
|
||||
issuer: "string",
|
||||
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||
refCommandNo: "string",
|
||||
isDate: true,
|
||||
profileHonorId: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async honorHistory(@Path() honorId: string) {
|
||||
const record = await this.honorHistoryRepo.findBy({
|
||||
profileHonorId: honorId,
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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 ProfileHonor();
|
||||
|
||||
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.honorRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{honorId}")
|
||||
public async editHonor(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileHonor,
|
||||
@Path() honorId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.honorRepo.findOneBy({ id: honorId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileHonorHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileHonorId = honorId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{honorId}")
|
||||
public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.honorHistoryRepo.delete({
|
||||
profileHonorId: honorId,
|
||||
});
|
||||
|
||||
const result = await this.honorRepo.delete({ id: honorId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -165,8 +165,11 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@Post()
|
||||
public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeInsignia) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
public async newInsignia(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeInsignia,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -206,7 +209,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileInsignia,
|
||||
@Path() insigniaId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.insigniaRepo.findOneBy({ id: insigniaId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -233,7 +236,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
|
||||
@Delete("{insigniaId}")
|
||||
public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.insigniaHistoryRepo.delete({
|
||||
profileInsigniaId: insigniaId,
|
||||
});
|
||||
|
|
|
|||
252
src/controllers/ProfileInsigniaEmployeeTempController.ts
Normal file
252
src/controllers/ProfileInsigniaEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateProfileEmployeeInsignia,
|
||||
ProfileInsignia,
|
||||
UpdateProfileInsignia,
|
||||
} from "../entities/ProfileInsignia";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { Insignia } from "../entities/Insignia";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/insignia")
|
||||
@Tags("ProfileEmployeeInsignia")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileInsigniaEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
||||
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
|
||||
private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
|
||||
|
||||
@Get("user")
|
||||
public async getInsigniaUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.insigniaRepo.find({
|
||||
relations: {
|
||||
insignia: {
|
||||
insigniaType: true,
|
||||
},
|
||||
},
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "c9d4dd52-25f5-491a-852d-28bfe00d66cb",
|
||||
createdAt: "2024-03-12T03:05:09.393Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T03:05:09.393Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
year: 0,
|
||||
no: "string",
|
||||
volume: "string",
|
||||
section: "string",
|
||||
page: "string",
|
||||
receiveDate: "2024-03-12T10:05:02.000Z",
|
||||
insigniaId: "string",
|
||||
insigniaType: "string",
|
||||
dateAnnounce: "2024-03-12T10:05:02.000Z",
|
||||
issue: "string",
|
||||
volumeNo: "string",
|
||||
refCommandDate: "2024-03-12T10:05:02.000Z",
|
||||
refCommandNo: "string",
|
||||
note: "string",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getInsignia(@Path() profileEmployeeId: string) {
|
||||
const record = await this.insigniaRepo.find({
|
||||
relations: {
|
||||
insignia: {
|
||||
insigniaType: true,
|
||||
},
|
||||
},
|
||||
where: { profileEmployeeId },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{InsigniaId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "c363d13c-88bd-4954-adf5-70d3f5ca9c30",
|
||||
createdAt: "2024-03-12T03:06:31.062Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T03:06:31.062Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
year: 0,
|
||||
no: "no",
|
||||
volume: "volume",
|
||||
section: "section",
|
||||
page: "page",
|
||||
receiveDate: "2024-03-12T10:05:44.000Z",
|
||||
insigniaId: "insigniaId",
|
||||
insigniaType: "insigniaType",
|
||||
dateAnnounce: "2024-03-12T10:05:44.000Z",
|
||||
issue: "string",
|
||||
volumeNo: "volumeNo",
|
||||
refCommandDate: "2024-03-12T10:05:44.000Z",
|
||||
refCommandNo: "refCommandNo",
|
||||
note: "string",
|
||||
profileInsigniaId: "c9d4dd52-25f5-491a-852d-28bfe00d66cb",
|
||||
},
|
||||
{
|
||||
id: "c9d4dd52-25f5-491a-852d-28bfe00d66cb",
|
||||
createdAt: "2024-03-12T03:05:09.393Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T03:09:04.905Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
year: 0,
|
||||
no: "string",
|
||||
volume: "string",
|
||||
section: "string",
|
||||
page: "string",
|
||||
receiveDate: "2024-03-12T10:05:02.000Z",
|
||||
insigniaId: "string",
|
||||
insigniaType: "string",
|
||||
dateAnnounce: "2024-03-12T10:05:02.000Z",
|
||||
issue: "string",
|
||||
volumeNo: "string",
|
||||
refCommandDate: "2024-03-12T10:05:02.000Z",
|
||||
refCommandNo: "string",
|
||||
note: "string",
|
||||
profileInsigniaId: "c9d4dd52-25f5-491a-852d-28bfe00d66cb",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getInsigniaHistory(@Path() InsigniaId: string) {
|
||||
const record = await this.insigniaHistoryRepo.find({
|
||||
relations: {
|
||||
insignia: {
|
||||
insigniaType: true,
|
||||
},
|
||||
},
|
||||
where: {
|
||||
profileInsigniaId: InsigniaId,
|
||||
},
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newInsignia(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeInsignia,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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 insignia = await this.insigniaMetaRepo.findOne({
|
||||
where: { id: body.insigniaId },
|
||||
});
|
||||
if (!insignia) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||
}
|
||||
|
||||
const data = new ProfileInsignia();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.insigniaRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{insigniaId}")
|
||||
public async editInsignia(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileInsignia,
|
||||
@Path() insigniaId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.insigniaRepo.findOneBy({ id: insigniaId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const insignia = await this.insigniaMetaRepo.findOne({
|
||||
where: { id: body.insigniaId },
|
||||
});
|
||||
if (!insignia) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||
}
|
||||
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileInsigniaId = insigniaId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{insigniaId}")
|
||||
public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.insigniaHistoryRepo.delete({
|
||||
profileInsigniaId: insigniaId,
|
||||
});
|
||||
|
||||
const result = await this.insigniaRepo.delete({ id: insigniaId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
|
||||
@Post()
|
||||
public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeLeave) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileLeave,
|
||||
@Path() leaveId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.leaveRepo.findOneBy({ id: leaveId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -134,7 +134,7 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
|
||||
@Delete("{leaveId}")
|
||||
public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.leaveHistoryRepo.delete({
|
||||
profileLeaveId: leaveId,
|
||||
});
|
||||
|
|
|
|||
150
src/controllers/ProfileLeaveEmployeeTempController.ts
Normal file
150
src/controllers/ProfileLeaveEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
ProfileLeaveHistory,
|
||||
CreateProfileEmployeeLeave,
|
||||
ProfileLeave,
|
||||
UpdateProfileLeave,
|
||||
} from "../entities/ProfileLeave";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { LeaveType } from "../entities/LeaveType";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/leave")
|
||||
@Tags("ProfileLeave")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileLeaveEmployeeController extends Controller {
|
||||
private profileRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private leaveRepo = AppDataSource.getRepository(ProfileLeave);
|
||||
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
|
||||
private leaveTypeRepository = AppDataSource.getRepository(LeaveType);
|
||||
|
||||
@Get("user")
|
||||
public async getLeaveUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.leaveRepo.find({
|
||||
relations: { leaveType: true },
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
public async getLeave(@Path() profileId: string) {
|
||||
const record = await this.leaveRepo.find({
|
||||
relations: { leaveType: true },
|
||||
where: { profileEmployeeId: profileId },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{leaveId}")
|
||||
public async leaveHistory(@Path() leaveId: string) {
|
||||
const record = await this.leaveHistoryRepo.find({
|
||||
relations: { leaveType: true },
|
||||
where: { profileLeaveId: leaveId },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeLeave) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
||||
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const leaveType = await this.leaveTypeRepository.findOne({
|
||||
where: { id: body.leaveTypeId },
|
||||
});
|
||||
if (!leaveType) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||
}
|
||||
|
||||
const data = new ProfileLeave();
|
||||
|
||||
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.leaveRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{leaveId}")
|
||||
public async editLeave(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileLeave,
|
||||
@Path() leaveId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.leaveRepo.findOneBy({ id: leaveId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const leaveType = await this.leaveTypeRepository.findOne({
|
||||
where: { id: body.leaveTypeId },
|
||||
});
|
||||
if (!leaveType) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||
}
|
||||
|
||||
const history = new ProfileLeaveHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileLeaveId = leaveId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{leaveId}")
|
||||
public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.leaveHistoryRepo.delete({
|
||||
profileLeaveId: leaveId,
|
||||
});
|
||||
|
||||
const result = await this.leaveRepo.delete({ id: leaveId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeNopaid,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileNopaid,
|
||||
@Path() nopaidId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -123,7 +123,7 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
|
||||
@Delete("{nopaidId}")
|
||||
public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.nopaidHistoryRepository.delete({
|
||||
profileNopaidId: nopaidId,
|
||||
});
|
||||
|
|
|
|||
139
src/controllers/ProfileNopaidEmployeeTempController.ts
Normal file
139
src/controllers/ProfileNopaidEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
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 { ProfileNopaidHistory } from "../entities/ProfileNopaidHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import {
|
||||
CreateProfileEmployeeNopaid,
|
||||
ProfileNopaid,
|
||||
UpdateProfileNopaid,
|
||||
} from "../entities/ProfileNopaid";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/nopaid")
|
||||
@Tags("ProfileNopaid")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileNopaidEmployeeController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
private nopaidRepository = AppDataSource.getRepository(ProfileNopaid);
|
||||
private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getNopaidUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const lists = await this.nopaidRepository.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
public async getNopaid(@Path() profileId: string) {
|
||||
const lists = await this.nopaidRepository.find({
|
||||
where: { profileEmployeeId: profileId },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("history/{nopaidId}")
|
||||
public async nopaidHistory(@Path() nopaidId: string) {
|
||||
const record = await this.nopaidHistoryRepository.find({
|
||||
where: { profileNopaidId: nopaidId },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newNopaid(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeNopaid,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileNopaid();
|
||||
|
||||
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.nopaidRepository.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{nopaidId}")
|
||||
public async editNopaid(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileNopaid,
|
||||
@Path() nopaidId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileNopaidHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileNopaidId = nopaidId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(record),
|
||||
this.nopaidHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{nopaidId}")
|
||||
public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.nopaidHistoryRepository.delete({
|
||||
profileNopaidId: nopaidId,
|
||||
});
|
||||
|
||||
const result = await this.nopaidRepository.delete({ id: nopaidId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
|
||||
@Post()
|
||||
public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileOther,
|
||||
@Path() otherId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.otherRepository.findOneBy({ id: otherId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -120,7 +120,7 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
|
||||
@Delete("{otherId}")
|
||||
public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.otherHistoryRepository.delete({
|
||||
profileOtherId: otherId,
|
||||
});
|
||||
|
|
|
|||
136
src/controllers/ProfileOtherEmployeeTempController.ts
Normal file
136
src/controllers/ProfileOtherEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
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 { ProfileOtherHistory } from "../entities/ProfileOtherHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import {
|
||||
CreateProfileEmployeeOther,
|
||||
ProfileOther,
|
||||
UpdateProfileOther,
|
||||
} from "../entities/ProfileOther";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/other")
|
||||
@Tags("ProfileOther")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileOtherEmployeeController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
private otherRepository = AppDataSource.getRepository(ProfileOther);
|
||||
private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getOtherUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const lists = await this.otherRepository.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
public async getOther(@Path() profileId: string) {
|
||||
const lists = await this.otherRepository.find({
|
||||
where: { profileEmployeeId: profileId },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("history/{otherId}")
|
||||
public async otherHistory(@Path() otherId: string) {
|
||||
const record = await this.otherHistoryRepository.find({
|
||||
where: { profileOtherId: otherId },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileOther();
|
||||
|
||||
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.otherRepository.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{otherId}")
|
||||
public async editOther(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileOther,
|
||||
@Path() otherId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.otherRepository.findOneBy({ id: otherId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileOtherHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileOtherId = otherId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.otherRepository.save(record),
|
||||
this.otherHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{otherId}")
|
||||
public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.otherHistoryRepository.delete({
|
||||
profileOtherId: otherId,
|
||||
});
|
||||
|
||||
const result = await this.otherRepository.delete({ id: otherId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileSalaryEmployee,
|
||||
) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileSalaryEmployee,
|
||||
@Path() salaryId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.salaryRepo.findOneBy({ id: salaryId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -128,7 +128,7 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
|
||||
@Delete("{salaryId}")
|
||||
public async deleteSalaryEmployee(@Path() salaryId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.salaryHistoryRepo.delete({
|
||||
profileSalaryId: salaryId,
|
||||
});
|
||||
|
|
|
|||
173
src/controllers/ProfileSalaryEmployeeTempController.ts
Normal file
173
src/controllers/ProfileSalaryEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateProfileSalaryEmployee,
|
||||
ProfileSalary,
|
||||
UpdateProfileSalaryEmployee,
|
||||
} from "../entities/ProfileSalary";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { LessThan, MoreThan } from "typeorm";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/salary")
|
||||
@Tags("ProfileSalary")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileSalaryEmployeeController extends Controller {
|
||||
private profileRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
|
||||
private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getSalaryUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.salaryRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
public async getSalaryEmployee(@Path() profileId: string) {
|
||||
const record = await this.salaryRepo.find({
|
||||
where: { profileEmployeeId: profileId },
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{salaryId}")
|
||||
public async salaryHistory(@Path() salaryId: string) {
|
||||
const record = await this.salaryHistoryRepo.findBy({
|
||||
profileSalaryId: salaryId,
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newSalaryEmployee(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileSalaryEmployee,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
||||
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const dest_item = await this.salaryRepo.findOne({
|
||||
where: { profileEmployeeId: body.profileEmployeeId },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
|
||||
const data = new ProfileSalary();
|
||||
|
||||
const meta = {
|
||||
order: dest_item == null ? 1 : dest_item.order + 1,
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.salaryRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{salaryId}")
|
||||
public async editSalaryEmployee(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileSalaryEmployee,
|
||||
@Path() salaryId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.salaryRepo.findOneBy({ id: salaryId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileSalaryHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileSalaryId = salaryId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{salaryId}")
|
||||
public async deleteSalaryEmployee(@Path() salaryId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.salaryHistoryRepo.delete({
|
||||
profileSalaryId: salaryId,
|
||||
});
|
||||
|
||||
const result = await this.salaryRepo.delete({ id: salaryId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Get("swap/{direction}/{salaryId}")
|
||||
public async swapSalaryEmployee(@Path() direction: string, salaryId: string) {
|
||||
const source_item = await this.salaryRepo.findOne({ where: { id: salaryId } });
|
||||
if (source_item == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const sourceOrder = source_item.order;
|
||||
if (direction.trim().toUpperCase() == "UP") {
|
||||
const dest_item = await this.salaryRepo.findOne({
|
||||
where: { profileEmployeeId: source_item.profileEmployeeId, order: LessThan(sourceOrder) },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
if (dest_item == null) return new HttpSuccess();
|
||||
var destOrder = dest_item.order;
|
||||
dest_item.order = sourceOrder;
|
||||
source_item.order = destOrder;
|
||||
await Promise.all([this.salaryRepo.save(source_item), this.salaryRepo.save(dest_item)]);
|
||||
} else {
|
||||
const dest_item = await this.salaryRepo.findOne({
|
||||
where: { profileEmployeeId: source_item.profileEmployeeId, order: MoreThan(sourceOrder) },
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
if (dest_item == null) return new HttpSuccess();
|
||||
var destOrder = dest_item.order;
|
||||
dest_item.order = sourceOrder;
|
||||
source_item.order = destOrder;
|
||||
await Promise.all([this.salaryRepo.save(source_item), this.salaryRepo.save(dest_item)]);
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -138,8 +138,11 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@Post()
|
||||
public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeTraining) {
|
||||
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
|
||||
public async newTraining(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeTraining,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
|
@ -172,7 +175,7 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
@Body() body: UpdateProfileTraining,
|
||||
@Path() trainingId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
|
||||
const record = await this.trainingRepo.findOneBy({ id: trainingId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -192,7 +195,7 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
|
||||
@Delete("{trainingId}")
|
||||
public async deleteTraining(@Path() trainingId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP");
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP");
|
||||
await this.trainingHistoryRepo.delete({
|
||||
profileTrainingId: trainingId,
|
||||
});
|
||||
|
|
|
|||
211
src/controllers/ProfileTrainingEmployeeTempController.ts
Normal file
211
src/controllers/ProfileTrainingEmployeeTempController.ts
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateProfileEmployeeTraining,
|
||||
ProfileTraining,
|
||||
UpdateProfileTraining,
|
||||
} from "../entities/ProfileTraining";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile-temp/training")
|
||||
@Tags("ProfileEmployeeTraining")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileTrainingEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private trainingRepo = AppDataSource.getRepository(ProfileTraining);
|
||||
private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getTrainingUser(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.trainingRepo.find({
|
||||
where: { profileEmployeeId: profile.id },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
|
||||
createdAt: "2024-03-12T02:55:56.915Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T02:55:56.915Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
isActive: true,
|
||||
startDate: "2024-03-12T09:55:23.000Z",
|
||||
endDate: "2024-03-12T09:55:23.000Z",
|
||||
numberOrder: "string",
|
||||
topic: "string",
|
||||
place: "string",
|
||||
dateOrder: "2024-03-12T09:55:23.000Z",
|
||||
department: "string",
|
||||
duration: "string",
|
||||
name: "string",
|
||||
yearly: 0,
|
||||
isDate: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getTraining(@Path() profileEmployeeId: string) {
|
||||
const record = await this.trainingRepo.findBy({ profileEmployeeId });
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{trainingId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "6d4e9dbe-8697-4546-9651-0a1c3ea0a82d",
|
||||
createdAt: "2024-03-12T02:55:56.971Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T02:55:56.971Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
isActive: true,
|
||||
startDate: "2024-03-12T09:55:23.000Z",
|
||||
endDate: "2024-03-12T09:55:23.000Z",
|
||||
numberOrder: "string",
|
||||
topic: "string",
|
||||
place: "string",
|
||||
dateOrder: "2024-03-12T09:55:23.000Z",
|
||||
department: "string",
|
||||
duration: "string",
|
||||
name: "string",
|
||||
yearly: 0,
|
||||
isDate: true,
|
||||
profileTrainingId: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
|
||||
},
|
||||
{
|
||||
id: "a251c176-3dac-4d09-9813-38c8db1127e3",
|
||||
createdAt: "2024-03-12T02:58:17.917Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T02:58:17.917Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
isActive: true,
|
||||
startDate: "2024-03-12T09:57:44.000Z",
|
||||
endDate: "2024-03-12T09:57:44.000Z",
|
||||
numberOrder: "string",
|
||||
topic: "topic",
|
||||
place: "place",
|
||||
dateOrder: "2024-03-12T09:57:44.000Z",
|
||||
department: "department",
|
||||
duration: "string",
|
||||
name: "name",
|
||||
yearly: 0,
|
||||
isDate: true,
|
||||
profileTrainingId: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async trainingHistory(@Path() trainingId: string) {
|
||||
const record = await this.trainingHistoryRepo.findBy({
|
||||
profileTrainingId: trainingId,
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newTraining(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEmployeeTraining,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_REGISTRY_TEMP");
|
||||
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 ProfileTraining();
|
||||
|
||||
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.trainingRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{trainingId}")
|
||||
public async editTraining(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileTraining,
|
||||
@Path() trainingId: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.trainingRepo.findOneBy({ id: trainingId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileTrainingId = trainingId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{trainingId}")
|
||||
public async deleteTraining(@Path() trainingId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");
|
||||
await this.trainingHistoryRepo.delete({
|
||||
profileTrainingId: trainingId,
|
||||
});
|
||||
|
||||
const result = await this.trainingRepo.delete({ id: trainingId });
|
||||
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue