เช็คเงื่อนไขการลบ
This commit is contained in:
parent
c75c3ef651
commit
8348c32e5b
17 changed files with 54 additions and 57 deletions
|
|
@ -52,10 +52,10 @@ import { OrgChild2 } from "../entities/OrgChild2";
|
|||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
import { OrgChild4 } from "../entities/OrgChild4";
|
||||
import { ProfileEmployeeInformationHistory } from "../entities/ProfileEmployeeInformationHistory";
|
||||
import {
|
||||
ProfileEmployeeEmployment,
|
||||
import {
|
||||
ProfileEmployeeEmployment,
|
||||
CreateEmploymentProfileEmployee,
|
||||
UpdateEmploymentProfileEmployee
|
||||
UpdateEmploymentProfileEmployee,
|
||||
} from "../entities/ProfileEmployeeEmployment";
|
||||
import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory";
|
||||
|
||||
|
|
@ -90,9 +90,13 @@ export class ProfileEmployeeController extends Controller {
|
|||
private child2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
private informationHistoryRepository = AppDataSource.getRepository(ProfileEmployeeInformationHistory);
|
||||
private employmentRepository = AppDataSource.getRepository(ProfileEmployeeEmployment);
|
||||
private employmentHistoryRepository = AppDataSource.getRepository(ProfileEmployeeEmploymentHistory);
|
||||
private informationHistoryRepository = AppDataSource.getRepository(
|
||||
ProfileEmployeeInformationHistory,
|
||||
);
|
||||
private employmentRepository = AppDataSource.getRepository(ProfileEmployeeEmployment);
|
||||
private employmentHistoryRepository = AppDataSource.getRepository(
|
||||
ProfileEmployeeEmploymentHistory,
|
||||
);
|
||||
|
||||
/**
|
||||
* report ประวัติแบบย่อ ลูกจ้าง
|
||||
|
|
@ -610,7 +614,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
async deleteProfile(@Path() id: string) {
|
||||
const result = await this.profileRepo.delete({ id });
|
||||
|
||||
if (result.affected && result.affected <= 0) {
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
|
|
@ -2523,7 +2527,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileEmployeeInformationHistory();
|
||||
Object.assign(history, { ...profileEmp, id: undefined });
|
||||
Object.assign(profileEmp, body)
|
||||
Object.assign(profileEmp, body);
|
||||
history.profileEmployeeId = profileEmployeeId;
|
||||
history.lastUpdateFullName = request.user.name;
|
||||
history.lastUpdateUserId = request.user.sub;
|
||||
|
|
@ -2540,7 +2544,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
/**
|
||||
* API ประวัติการแก้ไขข้อมูลลูกจ้างชั่วคราว
|
||||
*
|
||||
* @summary ประวัติการแก้ไขข้อมูลลูกจ้างชั่วคราว (ADMIN)
|
||||
* @summary ประวัติการแก้ไขข้อมูลลูกจ้างชั่วคราว (ADMIN)
|
||||
*
|
||||
* @param {string} profileEmployeeId profileEmployeeId ทะเบียนประวัติลูกจ้างชั่วคราว
|
||||
*/
|
||||
|
|
@ -2554,8 +2558,9 @@ export class ProfileEmployeeController extends Controller {
|
|||
});
|
||||
if (!profileInformation) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const mapData = profileInformation.flatMap((profile) =>
|
||||
profile.information_histories).map((history) => ({
|
||||
const mapData = profileInformation
|
||||
.flatMap((profile) => profile.information_histories)
|
||||
.map((history) => ({
|
||||
id: history.id,
|
||||
positionEmployeeGroupId: history.positionEmployeeGroupId,
|
||||
positionEmployeeLineId: history.positionEmployeeLineId,
|
||||
|
|
@ -2573,29 +2578,27 @@ export class ProfileEmployeeController extends Controller {
|
|||
lastUpdatedAt: history.lastUpdatedAt,
|
||||
lastUpdateUserId: history.lastUpdateUserId,
|
||||
lastUpdateFullName: history.lastUpdateFullName,
|
||||
}));
|
||||
}));
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการข้อมูลการจ้าง
|
||||
*
|
||||
* @summary รายการข้อมูลการจ้าง
|
||||
* @summary รายการข้อมูลการจ้าง
|
||||
*
|
||||
* @param {string} profileEmployeeId profileEmployeeId ทะเบียนประวัติลูกจ้างชั่วคราว
|
||||
*/
|
||||
@Get("employment/{profileEmployeeId}")
|
||||
async ProfileEmployeeEmployment(
|
||||
@Path() profileEmployeeId: string,
|
||||
) {
|
||||
async ProfileEmployeeEmployment(@Path() profileEmployeeId: string) {
|
||||
const employment = await this.employmentRepository.find({
|
||||
where: { profileEmployeeId: profileEmployeeId },
|
||||
order: { createdAt : "ASC"}
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
const mapData = employment.map((employment) => ({
|
||||
id: employment.id,
|
||||
date: employment.date,
|
||||
command: employment.command,
|
||||
id: employment.id,
|
||||
date: employment.date,
|
||||
command: employment.command,
|
||||
}));
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
|
@ -2603,14 +2606,12 @@ export class ProfileEmployeeController extends Controller {
|
|||
/**
|
||||
* API รายละเอียดข้อมูลการจ้าง
|
||||
*
|
||||
* @summary รายละเอียดข้อมูลการจ้าง
|
||||
* @summary รายละเอียดข้อมูลการจ้าง
|
||||
*
|
||||
* @param {string} id Id ข้อมูลการจ้าง
|
||||
*/
|
||||
@Get("employment/id/{id}")
|
||||
async GetEmploymentById(
|
||||
@Path() id: string,
|
||||
) {
|
||||
async GetEmploymentById(@Path() id: string) {
|
||||
const employment = await this.employmentRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
|
|
@ -2620,25 +2621,23 @@ export class ProfileEmployeeController extends Controller {
|
|||
/**
|
||||
* API ประวัติของข้อมูลการจ้าง
|
||||
*
|
||||
* @summary ประวัติของข้อมูลการจ้าง
|
||||
* @summary ประวัติของข้อมูลการจ้าง
|
||||
*
|
||||
* @param {string} id Id ข้อมูลการจ้าง
|
||||
*/
|
||||
@Get("employment/history/{id}")
|
||||
async GetHistoryEmploymentById(
|
||||
@Path() id: string,
|
||||
) {
|
||||
async GetHistoryEmploymentById(@Path() id: string) {
|
||||
const employmentHistory = await this.employmentHistoryRepository.find({
|
||||
where: { profileEmployeeEmploymentId: id },
|
||||
order: { lastUpdatedAt : "ASC"}
|
||||
order: { lastUpdatedAt: "ASC" },
|
||||
});
|
||||
return new HttpSuccess(employmentHistory);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API เพิ่มข้อมูลการจ้าง
|
||||
*
|
||||
* @summary เพิ่มข้อมูลการจ้าง
|
||||
* @summary เพิ่มข้อมูลการจ้าง
|
||||
*
|
||||
* @param {string} profileEmployeeId profileEmployeeId ทะเบียนประวัติลูกจ้างชั่วคราว
|
||||
*/
|
||||
|
|
@ -2655,7 +2654,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
|
||||
const employment = new ProfileEmployeeEmployment();
|
||||
// const history = new ProfileEmployeeEmploymentHistory();
|
||||
Object.assign(employment, body)
|
||||
Object.assign(employment, body);
|
||||
employment.profileEmployeeId = profileEmployeeId;
|
||||
employment.createdUserId = request.user.sub;
|
||||
employment.createdFullName = request.user.name;
|
||||
|
|
@ -2675,11 +2674,11 @@ export class ProfileEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API ลบข้อมูลการจ้าง
|
||||
* API ลบข้อมูลการจ้าง
|
||||
*
|
||||
* @summary ลบข้อมูลการจ้าง (ADMIN)
|
||||
*
|
||||
* @param {string} id Id ข้อมูลการจ้าง
|
||||
* @param {string} id Id ข้อมูลการจ้าง
|
||||
*/
|
||||
@Delete("employment/{id}")
|
||||
async DeleteEmployment(@Path() id: string) {
|
||||
|
|
@ -2688,14 +2687,14 @@ export class ProfileEmployeeController extends Controller {
|
|||
});
|
||||
|
||||
const result = await this.employmentRepository.delete({ id });
|
||||
if (result.affected && result.affected <= 0) {
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขข้อมูลการจ้าง
|
||||
* API แก้ไขข้อมูลการจ้าง
|
||||
*
|
||||
* @summary แก้ไขข้อมูลการจ้าง (ADMIN)
|
||||
*
|
||||
|
|
@ -2712,7 +2711,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
|
||||
const history = new ProfileEmployeeEmploymentHistory();
|
||||
Object.assign(history, { ...employment, id: undefined });
|
||||
Object.assign(employment, body)
|
||||
Object.assign(employment, body);
|
||||
|
||||
employment.lastUpdateUserId = request.user.sub;
|
||||
employment.lastUpdateFullName = request.user.name;
|
||||
|
|
@ -2722,10 +2721,9 @@ export class ProfileEmployeeController extends Controller {
|
|||
|
||||
await Promise.all([
|
||||
this.employmentRepository.save(employment),
|
||||
this.employmentHistoryRepository.save(history)
|
||||
this.employmentHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue