tango-app-api-audit 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  import { download, getUTC, insertOpenSearchData, logger, sendMessageToQueue } from 'tango-app-api-middleware';
2
2
  import { aggregateAuditClientData } from '../service/auditClientData.service.js';
3
- import { aggregateUserAudit, findOneUserAudit, updateOneUserAudit } from '../service/userAudit.service.js';
3
+ import { aggregateUserAudit, updateOneUserAudit } from '../service/userAudit.service.js';
4
4
  import mongoose from 'mongoose';
5
5
  import { aggregateStoreAudit, updateOneStoreAudit } from '../service/storeAudit.service.js';
6
6
  import { findOneUser } from '../service/user.service.js';
@@ -1164,7 +1164,6 @@ export async function reTrigger( req, res ) {
1164
1164
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1165
1165
  const inputData = req.body;
1166
1166
  const sqs = JSON.parse( process.env.SQS );
1167
- const userAudit = await findOneUserAudit( { _id: inputData.auditId } );
1168
1167
  const query ={
1169
1168
  storeId: inputData.storeId,
1170
1169
  fileDate: inputData.fileDate,
@@ -1195,12 +1194,18 @@ export async function reTrigger( req, res ) {
1195
1194
  const code = sqsQueue?.errorCode;
1196
1195
  return res.sendError( error, code );
1197
1196
  } else {
1198
- if ( userAudit?.auditStatus !== 'completed' ) {
1197
+ if ( req.audit.status !== 'completed' ) {
1199
1198
  const userRecord ={
1200
1199
  auditStatus: 'skipped',
1201
1200
  isDraft: false,
1202
1201
  };
1203
- await updateOneUserAudit( { _id: inputData.auditId }, userRecord );
1202
+ const query ={
1203
+ storeId: inputData.storeId,
1204
+ fileDate: inputData.fileDate,
1205
+ auditStatus: req.audit.status,
1206
+
1207
+ };
1208
+ await updateOneUserAudit( query, userRecord );
1204
1209
  }
1205
1210
 
1206
1211
  const storeRecord ={
@@ -1220,7 +1225,6 @@ export async function reTrigger( req, res ) {
1220
1225
  auditType: inputData.auditType,
1221
1226
  storeId: inputData.storeId,
1222
1227
  queueName: queueName,
1223
- auditId: inputData.auditId,
1224
1228
  message: inputData.comments,
1225
1229
  triggerBy: req.user.userName,
1226
1230
  triggerId: req.user._id,
@@ -1245,12 +1249,18 @@ export async function reTrigger( req, res ) {
1245
1249
  };
1246
1250
  await createAssignAudit( assignUserRecord );
1247
1251
 
1248
- if ( userAudit?.auditStatus !== 'completed' ) {
1252
+ if ( req.audit.status !== 'completed' ) {
1249
1253
  const userRecord ={
1250
1254
  auditStatus: 'skipped',
1251
1255
  isDraft: false,
1252
1256
  };
1253
- await updateOneUserAudit( { _id: inputData.auditId }, userRecord );
1257
+ const query ={
1258
+ storeId: inputData.storeId,
1259
+ fileDate: inputData.fileDate,
1260
+ auditStatus: req.audit.status,
1261
+
1262
+ };
1263
+ await updateOneUserAudit( query, userRecord );
1254
1264
  }
1255
1265
 
1256
1266
  const storeRecord ={
@@ -1270,7 +1280,6 @@ export async function reTrigger( req, res ) {
1270
1280
  auditType: inputData.auditType,
1271
1281
  storeId: inputData.storeId,
1272
1282
  queueName: queueName,
1273
- auditId: inputData.auditId,
1274
1283
  message: inputData.comments,
1275
1284
  triggerBy: req.user.userName,
1276
1285
  triggerId: req.user._id,
@@ -1287,3 +1296,14 @@ export async function reTrigger( req, res ) {
1287
1296
  return res.sendError( err, 500 );
1288
1297
  }
1289
1298
  }
1299
+
1300
+ export async function beforeCountImages( req, res ) {
1301
+ try {
1302
+ const inputData = req.body;
1303
+ return res.sendSuccess( { result: inputData } );
1304
+ } catch ( error ) {
1305
+ const err = error.message || 'Internal Server Error';
1306
+ logger.info( { error: error, message: req.body, function: 'beforeCountImages' } );
1307
+ return res.sendError( err, 500 );
1308
+ }
1309
+ }
@@ -159,10 +159,26 @@ export const reTriggerValidSchema = joi.object(
159
159
  triggerType: joi.string().optional(),
160
160
  totalCount: joi.number().required(),
161
161
  userId: joi.string().optional(),
162
- auditId: joi.string().required(),
162
+ comments: joi.string().optional().allow( '' ),
163
163
  },
164
164
  );
165
165
 
166
166
  export const reTriggerValid = {
167
167
  body: reTriggerValidSchema,
168
168
  };
169
+
170
+ export const beforeCountImageSchema = joi.object(
171
+ {
172
+ fileDate: joi.string().required(),
173
+ storeId: joi.string().required(),
174
+ auditType: joi.string().optional(),
175
+ triggerType: joi.string().optional(),
176
+ totalCount: joi.number().required(),
177
+ userId: joi.string().optional(),
178
+ auditId: joi.string().required(),
179
+ },
180
+ );
181
+
182
+ export const beforeCountImageValid = {
183
+ body: beforeCountImageSchema,
184
+ };
@@ -1,8 +1,8 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
- import { clientMetrics, overAllAuditSummary, overViewCard, overViewTable, reTrigger, storeMetrics, summarySplit, userAuditHistory, userMetrics } from '../controllers/auditMetrics.controllers.js';
5
- import { clientMetricsValid, overAllAuditSummaryValid, overViewCardValid, overViewTableValid, reTriggerValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid } from '../dtos/auditMetrics.dtos.js';
4
+ import { beforeCountImages, clientMetrics, overAllAuditSummary, overViewCard, overViewTable, reTrigger, storeMetrics, summarySplit, userAuditHistory, userMetrics } from '../controllers/auditMetrics.controllers.js';
5
+ import { beforeCountImageValid, clientMetricsValid, overAllAuditSummaryValid, overViewCardValid, overViewTableValid, reTriggerValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid } from '../dtos/auditMetrics.dtos.js';
6
6
  import { isAuditDocumentExist, isAuditInputFolderExist } from '../validation/audit.validation.js';
7
7
 
8
8
  export const auditMetricsRouter = express.Router();
@@ -16,5 +16,6 @@ auditMetricsRouter.post( '/summary-split-up', isAllowedSessionHandler, validate(
16
16
  auditMetricsRouter.post( '/overview-table', isAllowedSessionHandler, validate( overViewTableValid ), overViewTable );
17
17
  auditMetricsRouter.post( '/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
18
18
  auditMetricsRouter.post( '/re-trigger', isAllowedSessionHandler, validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
19
+ auditMetricsRouter.post( '/before-count-images', isAllowedSessionHandler, validate( beforeCountImageValid ), isAuditInputFolderExist, beforeCountImages );
19
20
 
20
21
  export default auditMetricsRouter;