tango-app-api-client 3.1.20-beta.0 → 3.1.21-alpha.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-beta.0",
3
+ "version": "3.1.21-alpha.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.155",
28
+ "tango-api-schema": "^2.0.162",
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, auditConfigurationUpdate, auditConfigurationGet, 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, 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, findOneStore, updateManyStore } from '../service/store.service.js';
4
+ import { aggregateStore, countDocumentsStore, findStore, 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, deleteOneAssignedStore, updateOneUserAssignedStore } from '../service/userAssignedStore.service.js';
8
+ import { aggregateUserAssignedStore, 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,67 +1093,75 @@ export async function updateDocuments( req, res ) {
1093
1093
 
1094
1094
  export async function getAuditConfiguration( req, res ) {
1095
1095
  try {
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 );
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 );
1109
1109
  }
1110
+ return res.sendSuccess( auditConfig );
1110
1111
  } catch ( error ) {
1112
+ const err = error.message || 'Internal Server Error';
1111
1113
  logger.error( { error: error, message: req.params, function: 'getAuditConfiguration' } );
1112
- return res.sendError( 'Internal Server Error', 500 );
1114
+ return res.sendError( err, 500 );
1113
1115
  }
1114
1116
  }
1115
1117
 
1116
1118
 
1117
1119
  export async function auditConfiguration( req, res ) {
1118
1120
  try {
1121
+ const inputData = req.body;
1119
1122
  const openSearch = JSON.parse( process.env.OPENSEARCH );
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 = {
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: {
1130
1150
  clientId: req.params?.id,
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
- };
1151
+ count: inputData.count,
1152
+ audit: inputData.audit,
1153
+ ratio: normalizeNumber( inputData.ratio, 0, 100 ),
1154
+ },
1155
+ };
1148
1156
 
1149
- await insertOpenSearchData( openSearch.activityLog, logObj );
1150
- }
1157
+ await insertOpenSearchData( openSearch.activityLog, logObj );
1151
1158
 
1152
1159
 
1153
- res.sendSuccess( { result: 'Updated Successfully' } );
1160
+ return res.sendSuccess( { result: 'Updated Successfully' } );
1154
1161
  } catch ( error ) {
1162
+ const err = message.error || 'Internal Server Error';
1155
1163
  logger.error( { error: error, message: req.params, function: 'auditConfiguration' } );
1156
- return res.sendError( 'Internal Server Error', 500 );
1164
+ return res.sendError( err, 500 );
1157
1165
  }
1158
1166
  }
1159
1167
 
@@ -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 store id',
322
+ description: 'Get audit configuration by client 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 store.',
329
+ description: 'The ID of the client.',
330
330
  schema: {
331
331
  type: 'string',
332
332
  },
@@ -340,9 +340,6 @@ export const clientDocs = {
340
340
  204: { description: 'Not Found' },
341
341
  },
342
342
  },
343
- },
344
-
345
- '/v3/client/audit-configuration/{id}': {
346
343
  post: {
347
344
  tags: [ 'Client' ],
348
345
  description: 'Audit configuration settings',
@@ -351,7 +348,7 @@ export const clientDocs = {
351
348
  in: 'path',
352
349
  name: 'id',
353
350
  required: true,
354
- description: 'The ID of the store.',
351
+ description: 'The ID of the client.',
355
352
  schema: {
356
353
  type: 'string',
357
354
  },
@@ -206,16 +206,11 @@ export const getAuditConfigValid = {
206
206
  };
207
207
 
208
208
 
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();
209
+ export const auditConfigSchemaBody = joi.object( {
210
+ ratio: joi.number().required(),
211
+ count: joi.number().required(),
212
+ audit: joi.boolean().required(),
213
+ } );
219
214
 
220
215
  export const auditConfigSchemaParam = joi.object( {
221
216
  id: joi.string().required(),
@@ -1,6 +1,5 @@
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';
4
3
  import userModel from 'tango-api-schema/schema/user.model.js';
5
4
  import { createQueue, getQueueUrl, logger } from 'tango-app-api-middleware';
6
5
 
@@ -197,27 +196,6 @@ export function documentsUpdate( { clientId, gstNumber, panNumber, cinNumber, ad
197
196
  } );
198
197
  }
199
198
 
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
- }
221
199
 
222
200
  export function CsmUsersGet( ) {
223
201
  return userModel.aggregate(