tango-app-api-infra 3.0.29-dev → 3.0.31-dev

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-infra",
3
- "version": "3.0.29-dev",
3
+ "version": "3.0.31-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -22,8 +22,8 @@
22
22
  "handlebars": "^4.7.8",
23
23
  "mongodb": "^6.4.0",
24
24
  "nodemon": "^3.1.0",
25
- "tango-api-schema": "^2.0.61",
26
- "tango-app-api-middleware": "^1.0.49-dev",
25
+ "tango-api-schema": "^2.0.65",
26
+ "tango-app-api-middleware": "^1.0.51-dev",
27
27
  "winston": "^3.12.0",
28
28
  "winston-daily-rotate-file": "^5.0.0"
29
29
  },
@@ -62,15 +62,30 @@ export async function bulkcreateTicket( req, res ) {
62
62
 
63
63
  export async function updateStatus( req, res ) {
64
64
  try {
65
- if ( req.body.status == 'inprogress' ) {
66
- req.body.ticketActivity.push( {
67
- actionType: 'statusChange',
68
- actionBy: 'User',
69
- } );
70
- }
71
- let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, req.body );
72
- if ( updateTicket ) {
73
- res.sendSuccess( 'Ticket Updated Successfully' );
65
+ if ( req.user.userType == 'tango' ) {
66
+ if ( req.body.status == 'inprogress' ) {
67
+ req.body.ticketActivity.push( {
68
+ actionType: 'statusChange',
69
+ actionBy: 'Tango',
70
+ } );
71
+ }
72
+ req.body.ticketDetails.addressingUser = req.user._id;
73
+ let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, req.body );
74
+ if ( updateTicket ) {
75
+ res.sendSuccess( 'Ticket Updated Successfully' );
76
+ }
77
+ } else if ( req.user.userType == 'client' ) {
78
+ if ( req.body.status == 'inprogress' ) {
79
+ req.body.ticketActivity.push( {
80
+ actionType: 'statusChange',
81
+ actionBy: 'User',
82
+ } );
83
+ }
84
+ req.body.ticketDetails.addressingClient = req.user._id;
85
+ let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, req.body );
86
+ if ( updateTicket ) {
87
+ res.sendSuccess( 'Ticket Updated Successfully' );
88
+ }
74
89
  }
75
90
  } catch ( error ) {
76
91
  logger.error( { error: error, function: 'updateStatus' } );
@@ -116,7 +116,7 @@ export async function downStoresList( req, res ) {
116
116
  }
117
117
  export async function openTicketList( req, res ) {
118
118
  try {
119
- let openTicketList = await findTangoTicket( { status: { $ne: 'closed' }, issueType: 'infra' }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
119
+ let openTicketList = await findTangoTicket( { status: { $ne: 'closed' } }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
120
120
  if ( openTicketList.length ) {
121
121
  res.sendSuccess( {
122
122
  count: openTicketList.length,
@@ -133,7 +133,7 @@ export async function storeTicketcard( req, res ) {
133
133
  { 'ticketDetails.issueStatus': 'identified' },
134
134
  { issueType: 'infra' },
135
135
  { createdAt: { $gte: date.start } },
136
- { createdAt: { $lte: date.start } },
136
+ { createdAt: { $lte: date.end } },
137
137
  ],
138
138
 
139
139
  },
@@ -12,9 +12,15 @@ export async function userTakeTicket( req, res ) {
12
12
  try {
13
13
  let userTicket = '';
14
14
  if ( req.body.issueType == 'infra' ) {
15
- userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'issueType': 'infra', 'ticketDetails.assigntoUser': true, 'ticketDetails.addressingUser': { $exists: false } } );
15
+ userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'issueType': 'infra', 'ticketDetails.assigntoUser': true, 'ticketDetails.addressingUser': { $exists: false }, 'ticketDetails.issueStatus': 'notidentified', 'ticketDetails.addressingClient': { $exists: false } } );
16
+ if ( !userTicket ) {
17
+ userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'issueType': 'infra', 'ticketType': 'refreshticket', 'ticketDetails.refreshTicketStatus': 'notidentified' } );
18
+ }
16
19
  } else if ( req.body.issueType == 'installation' ) {
17
- userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'issueType': 'installation', 'ticketDetails.addressingUser': { $exists: false } } );
20
+ userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'issueType': 'installation', 'ticketDetails.addressingUser': { $exists: false }, 'ticketDetails.issueStatus': 'notidentified', 'ticketDetails.addressingClient': { $exists: false } } );
21
+ if ( !userTicket ) {
22
+ userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'issueType': 'installation', 'ticketType': 'refreshticket', 'ticketDetails.refreshTicketStatus': 'notidentified' } );
23
+ }
18
24
  }
