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

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

@ -79,7 +79,6 @@ export class ProfileAbilityController extends Controller {
return new HttpSuccess(getProfileAbilityId);
}
@Get("history/{abilityId}")
@Example({
status: 200,
@ -192,7 +191,7 @@ export class ProfileAbilityController extends Controller {
const result = await this.profileAbilityRepo.delete({ id: abilityId });
if (result.affected && result.affected <= 0)
if (result.affected == undefined || result.affected <= 0)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess();

View file

@ -203,7 +203,7 @@ export class ProfileAssessmentsController extends Controller {
const result = await this.profileAssessmentsRepository.delete({ id: assessmentId });
if (result.affected && result.affected <= 0)
if (result.affected == undefined || result.affected <= 0)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess();

View file

@ -201,7 +201,7 @@ export class ProfileChangeNameController extends Controller {
const result = await this.changeNameRepository.delete({ id: changeNameId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -835,7 +835,7 @@ export class ProfileController 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, "ไม่พบข้อมูล");
}

View file

@ -184,7 +184,7 @@ export class ProfileDisciplineController extends Controller {
const result = await this.disciplineRepository.delete({ id: disciplineId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -185,7 +185,7 @@ export class ProfileDutyController extends Controller {
const result = await this.dutyRepository.delete({ id: dutyId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -239,7 +239,7 @@ export class ProfileEducationsController extends Controller {
const result = await this.profileEducationRepo.delete({ id: educationId });
if (result.affected && result.affected <= 0)
if (result.affected == undefined || result.affected <= 0)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess();

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

View file

@ -148,7 +148,7 @@ export class ProfileFamilyHistoryController extends Controller {
const family = await this.familyHistoryRepo.find({
order: { lastUpdatedAt: "DESC" },
where: {
profileId: profile.id
profileId: profile.id,
},
});
@ -413,7 +413,7 @@ export class ProfileFamilyHistoryController extends Controller {
public async deleteFamilyHistory(@Path() profileId: string) {
const result = await this.familyHistoryRepo.delete({ id: profileId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -318,7 +318,7 @@ export class ProfileGovernmentHistoryController extends Controller {
// public async deleteGov(@Path() profileId: string) {
// const result = await this.govRepo.delete({ profileId: profileId });
// if (result.affected && result.affected <= 0) {
// if (result.affected == undefined || result.affected <= 0) {
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// }

View file

@ -195,7 +195,7 @@ export class ProfileHonorController extends Controller {
const result = await this.honorRepo.delete({ id: honorId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -237,7 +237,7 @@ export class ProfileInsigniaController extends Controller {
const result = await this.insigniaRepo.delete({ id: insigniaId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -318,7 +318,7 @@ export class ProfileLeaveController extends Controller {
const result = await this.leaveRepo.delete({ id: leaveId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -156,7 +156,7 @@ export class ProfileNopaidController extends Controller {
const result = await this.nopaidRepository.delete({ id: nopaidId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -153,7 +153,7 @@ export class ProfileOtherController extends Controller {
const result = await this.otherRepository.delete({ id: otherId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -203,7 +203,7 @@ export class ProfileSalaryController extends Controller {
const result = await this.salaryRepo.delete({ id: salaryId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -196,7 +196,7 @@ export class ProfileTrainingController extends Controller {
const result = await this.trainingRepo.delete({ id: trainingId });
if (result.affected && result.affected <= 0) {
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}