empAddress and fix durationYear

This commit is contained in:
AdisakKanthawilang 2024-05-16 10:32:51 +07:00
parent da4eb54a59
commit ffb5b38936
6 changed files with 274 additions and 7 deletions

View file

@ -0,0 +1,135 @@
import {
Controller,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
SuccessResponse,
Response,
Get,
Query,
Patch,
Example,
} 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 { 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";
@Route("api/v1/org/profile-employee/address")
@Tags("ProfileAddressEmployee")
@Security("bearerAuth")
export class ProfileAddressEmployeeController extends Controller {
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory);
/**
*
* @summary
*
*/
@Get("{profileEmployeeId}")
public async detailProfileAddress(@Path() profileEmployeeId: string) {
const getProfileAddress = await this.profileEmployeeRepo.findOne({
where: { id: profileEmployeeId },
select: [
"id",
"registrationAddress",
"registrationProvinceId",
"registrationDistrictId",
"registrationSubDistrictId",
"registrationZipCode",
"currentAddress",
"currentProvinceId",
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
],
});
if (!getProfileAddress) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAddress);
}
/**
*
* @summary
*
*/
@Get("history/{addressId}")
public async getProfileAddressHistory(@Path() addressId: string) {
const record = await this.profileAddressHistoryRepo.find({
where: { profileEmployeeId: addressId },
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",
],
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
/**
*
* @summary
*
*/
@Patch("{addressId}")
public async editProfileAddress(
@Body() requestBody: UpdateProfileAddressEmployee,
@Request() req: RequestWithUser,
@Path() addressId: string,
) {
const record = await this.profileEmployeeRepo.findOneBy({ id: addressId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileAddressHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, requestBody);
history.profileEmployeeId = addressId;
history.lastUpdateFullName = req.user.name;
record.lastUpdateFullName = req.user.name;
await Promise.all([
this.profileEmployeeRepo.save(record),
this.profileAddressHistoryRepo.save(history),
]);
return new HttpSuccess();
}
}

View file

@ -242,7 +242,7 @@ export class ProfileController extends Controller {
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
profile.dateRetire = calculateRetireDate(profile.birthDate);
profile.dateRetireLaw = calculateRetireDate(profile.birthDate);
// profile.dateRetireLaw = calculateRetireDate(profile.birthDate);
await this.profileRepo.save(profile);
@ -383,7 +383,7 @@ export class ProfileController extends Controller {
record.lastUpdateUserId = request.user.sub;
record.lastUpdateFullName = request.user.name;
record.dateRetire = calculateRetireDate(record.birthDate);
record.dateRetireLaw = calculateRetireDate(record.birthDate);
// record.dateRetireLaw = calculateRetireDate(record.birthDate);
await this.profileRepo.save(record);
return new HttpSuccess();

View file

@ -115,7 +115,7 @@ export class ProfileEmployeeController extends Controller {
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
profile.dateRetire = calculateRetireDate(profile.birthDate);
profile.dateRetireLaw = calculateRetireDate(profile.birthDate);
// profile.dateRetireLaw = calculateRetireDate(profile.birthDate);
await this.profileRepo.save(profile);
return new HttpSuccess();
@ -205,7 +205,7 @@ export class ProfileEmployeeController extends Controller {
record.lastUpdateUserId = request.user.sub;
record.lastUpdateFullName = request.user.name;
record.dateRetire = calculateRetireDate(record.birthDate);
record.dateRetireLaw = calculateRetireDate(record.birthDate);
// record.dateRetireLaw = calculateRetireDate(record.birthDate);
await this.profileRepo.save(record);