log
This commit is contained in:
parent
ce8bb41bda
commit
0f79425d65
17 changed files with 611 additions and 202 deletions
|
|
@ -23,6 +23,8 @@ import { PosType, CreatePosType, UpdatePosType } from "../entities/PosType";
|
|||
import { PosLevel } from "../entities/PosLevel";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Not } from "typeorm";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/pos/type")
|
||||
@Tags("PosType")
|
||||
|
|
@ -50,7 +52,7 @@ export class PosTypeController extends Controller {
|
|||
async createType(
|
||||
@Body()
|
||||
requestBody: CreatePosType,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const posType = Object.assign(new PosType(), requestBody);
|
||||
if (!posType) {
|
||||
|
|
@ -68,11 +70,13 @@ export class PosTypeController extends Controller {
|
|||
);
|
||||
}
|
||||
// try {
|
||||
const before = null;
|
||||
posType.createdUserId = request.user.sub;
|
||||
posType.createdFullName = request.user.name;
|
||||
posType.lastUpdateUserId = request.user.sub;
|
||||
posType.lastUpdateFullName = request.user.name;
|
||||
await this.posTypeRepository.save(posType);
|
||||
await this.posTypeRepository.save(posType, { data: request });
|
||||
setLogDataDiff(request, { before, after: posType });
|
||||
return new HttpSuccess(posType);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
@ -94,7 +98,7 @@ export class PosTypeController extends Controller {
|
|||
async editType(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdatePosType,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const posType = await this.posTypeRepository.findOne({ where: { id } });
|
||||
if (!posType) {
|
||||
|
|
@ -113,10 +117,12 @@ export class PosTypeController extends Controller {
|
|||
);
|
||||
}
|
||||
// try {
|
||||
const before = structuredClone(posType);
|
||||
posType.lastUpdateUserId = request.user.sub;
|
||||
posType.lastUpdateFullName = request.user.name;
|
||||
this.posTypeRepository.merge(posType, requestBody);
|
||||
await this.posTypeRepository.save(posType);
|
||||
await this.posTypeRepository.save(posType, { data: request });
|
||||
setLogDataDiff(request, { before, after: posType });
|
||||
return new HttpSuccess(posType.id);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
@ -131,7 +137,7 @@ export class PosTypeController extends Controller {
|
|||
* @param {string} id Id ตำแหน่ง
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteType(@Path() id: string) {
|
||||
async deleteType(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const delPosType = await this.posTypeRepository.findOne({ where: { id } });
|
||||
if (!delPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
|
|
@ -144,7 +150,7 @@ export class PosTypeController extends Controller {
|
|||
}
|
||||
|
||||
// try {
|
||||
await this.posTypeRepository.remove(delPosType);
|
||||
await this.posTypeRepository.remove(delPosType, { data: request });
|
||||
return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue