fix current revision log

This commit is contained in:
AdisakKanthawilang 2024-10-22 18:30:27 +07:00
parent 9265f6ec80
commit 63ed0534d0

View file

@ -2,6 +2,7 @@ import { NextFunction, Request, Response } from "express";
import { Client } from "@elastic/elasticsearch";
import { AppDataSource } from "../database/data-source";
import { PosMaster } from "../entities/PosMaster";
import { OrgRevision } from "../entities/OrgRevision";
if (!process.env.ELASTICSEARCH_INDEX) {
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
@ -26,6 +27,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
let data: any;
const repoPosmaster = AppDataSource.getRepository(PosMaster);
const repoRevision = AppDataSource.getRepository(OrgRevision);
const originalJson = res.json;
@ -38,8 +40,12 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
req.app.locals.logData = {};
const revision = await repoRevision.findOne({
where: { orgRevisionIsCurrent: true , orgRevisionIsDraft: false },
})
const rootId = await repoPosmaster.findOne({
where: { current_holderId: req.app.locals.logData.userId },
where: { current_holderId: req.app.locals.logData.userId, orgRevisionId: revision?.id },
});
res.on("finish", () => {