log admin , master (ยกเว้น menu ข้อมูลปฎิทินวันหยุด)
This commit is contained in:
parent
e59f4f13e2
commit
f0e5a83d02
11 changed files with 122 additions and 63 deletions
|
|
@ -22,6 +22,7 @@ import { AuthRoleAttr } from "../entities/AuthRoleAttr";
|
|||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
import { promisify } from "util";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
const REDIS_HOST = process.env.REDIS_HOST;
|
||||
const REDIS_PORT = process.env.REDIS_PORT;
|
||||
|
|
@ -74,11 +75,11 @@ export class AuthRoleController extends Controller {
|
|||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
|
||||
const before = null;
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.authRoleRepo.save(data);
|
||||
|
||||
await this.authRoleRepo.save(data, { data: req });
|
||||
setLogDataDiff(req, { before, after: data });
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +97,7 @@ export class AuthRoleController extends Controller {
|
|||
getDetail = await this.authRoleRepo.findOneBy({ id: body.authRoleId });
|
||||
if (!getDetail) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const posMaster = await this.posMasterRepository.findOneBy({ id: body.posMasterId });
|
||||
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
|
||||
|
||||
|
|
@ -104,7 +105,8 @@ export class AuthRoleController extends Controller {
|
|||
posMaster.lastUpdateFullName = req.user.name;
|
||||
posMaster.lastUpdatedAt = new Date();
|
||||
posMaster.authRoleId = body.authRoleId;
|
||||
await this.posMasterRepository.save(posMaster);
|
||||
await this.posMasterRepository.save(posMaster, {data: req});
|
||||
setLogDataDiff(req, { before, after: posMaster });
|
||||
|
||||
// เช็คว่าถ้ามีค่า current_holderId ให้ลบ key สิทธิ์ใน redis
|
||||
if (posMaster.current_holderId) {
|
||||
|
|
@ -139,7 +141,7 @@ export class AuthRoleController extends Controller {
|
|||
getDetail = await this.authRoleRepo.findOneBy({ id: body.authRoleId });
|
||||
if (!getDetail) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const posMaster = await this.employeePosMasterRepository.findOneBy({ id: body.posMasterId });
|
||||
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
|
||||
|
||||
|
|
@ -147,7 +149,8 @@ export class AuthRoleController extends Controller {
|
|||
posMaster.lastUpdateFullName = req.user.name;
|
||||
posMaster.lastUpdatedAt = new Date();
|
||||
posMaster.authRoleId = body.authRoleId;
|
||||
await this.employeePosMasterRepository.save(posMaster);
|
||||
await this.employeePosMasterRepository.save(posMaster, {data: req});
|
||||
setLogDataDiff(req, { before, after: posMaster });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -226,7 +229,7 @@ export class AuthRoleController extends Controller {
|
|||
// ...newAttrs.map((attr) => this.authRoleAttrRepo.save(attr)),
|
||||
// ]);
|
||||
|
||||
await this.authRoleAttrRepo.remove(roleAttrData);
|
||||
await this.authRoleAttrRepo.remove(roleAttrData, {data: req});
|
||||
|
||||
const newAttrs = body.authRoleAttrs.map((attr) => {
|
||||
const newAttr = new AuthRoleAttr();
|
||||
|
|
@ -241,9 +244,10 @@ export class AuthRoleController extends Controller {
|
|||
});
|
||||
return newAttr;
|
||||
});
|
||||
|
||||
const before = structuredClone(record);
|
||||
await Promise.all([
|
||||
this.authRoleRepo.save(record),
|
||||
this.authRoleRepo.save(record, {data: req}),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
...newAttrs.map((attr) => this.authRoleAttrRepo.save(attr)),
|
||||
]);
|
||||
|
||||
|
|
@ -260,16 +264,17 @@ export class AuthRoleController extends Controller {
|
|||
}
|
||||
|
||||
@Delete("{roleId}")
|
||||
public async deleteRole(@Path() roleId: string) {
|
||||
public async deleteRole(@Path() roleId: string, @Request() req: RequestWithUser) {
|
||||
let result: any;
|
||||
try {
|
||||
result = await this.authRoleRepo.delete({ id: roleId });
|
||||
result = await this.authRoleRepo.findOneBy({ id: roleId });
|
||||
if (!result) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
await this.authRoleRepo.remove(result, {data: req});
|
||||
} catch {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
|
||||
}
|
||||
if (result.affected == undefined || result.affected <= 0)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue