tango-app-api-client 3.1.20-alpha.1 → 3.1.20-beta.0

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-client",
3
- "version": "3.1.20-alpha.1",
3
+ "version": "3.1.20-beta.0",
4
4
  "description": "client",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "mongodb": "^6.3.0",
26
26
  "nodemon": "^3.0.3",
27
27
  "swagger-ui-express": "^5.0.0",
28
- "tango-api-schema": "^2.0.161",
28
+ "tango-api-schema": "^2.0.155",
29
29
  "tango-app-api-middleware": "^3.1.30",
30
30
  "winston": "^3.11.0",
31
31
  "winston-daily-rotate-file": "^5.0.0"
@@ -1,11 +1,11 @@
1
- import { billingDetailsUpdate, brandInfoUpdate, domainDetailsConfigurationUpdate, featureConfigurationUpdate, getClientData, signatoryDetailsUpdate, ticketConfigurationUpdate, documentsUpdate, getUserData, CsmUsersGet, OpsUsersGet, userConfigurationUpdate, findClient, aggregateClient, createAuditQueue, findOne, insert, update, findOneClient, updateOneClient } from '../service/client.service.js';
1
+ import { billingDetailsUpdate, brandInfoUpdate, domainDetailsConfigurationUpdate, featureConfigurationUpdate, getClientData, signatoryDetailsUpdate, ticketConfigurationUpdate, documentsUpdate, getUserData, auditConfigurationUpdate, auditConfigurationGet, CsmUsersGet, OpsUsersGet, userConfigurationUpdate, findClient, aggregateClient, createAuditQueue, findOne, insert, update, findOneClient, updateOneClient } from '../service/client.service.js';
2
2
  import { checkFileExist, fileUpload, signedUrl, chunkArray, download, logger, getOpenSearchData, insertOpenSearchData, sendEmailWithSES, createCustomer, createVirtualAccount } from 'tango-app-api-middleware';
3
3
  import { countDocumentsUser, findOneAndUpdateUser, findOneUser, getUserNameEmailById, updateManyUser } from '../service/user.service.js';
4
- import { aggregateStore, countDocumentsStore, findStore, updateManyStore } from '../service/store.service.js';
4
+ import { aggregateStore, countDocumentsStore, findStore, findOneStore, updateManyStore } from '../service/store.service.js';
5
5
  import { aggregateCamera, countDocumentsCamera } from '../service/camera.service.js';
6
6
  import _ from 'lodash';
7
7
  import { findOneStandaredRole } from '../service/standaredRole.service.js';
8
- import { aggregateUserAssignedStore, updateOneUserAssignedStore } from '../service/userAssignedStore.service.js';
8
+ import { aggregateUserAssignedStore, deleteOneAssignedStore, updateOneUserAssignedStore } from '../service/userAssignedStore.service.js';
9
9
  import { aggregateTickets } from '../service/tangoticket.service.js';
10
10
  import { join } from 'path';
11
11
  import { readFileSync } from 'fs';
@@ -1093,75 +1093,67 @@ export async function updateDocuments( req, res ) {
1093
1093
 
1094
1094
  export async function getAuditConfiguration( req, res ) {
1095
1095
  try {
1096
- const query ={
1097
- clientId: req.params?.id,
1098
- };
1099
- const fields = {
1100
- 'auditConfigs.count': 1,
1101
- 'auditConfigs.audit': 1,
1102
- 'auditConfigs.ratio': 1,
1103
- 'clientId': 1,
1104
- '_id': 0,
1105
- };
1106
- const auditConfig = await findOneClient( query, fields );
1107
- if ( !auditConfig ) {
1108
- return res.sendError( 'Client not Found', 204 );
1096
+ const bucket = JSON.parse( process.env.BUCKET );
1097
+ const auditConfig = await auditConfigurationGet( { storeId: req.params?.id } );
1098
+ if ( auditConfig ) {
1099
+ const isDocExist = await checkFileExist( { Bucket: bucket.assets, Key: `templates/audit_bulk_update.xlsx` } );
1100
+ if ( isDocExist ) {
1101
+ const signedFilUrl = await signedUrl( { Bucket: bucket.assets, file_path: `templates/audit_bulk_update.xlsx` } );
1102
+ auditConfig._doc.templateUrl = signedFilUrl;
1103
+ } else {
1104
+ auditConfig._doc.templateUrl = '';
1105
+ }
1106
+ res.sendSuccess( auditConfig );
1107
+ } else {
1108
+ res.sendError( 'Store not Found', 404 );
1109
1109
  }
1110
- return res.sendSuccess( auditConfig );
1111
1110
  } catch ( error ) {
1112
- const err = error.message || 'Internal Server Error';
1113
1111
  logger.error( { error: error, message: req.params, function: 'getAuditConfiguration' } );
1114
- return res.sendError( err, 500 );
1112
+ return res.sendError( 'Internal Server Error', 500 );
1115
1113
  }
1116
1114
  }
1117
1115
 
1118
1116
 
1119
1117
  export async function auditConfiguration( req, res ) {
1120
1118
  try {
1121
- const inputData = req.body;
1122
1119
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1123
- const query ={
1124
- clientId: req.params?.id,
1125
- };
1126
- const fields ={
1127
- auditConfigs: 1, _id: 0,
1128
- };
1129
- const previousClient = await findOneClient( query, fields );
1130
- const record ={
1131
- 'auditConfigs.count': inputData.count,
1132
- 'auditConfigs.audit': inputData.audit,
1133
- 'auditConfigs.ratio': Number( normalizeNumber( inputData.ratio, 0, 100 ) ),
1134
- };
1135
- logger.info( { record: record, query: query } );
1136
- const a = await updateOneClient( query, record );
1137
- logger.info( { a: a } );
1138
- const logObj = {
1139
- clientId: req.params?.id,
1140
- userName: req.user?.userName,
1141
- email: req.user?.email,
1142
- date: new Date(),
1143
- logType: 'configuration',
1144
- logSubType: 'auditConfig',
1145
- eventType: 'update',
1146
- showTo: [ 'tango' ],
1147
- changes: [ `Audit config for client id ${req.params?.id}` ],
1148
- previous: previousClient,
1149
- current: {
1120
+ for ( let i = 0; i < req.body?.length; i++ ) {
1121
+ const previousStore = await findOneStore( { storeId: req.body[i].storeId }, { auditConfigs: 1, _id: 0 } );
1122
+ await auditConfigurationUpdate( {
1123
+ storeId: req.body[i].storeId,
1124
+ count: req.body[i].count,
1125
+ iteration: req.body[i].iteration,
1126
+ ratio: normalizeNumber( req.body[i].ratio, 0, 100 ),
1127
+ } );
1128
+
1129
+ const logObj = {
1150
1130
  clientId: req.params?.id,
1151
- count: inputData.count,
1152
- audit: inputData.audit,
1153
- ratio: normalizeNumber( inputData.ratio, 0, 100 ),
1154
- },
1155
- };
1131
+ userName: req.user?.userName,
1132
+ email: req.user?.email,
1133
+ date: new Date(),
1134
+ logType: 'configuration',
1135
+ logSubType: 'auditConfig',
1136
+ eventType: 'update',
1137
+ showTo: [ 'tango' ],
1138
+ changes: [ `Audit config for store id ${req.body[i].storeId}` ],
1139
+ storeId: req.body[i].storeId,
1140
+ previous: previousStore,
1141
+ current: {
1142
+ storeId: req.body[i].storeId,
1143
+ count: req.body[i].count,
1144
+ iteration: req.body[i].iteration,
1145
+ ratio: normalizeNumber( req.body[i].ratio, 0, 100 ),
1146
+ },
1147
+ };
1156
1148
 
1157
- await insertOpenSearchData( openSearch.activityLog, logObj );
1149
+ await insertOpenSearchData( openSearch.activityLog, logObj );
1150
+ }
1158
1151
 
1159
1152
 
1160
- return res.sendSuccess( { result: 'Updated Successfully' } );
1153
+ res.sendSuccess( { result: 'Updated Successfully' } );
1161
1154
  } catch ( error ) {
1162
- const err = message.error || 'Internal Server Error';
1163
1155
  logger.error( { error: error, message: req.params, function: 'auditConfiguration' } );
1164
- return res.sendError( err, 500 );
1156
+ return res.sendError( 'Internal Server Error', 500 );
1165
1157
  }
1166
1158
  }
1167
1159
 
@@ -319,14 +319,14 @@ export const clientDocs = {
319
319
  '/v3/client/audit-configuration/{id}': {
320
320
  get: {
321
321
  tags: [ 'Client' ],
322
- description: 'Get audit configuration by client id',
322
+ description: 'Get audit configuration by store id',
323
323
  operationId: 'get-audit-configuration',
324
324
  parameters: [
325
325
  {
326
326
  in: 'path',
327
327
  name: 'id',
328
328
  required: true,
329
- description: 'The ID of the client.',
329
+ description: 'The ID of the store.',
330
330
  schema: {
331
331
  type: 'string',
332
332
  },
@@ -340,6 +340,9 @@ export const clientDocs = {
340
340
  204: { description: 'Not Found' },
341
341
  },
342
342
  },
343
+ },
344
+
345
+ '/v3/client/audit-configuration/{id}': {
343
346
  post: {
344
347
  tags: [ 'Client' ],
345
348
  description: 'Audit configuration settings',
@@ -348,7 +351,7 @@ export const clientDocs = {
348
351
  in: 'path',
349
352
  name: 'id',
350
353
  required: true,
351
- description: 'The ID of the client.',
354
+ description: 'The ID of the store.',
352
355
  schema: {
353
356
  type: 'string',
354
357
  },
@@ -206,11 +206,16 @@ export const getAuditConfigValid = {
206
206
  };
207
207
 
208
208
 
209
- export const auditConfigSchemaBody = joi.object( {
210
- ratio: joi.number().required(),
211
- count: joi.number().required(),
212
- audit: joi.boolean().required(),
213
- } );
209
+ export const auditConfigSchemaBody = joi.array().items(
210
+ joi.object(
211
+ {
212
+ ratio: joi.number().required(),
213
+ count: joi.number().required(),
214
+ iteration: joi.number().required(),
215
+ storeId: joi.string().required(),
216
+ },
217
+ ).required(),
218
+ ).required();
214
219
 
215
220
  export const auditConfigSchemaParam = joi.object( {
216
221
  id: joi.string().required(),
@@ -1,5 +1,6 @@
1
1
  import clientModel from 'tango-api-schema/schema/client.model.js';
2
2
  import leadModel from 'tango-api-schema/schema/lead.model.js';
3
+ import storeModel from 'tango-api-schema/schema/store.model.js';
3
4
  import userModel from 'tango-api-schema/schema/user.model.js';
4
5
  import { createQueue, getQueueUrl, logger } from 'tango-app-api-middleware';
5
6
 
@@ -196,6 +197,27 @@ export function documentsUpdate( { clientId, gstNumber, panNumber, cinNumber, ad
196
197
  } );
197
198
  }
198
199
 
200
+ export function auditConfigurationGet( { storeId } ) {
201
+ return storeModel.findOne( { storeId: storeId },
202
+ {
203
+ 'auditConfigs.count': 1,
204
+ 'auditConfigs.iteration': 1,
205
+ 'auditConfigs.ratio': 1,
206
+ 'storeId': 1,
207
+ '_id': 0,
208
+ } );
209
+ }
210
+
211
+ export function auditConfigurationUpdate( { storeId, count, iteration, ratio } ) {
212
+ return storeModel.updateOne( { storeId: storeId },
213
+ {
214
+ $set: {
215
+ 'auditConfigs.count': count,
216
+ 'auditConfigs.iteration': iteration,
217
+ 'auditConfigs.ratio': ratio,
218
+ },
219
+ } );
220
+ }
199
221
 
200
222
  export function CsmUsersGet( ) {
201
223
  return userModel.aggregate(