เช็คเงื่อนไขการลบ

This commit is contained in:
Kittapath 2024-06-10 10:17:37 +07:00
parent c75c3ef651
commit 8348c32e5b
17 changed files with 54 additions and 57 deletions

View file

@ -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();
}
}