19
25
  if ( userTicket ) {
20
26
  let assignTicket = await updateOneTangoTicket( { ticketId: userTicket.ticketId }, { 'ticketDetails.addressingUser': req.body.userId } );
@@ -45,8 +51,8 @@ export async function userTicketList( req, res ) {
45
51
  query.push( {
46
52
  $match: {
47
53
  $and: [
48
- { createdAt: { $gte: date.start } },
49
- { createdAt: { $lte: date.end } },
54
+ { updatedAt: { $gte: date.start } },
55
+ { updatedAt: { $lte: date.end } },
50
56
  ],
51
57
  },
52
58
  } );
@@ -7,27 +7,27 @@ export const clientInfraRouter = express.Router();
7
7
 
8
8
 
9
9
  clientInfraRouter.post( '/infraCard', isAllowedSessionHandler, authorize( {
10
- userType: [ 'client' ], access: [
10
+ userType: [ 'client', 'tango' ], access: [
11
11
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
12
12
  } ), infraCard );
13
13
  clientInfraRouter.post( '/infraIssuesTable', isAllowedSessionHandler, authorize( {
14
- userType: [ 'client' ], access: [
14
+ userType: [ 'client', 'tango' ], access: [
15
15
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
16
16
  } ), infraIssuesTable );
17
17
  clientInfraRouter.post( '/installationCard', isAllowedSessionHandler, authorize( {
18
- userType: [ 'client' ], access: [
18
+ userType: [ 'client', 'tango' ], access: [
19
19
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
20
20
  } ), installationCard );
21
21
  clientInfraRouter.post( '/InstallationIssuesTable', isAllowedSessionHandler, authorize( {
22
- userType: [ 'client' ], access: [
22
+ userType: [ 'client', 'tango' ], access: [
23
23
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
24
24
  } ), InstallationIssuesTable );
25
25
  clientInfraRouter.post( '/hourWiseDownClients', isAllowedSessionHandler, authorize( {
26
- userType: [ 'client' ], access: [
26
+ userType: [ 'client', 'tango' ], access: [
27
27
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
28
28
  } ), hourWiseDownClients );
29
29
  clientInfraRouter.post( '/hourWiseDownstores', isAllowedSessionHandler, authorize( {
30
- userType: [ 'client' ], access: [
30
+ userType: [ 'client', 'tango' ], access: [
31
31
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
32
32
  } ), hourWiseDownstores );
33
33
 
@@ -171,41 +171,50 @@ export async function ticketExists( req, res, next ) {
171
171
  };
172
172
  export async function infraReasonExists( req, res, next ) {
173
173
  try {
174
- let primaryReason = await findOneinfraReason( { name: req.body.primary } );
175
- if ( !primaryReason ) {
176
- return res.sendError( 'Primary Reason Not exists in database', 500 );
177
- }
178
- const secondary = [];
179
- const steptoReslove = [];
180
- for ( let i = 0; i < req.body.secondary.length; i++ ) {
181
- let secondaryReason = await findOneinfraReason( { name: req.body.secondary[i] } );
182
- if ( !secondaryReason ) {
183
- return res.sendError( `secondary Reason - ${req.body.secondary[i]} Not exists in database`, 500 );
174
+ if ( req.body.primary&&req.body.secondary&&req.body.secondary.length ) {
175
+ let primaryReason = await findOneinfraReason( { name: req.body.primary } );
176
+ if ( !primaryReason ) {
177
+ return res.sendError( 'Primary Reason Not exists in database', 500 );
184
178
  }
185
- secondary.push( {
186
- name: secondaryReason.name,
187
- } );
188
- let resolveSteps = [];
189
- for ( let i = 0; i < secondaryReason.stepstoResolve.length; i++ ) {
190
- resolveSteps.push( {
191
- name: secondaryReason.stepstoResolve[i].name,
179
+ const secondary = [];
180
+ const steptoReslove = [];
181
+ for ( let i = 0; i < req.body.secondary.length; i++ ) {
182
+ let secondaryReason = await findOneinfraReason( { name: req.body.secondary[i] } );
183
+ if ( !secondaryReason ) {
184
+ return res.sendError( `secondary Reason - ${req.body.secondary[i]} Not exists in database`, 500 );
185
+ }
186
+ secondary.push( {
187
+ name: secondaryReason.name,
188
+ } );
189
+ let resolveSteps = [];
190
+ for ( let i = 0; i < secondaryReason.stepstoResolve.length; i++ ) {
191
+ resolveSteps.push( {
192
+ name: secondaryReason.stepstoResolve[i].name,
193
+ } );
194
+ }
195
+ steptoReslove.push( {
196
+ primaryIssue: secondaryReason.name,
197
+ secondaryIsssue: [ ...resolveSteps ],
192
198
  } );
193
199
  }
194
- steptoReslove.push( {
195
- primaryIssue: secondaryReason.name,
196
- secondaryIsssue: [ ...resolveSteps ],
197
- } );
200
+ let actionBy = '';
201
+ if ( req.user.userType == 'tango' ) {
202
+ actionBy = 'Tango';
203
+ } else if ( req.user.userType == 'client' ) {
204
+ actionBy = 'User';
205
+ }
206
+ req.body.ticketActivity.push( {
207
+ actionType: 'issueUpdate',
208
+ actionBy: actionBy,
209
+ comment: req.body.comment,
210
+ reasons: [ {
211
+ primaryIssue: primaryReason.name,
212
+ secondaryIssue: secondary,
213
+ } ],
214
+ },
215
+ );
198
216
  }
199
- req.body.ticketActivity.push( {
200
- actionType: 'issueUpdate',
201
- actionBy: 'User',
202
- comment: req.body.comment,
203
- reasons: [ {
204
- primaryIssue: primaryReason.name,
205
- secondaryIssue: secondary,
206
- } ],
207
- },
208
- );
217
+
209
218
  next();
210
219
  } catch ( error ) {
211
220
  logger.error( { error: error, function: 'infraReasonExists' } );
@@ -215,27 +224,29 @@ export async function infraReasonExists( req, res, next ) {
215
224
  export async function InfrastepstoResolve( req, res, next ) {
216
225
  try {
217
226
  const steptoReslove = [];
218
- for ( let i = 0; i < req.body.secondary.length; i++ ) {
219
- let secondaryReason = await findOneinfraReason( { name: req.body.secondary[i] } );
220
- if ( !secondaryReason ) {
221
- return res.sendError( `secondary Reason - ${req.body.secondary[i]} Not exists in database`, 500 );
227
+ if ( req.body.primary&&req.body.secondary&&req.body.secondary.length ) {
228
+ for ( let i = 0; i < req.body.secondary.length; i++ ) {
229
+ let secondaryReason = await findOneinfraReason( { name: req.body.secondary[i] } );
230
+ if ( !secondaryReason ) {
231
+ return res.sendError( `secondary Reason - ${req.body.secondary[i]} Not exists in database`, 500 );
232
+ }
233
+ steptoReslove.push( {
234
+ primaryIssue: secondaryReason.name,
235
+ secondaryIsssue: [ ...secondaryReason.stepstoResolve ],
236
+ } );
222
237
  }
223
- steptoReslove.push( {
224
- primaryIssue: secondaryReason.name,
225
- secondaryIsssue: [ ...secondaryReason.stepstoResolve ],
226
- } );
227
- }
228
- if ( req.body.primary != 'Store Operation Issues' && req.body.primary != 'Application Issues' ) {
229
- req.body.ticketActivity.push( {
230
- actionType: 'stepsToResolve',
231
- actionBy: 'Tango',
232
- reasons: steptoReslove.map( ( item ) => ( {
233
- primaryIssue: item.primaryIssue,
234
- secondaryIssue: item.secondaryIsssue.map( ( issue ) => ( {
235
- name: issue.name, // Assuming each object has a 'name' property
238
+ if ( req.body.primary != 'Store Operation Issues' && req.body.primary != 'Application Issues' ) {
239
+ req.body.ticketActivity.push( {
240
+ actionType: 'stepsToResolve',
241
+ actionBy: 'Tango',
242
+ reasons: steptoReslove.map( ( item ) => ( {
243
+ primaryIssue: item.primaryIssue,
244
+ secondaryIssue: item.secondaryIsssue.map( ( issue ) => ( {
245
+ name: issue.name, // Assuming each object has a 'name' property
246
+ } ) ),
236
247
  } ) ),
237
- } ) ),
238
- } );
248
+ } );
249
+ }
239
250
  }
240
251
  next();
241
252
  } catch ( error ) {
@@ -258,13 +269,29 @@ export async function InfraAlert( req, res, next ) {
258
269
  await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'hibernation': new Date( req.body.hibernationDays ) } );
259
270
  } else {
260
271
  if ( req.body.issueType == 'infra' ) {
261
- let client = await findOneClient( { clientId: req.body.basicDetails.clientId }, { ticketConfigs: 1 } );
262
- let statusCheckAlertTime = dayjs().add( client.ticketConfigs.statusCheckAlert, 'hours' ).format( 'YYYY-MM-DD hh:mm' );
263
- req.body.ticketActivity.push( {
264
- actionType: 'statusCheck',
265
- actionBy: 'Tango',
266
- statusCheckAlertTime: statusCheckAlertTime,
267
- } );
272
+ if ( req.body.primary&&req.body.secondary&&req.body.secondary.length ) {
273
+ let client = await findOneClient( { clientId: req.body.basicDetails.clientId }, { ticketConfigs: 1 } );
274
+ let statusCheckAlertTime = dayjs().add( client.ticketConfigs.statusCheckAlert, 'hours' ).format( 'YYYY-MM-DD hh:mm' );
275
+ req.body.ticketActivity.push( {
276
+ actionType: 'statusCheck',
277
+ actionBy: 'Tango',
278
+ statusCheckAlertTime: statusCheckAlertTime,
279
+ } );
280
+ } else {
281
+ if ( req.body.comment !='' ) {
282
+ let actionBy = '';
283
+ if ( req.user.userType == 'tango' ) {
284
+ actionBy = 'Tango';
285
+ } else if ( req.user.userType == 'client' ) {
286
+ actionBy = 'User';
287
+ }
288
+ req.body.ticketActivity.push( {
289
+ actionType: 'comment',
290
+ actionBy: actionBy,
291
+ comment: req.body.comment,
292
+ } );
293
+ }
294
+ }
268
295
  }
269
296
  }
270
297