tango-app-api-infra 3.0.58-dev → 3.0.60-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/index.js CHANGED
@@ -5,6 +5,10 @@ import { internalInfraRouter } from './src/routes/internalInfra.routes.js';
5
5
  import { userInfraRouter } from './src/routes/userInfra.routes.js';
6
6
  import { storeInfraRouter } from './src/routes/storeInfra.routes.js';
7
7
  import { clientInfraRouter } from './src/routes/clientInfra.routes.js';
8
- export { infraRouter, internalInfraRouter, userInfraRouter, storeInfraRouter, clientInfraRouter };
8
+ import { employeeTrainigRouter } from './src/routes/employeetrainig.routes.js';
9
+ import { dataMismatchRouter } from './src/routes/dataMismatch.routes.js';
10
+
11
+
12
+ export { infraRouter, internalInfraRouter, userInfraRouter, storeInfraRouter, dataMismatchRouter, clientInfraRouter, employeeTrainigRouter };
9
13
 
10
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-infra",
3
- "version": "3.0.58-dev",
3
+ "version": "3.0.60-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,8 +24,8 @@
24
24
  "html-pdf-node": "^1.0.8",
25
25
  "mongodb": "^6.4.0",
26
26
  "nodemon": "^3.1.0",
27
- "tango-api-schema": "^2.0.90",
28
- "tango-app-api-middleware": "^1.0.60-dev",
27
+ "tango-api-schema": "^2.0.94",
28
+ "tango-app-api-middleware": "^3.1.7",
29
29
  "winston": "^3.12.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
31
31
  },
@@ -10,7 +10,7 @@ import { getOpenSearchData } from 'tango-app-api-middleware';
10
10
  export async function infraCard( req, res ) {
11
11
  try {
12
12
  let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
13
- let storeCount = await countDocumentsStore( { clientId: { $in: req.body.clientId }, status: 'active' } );
13
+ let storeCount = await countDocumentsStore( { 'clientId': { $in: req.body.clientId }, 'edge.firstFile': true, 'status': 'active' } );
14
14
  let infraStoreCount = await aggregateTangoTicket( [
15
15
  {
16
16
  $match: {
@@ -46,13 +46,14 @@ export async function infraCard( req, res ) {
46
46
  },
47
47
  },
48
48
  ] );
49
+
49
50
  let query = [ {
50
51
  $match: {
51
52
  $and: [
52
53
  { issueType: 'infra' },
54
+ { status: { $ne: 'closed' } },
53
55
  { 'ticketDetails.issueStatus': 'identified' },
54
56
  { 'basicDetails.clientId': { $in: req.body.clientId } },
55
- { 'ticketDetails.issueStatus': 'identified' },
56
57
  { createdAt: { $gte: date.start } },
57
58
  { createdAt: { $lte: date.end } },
58
59
  ],
@@ -148,8 +149,13 @@ export async function infraCard( req, res ) {
148
149
  }
149
150
  export async function installationCard( req, res ) {
150
151
  try {
151
- let onboardedCount = await countDocumentsStore( { clientId: { $in: req.body.clientId } } );
152
- let installedCount = await countDocumentsStore( { 'clientId': { $in: req.body.clientId }, 'edge.firstFile': true } );
152
+ let onboardedCount = await countDocumentsStore( {
153
+ '$and': [
154
+ { 'clientId': { $in: req.body.clientId } },
155
+ ],
156
+ } );
157
+ let installedCount = await countDocumentsStore( { 'clientId': { $in: req.body.clientId },
158
+ 'edge.firstFile': true, 'status': 'active' } );
153
159
 
154
160
  let yettoInstallCount = await aggregateTangoTicket( [
155
161
  {
@@ -250,7 +256,7 @@ export async function installationCard( req, res ) {
250
256
  infraIssues: response,
251
257
  } );
252
258
  } catch ( error ) {
253
- logger.error( { error: error, function: 'infraCard' } );
259
+ logger.error( { error: error, function: 'installationCard' } );
254
260
  return res.sendError( error, 500 );
255
261
  }
256
262
  }
@@ -261,6 +267,7 @@ export async function infraIssuesTable( req, res ) {
261
267
  $match: {
262
268
  $and: [
263
269
  { issueType: 'infra' },
270
+ { status: { $ne: 'closed' } },
264
271
  { 'basicDetails.clientId': { $in: req.body.clientId } },
265
272
  { 'ticketDetails.issueStatus': 'identified' },
266
273
  { createdAt: { $gte: date.start } },
@@ -681,6 +688,7 @@ export async function hourWiseDownstores( req, res ) {
681
688
  let query = [ {
682
689
  $match: {
683
690
  clientId: req.body.clientId,
691
+ status: 'active',
684
692
  },
685
693
  },
686
694
  {
@@ -783,7 +791,7 @@ function downStoresCheck( data, inputData ) {
783
791
  const average = sum / streamwiseDowntime.length;
784
792
  obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
785
793
  } else {
786
- obj[obj.startTime + '-' + obj.endTime] = 0;
794
+ obj[obj.startTime + '-' + obj.endTime] = '';
787
795
  }
788
796
 
789
797
  timewise.push( obj );
@@ -0,0 +1,15 @@
1
+
2
+
3
+ export async function createTicket() {
4
+ try {
5
+ let ticketExist = await findOneTangoTicket( { 'issueType': req.body.issueType, 'basicDetails.storeId': req.body.storeId } );
6
+
7
+ if ( ticketExist ) {
8
+ return res.sendSuccess( 'MAT Ticket Already Exists for the store' );
9
+ }
10
+ console.log();
11
+ } catch ( error ) {
12
+ logger.error( { error: error, function: 'createTicket Data Mismatch' } );
13
+ return res.sendError( error, 500 );
14
+ }
15
+ }
@@ -0,0 +1,50 @@
1
+
2
+ import { createTangoTicket, findOneTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
3
+ import { logger } from 'tango-app-api-middleware';
4
+ export async function createTicket( req, res ) {
5
+ try {
6
+ let ticketExist = await findOneTangoTicket( { 'issueType': req.body.issueType, 'basicDetails.storeId': req.body.storeId } );
7
+ if ( ticketExist ) {
8
+ return res.sendSuccess( 'MAT Ticket Already Exists for the store' );
9
+ }
10
+
11
+ req.body.issueDate = new Date( req.body.Date );
12
+ req.body.ticketId = 'TE_MAT_' + new Date().valueOf();
13
+ let create = await createTangoTicket( req.body );
14
+ if ( create ) {
15
+ res.sendSuccess( 'Ticket Created Successfully' );
16
+ }
17
+ } catch ( error ) {
18
+ logger.error( { error: error, function: 'createTicket mat' } );
19
+ return res.sendError( error, 500 );
20
+ }
21
+ }
22
+
23
+ export async function updatecomment( req, res ) {
24
+ try {
25
+ if ( req.body.comment != '' ) {
26
+ req.body.ticketActivity.push( {
27
+ actionType: 'comment',
28
+ actionBy: 'Tango',
29
+ timeStamp: new Date(),
30
+ IdentifiedBy: req.user.userName,
31
+ comment: req.body.comment,
32
+ } );
33
+ }
34
+ let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, { ticketActivity: req.body.ticketActivity } );
35
+ if ( updateTicket ) {
36
+ res.sendSuccess( 'Ticket Updated Successfully' );
37
+ }
38
+ } catch ( error ) {
39
+ logger.error( { error: error, function: 'updatecomment mat' } );
40
+ return res.sendError( error, 500 );
41
+ }
42
+ }
43
+ export async function activityLog( req, res ) {
44
+ try {
45
+ res.sendSuccess( req.body );
46
+ } catch ( error ) {
47
+ logger.error( { error: error, function: 'activityLog mat' } );
48
+ return res.sendError( error, 500 );
49
+ }
50
+ }
@@ -642,7 +642,8 @@ export async function infraTable( req, res ) {
642
642
  { createdAt: { $lte: date.end } },
643
643
  ],
644
644
  },
645
- }, {
645
+ },
646
+ {
646
647
  $project: {
647
648
  storeId: '$basicDetails.storeId',
648
649
  clientId: '$basicDetails.clientId',
@@ -739,6 +740,11 @@ export async function infraTable( req, res ) {
739
740
  secondaryIssue: { $last: '$secondaryIssue' },
740
741
  },
741
742
  },
743
+ {
744
+ $sort: {
745
+ ticketId: -1,
746
+ },
747
+ },
742
748
  );
743
749
  if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
744
750
  query.push( {
@@ -841,15 +847,11 @@ export async function infraTable( req, res ) {
841
847
  await download( exportdata, res );
842
848
  return;
843
849
  }
844
- if ( result.length > 0 ) {
845
- res.sendSuccess( {
846
- response: response,
847
- count: count.length,
848
- result: result,
849
- } );
850
- } else {
851
- res.sendError( 'no data', 204 );
852
- }
850
+ res.sendSuccess( {
851
+ response: response,
852
+ count: count.length,
853
+ result: result,
854
+ } );
853
855
  } catch ( error ) {
854
856
  logger.error( { error: error, function: 'infraTable' } );
855
857
  return res.sendError( error, 500 );
@@ -976,6 +978,11 @@ export async function installationTable( req, res ) {
976
978
  secondaryIssue: { $last: '$secondaryIssue' },
977
979
  },
978
980
  },
981
+ {
982
+ $sort: {
983
+ ticketId: -1,
984
+ },
985
+ },
979
986
  );
980
987
  if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
981
988
  query.push( {
@@ -1077,9 +1084,170 @@ export async function installationTable( req, res ) {
1077
1084
  await download( exportdata, res );
1078
1085
  return;
1079
1086
  }
1087
+ res.sendSuccess( {
1088
+ response: response,
1089
+ count: count.length,
1090
+ result: result,
1091
+ } );
1092
+ } catch ( error ) {
1093
+ logger.error( { error: error, function: 'installationTable' } );
1094
+ return res.sendError( error, 500 );
1095
+ }
1096
+ }
1097
+ export async function matTable( req, res ) {
1098
+ try {
1099
+ let query = [];
1100
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
1101
+ if ( req.body.clientId && req.body.clientId.length > 0 ) {
1102
+ query.push( {
1103
+ $match: {
1104
+ 'basicDetails.clientId': { $in: req.body.clientId },
1105
+ },
1106
+ } );
1107
+ }
1108
+
1109
+ query.push( {
1110
+ $match: {
1111
+ $and: [
1112
+ { issueType: 'mat' },
1113
+ { createdAt: { $gte: date.start } },
1114
+ { createdAt: { $lte: date.end } },
1115
+ ],
1116
+ },
1117
+ },
1118
+ {
1119
+ $project: {
1120
+ storeId: '$basicDetails.storeId',
1121
+ clientId: '$basicDetails.clientId',
1122
+ ticketId: 1,
1123
+ storeName: '$basicDetails.storeName',
1124
+ clientName: '$basicDetails.clientName',
1125
+ status: 1,
1126
+ createdAt: 1,
1127
+ addressingUser: '$ticketDetails.addressingUser',
1128
+ issueDate: 1,
1129
+ },
1130
+ },
1131
+
1132
+ {
1133
+ '$lookup': {
1134
+ 'from': 'users',
1135
+ 'let': { 'userId': '$addressingUser' },
1136
+ 'pipeline': [
1137
+ {
1138
+ '$match': {
1139
+ '$expr': {
1140
+ '$eq': [ '$_id', '$$userId' ],
1141
+ },
1142
+ },
1143
+ },
1144
+ {
1145
+ '$project': {
1146
+ 'userName': 1,
1147
+ 'email': 1,
1148
+ 'role': 1,
1149
+ },
1150
+ },
1151
+ ],
1152
+ 'as': 'user',
1153
+ },
1154
+ },
1155
+
1156
+ {
1157
+ $unwind: {
1158
+ path: '$user',
1159
+ preserveNullAndEmptyArrays: true,
1160
+ },
1161
+ },
1162
+ {
1163
+ $group: {
1164
+ _id: '$ticketId',
1165
+ storeId: { $first: '$storeId' },
1166
+ clientId: { $first: '$clientId' },
1167
+ ticketId: { $first: '$ticketId' },
1168
+ storeName: { $first: '$storeName' },
1169
+ userName: { $first: { $ifNull: [ '$user.userName', '-' ] } },
1170
+ userEmail: { $first: { $ifNull: [ '$user.email', '-' ] } },
1171
+ clientName: { $first: '$clientName' },
1172
+ createdAt: { $first: '$createdAt' },
1173
+ issueDate: { $last: '$issueDate' },
1174
+ status: { $last: '$status' },
1175
+ },
1176
+ },
1177
+ );
1178
+ if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
1179
+ query.push( {
1180
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
1181
+ } );
1182
+ }
1183
+ if ( req.body.storeIdFilter && req.body.storeIdFilter.length > 0 ) {
1184
+ query.push( {
1185
+ $match: {
1186
+ storeId: { $in: req.body.storeIdFilter },
1187
+ },
1188
+ } );
1189
+ }
1190
+ if ( req.body.statusFilter && req.body.statusFilter.length > 0 ) {
1191
+ query.push( {
1192
+ $match: {
1193
+ status: { $in: req.body.statusFilter },
1194
+ },
1195
+ } );
1196
+ }
1197
+ if ( req.body.userFilter && req.body.userFilter.length > 0 ) {
1198
+ query.push( {
1199
+ $match: {
1200
+ userEmail: { $in: req.body.userFilter },
1201
+ },
1202
+ } );
1203
+ }
1204
+
1205
+ if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'total' ) {
1206
+ query.push( {
1207
+ $match: {
1208
+ primaryIssue: req.body.filterIssue,
1209
+ },
1210
+ } );
1211
+ }
1212
+ if ( req.body.searchValue && req.body.searchValue != '' ) {
1213
+ query.push( {
1214
+ $match: {
1215
+ $or: [
1216
+ { storeId: { $regex: req.body.searchValue, $options: 'i' } },
1217
+ { storeName: { $regex: req.body.searchValue, $options: 'i' } },
1218
+ ],
1219
+ },
1220
+ } );
1221
+ }
1222
+ let count = await aggregateTangoTicket( query );
1223
+ if ( req.body.limit && req.body.offset && !req.body.export ) {
1224
+ query.push(
1225
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
1226
+ { $limit: Number( req.body.limit ) },
1227
+ );
1228
+ }
1229
+ let result = await aggregateTangoTicket( query );
1230
+
1231
+ if ( req.body.export && result.length > 0 ) {
1232
+ const exportdata = [];
1233
+ result.forEach( ( element ) => {
1234
+ exportdata.push( {
1235
+ 'ticketId': element.ticketId,
1236
+ 'issueDate': dayjs( element.issueDate ).format( 'DD-MM-YYYY' ),
1237
+ 'storeId': element.storeId,
1238
+ 'storeName': element.storeName,
1239
+ 'clientId': element.clientId,
1240
+ 'clientName': element.clientName,
1241
+ 'userName': element.userName,
1242
+ 'userEmail': element.userEmail,
1243
+ 'Status': element.installationStatus,
1244
+ } );
1245
+ } );
1246
+ await download( exportdata, res );
1247
+ return;
1248
+ }
1080
1249
  if ( result.length > 0 ) {
1081
1250
  res.sendSuccess( {
1082
- response: response,
1083
1251
  count: count.length,
1084
1252
  result: result,
1085
1253
  } );
@@ -123,7 +123,7 @@ export async function downStoresList( req, res ) {
123
123
  }
124
124
  export async function openTicketList( req, res ) {
125
125
  try {
126
- let openTicketList = await findTangoTicket( { status: { $ne: 'closed' } }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
126
+ let openTicketList = await findTangoTicket( { 'issueType': 'infra', 'status': { $ne: 'closed' } }, { issueType: 1, ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
127
127
  if ( openTicketList.length ) {
128
128
  res.sendSuccess( {
129
129
  count: openTicketList.length,
@@ -446,11 +446,11 @@ export async function emailUserList( req, res ) {
446
446
  export async function infraReportSent( req, res ) {
447
447
  try {
448
448
  let date;
449
- if ( req.body.type == 'start' ) {
450
- date = dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
451
- } else if ( req.body.type == 'end' ) {
452
- date = dayjs().format( 'YYYY-MM-DD' );
453
- };
449
+ // if ( req.body.type == 'start' ) {
450
+ // date = dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
451
+ // } else if ( req.body.type == 'end' ) {
452
+ date = dayjs().format( 'YYYY-MM-DD' );
453
+ // };
454
454
  let query = [ {
455
455
  $match: {
456
456
  $and: [
@@ -527,18 +527,17 @@ export async function infraReportSent( req, res ) {
527
527
  exportdata.push( {
528
528
  'Client ID': element.basicDetails.clientId,
529
529
  'Client Name': element.basicDetails.clientName,
530
- 'Created Date & Time': dayjs( element.createdAt ).format( 'YYYY-MM-DD HH:mm A' ),
531
- 'Store ID': element.basicDetails.clientName,
532
- 'Store Name': element.basicDetails.clientName,
530
+ 'Ticket Created Date & Time': dayjs( element.createdAt ).format( 'YYYY-MM-DD HH:mm A' ),
531
+ 'Store ID': element.basicDetails.storeId,
532
+ 'Store Name': element.basicDetails.storeName,
533
533
  'Issue ': element.primaryIssue,
534
534
  'Secondary Issue': element.secondaryIssue,
535
- 'Issue Date & Time': dayjs( element.date ).format( 'YYYY-MM-DD' ),
536
535
  'Status ': element.status,
537
536
  'Responded By': clientuser && clientuser.userName ? clientuser.userName : '-',
538
537
  'Resolved By': tangouser && tangouser.userName ? tangouser.userName : '-',
539
- 'Closed Date & Time': element.issueClosedDate ? dayjs( element.issueClosedDate ).format( 'YYYY-MM-DD HH:mm A' ) : '-',
538
+ 'Ticket Closed Date & Time': element.issueClosedDate ? dayjs( element.issueClosedDate ).format( 'YYYY-MM-DD HH:mm A' ) : '-',
540
539
  'Latest Comment': '',
541
- 'Activity Log': '',
540
+ 'Activity Log': `${appConfig.url.domain+'/manage/stores/infra-ticket?storeId='+element.basicDetails.storeId}`,
542
541
  } );
543
542
  }
544
543
 
@@ -611,7 +610,6 @@ export async function infraReportSent( req, res ) {
611
610
  const result = await sendEmailWithSES( req.body.email, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
612
611
  res.sendSuccess( result );
613
612
  }
614
- res.sendSuccess( result );
615
613
  } catch ( error ) {
616
614
  logger.error( { error: error, function: 'infraReportSent' } );
617
615
  res.sendError( error, 500 );
@@ -71,6 +71,15 @@ export async function userTakeTicket( req, res ) {
71
71
  }
72
72
  userTicket = await findOneTangoTicket( query );
73
73
  }
74
+ } else if ( req.body.issueType == 'mat' ) {
75
+ let query = {
76
+ 'status': { $ne: 'closed' },
77
+ 'issueType': 'mat',
78
+ };
79
+ if ( assignedClients.length > 0 ) {
80
+ query =( { ...query, ...{ 'basicDetails.clientId': { $in: assignedClients } } } );
81
+ }
82
+ userTicket = await findOneTangoTicket( query );
74
83
  }
75
84
  if ( userTicket ) {
76
85
  let assignTicket = await updateOneTangoTicket( { ticketId: userTicket.ticketId }, { 'ticketDetails.addressingUser': req.body.userId } );
@@ -364,6 +373,7 @@ export async function workHistory( req, res ) {
364
373
  issueClosedDate: { $dateToString: { format: '%Y-%m-%d', date: '$issueClosedDate' } },
365
374
  issueIdentifiedDate: { $dateToString: { format: '%Y-%m-%d', date: '$ticketDetails.issueIdentifiedDate' } },
366
375
  ticketId: 1,
376
+ status: 1,
367
377
  issueStatus: '$ticketDetails.issueStatus',
368
378
  ticketType: '$ticketDetails.ticketType',
369
379
  primaryIssue: {
@@ -437,15 +447,15 @@ export async function workHistory( req, res ) {
437
447
  const exportdata = [];
438
448
  result.forEach( ( element ) => {
439
449
  exportdata.push( {
440
- 'CREATED ON': element.createdAt,
450
+ 'CREATED ON': dayjs( element.issueDate ).format( 'DD-MM-YYYY' ),
441
451
  'TICKET ID': element.ticketId,
442
452
  'STORE ID': element.storeId,
443
453
  'STORE NAME': element.storeName,
444
454
  'CLIENT ID': element.clientId,
445
455
  'CLIENT NAME': element.clientName,
446
- 'CREATED STATUS': element.status,
447
456
  'ISSUE IDENTIFIED DATE': element.issueIdentifiedDate,
448
457
  'CLOSED ON': element.issueClosedDate,
458
+ 'ISSUE': element.infraIssue?element.infraIssue:'-',
449
459
  'STATUS': element.status,
450
460
  } );
451
461
  } );
@@ -591,7 +601,7 @@ export async function storeInfraList( req, res ) {
591
601
  if ( installationcheck ) {
592
602
  store.ticketId = installationcheck.ticketId;
593
603
  store.status = installationcheck.ticketDetails.installationStatus;
594
- if ( store.status === 'onboareded' ) {
604
+ if ( store.status === 'onboarded' ) {
595
605
  store.statusDetail = 'Ready to pair';
596
606
  }
597
607
  if ( store.status === 'paired' ) {
@@ -0,0 +1,10 @@
1
+ import express from 'express';
2
+ import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
3
+ import { createTicket } from '../controllers/dataMismatch.controller.js';
4
+ import { validateDetails } from '../validations/infra.validation.js';
5
+ export const dataMismatchRouter = express.Router();
6
+
7
+ dataMismatchRouter.post( '/createTicket', isAllowedSessionHandler, authorize( {
8
+ userType: [ 'client', 'tango' ], access: [
9
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView', 'isEdit' ] } ],
10
+ } ), validateDetails, createTicket );
@@ -0,0 +1,17 @@
1
+ import { createTicket, updatecomment, activityLog } from '../controllers/employeeTraning.controller.js';
2
+ import { ticketExists, validateDetails } from '../validations/infra.validation.js';
3
+ import express from 'express';
4
+ import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
5
+ export const employeeTrainigRouter = express.Router();
6
+
7
+
8
+ employeeTrainigRouter.post( '/createTicket', validateDetails, createTicket );
9
+ employeeTrainigRouter.post( '/updatecomment', isAllowedSessionHandler, authorize( {
10
+ userType: [ 'tango' ], access: [
11
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isEdit' ] } ],
12
+ } ), ticketExists, updatecomment );
13
+
14
+ employeeTrainigRouter.post( '/activityLog', isAllowedSessionHandler, authorize( {
15
+ userType: [ 'tango' ], access: [
16
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
17
+ } ), ticketExists, activityLog );
@@ -1,8 +1,8 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
4
- import { validateDetails, bulkvalidateDetails, validateTicket, bulkvalidateTicket, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
- import { createTicket, bulkcreateTicket, updateStatus, createReason, PrimaryReasons,
4
+ import { validateDetails, bulkvalidateDetails, validateTicket, bulkvalidateTicket, validateTicketstatus, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
+ import { createTicket, bulkcreateTicket, updateStatus, createReason, PrimaryReasons, matTable,
6
6
  secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply, uploadAttachments,
7
7
  updateInstallationTicket, emailUserList, saveInfraEmailConfig, invoice, infraTable, storeFilter, assignTicket, installationTable } from '../controllers/infra.controllers.js';
8
8
 
@@ -29,7 +29,7 @@ infraRouter.post( '/secondaryReason', isAllowedSessionHandler, authorize( {
29
29
  infraRouter.post( '/updateTicketIssue', isAllowedSessionHandler, authorize( {
30
30
  userType: [ 'client', 'tango' ], access: [
31
31
  { featureName: 'manage', name: 'tickets', permissions: [ 'isEdit' ] } ],
32
- } ), ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert, updateTicketIssue );
32
+ } ), ticketExists, validateTicketstatus, infraReasonExists, InfrastepstoResolve, InfraAlert, updateTicketIssue );
33
33
  infraRouter.post( '/viewTicket', isAllowedSessionHandler, authorize( {
34
34
  userType: [ 'client', 'tango' ], access: [
35
35
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
@@ -63,6 +63,10 @@ infraRouter.post( '/installationTable', isAllowedSessionHandler, authorize( {
63
63
  userType: [ 'client', 'tango' ], access: [
64
64
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
65
65
  } ), installationTable );
66
+ infraRouter.post( '/matTable', isAllowedSessionHandler, authorize( {
67
+ userType: [ 'client', 'tango' ], access: [
68
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
69
+ } ), matTable );
66
70
  infraRouter.post( '/assignTicket', isAllowedSessionHandler, authorize( {
67
71
  userType: [ 'client', 'tango' ], access: [
68
72
  { featureName: 'manage', name: 'tickets', permissions: [ 'isEdit', 'isView' ] } ],
@@ -184,12 +184,47 @@ export async function ticketExists( req, res, next ) {
184
184
  req.body.basicDetails = Ticket.basicDetails;
185
185
  req.body.ticketDetails = Ticket.ticketDetails;
186
186
  req.body.ticketActivity = Ticket.ticketActivity;
187
+ req.body.status = Ticket.status;
188
+ req.body.issueDate = Ticket.issueDate;
189
+
190
+
187
191
  next();
188
192
  } catch ( error ) {
189
193
  logger.error( { error: error, function: 'ticketExists' } );
190
194
  return res.sendError( error, 500 );
191
195
  }
192
196
  };
197
+
198
+ export async function validateTicketstatus( req, res, next ) {
199
+ try {
200
+ if ( req.body.issueType == 'infra' ) {
201
+ if ( req.body.secondary.length>0 ) {
202
+ if ( req.body.status == 'closed' ) {
203
+ return res.sendSuccess( 'Ticket already closed' );
204
+ }
205
+ console.log( req.body.ticketDetails );
206
+
207
+ if ( req.body.ticketDetails.ticketType==='firsttimeticket'&&req.body.ticketDetails.issueStatus==='identified' ) {
208
+ return res.sendSuccess( 'Ticket already Addressed' );
209
+ }
210
+ } else {
211
+ if ( req.body.primary == 'Application Issues' ) {
212
+ if ( req.body.status == 'closed' ) {
213
+ return res.sendSuccess( 'Ticket already closed' );
214
+ }
215
+ if ( req.body.ticketDetails.ticketType==='firsttimeticket'&&req.body.ticketDetails.issueStatus==='identified' ) {
216
+ return res.sendSuccess( 'Ticket already Addressed' );
217
+ }
218
+ }
219
+ }
220
+ }
221
+ next();
222
+ } catch ( error ) {
223
+ logger.error( { error: error, function: 'validateTicket' } );
224
+ return res.sendError( error, 500 );
225
+ }
226
+ }
227
+
193
228
  export async function infraReasonExists( req, res, next ) {
194
229
  try {
195
230
  if ( req.body.primary && req.body.secondary && req.body.secondary.length ) {