add update time

This commit is contained in:
kittapath 2024-09-01 22:44:23 +07:00
parent ad4efc2b47
commit a2292d6048
57 changed files with 257 additions and 98 deletions

View file

@ -34,7 +34,6 @@ export class ProfileAddressController extends Controller {
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
"createdAt",
],
order: { createdAt: "ASC" },
});
@ -66,7 +65,6 @@ export class ProfileAddressController extends Controller {
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
"createdAt",
],
});
if (!getProfileAddress) {
@ -88,12 +86,32 @@ export class ProfileAddressController extends Controller {
}
const record = await this.profileAddressHistoryRepo.find({
where: { profileId: profile.id },
order: { createdAt: "DESC" },
relations: [
"registrationProvince",
"registrationDistrict",
"registrationSubDistrict",
"currentProvince",
"currentDistrict",
"currentSubDistrict",
],
order: { createdAt: "ASC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
const _record = record.map((item) => ({
id: item.id,
currentAddress: item.currentAddress,
registrationAddress: item.registrationAddress,
currentZipCode: item.currentZipCode,
registrationZipCode: item.registrationZipCode,
currentProvince: item.currentProvince?.name ?? null,
registrationProvince: item.registrationProvince?.name ?? null,
currentDistrict: item.currentDistrict?.name ?? null,
registrationDistrict: item.registrationDistrict?.name ?? null,
currentSubDistrict: item.currentSubDistrict?.name ?? null,
registrationSubDistrict: item.registrationSubDistrict?.name ?? null,
lastUpdatedAt: item.lastUpdatedAt,
lastUpdateFullName: item.lastUpdateFullName,
}));
return new HttpSuccess(_record);
}
/**
@ -109,12 +127,32 @@ export class ProfileAddressController extends Controller {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const record = await this.profileAddressHistoryRepo.find({
where: { profileId: profileId },
order: { createdAt: "DESC" },
relations: [
"registrationProvince",
"registrationDistrict",
"registrationSubDistrict",
"currentProvince",
"currentDistrict",
"currentSubDistrict",
],
order: { createdAt: "ASC" },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
const _record = record.map((item) => ({
id: item.id,
currentAddress: item.currentAddress,
registrationAddress: item.registrationAddress,
currentZipCode: item.currentZipCode,
registrationZipCode: item.registrationZipCode,
currentProvince: item.currentProvince?.name ?? null,
registrationProvince: item.registrationProvince?.name ?? null,
currentDistrict: item.currentDistrict?.name ?? null,
registrationDistrict: item.registrationDistrict?.name ?? null,
currentSubDistrict: item.currentSubDistrict?.name ?? null,
registrationSubDistrict: item.registrationSubDistrict?.name ?? null,
lastUpdatedAt: item.lastUpdatedAt,
lastUpdateFullName: item.lastUpdateFullName,
}));
return new HttpSuccess(_record);
}
/**
@ -135,7 +173,7 @@ export class ProfileAddressController extends Controller {
const history = new ProfileAddressHistory();
Object.assign(record, body);
Object.assign(history, { ...body, id: undefined });
Object.assign(history, { ...record, id: undefined });
history.profileId = profileId;
record.lastUpdateUserId = req.user.sub;