tango-app-api-infra 3.0.14 → 3.0.16

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.14",
3
+ "version": "3.0.16",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "handlebars": "^4.7.8",
21
21
  "mongodb": "^6.4.0",
22
22
  "nodemon": "^3.1.0",
23
- "tango-api-schema": "^2.0.39",
23
+ "tango-api-schema": "^2.0.44",
24
24
  "tango-app-api-middleware": "^1.0.21",
25
25
  "winston": "^3.12.0",
26
26
  "winston-daily-rotate-file": "^5.0.0"
@@ -1,9 +1,9 @@
1
1
 
2
- import { countDocumentsStore, findStorewithpagination } from '../services/store.service.js';
3
- import { logger } from 'tango-app-api-middleware';
2
+ import { aggregateStore, countDocumentsStore } from '../services/store.service.js';
3
+ import { logger, download } from 'tango-app-api-middleware';
4
4
  import { aggregateTangoTicket } from '../services/tangoTicket.service.js';
5
5
  import { findinfraReason } from '../services/infraReason.service.js';
6
- import { findClientwithpagination } from '../services/client.service.js';
6
+ import { aggregateClient } from '../services/client.service.js';
7
7
  import dayjs from 'dayjs';
8
8
  import { getOpenSearchData } from 'tango-app-api-middleware';
9
9
 
@@ -26,7 +26,7 @@ export async function infraCard( req, res ) {
26
26
  $project: {
27
27
  storeId: '$basicDetails.storeId',
28
28
  identifiedcount: {
29
- $cond: [ { $eq: [ '$infraTicketDetails.issueStatus', 'identified' ] }, 1, 0 ],
29
+ $cond: [ { $eq: [ '$ticketDetails.issueStatus', 'identified' ] }, 1, 0 ],
30
30
  },
31
31
  },
32
32
  },
@@ -51,7 +51,7 @@ export async function infraCard( req, res ) {
51
51
  { issueType: 'infra' },
52
52
  { 'status': { $ne: 'closed' } },
53
53
  { 'basicDetails.clientId': { $in: req.body.clientId } },
54
- { 'infraTicketDetails.issueStatus': 'identified' },
54
+ { 'ticketDetails.issueStatus': 'identified' },
55
55
  { createdAt: { $gte: new Date( req.body.fromDate ) } },
56
56
  { createdAt: { $lte: new Date( req.body.toDate ) } },
57
57
  ],
@@ -60,10 +60,11 @@ export async function infraCard( req, res ) {
60
60
  {
61
61
  $project: {
62
62
  ticketId: 1,
63
- issueStatus: '$infraTicketDetails.issueStatus',
63
+ issueStatus: '$ticketDetails.issueStatus',
64
+ issueIdentifiedBy: '$ticketDetails.issueIdentifiedBy',
64
65
  primaryIssue: {
65
66
  $filter: {
66
- input: '$infraActivity',
67
+ input: '$ticketActivity',
67
68
  as: 'item',
68
69
  cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
69
70
  },
@@ -85,10 +86,20 @@ export async function infraCard( req, res ) {
85
86
  ticketId: 1,
86
87
  issueStatus: 1,
87
88
  ticketType: 1,
89
+ issueIdentifiedBy: 1,
88
90
  primaryIssue: '$primaryIssue.reasons.primaryIssue',
89
91
  },
90
92
  },
91
93
  ];
94
+ if ( req.body.filter && req.body.filter.length > 0 ) {
95
+ query.push(
96
+ {
97
+ $match: {
98
+ issueIdentifiedBy: { $in: req.body.filter },
99
+ },
100
+ },
101
+ );
102
+ }
92
103
  let ticketList = await aggregateTangoTicket( query );
93
104
  let issueList = await findinfraReason( { parentId: { '$exists': false } } );
94
105
  const categoryCounts = {};
@@ -125,7 +136,104 @@ export async function infraCard( req, res ) {
125
136
  return res.sendError( error, 500 );
126
137
  }
127
138
  }
139
+ export async function installationCard( req, res ) {
140
+ try {
141
+ let onboardedCount = await countDocumentsStore( { clientId: { $in: req.body.clientId } } );
142
+ let installedCount = await countDocumentsStore( { 'clientId': { $in: req.body.clientId }, 'edge.deployed': true } );
128
143
 
144
+ let yettoInstallCount = await aggregateTangoTicket( [
145
+ {
146
+ $match: {
147
+ $and: [
148
+ { issueType: 'installation' },
149
+ { 'status': { $ne: 'closed' } },
150
+ { 'ticketDetails.issueStatus': 'notidentified' },
151
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
152
+ { createdAt: { $gte: new Date( req.body.fromDate ) } },
153
+ ],
154
+ },
155
+ },
156
+ ] );
157
+ let query = [ {
158
+ $match: {
159
+ $and: [
160
+ { issueType: 'installation' },
161
+ { 'status': { $ne: 'closed' } },
162
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
163
+ { 'ticketDetails.issueStatus': 'identified' },
164
+ { createdAt: { $gte: new Date( req.body.fromDate ) } },
165
+ ],
166
+ },
167
+ },
168
+ {
169
+ $project: {
170
+ ticketId: 1,
171
+ issueStatus: '$ticketDetails.issueStatus',
172
+ issueIdentifiedBy: '$ticketDetails.issueIdentifiedBy',
173
+ primaryIssue: {
174
+ $filter: {
175
+ input: '$ticketActivity',
176
+ as: 'item',
177
+ cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
178
+ },
179
+ },
180
+ },
181
+ },
182
+ {
183
+ $unwind: {
184
+ path: '$primaryIssue', preserveNullAndEmptyArrays: true,
185
+ },
186
+ },
187
+ {
188
+ $unwind: {
189
+ path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
190
+ },
191
+ },
192
+ {
193
+ $project: {
194
+ ticketId: 1,
195
+ issueStatus: 1,
196
+ ticketType: 1,
197
+ issueIdentifiedBy: 1,
198
+ primaryIssue: '$primaryIssue.reasons.primaryIssue',
199
+ },
200
+ },
201
+ ];
202
+ let installFailedCount = await aggregateTangoTicket( query );
203
+ let issueList = await findinfraReason( { parentId: { '$exists': false } } );
204
+ const categoryCounts = {};
205
+ let response;
206
+ if ( installFailedCount.length > 0 ) {
207
+ installFailedCount.forEach( ( item ) => {
208
+ const categoryName = item.primaryIssue;
209
+ if ( categoryCounts[categoryName] ) {
210
+ categoryCounts[categoryName]++;
211
+ } else {
212
+ categoryCounts[categoryName] = 1;
213
+ }
214
+ } );
215
+ response = issueList.map( ( category ) => ( {
216
+ name: category.name,
217
+ count: categoryCounts[category.name] || 0,
218
+ } ) );
219
+ } else {
220
+ response = issueList.map( ( category ) => ( {
221
+ name: category.name,
222
+ count: 0,
223
+ } ) );
224
+ }
225
+ res.sendSuccess( {
226
+ onboardedStoresCount: onboardedCount,
227
+ installedStoresCount: installedCount,
228
+ yettoInstallCount: yettoInstallCount.length,
229
+ installFailedCount: installFailedCount.length,
230
+ infraIssues: response,
231
+ } );
232
+ } catch ( error ) {
233
+ logger.error( { error: error, function: 'infraCard' } );
234
+ return res.sendError( error, 500 );
235
+ }
236
+ }
129
237
  export async function infraIssuesTable( req, res ) {
130
238
  try {
131
239
  let query = [ {
@@ -134,7 +242,7 @@ export async function infraIssuesTable( req, res ) {
134
242
  { issueType: 'infra' },
135
243
  { status: { $ne: 'closed' } },
136
244
  { 'basicDetails.clientId': { $in: req.body.clientId } },
137
- { 'infraTicketDetails.issueStatus': 'identified' },
245
+ { 'ticketDetails.issueStatus': 'identified' },
138
246
  { createdAt: { $gte: new Date( req.body.fromDate ) } },
139
247
  { createdAt: { $lte: new Date( req.body.toDate ) } },
140
248
  ],
@@ -146,11 +254,11 @@ export async function infraIssuesTable( req, res ) {
146
254
  storeName: '$basicDetails.storeName',
147
255
  status: 1,
148
256
  createdAt: { $dateToString: { format: '%d-%m-%Y', date: '$createdAt' } },
149
- issueIdentifiedDate: { $dateToString: { format: '%d-%m-%Y', date: '$infraTicketDetails.issueIdentifiedDate' } },
257
+ issueIdentifiedDate: { $dateToString: { format: '%d-%m-%Y', date: '$ticketDetails.issueIdentifiedDate' } },
150
258
  issueClosedDate: { $dateToString: { format: '%d-%m-%Y', date: '$issueClosedDate' } },
151
259
  primaryIssue: {
152
260
  $filter: {
153
- input: '$infraActivity',
261
+ input: '$ticketActivity',
154
262
  as: 'item',
155
263
  cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
156
264
  },
@@ -187,6 +295,7 @@ export async function infraIssuesTable( req, res ) {
187
295
  {
188
296
  $group: {
189
297
  _id: '$storeId',
298
+ storeId: { $first: '$storeId' },
190
299
  storeName: { $first: '$storeName' },
191
300
  createdAt: { $first: '$createdAt' },
192
301
  issueIdentifiedDate: { $first: '$issueIdentifiedDate' },
@@ -197,14 +306,14 @@ export async function infraIssuesTable( req, res ) {
197
306
  },
198
307
  },
199
308
  ];
200
- if ( req.body.filterIssue && req.body.filterIssue !== '' ) {
309
+ if ( req.body.filterIssue && req.body.filterIssue != '' ) {
201
310
  query.push( {
202
311
  $match: {
203
312
  primaryIssue: req.body.filterIssue,
204
313
  },
205
314
  } );
206
315
  }
207
- if ( req.body.searchValue && req.body.searchValue !== '' ) {
316
+ if ( req.body.searchValue && req.body.searchValue != '' ) {
208
317
  query.push( {
209
318
  $match: {
210
319
  $or: [
@@ -227,7 +336,7 @@ export async function infraIssuesTable( req, res ) {
227
336
  );
228
337
  }
229
338
  let result = await aggregateTangoTicket( query );
230
- if ( req.body.export ) {
339
+ if ( req.body.export && result.length > 0 ) {
231
340
  const exportdata = [];
232
341
  result.forEach( ( element ) => {
233
342
  exportdata.push( {
@@ -278,7 +387,7 @@ export async function InstallationIssuesTable( req, res ) {
278
387
  clientName: '$basicDetails.clientName',
279
388
  storeId: '$basicDetails.storeId',
280
389
  storeName: '$basicDetails.storeName',
281
- status: '$basicDetails.status',
390
+ status: 1,
282
391
  },
283
392
  },
284
393
  ];
@@ -336,13 +445,47 @@ export async function InstallationIssuesTable( req, res ) {
336
445
  export async function hourWiseDownClients( req, res ) {
337
446
  try {
338
447
  let inputData = req.body;
339
- let skip = 0;
340
- let limit = 10;
448
+
449
+ let query = [
450
+ {
451
+ $match: {
452
+ clientId: { $in: req.body.clientId },
453
+ },
454
+ },
455
+ {
456
+ $project: {
457
+ clientId: 1,
458
+ clientName: 1,
459
+ },
460
+ },
461
+ ];
462
+
463
+
464
+ if ( req.body.searchValue && req.body.searchValue !== '' ) {
465
+ query.push( {
466
+ $match: {
467
+ $or: [
468
+ { clientName: { $regex: req.body.searchValue, $options: 'i' } },
469
+ ],
470
+ },
471
+ } );
472
+ }
473
+ if ( req.body.sortColumName && req.body.sortColumName != '' && req.body.sortBy && req.body.sortBy != '' ) {
474
+ query.push( {
475
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
476
+ } );
477
+ }
478
+ let count = await aggregateClient( query );
341
479
  if ( req.body.limit && req.body.offset && !req.body.export ) {
342
- skip = ( req.body.offset - 1 ) * req.body.limit,
343
- limit = Number( req.body.limit );
480
+ query.push(
481
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
482
+ { $limit: Number( req.body.limit ) },
483
+ );
484
+ }
485
+ let clientlist = await aggregateClient( query );
486
+ if ( clientlist.length == 0 ) {
487
+ return res.sendError( 'no data', 204 );
344
488
  }
345
- let clientlist = await findClientwithpagination( { clientId: { $in: req.body.clientId } }, { clientId: 1, clientName: 1 }, skip, limit );
346
489
  let data = {};
347
490
  let result = [];
348
491
  for ( const client of clientlist ) {
@@ -351,7 +494,7 @@ export async function hourWiseDownClients( req, res ) {
351
494
  let clientdata = await livecountCheck( data, inputData );
352
495
  result.push( clientdata[0] );
353
496
  }
354
- res.sendSuccess( { result: result } );
497
+ res.sendSuccess( { count: count.length, result: result } );
355
498
  } catch ( error ) {
356
499
  logger.error( { error: error, function: 'hourWiseDownClients' } );
357
500
  return res.sendError( error, 500 );
@@ -399,7 +542,7 @@ export async function livecountCheck( data, inputData ) {
399
542
  timewise.push( obj );
400
543
  }
401
544
  const mergedData = {
402
- brandName: data.brandName,
545
+ clientName: data.clientName,
403
546
  };
404
547
  timewise.forEach( ( obj ) => {
405
548
  for ( const key in obj ) {
@@ -447,13 +590,47 @@ export async function hourWiseDownstores( req, res ) {
447
590
  try {
448
591
  let inputData = req.body;
449
592
  inputData.Date = dayjs().format( 'YYYY-MM-DD' );
450
- let skip = 0;
451
- let limit = 10;
593
+
594
+ let query = [ {
595
+ $match: {
596
+ clientId: req.body.clientId,
597
+ },
598
+ },
599
+ {
600
+ $project: {
601
+ storeId: 1,
602
+ storeName: 1,
603
+ storeProfile: 1,
604
+ },
605
+ },
606
+
607
+ ];
608
+ if ( req.body.searchValue && req.body.searchValue !== '' ) {
609
+ query.push( {
610
+ $match: {
611
+ $or: [
612
+ { storeName: { $regex: req.body.searchValue, $options: 'i' } },
613
+ { storeId: { $regex: req.body.searchValue, $options: 'i' } },
614
+ ],
615
+ },
616
+ } );
617
+ }
618
+ if ( req.body.sortColumName && req.body.sortColumName != '' && req.body.sortBy && req.body.sortBy != '' ) {
619
+ query.push( {
620
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
621
+ } );
622
+ }
623
+ let count = await aggregateStore( query );
452
624
  if ( req.body.limit && req.body.offset && !req.body.export ) {
453
- skip = ( req.body.offset - 1 ) * req.body.limit,
454
- limit = Number( req.body.limit );
625
+ query.push(
626
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
627
+ { $limit: Number( req.body.limit ) },
628
+ );
629
+ }
630
+ let storeslist = await aggregateStore( query );
631
+ if ( storeslist.length == 0 ) {
632
+ return res.sendError( 'no data', 204 );
455
633
  }
456
- let storeslist = await findStorewithpagination( { clientId: req.body.clientId }, { storeId: 1, storeName: 1, storeProfile: 1 }, skip, limit );
457
634
  let data = {};
458
635
  let result = [];
459
636
  for ( const store of storeslist ) {
@@ -462,7 +639,7 @@ export async function hourWiseDownstores( req, res ) {
462
639
  let storedata = await downStoresCheck( data, inputData );
463
640
  result.push( storedata[0] );
464
641
  }
465
- res.sendSuccess( { result: result } );
642
+ res.sendSuccess( { count: count.length, result: result } );
466
643
  } catch ( error ) {
467
644
  logger.error( { error: error, function: 'hourWiseDownstores' } );
468
645
  return res.sendError( error, 500 );
@@ -2,18 +2,23 @@
2
2
 
3
3
  import { createTangoTicket, findOneTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
4
4
  import { createinfraReason, findinfraReason } from '../services/infraReason.service.js';
5
- import { logger } from 'tango-app-api-middleware';
5
+ import { updateOneStore } from '../services/store.service.js';
6
+ import { logger, fileUpload } from 'tango-app-api-middleware';
7
+ import dayjs from 'dayjs';
6
8
  export async function createTicket( req, res ) {
7
9
  try {
8
10
  req.body.issueDate = new Date( req.body.Date );
9
- req.body.infraTicketDetails.filesCount = req.body.filesCount;
11
+ req.body.ticketDetails.filesCount = req.body.filesCount;
10
12
  if ( req.body.issueType == 'infra' ) {
11
13
  req.body.ticketId = 'TE_INF_' + new Date().valueOf();
12
- req.body.infraActivity = [ {
14
+ req.body.ticketActivity = [ {
13
15
  actionType: 'defaultInfra',
14
16
  actionBy: 'Tango',
15
17
  } ];
16
18
  }
19
+ if ( req.body.issueType == 'installation' ) {
20
+ req.body.ticketId = 'TE_INS_' + new Date().valueOf();
21
+ }
17
22
  let create = await createTangoTicket( req.body );
18
23
  if ( create ) {
19
24
  res.sendSuccess( 'Ticket Created Successfully' );
@@ -27,7 +32,7 @@ export async function createTicket( req, res ) {
27
32
  export async function updateStatus( req, res ) {
28
33
  try {
29
34
  if ( req.body.status == 'inprogress' ) {
30
- req.body.infraActivity.push( {
35
+ req.body.ticketActivity.push( {
31
36
  actionType: 'statusChange',
32
37
  actionBy: 'User',
33
38
  } );
@@ -91,7 +96,7 @@ export async function secondaryReason( req, res ) {
91
96
 
92
97
  export async function updateTicketIssue( req, res ) {
93
98
  try {
94
- let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'infraActivity': req.body.infraActivity, 'infraTicketDetails.issueIdentifiedDate': new Date(), 'infraTicketDetails.issueIdentifiedBy': req.body.issueIdentifiedBy, 'infraTicketDetails.issueStatus': 'identified' } );
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' } );
95
100
  if ( updateTicket ) {
96
101
  res.sendSuccess( 'Ticket Updated Successfully' );
97
102
  }
@@ -103,7 +108,7 @@ export async function updateTicketIssue( req, res ) {
103
108
 
104
109
  export async function viewTicket( req, res ) {
105
110
  try {
106
- let ticket = await findOneTangoTicket( { ticketId: req.body.ticketId }, { ticketId: 1, status: 1, infraActivity: 1 } );
111
+ let ticket = await findOneTangoTicket( { ticketId: req.body.ticketId }, { ticketId: 1, status: 1, ticketActivity: 1 } );
107
112
  if ( ticket ) {
108
113
  res.sendSuccess( ticket );
109
114
  }
@@ -114,15 +119,37 @@ export async function viewTicket( req, res ) {
114
119
  }
115
120
  export async function AlertTicketReply( req, res ) {
116
121
  try {
117
- req.body.infraActivity = req.body.infraActivity.filter( ( data ) => data.action !='statusCheck' );
118
- req.body.infraActivity.push( {
122
+ req.body.ticketActivity = req.body.ticketActivity.filter( ( data ) => data.action !='statusCheck' );
123
+ req.body.ticketActivity.push( {
119
124
  actionType: 'statusCheckReply',
120
125
  actionBy: 'Tango',
121
126
  statusCheckReply: req.body.statusCheckReply,
122
127
  hibernationDays: req.body.hibernationDays,
123
128
  } );
129
+ await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketActivity': req.body.ticketActivity } );
130
+ if ( req.body.hibernationDays ) {
131
+ req.body.hibernationDays = dayjs().add( req.body.hibernationDays, 'days' ).format( 'YYYY-MM-DD' );
132
+ await updateOneStore( { storeId: req.body.basicDetails.storeId }, { 'ticketConfigs.hibernation': new Date( req.body.hibernationDays ) } );
133
+ }
134
+ res.sendSuccess( 'Updated Successfully' );
124
135
  } catch ( error ) {
125
136
  logger.error( { error: error, function: 'AlertTicketReply' } );
126
137
  return res.sendError( error, 500 );
127
138
  }
128
139
  }
140
+ export async function uploadAttachments( req, res ) {
141
+ try {
142
+ let params ={
143
+ Bucket: 'tango-brand-info-uat',
144
+ key: req.params.ticketId,
145
+ fileName: req.files[0].name,
146
+
147
+
148
+ };
149
+ let response =await fileUpload( params );
150
+ res.sendSuccess( response );
151
+ } catch ( error ) {
152
+ logger.error( { error: error, function: 'uploadAttachments' } );
153
+ return res.sendError( error, 500 );
154
+ }
155
+ }
@@ -1,6 +1,11 @@
1
1
 
2
2
  import { logger } from 'tango-app-api-middleware';
3
3
  import dayjs from 'dayjs';
4
+ import utc from 'dayjs/plugin/utc.js';
5
+ import timezone from 'dayjs/plugin/timezone.js';
6
+ import 'dayjs/locale/en.js';
7
+ dayjs.extend( utc );
8
+ dayjs.extend( timezone );
4
9
  import { createClient, findClient } from '../services/client.service.js';
5
10
  import { createStore, findStore, updateOneStore } from '../services/store.service.js';
6
11
  import { findTangoTicket, findOneTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
@@ -98,8 +103,7 @@ export async function setTicketTime( req, res ) {
98
103
 
99
104
  export async function downStoresList( req, res ) {
100
105
  try {
101
- let getCurrentHour = dayjs().startOf( 'hour' ).format( 'YYYY-MM-DDTHH:mm' );
102
- let storesList = await findStore( { 'ticketConfigs.nextTicektGenerationTime': new Date( getCurrentHour ) }, { storeId: 1, storeName: 1, storeProfile: 1, ticketConfigs: 1 } );
106
+ let storesList = await findStore( { 'ticketConfigs.hibernation': { $lt: new Date() }, 'ticketConfigs.nextTicektGenerationTime': new Date( req.body.getTime ) }, { storeId: 1, storeName: 1, storeProfile: 1, ticketConfigs: 1 } );
103
107
  if ( storesList.length > 0 ) {
104
108
  res.sendSuccess( storesList );
105
109
  } else {
@@ -112,7 +116,7 @@ export async function downStoresList( req, res ) {
112
116
  }
113
117
  export async function openTicketList( req, res ) {
114
118
  try {
115
- let openTicketList = await findTangoTicket( { status: { $ne: 'closed' } }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, infraTicketDetails: 1 } );
119
+ let openTicketList = await findTangoTicket( { status: { $ne: 'closed' } }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
116
120
  if ( openTicketList.length ) {
117
121
  res.sendSuccess( {
118
122
  count: openTicketList.length,
@@ -129,7 +133,7 @@ export async function openTicketList( req, res ) {
129
133
 
130
134
  export async function assigntoUser( req, res ) {
131
135
  try {
132
- await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'infraTicketDetails.assigntoUser': true } );
136
+ await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketDetails.assigntoUser': true } );
133
137
  res.sendSuccess( 'assigntoUser Successfully' );
134
138
  } catch ( error ) {
135
139
  logger.error( { error: error, function: 'assigntoUser' } );
@@ -138,7 +142,7 @@ export async function assigntoUser( req, res ) {
138
142
  }
139
143
  export async function updateRefreshTicket( req, res ) {
140
144
  try {
141
- await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'infraTicketDetails.ticketType': 'refreshticket' } );
145
+ await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketDetails.ticketType': 'refreshticket' } );
142
146
  res.sendSuccess( 'updated Successfully' );
143
147
  } catch ( error ) {
144
148
  logger.error( { error: error, function: 'updateRefreshTicket' } );
@@ -150,7 +154,7 @@ export async function closeTicket( req, res ) {
150
154
  for ( let ticket of req.body.TicketList ) {
151
155
  let getTicket = await findOneTangoTicket( { ticketId: ticket.ticketId } );
152
156
  if ( ticket.status == 'closed' ) {
153
- getTicket.infraActivity.push( {
157
+ getTicket.ticketActivity.push( {
154
158
  actionType: 'dataRecived',
155
159
  actionBy: 'Tango',
156
160
  } );
@@ -158,7 +162,7 @@ export async function closeTicket( req, res ) {
158
162
  await updateOneTangoTicket( { ticketId: ticket.ticketId },
159
163
  {
160
164
  status: ticket.status,
161
- infraActivity: getTicket.infraActivity,
165
+ ticketActivity: getTicket.ticketActivity,
162
166
  issueClosedDate: new Date(),
163
167
  },
164
168
  );
@@ -18,11 +18,11 @@ export async function storeTicketList( req, res ) {
18
18
  Date: { $dateToString: { format: '%d-%m-%Y', date: '$issueDate' } },
19
19
  issueClosedDate: 1,
20
20
  ticketId: 1,
21
- issueStatus: '$infraTicketDetails.issueStatus',
22
- ticketType: '$infraTicketDetails.ticketType',
21
+ issueStatus: '$ticketDetails.issueStatus',
22
+ ticketType: '$ticketDetails.ticketType',
23
23
  primaryIssue: {
24
24
  $filter: {
25
- input: '$infraActivity',
25
+ input: '$ticketActivity',
26
26
  as: 'item',
27
27
  cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
28
28
  },
@@ -73,16 +73,16 @@ export async function storeTicketcard( req, res ) {
73
73
  let query = [ {
74
74
  $match: {
75
75
  'basicDetails.storeId': req.body.storeId,
76
- 'infraTicketDetails.issueStatus': 'identified',
76
+ 'ticketDetails.issueStatus': 'identified',
77
77
  },
78
78
  },
79
79
  {
80
80
  $project: {
81
81
  ticketId: 1,
82
- issueStatus: '$infraTicketDetails.issueStatus',
82
+ issueStatus: '$ticketDetails.issueStatus',
83
83
  primaryIssue: {
84
84
  $filter: {
85
- input: '$infraActivity',
85
+ input: '$ticketActivity',
86
86
  as: 'item',
87
87
  cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
88
88
  },
@@ -8,9 +8,14 @@ import mongoose from 'mongoose';
8
8
 
9
9
  export async function userTakeTicket( req, res ) {
10
10
  try {
11
- let userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'infraTicketDetails.assigntoUser': true, 'infraTicketDetails.addressingUser': { $exists: false } } );
11
+ let userTicket = '';
12
+ if ( req.body.issueType == 'infra' ) {
13
+ userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'issueType': 'infra', 'ticketDetails.assigntoUser': true, 'ticketDetails.addressingUser': { $exists: false } } );
14
+ } else if ( req.body.issueType == 'installation' ) {
15
+ userTicket = await findOneTangoTicket( { 'status': { $ne: 'closed' }, 'issueType': 'installation', 'ticketDetails.addressingUser': { $exists: false } } );
16
+ }
12
17
  if ( userTicket ) {
13
- let assignTicket = await updateOneTangoTicket( { ticketId: userTicket.ticketId }, { 'infraTicketDetails.addressingUser': req.body.userId } );
18
+ let assignTicket = await updateOneTangoTicket( { ticketId: userTicket.ticketId }, { 'ticketDetails.addressingUser': req.body.userId } );
14
19
  if ( assignTicket ) {
15
20
  res.sendSuccess( 'Ticket Assigned Successfully' );
16
21
  }
@@ -28,7 +33,8 @@ export async function userTicketList( req, res ) {
28
33
  $match: {
29
34
  $and: [
30
35
  { 'status': req.body.status },
31
- { 'infraTicketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
36
+ { issueType: req.body.issueType },
37
+ { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
32
38
  ],
33
39
  },
34
40
  } ];
@@ -58,11 +64,11 @@ export async function userTicketList( req, res ) {
58
64
  storeId: '$basicDetails.storeId',
59
65
  Date: { $dateToString: { format: '%d-%m-%Y', date: '$issueDate' } },
60
66
  ticketId: 1,
61
- issueStatus: '$infraTicketDetails.issueStatus',
62
- ticketType: '$infraTicketDetails.ticketType',
67
+ issueStatus: '$ticketDetails.issueStatus',
68
+ ticketType: '$ticketDetails.ticketType',
63
69
  primaryIssue: {
64
70
  $filter: {
65
- input: '$infraActivity',
71
+ input: '$ticketActivity',
66
72
  as: 'item',
67
73
  cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
68
74
  },
@@ -109,8 +115,8 @@ export async function basicDetails( req, res ) {
109
115
  if ( !user ) {
110
116
  return res.sendError( 'User Not Found', 500 );
111
117
  }
112
- let infraCount = await countDocumentsTangoTicket( { 'infraTicketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ), 'issueType': 'infra' } );
113
- let installationCount = await countDocumentsTangoTicket( { 'infraTicketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ), 'issueType': 'installation' } );
118
+ let infraCount = await countDocumentsTangoTicket( { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ), 'issueType': 'infra' } );
119
+ let installationCount = await countDocumentsTangoTicket( { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ), 'issueType': 'installation' } );
114
120
  res.sendSuccess( {
115
121
  userName: user.userName,
116
122
  userType: user.userType,
@@ -133,7 +139,8 @@ export async function workHistory( req, res ) {
133
139
  $match: {
134
140
  $and: [
135
141
  { 'status': 'closed' },
136
- { 'infraTicketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
142
+ { issueType: req.body.issueType },
143
+ { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
137
144
  { createdAt: { $gte: new Date( req.body.fromDate ) } },
138
145
  { createdAt: { $lte: new Date( req.body.toDate ) } },
139
146
  ],
@@ -147,13 +154,13 @@ export async function workHistory( req, res ) {
147
154
  clientName: '$basicDetails.clientName',
148
155
  issueDate: { $dateToString: { format: '%d-%m-%Y', date: '$issueDate' } },
149
156
  issueClosedDate: { $dateToString: { format: '%d-%m-%Y', date: '$issueClosedDate' } },
150
- issueIdentifiedDate: { $dateToString: { format: '%d-%m-%Y', date: '$infraTicketDetails.issueIdentifiedDate' } },
157
+ issueIdentifiedDate: { $dateToString: { format: '%d-%m-%Y', date: '$ticketDetails.issueIdentifiedDate' } },
151
158
  ticketId: 1,
152
- issueStatus: '$infraTicketDetails.issueStatus',
153
- ticketType: '$infraTicketDetails.ticketType',
159
+ issueStatus: '$ticketDetails.issueStatus',
160
+ ticketType: '$ticketDetails.ticketType',
154
161
  primaryIssue: {
155
162
  $filter: {
156
- input: '$infraActivity',
163
+ input: '$ticketActivity',
157
164
  as: 'item',
158
165
  cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
159
166
  },
@@ -283,7 +290,13 @@ export async function storeInfraList( req, res ) {
283
290
  },
284
291
  },
285
292
  ];
286
-
293
+ if ( req.body.storeId && req.body.storeId.length>0 ) {
294
+ query.push( {
295
+ $match: {
296
+ storeId: { $in: req.body.storeId },
297
+ },
298
+ } );
299
+ }
287
300
  if ( req.body.searchValue && req.body.searchValue !== '' ) {
288
301
  query.push( {
289
302
  $match: {
@@ -1,13 +1,14 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler } from 'tango-app-api-middleware';
4
- import { infraCard, InstallationIssuesTable, infraIssuesTable, hourWiseDownClients, hourWiseDownstores } from '../controllers/clientInfra.controller.js';
4
+ import { infraCard, installationCard, InstallationIssuesTable, infraIssuesTable, hourWiseDownClients, hourWiseDownstores } from '../controllers/clientInfra.controller.js';
5
5
 
6
6
  export const clientInfraRouter = express.Router();
7
7
 
8
8
 
9
9
  clientInfraRouter.post( '/infraCard', isAllowedSessionHandler, infraCard );
10
10
  clientInfraRouter.post( '/infraIssuesTable', isAllowedSessionHandler, infraIssuesTable );
11
+ clientInfraRouter.post( '/installationCard', isAllowedSessionHandler, installationCard );
11
12
  clientInfraRouter.post( '/InstallationIssuesTable', isAllowedSessionHandler, InstallationIssuesTable );
12
13
  clientInfraRouter.post( '/hourWiseDownClients', isAllowedSessionHandler, hourWiseDownClients );
13
14
  clientInfraRouter.post( '/hourWiseDownstores', isAllowedSessionHandler, hourWiseDownstores );
@@ -2,7 +2,7 @@
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler } from 'tango-app-api-middleware';
4
4
  import { validateDetails, validateTicket, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
- import { createTicket, updateStatus, createReason, PrimaryReasons, secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply } from '../controllers/infra.controllers.js';
5
+ import { createTicket, updateStatus, createReason, PrimaryReasons, secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply, uploadAttachments } from '../controllers/infra.controllers.js';
6
6
 
7
7
 
8
8
  export const infraRouter = express.Router();
@@ -15,5 +15,6 @@ infraRouter.post( '/secondaryReason', isAllowedSessionHandler, secondaryReason )
15
15
  infraRouter.post( '/updateTicketIssue', isAllowedSessionHandler, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert, updateTicketIssue );
16
16
  infraRouter.post( '/viewTicket', isAllowedSessionHandler, ticketExists, viewTicket );
17
17
  infraRouter.post( '/AlertTicketReply', isAllowedSessionHandler, ticketExists, AlertTicketReply );
18
+ infraRouter.put( '/uploadAttachments/:ticketId', isAllowedSessionHandler, ticketExists, uploadAttachments );
18
19
 
19
20
 
@@ -13,3 +13,6 @@ export async function findOneClient( query, project ) {
13
13
  export async function findClientwithpagination( query, project ) {
14
14
  return await dataModel.clientModel.find( query, project );
15
15
  }
16
+ export async function aggregateClient( query ) {
17
+ return await dataModel.clientModel.aggregate( query );
18
+ }
@@ -21,9 +21,16 @@ export async function validateDetails( req, res, next ) {
21
21
  clientId: store.clientId,
22
22
  clientName: client.clientName,
23
23
  };
24
- req.body.infraTicketDetails = {
25
- ticketRefreshTime: dayjs().add( client.ticketConfigs.refreshAlert, 'days' ),
26
- };
24
+
25
+ if ( req.body.issueType == 'infra' ) {
26
+ req.body.ticketDetails = {
27
+ ticketRefreshTime: dayjs().add( client.ticketConfigs.refreshAlert, 'days' ),
28
+ };
29
+ } else if ( req.body.issueType == 'installation' ) {
30
+ req.body.ticketDetails = {
31
+ ticketRefreshTime: dayjs().add( client.ticketConfigs.installationReAssign, 'days' ),
32
+ };
33
+ }
27
34
 
28
35
  next();
29
36
  } catch ( error ) {
@@ -38,12 +45,23 @@ export async function validateTicket( req, res, next ) {
38
45
  let Ticket = await findOneTangoTicket(
39
46
  {
40
47
  'basicDetails.storeId': req.body.basicDetails.storeId,
48
+ 'issueType': 'infra',
41
49
  'issueDate': new Date( req.body.Date ),
42
50
  },
43
51
  );
44
52
  if ( Ticket ) {
45
53
  return res.sendSuccess( 'Ticket Already Exists for the day' );
46
54
  }
55
+ } else if ( req.body.issueType == 'installation' ) {
56
+ let Ticket = await findOneTangoTicket(
57
+ {
58
+ 'basicDetails.storeId': req.body.basicDetails.storeId,
59
+ 'issueType': req.body.issueType,
60
+ },
61
+ );
62
+ if ( Ticket ) {
63
+ return res.sendSuccess( 'Ticket Already Exists' );
64
+ }
47
65
  }
48
66
  next();
49
67
  } catch ( error ) {
@@ -53,16 +71,17 @@ export async function validateTicket( req, res, next ) {
53
71
  };
54
72
  export async function ticketExists( req, res, next ) {
55
73
  try {
74
+ let ticketId = req.body.ticketId?req.body.ticketId:req.params.ticketId;
56
75
  let Ticket = await findOneTangoTicket(
57
76
  {
58
- ticketId: req.body.ticketId,
77
+ ticketId: ticketId,
59
78
  },
60
79
  );
61
80
  if ( !Ticket ) {
62
81
  return res.sendError( 'Ticket Not Found', 204 );
63
82
  }
64
83
  req.body.basicDetails = Ticket.basicDetails;
65
- req.body.infraActivity = Ticket.infraActivity;
84
+ req.body.ticketActivity = Ticket.ticketActivity;
66
85
  next();
67
86
  } catch ( error ) {
68
87
  logger.error( { error: error, function: 'ticketExists' } );
@@ -97,7 +116,7 @@ export async function infraReasonExists( req, res, next ) {
97
116
  secondaryIsssue: [ ...resolveSteps ],
98
117
  } );
99
118
  }
100
- req.body.infraActivity.push( {
119
+ req.body.ticketActivity.push( {
101
120
  actionType: 'issueUpdate',
102
121
  actionBy: 'User',
103
122
  comment: req.body.comment,
@@ -127,7 +146,7 @@ export async function InfrastepstoResolve( req, res, next ) {
127
146
  } );
128
147
  }
129
148
 
130
- req.body.infraActivity.push( {
149
+ req.body.ticketActivity.push( {
131
150
  actionType: 'stepsToResolve',
132
151
  actionBy: 'Tango',
133
152
  reasons: steptoReslove.map( ( item ) => ( {
@@ -150,7 +169,7 @@ export async function InfraAlert( req, res, next ) {
150
169
  if ( req.body.hibernationDays ) {
151
170
  req.body.hibernationDays = dayjs().add( req.body.hibernationDays, 'days' ).format( 'YYYY-MM-DD' );
152
171
  await updateOneStore( { storeId: req.body.basicDetails.storeId }, { 'ticketConfigs.hibernation': new Date( req.body.hibernationDays ) } );
153
- req.body.infraActivity.push( {
172
+ req.body.ticketActivity.push( {
154
173
  actionType: 'statusCheckReply',
155
174
  actionBy: 'Tango',
156
175
  hibernationDays: req.body.hibernationDays,
@@ -159,7 +178,7 @@ export async function InfraAlert( req, res, next ) {
159
178
  } else {
160
179
  let client = await findOneClient( { clientId: req.body.basicDetails.clientId }, { ticketConfigs: 1 } );
161
180
  let statusCheckAlertTime = dayjs().add( client.ticketConfigs.statusCheckAlert, 'hours' ).format( 'YYYY-MM-DD hh:mm' );
162
- req.body.infraActivity.push( {
181
+ req.body.ticketActivity.push( {
163
182
  actionType: 'statusCheck',
164
183
  actionBy: 'Tango',
165
184
  statusCheckAlertTime: statusCheckAlertTime,