tango-app-api-infra 3.0.54-dev → 3.0.56-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.54-dev",
3
+ "version": "3.0.56-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "mongodb": "^6.4.0",
26
26
  "nodemon": "^3.1.0",
27
27
  "tango-api-schema": "^2.0.90",
28
- "tango-app-api-middleware": "^3.1.3",
28
+ "tango-app-api-middleware": "^1.0.60-dev",
29
29
  "winston": "^3.12.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
31
31
  },
@@ -211,10 +211,10 @@ export async function installationCard( req, res ) {
211
211
  $group: {
212
212
  _id: '$ticketId',
213
213
  ticketId: { $first: '$ticketId' },
214
- issueStatus: { $first: '$issueStatus' },
215
- ticketType: { $first: '$ticketType' },
216
- issueIdentifiedBy: { $first: '$issueIdentifiedBy' },
217
- primaryIssue: { $first: '$primaryIssue' },
214
+ issueStatus: { $last: '$issueStatus' },
215
+ ticketType: { $last: '$ticketType' },
216
+ issueIdentifiedBy: { $last: '$issueIdentifiedBy' },
217
+ primaryIssue: { $last: '$primaryIssue' },
218
218
  },
219
219
  },
220
220
  ];
@@ -461,8 +461,8 @@ export async function InstallationIssuesTable( req, res ) {
461
461
  storeId: { $first: '$storeId' },
462
462
  clientId: { $first: '$clientId' },
463
463
  storeName: { $first: '$storeName' },
464
- status: { $first: '$status' },
465
- primaryIssue: { $first: '$primaryIssue' },
464
+ status: { $last: '$status' },
465
+ primaryIssue: { $last: '$primaryIssue' },
466
466
  },
467
467
  },
468
468
  ];
@@ -1,9 +1,9 @@
1
1
 
2
2
 
