แก้ วันที่ update

This commit is contained in:
kittapath 2024-08-30 18:02:34 +07:00
parent 6d36c9b05f
commit 218886b3f4
83 changed files with 1671 additions and 3483 deletions

View file

@ -1,31 +1,11 @@
import {
Controller,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
SuccessResponse,
Response,
Get,
Query,
Patch,
Example,
} from "tsoa";
import { Controller, Route, Security, Tags, Body, Path, Request, Get, Patch } 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 { ProfileAddressHistory } 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-employee/address")
@ -55,7 +35,9 @@ export class ProfileAddressEmployeeController extends Controller {
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
"createdAt",
],
order: { createdAt: "ASC" },
});
if (!getProfileAddress) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -69,7 +51,10 @@ export class ProfileAddressEmployeeController extends Controller {
*
*/
@Get("{profileEmployeeId}")
public async detailProfileAddress(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
public async detailProfileAddress(
@Path() profileEmployeeId: string,
@Request() req: RequestWithUser,
) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileAddress = await this.profileEmployeeRepo.findOne({
where: { id: profileEmployeeId },
@ -85,6 +70,7 @@ export class ProfileAddressEmployeeController extends Controller {
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
"createdAt",
],
});
if (!getProfileAddress) {
@ -106,28 +92,7 @@ export class ProfileAddressEmployeeController extends Controller {
}
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",
],
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -141,32 +106,14 @@ export class ProfileAddressEmployeeController extends Controller {
*
*/
@Get("history/{profileId}")
public async getProfileAddressHistory(@Path() profileId: string, @Request() req: RequestWithUser) {
public async getProfileAddressHistory(
@Path() profileId: string,
@Request() req: RequestWithUser,
) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
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",
],
order: { createdAt: "DESC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -188,19 +135,22 @@ export class ProfileAddressEmployeeController extends Controller {
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.id);
const history = new ProfileAddressHistory();
Object.assign(record, body);
Object.assign(history, body);
Object.assign(history, { ...body, id: undefined });
history.profileEmployeeId = profileId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileEmployeeRepo.save(record),