Migrate เพิ่มฟิลด์ privac + API update status privac #2186
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s

This commit is contained in:
harid 2026-01-16 17:54:11 +07:00
parent b8421d29ed
commit f6b03752e1
4 changed files with 146 additions and 0 deletions

View file

@ -30,6 +30,7 @@ import {
UpdateProfileFather,
UpdateProfileMother,
UpdateProfileCouple,
UpdatePrivacyDto
} from "../entities/Profile";
import { Brackets, In, IsNull, Like, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
@ -5176,6 +5177,67 @@ export class ProfileController extends Controller {
return new HttpSuccess(lastestData.id);
}
/**
* API privacy
*
* @summary API privacy
*
*/
@Put("privacy")
async updatePrivacy(
@Request() request: { user: Record<string, any> },
@Body() body: UpdatePrivacyDto
) {
let isEmployee = false;
let profile: any = null;
profile = await this.profileRepo.findOneBy({
keycloak: request.user.sub,
});
if (!profile) {
profile = await this.profileEmpRepo.findOne({
where: { keycloak: request.user.sub },
});
isEmployee = true;
}
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const system = body.system.trim().toUpperCase();
switch (system) {
case "CHECKIN":
profile.privacyCheckin = body.accept;
break;
case "USER":
profile.privacyUser = body.accept;
break;
case "MGT":
profile.privacyMgt = body.accept;
break;
default:
throw new HttpError(
HttpStatus.BAD_REQUEST,
"system ไม่ถูกต้อง"
);
}
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
profile.lastUpdatedAt = new Date();
if (isEmployee) {
await this.profileEmpRepo.save(profile, { data: request });
} else {
await this.profileRepo.save(profile, { data: request });
}
return new HttpSuccess();
}
/**
* API
*
@ -7354,6 +7416,9 @@ export class ProfileController extends Controller {
type: profile.employeeClass,
salary: profile.amount,
posNo: null,
privacyCheckin: profile.privacyCheckin,
privacyUser: profile.privacyUser,
privacyMgt : profile.privacyMgt
// root?.orgRootShortName && posMaster?.posMasterNo
// ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}`
// : "",
@ -7523,6 +7588,9 @@ export class ProfileController extends Controller {
salary: profile ? profile.amount : null,
amountSpecial: profile ? profile.amountSpecial : null,
posNo: null,
privacyCheckin: profile.privacyCheckin,
privacyUser: profile.privacyUser,
privacyMgt : profile.privacyMgt
// root?.orgRootShortName && posMaster?.posMasterNo
// ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}`
// : "",