3
- import { createTangoTicket, findOneTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
3
+ import { aggregateTangoTicket, createTangoTicket, findOneTangoTicket, updateOneTangoTicket, updateManyTangoTicket } from '../services/tangoTicket.service.js';
4
4
  import { createinfraReason, findinfraReason } from '../services/infraReason.service.js';
5
5
  import { updateOneStore, findStore } from '../services/store.service.js';
6
- import { logger, fileUpload, signedUrl, sendEmailWithSES, getOpenSearchData, appConfig } from 'tango-app-api-middleware';
6
+ import { logger, fileUpload, signedUrl, sendEmailWithSES, getOpenSearchData, appConfig, getUTC } from 'tango-app-api-middleware';
7
7
  import { aggregateUser, updateOneUser } from '../services/user.service.js';
8
8
  import { updateoneClient } from '../services/client.service.js';
9
9
  import dayjs from 'dayjs';
@@ -75,7 +75,7 @@ export async function createTicket( req, res ) {
75
75
  let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${req.body.basicDetails.storeId}`;
76
76
 
77
77
  const html = htmlContent( { ...req.body, Uidomain: Uidomain, domain: appConfig.url.apiDomain, date: dayjs( req.body.issueDate ).format( 'YYYY-MM-DD' ), downtimetotal: downtimetotal, Timestamp: Timestamp } );
78
- if ( req.body.emailAlert&&req.body.spocEmail&&req.body.issueType == 'infra'&&isValidEmail( req.body.spocEmail ) ) {
78
+ if ( req.body.emailAlert && req.body.spocEmail && req.body.issueType == 'infra' && isValidEmail( req.body.spocEmail ) ) {
79
79
  await sendEmailWithSES( req.body.spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
80
80
  }
81
81
  if ( create ) {
@@ -621,3 +621,359 @@ function inWords( num ) {
621
621
 
622
622
  return str.toLowerCase().split( ' ' ).map( ( word ) => word.charAt( 0 ).toUpperCase() + word.slice( 1 ) ).join( ' ' );
623
623
  }
624
+
625
+
626
+ export async function infraTable( req, res ) {
627
+ try {
628
+ let query = [];
629
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
630
+ if ( req.body.clientId && req.body.clientId.length > 0 ) {
631
+ query.push( {
632
+ $match: {
633
+ 'basicDetails.clientId': { $in: req.body.clientId },
634
+ },
635
+ } );
636
+ }
637
+ query.push( {
638
+ $match: {
639
+ $and: [
640
+ { issueType: 'infra' },
641
+ { createdAt: { $gte: date.start } },
642
+ { createdAt: { $lte: date.end } },
643
+ ],
644
+ },
645
+ }, {
646
+ $project: {
647
+ storeId: '$basicDetails.storeId',
648
+ clientId: '$basicDetails.clientId',
649
+ ticketId: 1,
650
+ storeName: '$basicDetails.storeName',
651
+ clientName: '$basicDetails.clientName',
652
+ status: 1,
653
+ createdAt: 1,
654
+ issueDate: 1,
655
+ primaryIssue: {
656
+ $filter: {
657
+ input: '$ticketActivity',
658
+ as: 'item',
659
+ cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
660
+ },
661
+ },
662
+ },
663
+ },
664
+ {
665
+ $unwind: {
666
+ path: '$primaryIssue', preserveNullAndEmptyArrays: true,
667
+ },
668
+ },
669
+ {
670
+ $unwind: {
671
+ path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
672
+ },
673
+ },
674
+ {
675
+ $unwind: {
676
+ path: '$primaryIssue.reasons.secondaryIssue', preserveNullAndEmptyArrays: true,
677
+ },
678
+ },
679
+ {
680
+ $project: {
681
+ storeId: 1,
682
+ clientId: 1,
683
+ storeName: 1,
684
+ clientName: 1,
685
+ createdAt: 1,
686
+ ticketId: 1,
687
+ issueDate: { $ifNull: [ '$issueDate', '' ] },
688
+ status: 1,
689
+ primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
690
+ secondaryIssue: { $ifNull: [ '$primaryIssue.reasons.secondaryIssue.name', '-' ] },
691
+ },
692
+ },
693
+ {
694
+ $group: {
695
+ _id: '$ticketId',
696
+ storeId: { $first: '$storeId' },
697
+ clientId: { $first: '$clientId' },
698
+ ticketId: { $first: '$ticketId' },
699
+ storeName: { $first: '$storeName' },
700
+ clientName: { $first: '$clientName' },
701
+ createdAt: { $first: '$createdAt' },
702
+ issueDate: { $last: '$issueDate' },
703
+ status: { $last: '$status' },
704
+ primaryIssue: { $last: '$primaryIssue' },
705
+ secondaryIssue: { $last: '$secondaryIssue' },
706
+ },
707
+ } );
708
+ if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
709
+ query.push( {
710
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
711
+ } );
712
+ }
713
+ if ( req.body.storeIdFilter && req.body.storeIdFilter.length>0 ) {
714
+ query.push( {
715
+ $match: {
716
+ storeId: { $in: req.body.storeIdFilter },
717
+ },
718
+ } );
719
+ }
720
+ let ticketList = await aggregateTangoTicket( query );
721
+ let issueList = await findinfraReason( { parentId: { '$exists': false } } );
722
+ const categoryCounts = {};
723
+ let response;
724
+ if ( ticketList.length > 0 ) {
725
+ ticketList.forEach( ( item ) => {
726
+ const categoryName = item.primaryIssue;
727
+ if ( categoryCounts[categoryName] ) {
728
+ categoryCounts[categoryName]++;
729
+ } else {
730
+ categoryCounts[categoryName] = 1;
731
+ }
732
+ } );
733
+ response = issueList.map( ( category ) => ( {
734
+ name: category.name,
735
+ count: categoryCounts[category.name] || 0,
736
+ } ) );
737
+ } else {
738
+ response = issueList.map( ( category ) => ( {
739
+ name: category.name,
740
+ count: 0,
741
+ } ) );
742
+ }
743
+ response.push( {
744
+ 'name': 'total',
745
+ 'count': ticketList.length,
746
+
747
+ } );
748
+ if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'total' ) {
749
+ query.push( {
750
+ $match: {
751
+ primaryIssue: req.body.filterIssue,
752
+ },
753
+ } );
754
+ }
755
+
756
+ if ( req.body.searchValue && req.body.searchValue != '' ) {
757
+ query.push( {
758
+ $match: {
759
+ $or: [
760
+ { storeId: { $regex: req.body.searchValue, $options: 'i' } },
761
+ { storeName: { $regex: req.body.searchValue, $options: 'i' } },
762
+ ],
763
+ },
764
+ } );
765
+ }
766
+ let count = await aggregateTangoTicket( query );
767
+
768
+ if ( req.body.limit && req.body.offset && !req.body.export ) {
769
+ query.push(
770
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
771
+ { $limit: Number( req.body.limit ) },
772
+ );
773
+ }
774
+ let result = await aggregateTangoTicket( query );
775
+ if ( req.body.export && result.length > 0 ) {
776
+ const exportdata = [];
777
+ result.forEach( ( element ) => {
778
+ exportdata.push( {
779
+
780
+ } );
781
+ } );
782
+ await download( exportdata, res );
783
+ return;
784
+ }
785
+ if ( result.length > 0 ) {
786
+ res.sendSuccess( {
787
+ response: response,
788
+ count: count.length,
789
+ result: result,
790
+ } );
791
+ } else {
792
+ res.sendError( 'no data', 204 );
793
+ }
794
+ } catch ( error ) {
795
+ logger.error( { error: error, function: 'infraTable' } );
796
+ return res.sendError( error, 500 );
797
+ }
798
+ }
799
+ export async function installationTable( req, res ) {
800
+ try {
801
+ let query = [];
802
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
803
+ if ( req.body.clientId && req.body.clientId.length > 0 ) {
804
+ query.push( {
805
+ $match: {
806
+ 'basicDetails.clientId': { $in: req.body.clientId },
807
+ },
808
+ } );
809
+ }
810
+
811
+ query.push( {
812
+ $match: {
813
+ $and: [
814
+ { issueType: 'installation' },
815
+ { createdAt: { $gte: date.start } },
816
+ { createdAt: { $lte: date.end } },
817
+ ],
818
+ },
819
+ }, {
820
+ $project: {
821
+ storeId: '$basicDetails.storeId',
822
+ clientId: '$basicDetails.clientId',
823
+ ticketId: 1,
824
+ storeName: '$basicDetails.storeName',
825
+ clientName: '$basicDetails.clientName',
826
+ status: 1,
827
+ createdAt: 1,
828
+ installationStatus: '$ticketDetails.installationStatus',
829
+ issueDate: 1,
830
+ primaryIssue: {
831
+ $filter: {
832
+ input: '$ticketActivity',
833
+ as: 'item',
834
+ cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
835
+ },
836
+ },
837
+ },
838
+ },
839
+ {
840
+ $unwind: {
841
+ path: '$primaryIssue', preserveNullAndEmptyArrays: true,
842
+ },
843
+ },
844
+ {
845
+ $unwind: {
846
+ path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
847
+ },
848
+ },
849
+ {
850
+ $unwind: {
851
+ path: '$primaryIssue.reasons.secondaryIssue', preserveNullAndEmptyArrays: true,
852
+ },
853
+ },
854
+ {
855
+ $project: {
856
+ storeId: 1,
857
+ clientId: 1,
858
+ storeName: 1,
859
+ clientName: 1,
860
+ createdAt: 1,
861
+ ticketId: 1,
862
+ installationStatus: 1,
863
+ issueDate: { $ifNull: [ '$issueDate', '' ] },
864
+ status: 1,
865
+ primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
866
+ secondaryIssue: { $ifNull: [ '$primaryIssue.reasons.secondaryIssue.name', '-' ] },
867
+ },
868
+ },
869
+ {
870
+ $group: {
871
+ _id: '$ticketId',
872
+ storeId: { $first: '$storeId' },
873
+ clientId: { $first: '$clientId' },
874
+ ticketId: { $first: '$ticketId' },
875
+ storeName: { $first: '$storeName' },
876
+ clientName: { $first: '$clientName' },
877
+ createdAt: { $first: '$createdAt' },
878
+ issueDate: { $last: '$issueDate' },
879
+ installationStatus: { $last: '$installationStatus' },
880
+ status: { $last: '$status' },
881
+ primaryIssue: { $last: '$primaryIssue' },
882
+ secondaryIssue: { $last: '$secondaryIssue' },
883
+ },
884
+ } );
885
+ if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
886
+ query.push( {
887
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
888
+ } );
889
+ }
890
+ let ticketList = await aggregateTangoTicket( query );
891
+ let issueList = await findinfraReason( { parentId: { '$exists': false } } );
892
+ const categoryCounts = {};
893
+ let response;
894
+ if ( ticketList.length > 0 ) {
895
+ ticketList.forEach( ( item ) => {
896
+ const categoryName = item.primaryIssue;
897
+ if ( categoryCounts[categoryName] ) {
898
+ categoryCounts[categoryName]++;
899
+ } else {
900
+ categoryCounts[categoryName] = 1;
901
+ }
902
+ } );
903
+ response = issueList.map( ( category ) => ( {
904
+ name: category.name,
905
+ count: categoryCounts[category.name] || 0,
906
+ } ) );
907
+ } else {
908
+ response = issueList.map( ( category ) => ( {
909
+ name: category.name,
910
+ count: 0,
911
+ } ) );
912
+ }
913
+ response.push( {
914
+ 'name': 'total',
915
+ 'count': ticketList.length,
916
+
917
+ } );
918
+ if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'total' ) {
919
+ query.push( {
920
+ $match: {
921
+ primaryIssue: req.body.filterIssue,
922
+ },
923
+ } );
924
+ }
925
+ if ( req.body.searchValue && req.body.searchValue != '' ) {
926
+ query.push( {
927
+ $match: {
928
+ $or: [
929
+ { storeId: { $regex: req.body.searchValue, $options: 'i' } },
930
+ { storeName: { $regex: req.body.searchValue, $options: 'i' } },
931
+ ],
932
+ },
933
+ } );
934
+ }
935
+ let count = await aggregateTangoTicket( query );
936
+ console.log( count.length );
937
+ if ( req.body.limit && req.body.offset && !req.body.export ) {
938
+ query.push(
939
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
940
+ { $limit: Number( req.body.limit ) },
941
+ );
942
+ }
943
+ let result = await aggregateTangoTicket( query );
944
+
945
+ if ( req.body.export && result.length > 0 ) {
946
+ const exportdata = [];
947
+ result.forEach( ( element ) => {
948
+ exportdata.push( {
949
+
950
+ } );
951
+ } );
952
+ await download( exportdata, res );
953
+ return;
954
+ }
955
+ if ( result.length > 0 ) {
956
+ res.sendSuccess( {
957
+ response: response,
958
+ count: count.length,
959
+ result: result,
960
+ } );
961
+ } else {
962
+ res.sendError( 'no data', 204 );
963
+ }
964
+ } catch ( error ) {
965
+ logger.error( { error: error, function: 'installationTable' } );
966
+ return res.sendError( error, 500 );
967
+ }
968
+ }
969
+ export async function assignTicket( req, res ) {
970
+ try {
971
+ let tickets = await updateManyTangoTicket( { ticketId: { $in: req.body.tickets } }, { 'ticketDetails.assigntoUser': true, 'ticketDetails.addressingUser': req.body.user } );
972
+ if ( tickets ) {
973
+ res.sendSuccess( 'Ticket Assigned Successfully' );
974
+ }
975
+ } catch ( error ) {
976
+ logger.error( { error: error, function: 'assignTicket' } );
977
+ return res.sendError( error, 500 );
978
+ }
979
+ }
@@ -697,12 +697,14 @@ export async function camAngleChangeReport( req, res ) {
697
697
  content: buffer,
698
698
  contentType: 'application/xlsx', // e.g., 'application/pdf'
699
699
  };
700
- let subject ='Camera Angle Modified';
700
+ let subject =`Camera Angle Modified - ${formattedPreviousDay}`;
701
701
  let html = `<div>We wanted to inform you that the camera angle in your stores has been adjusted recently.</div>`;
702
702
  let result = await sendEmailWithSES( req.body.toMail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
703
703
  if ( result ) {
704
704
  res.sendSuccess( 'Email send successfully' );
705
705
  }
706
+ } else {
707
+ res.sendSuccess( 'No changes in camera Angle' );
706
708
  }
707
709
  } catch ( error ) {
708
710
  logger.error( { error: error, function: 'camAngleChangeList' } );
@@ -337,7 +337,7 @@ export async function edgeAppLogTable( req, res ) {
337
337
  const average = sum / streamwiseDowntime.length;
338
338
  obj.downtime = Math.round( average );
339
339
  } else {
340
- obj.downtime = 0;
340
+ obj.downtime ='';
341
341
  }
342
342
  let appStatusQuery = {
343
343
  'size': 1,
@@ -4,7 +4,7 @@ import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
4
4
  import { validateDetails, bulkvalidateDetails, validateTicket, bulkvalidateTicket, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
5
  import { createTicket, bulkcreateTicket, updateStatus, createReason, PrimaryReasons,
6
6
  secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply, uploadAttachments,
7
- updateInstallationTicket, emailUserList, saveInfraEmailConfig, invoice } from '../controllers/infra.controllers.js';
7
+ updateInstallationTicket, emailUserList, saveInfraEmailConfig, invoice, infraTable, assignTicket, installationTable } from '../controllers/infra.controllers.js';
8
8
 
9
9
 
10
10
  export const infraRouter = express.Router();
@@ -55,3 +55,15 @@ infraRouter.post( '/saveInfraEmailConfig', isAllowedSessionHandler, authorize( {
55
55
  { featureName: 'settings', name: 'configuration', permissions: [ 'isEdit', 'isView' ] } ],
56
56
  } ), saveInfraEmailConfig );
57
57
  infraRouter.post( '/invoice', invoice );
58
+ infraRouter.post( '/infraTable', isAllowedSessionHandler, authorize( {
59
+ userType: [ 'client', 'tango' ], access: [
60
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
61
+ } ), infraTable );
62
+ infraRouter.post( '/installationTable', isAllowedSessionHandler, authorize( {
63
+ userType: [ 'client', 'tango' ], access: [
64
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
65
+ } ), installationTable );
66
+ infraRouter.post( '/assignTicket', isAllowedSessionHandler, authorize( {
67
+ userType: [ 'client', 'tango' ], access: [
68
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isEdit', 'isView' ] } ],
69
+ } ), assignTicket );
@@ -13,6 +13,9 @@ export async function findOneTangoTicket( query, project ) {
13
13
  export async function updateOneTangoTicket( query, data ) {
14
14
  return await dataModel.tangoTicketModel.updateOne( query, { $set: data } );
15
15
  }
16
+ export async function updateManyTangoTicket( query, data ) {
17
+ return await dataModel.tangoTicketModel.updateMany( query, { $set: data } );
18
+ }
16
19
  export async function countDocumentsTangoTicket( query, data ) {
17
20
  return await dataModel.tangoTicketModel.countDocuments( query );
18
21
  }