tango-app-api-infra 3.0.22-dev → 3.0.24-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.22-dev",
3
+ "version": "3.0.24-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.56",
26
- "tango-app-api-middleware": "^1.0.41-dev",
25
+ "tango-api-schema": "^2.0.61",
26
+ "tango-app-api-middleware": "^1.0.48-dev",
27
27
  "winston": "^3.12.0",
28
28
  "winston-daily-rotate-file": "^5.0.0"
29
29
  },
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { aggregateStore, countDocumentsStore } from '../services/store.service.js';
3
- import { logger, download } from 'tango-app-api-middleware';
3
+ import { logger, download, getUTC } from 'tango-app-api-middleware';
4
4
  import { aggregateTangoTicket } from '../services/tangoTicket.service.js';
5
5
  import { findinfraReason } from '../services/infraReason.service.js';
6
6
  import { aggregateClient } from '../services/client.service.js';
@@ -9,6 +9,7 @@ import { getOpenSearchData } from 'tango-app-api-middleware';
9
9
 
10
10
  export async function infraCard( req, res ) {
11
11
  try {
12
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
12
13
  let storeCount = await countDocumentsStore( { clientId: { $in: req.body.clientId }, status: 'active' } );
13
14
  let infraStoreCount = await aggregateTangoTicket( [
14
15
  {
@@ -17,8 +18,8 @@ export async function infraCard( req, res ) {
17
18
  { issueType: 'infra' },
18
19
  { 'status': { $ne: 'closed' } },
19
20
  { 'basicDetails.clientId': { $in: req.body.clientId } },
20
- { createdAt: { $gte: new Date( req.body.fromDate ) } },
21
- { createdAt: { $lte: new Date( req.body.toDate ) } },
21
+ { createdAt: { $gte: date.start } },
22
+ { createdAt: { $lte: date.end } },
22
23
  ],
23
24
  },
24
25
  },
@@ -52,8 +53,8 @@ export async function infraCard( req, res ) {
52
53
  { 'status': { $ne: 'closed' } },
53
54
  { 'basicDetails.clientId': { $in: req.body.clientId } },
54
55
  { 'ticketDetails.issueStatus': 'identified' },
55
- { createdAt: { $gte: new Date( req.body.fromDate ) } },
56
- { createdAt: { $lte: new Date( req.body.toDate ) } },
56
+ { createdAt: { $gte: date.start } },
57
+ { createdAt: { $lte: date.end } },
57
58
  ],
58
59
  },
59
60
  },
@@ -61,6 +62,7 @@ export async function infraCard( req, res ) {
61
62
  $project: {
62
63
  ticketId: 1,
63
64
  issueStatus: '$ticketDetails.issueStatus',
65
+ ticketType: '$ticketDetails.ticketType',
64
66
  issueIdentifiedBy: '$ticketDetails.issueIdentifiedBy',
65
67
  primaryIssue: {
66
68
  $filter: {
@@ -90,6 +92,15 @@ export async function infraCard( req, res ) {
90
92
  primaryIssue: '$primaryIssue.reasons.primaryIssue',
91
93
  },
92
94
  },
95
+ {
96
+ $group: {
97
+ _id: '$ticketId',
98
+ issueStatus: { $first: '$issueStatus' },
99
+ ticketType: { $first: '$ticketType' },
100
+ issueIdentifiedBy: { $first: '$issueIdentifiedBy' },
101
+ primaryIssue: { $last: '$primaryIssue' },
102
+ },
103
+ },
93
104
  ];
94
105
  if ( req.body.filter && req.body.filter.length > 0 ) {
95
106
  query.push(
@@ -237,6 +248,7 @@ export async function installationCard( req, res ) {
237
248
  }
238
249
  export async function infraIssuesTable( req, res ) {
239
250
  try {
251
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
240
252
  let query = [ {
241
253
  $match: {
242
254
  $and: [
@@ -244,14 +256,15 @@ export async function infraIssuesTable( req, res ) {
244
256
  { status: { $ne: 'closed' } },
245
257
  { 'basicDetails.clientId': { $in: req.body.clientId } },
246
258
  { 'ticketDetails.issueStatus': 'identified' },
247
- { createdAt: { $gte: new Date( req.body.fromDate ) } },
248
- { createdAt: { $lte: new Date( req.body.toDate ) } },
259
+ { createdAt: { $gte: date.start } },
260
+ { createdAt: { $lte: date.end } },
249
261
  ],
250
262
  },
251
263
  },
252
264
  {
253
265
  $project: {
254
266
  storeId: '$basicDetails.storeId',
267
+ ticketId: 1,
255
268
  storeName: '$basicDetails.storeName',
256
269
  status: 1,
257
270
  createdAt: { $dateToString: { format: '%d-%m-%Y', date: '$createdAt' } },
@@ -286,6 +299,7 @@ export async function infraIssuesTable( req, res ) {
286
299
  storeId: 1,
287
300
  storeName: 1,
288
301
  createdAt: 1,
302
+ ticketId: 1,
289
303
  issueIdentifiedDate: { $ifNull: [ '$issueIdentifiedDate', '-' ] },
290
304
  issueClosedDate: { $ifNull: [ '$issueClosedDate', '-' ] },
291
305
  status: 1,
@@ -295,15 +309,16 @@ export async function infraIssuesTable( req, res ) {
295
309
  },
296
310
  {
297
311
  $group: {
298
- _id: '$storeId',
312
+ _id: '$ticketId',
299
313
  storeId: { $first: '$storeId' },
314
+ ticketId: { $first: '$ticketId' },
300
315
  storeName: { $first: '$storeName' },
301
316
  createdAt: { $first: '$createdAt' },
302
- issueIdentifiedDate: { $first: '$issueIdentifiedDate' },
303
- issueClosedDate: { $first: '$issueClosedDate' },
304
- status: { $first: '$status' },
305
- primaryIssue: { $first: '$primaryIssue' },
306
- secondaryIssue: { $first: '$secondaryIssue' },
317
+ issueIdentifiedDate: { $last: '$issueIdentifiedDate' },
318
+ issueClosedDate: { $last: '$issueClosedDate' },
319
+ status: { $last: '$status' },
320
+ primaryIssue: { $last: '$primaryIssue' },
321
+ secondaryIssue: { $last: '$secondaryIssue' },
307
322
  },
308
323
  },
309
324
  ];
@@ -28,6 +28,37 @@ export async function createTicket( req, res ) {
28
28
  return res.sendError( error, 500 );
29
29
  }
30
30
  }
31
+ export async function bulkcreateTicket( req, res ) {
32
+ try {
33
+ let response = {};
34
+ response.success = [];
35
+ response.error = [];
36
+
37
+ for ( let data of req.body.filteredstore ) {
38
+ data.issueDate = new Date( data.Date );
39
+ data.ticketDetails.filesCount = data.filesCount;
40
+ if ( data.issueType == 'infra' ) {
41
+ data.ticketId = 'TE_INF_' + new Date().valueOf();
42
+ data.ticketActivity = [ {
43
+ actionType: 'defaultInfra',
44
+ actionBy: 'Tango',
45
+ } ];
46
+ }
47
+ if ( data.issueType == 'installation' ) {
48
+ data.ticketId = 'TE_INS_' + new Date().valueOf();
49
+ }
50
+ let create = await createTangoTicket( data );
51
+ if ( create ) {
52
+ response.success.push( `Ticket Created Successfully${data.basicDetails.storeId}` );
53
+ }
54
+ }
55
+ response.error = req.body.error;
56
+ res.sendSuccess( response );
57
+ } catch ( error ) {
58
+ logger.error( { error: error, function: 'bulkcreateTicket' } );
59
+ return res.sendError( error, 500 );
60
+ }
61
+ }
31
62
 
32
63
  export async function updateStatus( req, res ) {
33
64
  try {
@@ -96,7 +127,10 @@ export async function secondaryReason( req, res ) {
96
127
 
97
128
  export async function updateTicketIssue( req, res ) {
98
129
  try {
99
- let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketActivity': req.body.ticketActivity, 'ticketDetails.issueIdentifiedDate': new Date(), 'ticketDetails.issueIdentifiedBy': req.body.issueIdentifiedBy, 'ticketDetails.issueStatus': 'identified', 'status': 'inprogress' } );
130
+ let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketActivity': req.body.ticketActivity, 'cameraList': req.body.cameraList, 'ticketDetails.issueIdentifiedDate': new Date(), 'ticketDetails.issueIdentifiedBy': req.body.issueIdentifiedBy, 'ticketDetails.issueStatus': 'identified', 'status': 'inprogress' } );
131
+ if ( req.body.ticketDetails.ticketType === 'refreshticket' ) {
132
+ await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketDetails.refreshTicketStatus': 'identified' } );
133
+ }
100
134
  if ( updateTicket ) {
101
135
  res.sendSuccess( 'Ticket Updated Successfully' );
102
136
  }
@@ -106,6 +140,31 @@ export async function updateTicketIssue( req, res ) {
106
140
  }
107
141
  }
108
142
 
143
+
144
+ export async function updateInstallationTicket( req, res ) {
145
+ try {
146
+ let updateValue = {};
147
+ if ( req.body.installationStatus && req.body.installationStatus != '' ) {
148
+ updateValue = { 'ticketDetails.installationStatus': req.body.installationStatus, 'status': 'inprogress' };
149
+ }
150
+ if ( req.body.actionType && req.body.actionType != '' ) {
151
+ req.body.ticketActivity.push( {
152
+ actionType: req.body.actionType,
153
+ actionBy: 'Tango',
154
+ } );
155
+ updateValue = { ticketActivity: req.body.ticketActivity };
156
+ }
157
+
158
+ let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, updateValue );
159
+ if ( updateTicket ) {
160
+ res.sendSuccess( 'Ticket Updated Successfully' );
161
+ }
162
+ } catch ( error ) {
163
+ logger.error( { error: error, function: 'updateInstallationTicket' } );
164
+ return res.sendError( error, 500 );
165
+ }
166
+ }
167
+
109
168
  export async function viewTicket( req, res ) {
110
169
  try {
111
170
  let ticket = await findOneTangoTicket( { ticketId: req.body.ticketId }, { ticketId: 1, status: 1, ticketDetails: 1, basicDetails: 1, ticketActivity: 1, createdAt: 1, attachments: 1 } );
@@ -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' } }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
119
+ let openTicketList = await findTangoTicket( { status: { $ne: 'closed' }, issueType: 'infra' }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
120
120
  if ( openTicketList.length ) {
121
121
  res.sendSuccess( {
122
122
  count: openTicketList.length,
@@ -1,17 +1,18 @@
1
1
 
2
- import { logger, getOpenSearchData, download } from 'tango-app-api-middleware';
2
+ import { logger, getOpenSearchData, download, getUTC } from 'tango-app-api-middleware';
3
3
  import { aggregateTangoTicket } from '../services/tangoTicket.service.js';
4
4
  import { findOneStore } from '../services/store.service.js';
5
5
  import dayjs from 'dayjs';
6
6
  import { findinfraReason } from '../services/infraReason.service.js';
7
7
  export async function storeTicketList( req, res ) {
8
8
  try {
9
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
9
10
  let query = [ {
10
11
  $match: {
11
12
  $and: [
12
13
  { 'basicDetails.storeId': req.body.storeId },
13
- { createdAt: { $gte: new Date( req.body.fromDate ) } },
14
- { createdAt: { $lte: new Date( req.body.toDate ) } },
14
+ { createdAt: { $gte: date.start } },
15
+ { createdAt: { $lte: date.end } },
15
16
  ],
16
17
  },
17
18
  },
@@ -24,6 +25,7 @@ export async function storeTicketList( req, res ) {
24
25
  ticketId: 1,
25
26
  issueStatus: '$ticketDetails.issueStatus',
26
27
  ticketType: '$ticketDetails.ticketType',
28
+ comments: { $size: '$ticketActivity' },
27
29
  primaryIssue: {
28
30
  $filter: {
29
31
  input: '$ticketActivity',
@@ -52,10 +54,26 @@ export async function storeTicketList( req, res ) {
52
54
  ticketId: 1,
53
55
  issueStatus: 1,
54
56
  ticketType: 1,
57
+ comments: 1,
55
58
  primaryIssue: '$primaryIssue.reasons.primaryIssue',
56
59
  secondaryIssue: '$primaryIssue.reasons.secondaryIssue',
57
60
  },
58
61
  },
62
+ {
63
+ $group: {
64
+ _id: '$ticketId',
65
+ storeId: { $first: '$storeId' },
66
+ Date: { $first: '$Date' },
67
+ issueClosedDate: { $first: '$issueClosedDate' },
68
+ status: { $first: '$status' },
69
+ ticketId: { $first: '$ticketId' },
70
+ issueStatus: { $first: '$issueStatus' },
71
+ ticketType: { $first: '$ticketType' },
72
+ comments: { $first: '$comments' },
73
+ primaryIssue: { $last: '$primaryIssue' },
74
+ secondaryIssue: { $last: '$secondaryIssue' },
75
+ },
76
+ },
59
77
  ];
60
78
 
61
79
  if ( req.body.filter && req.body.filter !== '' ) {
@@ -97,13 +115,14 @@ export async function storeTicketList( req, res ) {
97
115
 
98
116
  export async function storeTicketcard( req, res ) {
99
117
  try {
118
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
100
119
  let query = [ {
101
120
  $match: {
102
121
  $and: [
103
122
  { 'basicDetails.storeId': req.body.storeId },
104
123
  { 'ticketDetails.issueStatus': 'identified' },
105
- { createdAt: { $gte: new Date( req.body.fromDate ) } },
106
- { createdAt: { $lte: new Date( req.body.toDate ) } },
124
+ { createdAt: { $gte: date.start } },
125
+ { createdAt: { $lte: date.start } },
107
126
  ],
108
127
 
109
128
  },
@@ -138,6 +157,14 @@ export async function storeTicketcard( req, res ) {
138
157
  ticketType: 1,
139
158
  primaryIssue: '$primaryIssue.reasons.primaryIssue',
140
159
  },
160
+ }, {
161
+ $group: {
162
+ _id: '$ticketId',
163
+ ticketId: { $first: '$ticketId' },
164
+ issueStatus: { $first: '$issueStatus' },
165
+ ticketType: { $first: '$ticketType' },
166
+ primaryIssue: { $last: '$primaryIssue' },
167
+ },
141
168
  },
142
169
  ];
143
170
  let ticketList = await aggregateTangoTicket( query );
@@ -1,8 +1,9 @@
1
1
 
2
2
  import { findOneTangoTicket, updateOneTangoTicket, aggregateTangoTicket, countDocumentsTangoTicket } from '../services/tangoTicket.service.js';
3
- import { logger, download } from 'tango-app-api-middleware';
3
+ import { logger, download, getUTC } from 'tango-app-api-middleware';
4
4
  import { findOneUser } from '../services/user.service.js';
5
5
  import { aggregateStore } from '../services/store.service.js';
6
+ import { findOneGroup } from '../services/group.service.js';
6
7
 
7
8
  import mongoose from 'mongoose';
8
9
  import dayjs from 'dayjs';
@@ -30,6 +31,7 @@ export async function userTakeTicket( req, res ) {
30
31
  }
31
32
  export async function userTicketList( req, res ) {
32
33
  try {
34
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
33
35
  let query = [ {
34
36
  $match: {
35
37
  $and: [
@@ -43,8 +45,8 @@ export async function userTicketList( req, res ) {
43
45
  query.push( {
44
46
  $match: {
45
47
  $and: [
46
- { createdAt: { $gte: new Date( req.body.fromDate ) } },
47
- { createdAt: { $lte: new Date( req.body.toDate ) } },
48
+ { createdAt: { $gte: date.start } },
49
+ { createdAt: { $lte: date.end } },
48
50
  ],
49
51
  },
50
52
  } );
@@ -62,8 +64,10 @@ export async function userTicketList( req, res ) {
62
64
  storeId: '$basicDetails.storeId',
63
65
  Date: { $dateToString: { format: '%d-%m-%Y', date: '$issueDate' } },
64
66
  ticketId: 1,
67
+ issueType: 1,
65
68
  issueStatus: '$ticketDetails.issueStatus',
66
69
  ticketType: '$ticketDetails.ticketType',
70
+ installationStatus: '$ticketDetails.installationStatus',
67
71
  primaryIssue: {
68
72
  $filter: {
69
73
  input: '$ticketActivity',
@@ -82,16 +86,33 @@ export async function userTicketList( req, res ) {
82
86
  $unwind: {
83
87
  path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
84
88
  },
85
- }, {
89
+ },
90
+ {
86
91
  $project: {
87
92
  storeId: 1,
88
93
  Date: 1,
89
94
  ticketId: 1,
90
95
  issueStatus: 1,
91
96
  ticketType: 1,
97
+ issueType: 1,
98
+ installationStatus: 1,
92
99
  infraIssue: '$primaryIssue.reasons.primaryIssue',
93
100
  },
94
- } );
101
+ },
102
+ {
103
+ $group: {
104
+ _id: '$ticketId',
105
+ storeId: { $first: '$storeId' },
106
+ Date: { $first: '$Date' },
107
+ ticketId: { $first: '$ticketId' },
108
+ issueType: { $first: '$issueType' },
109
+ installationStatus: { $first: '$installationStatus' },
110
+ issueStatus: { $first: '$issueStatus' },
111
+ ticketType: { $first: '$ticketType' },
112
+ infraIssue: { $last: '$infraIssue' },
113
+ },
114
+ },
115
+ );
95
116
 
96
117
  if ( req.body.searchValue && req.body.searchValue !== '' ) {
97
118
  query.push( {
@@ -204,6 +225,7 @@ export async function basicDetails( req, res ) {
204
225
 
205
226
  export async function workHistory( req, res ) {
206
227
  try {
228
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
207
229
  let query = [ {
208
230
  $match: {
209
231
  $and: [
@@ -214,14 +236,14 @@ export async function workHistory( req, res ) {
214
236
  },
215
237
  } ];
216
238
 
217
- if ( req.body.dateFilter&&req.body.dateFilter !='' ) {
239
+ if ( req.body.dateFilter && req.body.dateFilter != '' ) {
218
240
  if ( req.body.dateFilter === 'issueIdentifiedDate' ) {
219
241
  query.push(
220
242
  {
221
243
  $match: {
222
244
  $and: [
223
- { 'ticketDetails.issueIdentifiedDate': { $gte: new Date( req.body.fromDate ) } },
224
- { 'ticketDetails.issueIdentifiedDate': { $lte: new Date( req.body.toDate ) } },
245
+ { 'ticketDetails.issueIdentifiedDate': { $gte: date.start } },
246
+ { 'ticketDetails.issueIdentifiedDate': { $lte: date.end } },
225
247
  ],
226
248
 
227
249
  },
@@ -232,8 +254,8 @@ export async function workHistory( req, res ) {
232
254
  {
233
255
  $match: {
234
256
  $and: [
235
- { 'issueClosedDate': { $gte: new Date( req.body.fromDate ) } },
236
- { 'issueClosedDate': { $lte: new Date( req.body.toDate ) } },
257
+ { 'issueClosedDate': { $gte: date.start } },
258
+ { 'issueClosedDate': { $lte: date.end } },
237
259
  ],
238
260
 
239
261
  },
@@ -244,8 +266,8 @@ export async function workHistory( req, res ) {
244
266
  {
245
267
  $match: {
246
268
  $and: [
247
- { createdAt: { $gte: new Date( req.body.fromDate ) } },
248
- { createdAt: { $lte: new Date( req.body.toDate ) } },
269
+ { createdAt: { $gte: date.start } },
270
+ { createdAt: { $lte: date.end } },
249
271
  ],
250
272
 
251
273
  },
@@ -254,11 +276,12 @@ export async function workHistory( req, res ) {
254
276
  }
255
277
  }
256
278
 
257
- if ( req.body.storeFilter&&req.body.storeFilter.length>0 ) {
279
+ if ( req.body.storeFilter && req.body.storeFilter.length > 0 ) {
258
280
  query.push(
259
281
  {
260
282
  $match: {
261
- 'basicDetails.storeId': { $in: req.body.storeFilter } },
283
+ 'basicDetails.storeId': { $in: req.body.storeFilter },
284
+ },
262
285
  },
263
286
  );
264
287
  }
@@ -392,6 +415,7 @@ export async function storeInfraList( req, res ) {
392
415
  storeProfile: 1,
393
416
  status: 1,
394
417
  spocDetails: 1,
418
+ progress: 1,
395
419
  },
396
420
  },
397
421
  {
@@ -406,6 +430,7 @@ export async function storeInfraList( req, res ) {
406
430
  storeId: { $first: '$storeId' },
407
431
  storeName: { $first: '$storeName' },
408
432
  status: { $first: '$status' },
433
+ progress: { $first: '$progress' },
409
434
  city: { $first: '$storeProfile.city' },
410
435
  state: { $first: '$storeProfile.state' },
411
436
  country: { $first: '$storeProfile.country' },
@@ -414,6 +439,27 @@ export async function storeInfraList( req, res ) {
414
439
  },
415
440
  },
416
441
  ];
442
+
443
+ if ( req.body.groupName && req.body.groupName != '' ) {
444
+ let group = await findOneGroup(
445
+ { clientId: req.body.clientId, groupName: req.body.groupName },
446
+ { _id: 0, storeList: 1 },
447
+ );
448
+ if ( group ) {
449
+ query.push( {
450
+ $match: {
451
+ storeId: { $in: group.storeList },
452
+ },
453
+ } );
454
+ }
455
+ }
456
+ if ( req.body.completeness && req.body.completeness.length > 0 ) {
457
+ query.push( {
458
+ $match: {
459
+ progress: { $in: req.body.completeness },
460
+ },
461
+ } );
462
+ }
417
463
  if ( req.body.storeId && req.body.storeId.length > 0 ) {
418
464
  query.push( {
419
465
  $match: {
@@ -471,18 +517,32 @@ export async function storeInfraList( req, res ) {
471
517
  let infrastoreList = [];
472
518
  for ( let store of storesList ) {
473
519
  store.downTime = 'NA';
474
- let infracheck = await findOneTangoTicket( { 'basicDetails.storeId': store.storeId, 'issueDate': new Date() } );
475
- if ( infracheck ) {
476
- store.status = 'Infra Issue';
520
+ let installationcheck = await findOneTangoTicket( { 'basicDetails.storeId': store.storeId, 'issueType': 'installation', 'status': { $ne: 'closed' } } );
521
+ if ( installationcheck ) {
522
+ store.ticketId = installationcheck.ticketId;
523
+ store.status = installationcheck.ticketDetails.installationStatus;
477
524
  } else {
478
- if ( store.status == 'active' ) {
479
- store.status = 'Live';
480
- store.statusDetail = 'Connected';
525
+ let infracheck = await findOneTangoTicket( { 'basicDetails.storeId': store.storeId, 'issueType': 'infra', 'issueDate': new Date( dayjs().format( 'YYYY-MM-DD' ) ), 'status': { $ne: 'closed' } } );
526
+ if ( infracheck ) {
527
+ store.ticketId = infracheck.ticketId;
528
+ store.status = 'Infra Issue';
529
+ if ( infracheck.ticketActivity.length > 0 ) {
530
+ let issue = infracheck.ticketActivity.filter( ( a ) => a.actionType === 'issueUpdate' );
531
+ if ( issue.length > 0 && issue[0].reasons.length > 0 ) {
532
+ store.statusDetail = issue[0].reasons[0].primaryIssue;
533
+ }
534
+ }
481
535
  } else {
482
- store.statusDetail = 'Disconnected';
483
- store.status = 'Deactivated';
536
+ if ( store.status == 'active' ) {
537
+ store.status = 'Live';
538
+ store.statusDetail = 'Connected';
539
+ } else {
540
+ store.statusDetail = 'Disconnected';
541
+ store.status = 'Deactivated';
542
+ }
484
543
  }
485
544
  }
545
+
486
546
  infrastoreList.push( store );
487
547
  }
488
548
  if ( req.body.export ) {
@@ -1,13 +1,15 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler } from 'tango-app-api-middleware';
4
- import { validateDetails, validateTicket, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
- import { createTicket, updateStatus, createReason, PrimaryReasons, secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply, uploadAttachments } from '../controllers/infra.controllers.js';
4
+ import { validateDetails, bulkvalidateDetails, validateTicket, bulkvalidateTicket, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
+ import { createTicket, bulkcreateTicket, updateStatus, createReason, PrimaryReasons, secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply, uploadAttachments, updateInstallationTicket } from '../controllers/infra.controllers.js';
6
6
 
7
7
 
8
8
  export const infraRouter = express.Router();
9
9
 
10
10
  infraRouter.post( '/createTicket', validateDetails, validateTicket, createTicket );
11
+ infraRouter.post( '/bulkcreateTicket', bulkvalidateDetails, bulkvalidateTicket, bulkcreateTicket );
12
+
11
13
  infraRouter.post( '/updateStatus', isAllowedSessionHandler, ticketExists, updateStatus );
12
14
  infraRouter.post( '/createReason', createReason );
13
15
  infraRouter.get( '/PrimaryReasons', isAllowedSessionHandler, PrimaryReasons );
@@ -16,5 +18,6 @@ infraRouter.post( '/updateTicketIssue', isAllowedSessionHandler, ticketExists, i
16
18
  infraRouter.post( '/viewTicket', isAllowedSessionHandler, ticketExists, viewTicket );
17
19
  infraRouter.post( '/AlertTicketReply', isAllowedSessionHandler, ticketExists, AlertTicketReply );
18
20
  infraRouter.put( '/uploadAttachments/:ticketId', isAllowedSessionHandler, ticketExists, uploadAttachments );
21
+ infraRouter.post( '/updateInstallationTicket', isAllowedSessionHandler, ticketExists, updateInstallationTicket );
19
22
 
20
23
 
@@ -0,0 +1,13 @@
1
+ import groupModel from 'tango-api-schema/schema/group.model.js';
2
+
3
+ export async function updateOneGroup( query, record ) {
4
+ return await groupModel.updateOne( query, { $set: record }, { upsert: true } );
5
+ };
6
+
7
+ export async function aggregateGroup( query ) {
8
+ return await groupModel.aggregate( query );
9
+ };
10
+
11
+ export async function findOneGroup( query ={}, field={} ) {
12
+ return await groupModel.findOne( query, field );
13
+ };
@@ -9,7 +9,7 @@ export async function validateDetails( req, res, next ) {
9
9
  try {
10
10
  let store = await findOneStore( { storeId: req.body.storeId } );
11
11
  if ( !store ) {
12
- return res.sendError( 'StoreID Not Available' );
12
+ return res.sendError( 'Store Not Available' );
13
13
  }
14
14
  let client = await findOneClient( { clientId: store.clientId } );
15
15
  if ( !client ) {
@@ -51,7 +51,7 @@ export async function validateTicket( req, res, next ) {
51
51
  },
52
52
  );
53
53
  if ( Ticket ) {
54
- return res.sendSuccess( 'Ticket Already Exists for the day' );
54
+ return res.sendSuccess( 'Infra Ticket Already Exists for the day' );
55
55
  }
56
56
  } else if ( req.body.issueType == 'installation' ) {
57
57
  let Ticket = await findOneTangoTicket(
@@ -61,7 +61,85 @@ export async function validateTicket( req, res, next ) {
61
61
  },
62
62
  );
63
63
  if ( Ticket ) {
64
- return res.sendSuccess( 'Ticket Already Exists' );
64
+ return res.sendSuccess( 'Insatallation Ticket Already Exists' );
65
+ }
66
+ }
67
+ next();
68
+ } catch ( error ) {
69
+ logger.error( { error: error, function: 'validateTicket' } );
70
+ return res.sendError( error, 500 );
71
+ }
72
+ };
73
+
74
+
75
+ export async function bulkvalidateDetails( req, res, next ) {
76
+ try {
77
+ req.body.error = [];
78
+ req.body.validatedStore = [];
79
+ for ( let data of req.body ) {
80
+ let store = await findOneStore( { storeId: data.storeId } );
81
+ if ( !store ) {
82
+ req.body.error.push( `Store Not Available ${data.storeId}` );
83
+ }
84
+ let client = await findOneClient( { clientId: store.clientId } );
85
+ if ( !client ) {
86
+ req.body.error.push( `Store Not Available ${store.clientId}` );
87
+ }
88
+ data.basicDetails = {
89
+ storeId: data.storeId,
90
+ storeName: store.storeName,
91
+ address: store.storeProfile && store.storeProfile.address ? store.storeProfile.address : '',
92
+ clientId: store.clientId,
93
+ clientName: client.clientName,
94
+ };
95
+
96
+ if ( data.issueType == 'infra' ) {
97
+ data.ticketDetails = {
98
+ ticketRefreshTime: dayjs().add( client.ticketConfigs.refreshAlert, 'days' ),
99
+ };
100
+ } else if ( data.issueType == 'installation' ) {
101
+ data.ticketDetails = {
102
+ ticketRefreshTime: dayjs().add( client.ticketConfigs.installationReAssign, 'days' ),
103
+ };
104
+ }
105
+ req.body.validatedStore.push( data );
106
+ }
107
+
108
+ next();
109
+ } catch ( error ) {
110
+ logger.error( { error: error, function: 'validateDetails' } );
111
+ return res.sendError( error, 500 );
112
+ }
113
+ };
114
+ export async function bulkvalidateTicket( req, res, next ) {
115
+ try {
116
+ req.body.filteredstore = [];
117
+ for ( let data of req.body.validatedStore ) {
118
+ if ( data.issueType == 'infra' ) {
119
+ let Ticket = await findOneTangoTicket(
120
+ {
121
+ 'basicDetails.storeId': data.basicDetails.storeId,
122
+ 'issueType': 'infra',
123
+ 'issueDate': new Date( data.Date ),
124
+ },
125
+ );
126
+ if ( Ticket ) {
127
+ req.body.error.push( `Infra Ticket Already Exists for the day ${data.basicDetails.storeId}` );
128
+ } else {
129
+ req.body.filteredstore.push( data );
130
+ }
131
+ } else if ( data.issueType == 'installation' ) {
132
+ let Ticket = await findOneTangoTicket(
133
+ {
134
+ 'basicDetails.storeId': data.basicDetails.storeId,
135
+ 'issueType': data.issueType,
136
+ },
137
+ );
138
+ if ( Ticket ) {
139
+ req.body.error.push( `Insatallation Ticket Already Exists ${data.basicDetails.storeId}` );
140
+ } else {
141
+ req.body.filteredstore.push( data );
142
+ }
65
143
  }
66
144
  }
67
145
  next();
@@ -81,7 +159,9 @@ export async function ticketExists( req, res, next ) {
81
159
  if ( !Ticket ) {
82
160
  return res.sendError( 'Ticket Not Found', 204 );
83
161
  }
162
+ req.body.issueType = Ticket.issueType;
84
163
  req.body.basicDetails = Ticket.basicDetails;
164
+ req.body.ticketDetails = Ticket.ticketDetails;
85
165
  req.body.ticketActivity = Ticket.ticketActivity;
86
166
  next();
87
167
  } catch ( error ) {
@@ -89,7 +169,6 @@ export async function ticketExists( req, res, next ) {
89
169
  return res.sendError( error, 500 );
90
170
  }
91
171
  };
92
-
93
172
  export async function infraReasonExists( req, res, next ) {
94
173
  try {
95
174
  let primaryReason = await findOneinfraReason( { name: req.body.primary } );
@@ -178,13 +257,15 @@ export async function InfraAlert( req, res, next ) {
178
257
  } );
179
258
  await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'hibernation': new Date( req.body.hibernationDays ) } );
180
259
  } else {
181
- let client = await findOneClient( { clientId: req.body.basicDetails.clientId }, { ticketConfigs: 1 } );
182
- let statusCheckAlertTime = dayjs().add( client.ticketConfigs.statusCheckAlert, 'hours' ).format( 'YYYY-MM-DD hh:mm' );
183
- req.body.ticketActivity.push( {
184
- actionType: 'statusCheck',
185
- actionBy: 'Tango',
186
- statusCheckAlertTime: statusCheckAlertTime,
187
- } );
260
+ 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
+ } );
268
+ }
188
269
  }
189
270
 
190
271
  next();