แก้ วันที่ update
This commit is contained in:
parent
6d36c9b05f
commit
218886b3f4
83 changed files with 1671 additions and 3483 deletions
|
|
@ -1,21 +1,4 @@
|
|||
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";
|
||||
|
|
@ -23,9 +6,6 @@ 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 permission from "../interfaces/permission";
|
||||
@Route("api/v1/org/profile/address")
|
||||
@Tags("ProfileAddress")
|
||||
|
|
@ -54,7 +34,9 @@ export class ProfileAddressController extends Controller {
|
|||
"currentDistrictId",
|
||||
"currentSubDistrictId",
|
||||
"currentZipCode",
|
||||
"createdAt",
|
||||
],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
if (!getProfileAddress) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -84,6 +66,7 @@ export class ProfileAddressController extends Controller {
|
|||
"currentDistrictId",
|
||||
"currentSubDistrictId",
|
||||
"currentZipCode",
|
||||
"createdAt",
|
||||
],
|
||||
});
|
||||
if (!getProfileAddress) {
|
||||
|
|
@ -105,28 +88,7 @@ export class ProfileAddressController extends Controller {
|
|||
}
|
||||
const record = await this.profileAddressHistoryRepo.find({
|
||||
where: { profileId: 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, "ไม่พบข้อมูล");
|
||||
|
|
@ -140,32 +102,14 @@ export class ProfileAddressController 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_OFFICER", profileId);
|
||||
const record = await this.profileAddressHistoryRepo.find({
|
||||
where: { profileId: 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, "ไม่พบข้อมูล");
|
||||
|
|
@ -191,15 +135,18 @@ export class ProfileAddressController extends Controller {
|
|||
const history = new ProfileAddressHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
Object.assign(history, { ...body, id: undefined });
|
||||
|
||||
history.profileId = 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.profileRepo.save(record),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue