tango-app-api-infra 3.0.63-dev → 3.0.65-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.
@@ -1,9 +1,9 @@
1
1
 
2
2
 
3
- import { aggregateTangoTicket, createTangoTicket, findOneTangoTicket, updateOneTangoTicket, updateManyTangoTicket, findTangoTicket } from '../services/tangoTicket.service.js';
3
+ import { aggregateTangoTicket, createTangoTicket, findOneTangoTicket, updateOneTangoTicket } 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, download, appConfig, getUTC } from 'tango-app-api-middleware';
6
+ import { logger, fileUpload, signedUrl, sendEmailWithSES, getOpenSearchData, appConfig } 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,9 +75,9 @@ 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 ) ) {
79
- await sendEmailWithSES( req.body.spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
80
- }
78
+ await sendEmailWithSES( req.body.spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
79
+
80
+
81
81
  if ( create ) {
82
82
  res.sendSuccess( 'Ticket Created Successfully' );
83
83
  }
@@ -86,10 +86,6 @@ export async function createTicket( req, res ) {
86
86
  return res.sendError( error, 500 );
87
87
  }
88
88
  }
89
- function isValidEmail( email ) {
90
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
91
- return emailRegex.test( email );
92
- }
93
89
  export async function bulkcreateTicket( req, res ) {
94
90
  try {
95
91
  let response = {};
@@ -125,7 +121,6 @@ export async function bulkcreateTicket( req, res ) {
125
121
 
126
122
  export async function updateStatus( req, res ) {
127
123
  try {
128
- console.log( req.user.userType );
129
124
  if ( req.user.userType == 'tango' ) {
130
125
  if ( req.body.status == 'inprogress' ) {
131
126
  req.body.ticketActivity.push( {
@@ -134,10 +129,8 @@ export async function updateStatus( req, res ) {
134
129
  actionBy: 'Tango',
135
130
  IdentifiedBy: req.user.userName,
136
131
  } );
137
- req.body.status ='inprogress';
138
132
  }
139
133
  req.body.ticketDetails.addressingUser = req.user._id;
140
- console.log( req.body );
141
134
  let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, req.body );
142
135
  if ( updateTicket ) {
143
136
  res.sendSuccess( 'Ticket Updated Successfully' );
@@ -150,7 +143,6 @@ export async function updateStatus( req, res ) {
150
143
  actionBy: 'User',
151
144
  IdentifiedBy: req.user.userName,
152
145
  } );
153
- req.body.status ='inprogress';
154
146
  }
155
147
  req.body.ticketDetails.addressingClient = req.user._id;
156
148
  let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, req.body );
@@ -292,7 +284,7 @@ export async function viewTicket( req, res ) {
292
284
  if ( ticket.attachments.hasOwnProperty( index ) ) {
293
285
  let file = ticket.attachments[index];
294
286
  let params = {
295
- Bucket: appConfig.cloud.aws.bucket.ticket,
287
+ Bucket: 'tango-client-sandbox',
296
288
  file_path: file.filePath,
297
289
  };
298
290
  let attachments = await signedUrl( params );
@@ -344,7 +336,7 @@ export async function uploadAttachments( req, res ) {
344
336
  for ( let singleImg in req.files.img ) {
345
337
  if ( req.files.img.hasOwnProperty( singleImg ) ) {
346
338
  let params = {
347
- Bucket: appConfig.cloud.aws.bucket.ticket,
339
+ Bucket: 'tango-client-sandbox',
348
340
  Key: req.params.ticketId + '/',
349
341
  ContentType: 'multipart/form-data',
350
342
  body: req.files.img[singleImg].data,
@@ -368,7 +360,7 @@ export async function uploadAttachments( req, res ) {
368
360
  let oldticket = await findOneTangoTicket( { ticketId: req.params.ticketId } );
369
361
  let attachments = oldticket.attachments;
370
362
  let params = {
371
- Bucket: appConfig.cloud.aws.bucket.ticket,
363
+ Bucket: 'tango-client-sandbox',
372
364
  Key: req.params.ticketId + '/',
373
365
  ContentType: 'multipart/form-data',
374
366
  body: req.files.img.data,
@@ -611,683 +603,112 @@ export async function invoice( req, res ) {
611
603
  } );
612
604
  }
613
605
 
614
-
615
- function inWords( num ) {
616
- let a = [ '', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ', 'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', 'nineteen ' ]; let b = [ '', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety' ];
617
- if ( ( num = num.toString() ).length > 9 ) return 'overflow';
618
- let n = ( '000000000' + num ).substr( -9 ).match( /^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/ );
619
- if ( !n ) return; let str = '';
620
- str += ( n[1] != 0 ) ? ( a[Number( n[1] )] || b[n[1][0]] + ' ' + a[n[1][1]] ) + 'crore ' : '';
621
- str += ( n[2] != 0 ) ? ( a[Number( n[2] )] || b[n[2][0]] + ' ' + a[n[2][1]] ) + 'lakh ' : '';
622
- str += ( n[3] != 0 ) ? ( a[Number( n[3] )] || b[n[3][0]] + ' ' + a[n[3][1]] ) + 'thousand ' : '';
623
- str += ( n[4] != 0 ) ? ( a[Number( n[4] )] || b[n[4][0]] + ' ' + a[n[4][1]] ) + 'hundred ' : '';
624
- str += ( n[5] != 0 ) ? ( ( str != '' ) ? 'and ' : '' ) + ( a[Number( n[5] )] || b[n[5][0]] + ' ' + a[n[5][1]] ) : '';
625
-
626
- return str.toLowerCase().split( ' ' ).map( ( word ) => word.charAt( 0 ).toUpperCase() + word.slice( 1 ) ).join( ' ' );
627
- }
628
-
629
-
630
- export async function infraTable( req, res ) {
606
+ export async function getInfraIssues( req, res ) {
631
607
  try {
632
- let query = [];
633
- let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
634
- if ( req.body.clientId && req.body.clientId.length > 0 ) {
635
- query.push( {
608
+ const inputData = req.body;
609
+ const query=[
610
+ {
636
611
  $match: {
637
- 'basicDetails.clientId': { $in: req.body.clientId },
638
- },
639
- } );
640
- }
641
- query.push( {
642
- $match: {
643
- $and: [
644
- { issueType: 'infra' },
645
- { createdAt: { $gte: date.start } },
646
- { createdAt: { $lte: date.end } },
647
- ],
648
- },
649
- },
650
- {
651
- $project: {
652
- storeId: '$basicDetails.storeId',
653
- clientId: '$basicDetails.clientId',
654
- ticketId: 1,
655
- storeName: '$basicDetails.storeName',
656
- clientName: '$basicDetails.clientName',
657
- status: 1,
658
- createdAt: 1,
659
- issueDate: 1,
660
- addressingUser: { $toObjectId: '$ticketDetails.addressingUser' },
661
- primaryIssue: {
662
- $filter: {
663
- input: '$ticketActivity',
664
- as: 'item',
665
- cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
666
- },
667
- },
668
- },
669
- },
670
- {
671
- $unwind: {
672
- path: '$primaryIssue', preserveNullAndEmptyArrays: true,
673
- },
674
- },
675
- {
676
- $unwind: {
677
- path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
678
- },
679
- },
680
- {
681
- $unwind: {
682
- path: '$primaryIssue.reasons.secondaryIssue', preserveNullAndEmptyArrays: true,
683
- },
684
- },
685
- {
686
- $project: {
687
- storeId: 1,
688
- clientId: 1,
689
- storeName: 1,
690
- clientName: 1,
691
- createdAt: 1,
692
- addressingUser: 1,
693
- ticketId: 1,
694
- issueDate: { $ifNull: [ '$issueDate', '' ] },
695
- status: 1,
696
- primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
697
- secondaryIssue: { $ifNull: [ '$primaryIssue.reasons.secondaryIssue.name', '-' ] },
698
- },
699
- },
700
- {
701
- '$lookup': {
702
- 'from': 'users',
703
- 'let': { 'userId': '$addressingUser' },
704
- 'pipeline': [
705
- {
706
- '$match': {
707
- '$expr': {
708
- '$eq': [ '$_id', '$$userId' ],
709
- },
612
+ $and: [
613
+ {
614
+ 'issueType': { $eq: 'infra' },
615
+
710
616
  },
711
- },
712
- {
713
- '$project': {
714
- 'userName': 1,
715
- 'email': 1,
716
- 'role': 1,
617
+ {
618
+ 'basicDetails.storeId': { $eq: inputData.storeId },
619
+
717
620
  },
718
- },
719
- ],
720
- 'as': 'user',
721
- },
722
- },
621
+ {
622
+ 'issueDate': { $gte: new Date( inputData.fromDate ) },
723
623
 
724
- {
725
- $unwind: {
726
- path: '$user',
727
- preserveNullAndEmptyArrays: true,
728
- },
729
- },
730
- {
731
- $group: {
732
- _id: '$ticketId',
733
- storeId: { $first: '$storeId' },
734
- clientId: { $first: '$clientId' },
735
- ticketId: { $first: '$ticketId' },
736
- storeName: { $first: '$storeName' },
737
- userName: { $first: { $ifNull: [ '$user.userName', '-' ] } },
738
- userEmail: { $first: { $ifNull: [ '$user.email', '-' ] } },
739
- clientName: { $first: '$clientName' },
740
- createdAt: { $first: '$createdAt' },
741
- issueDate: { $last: '$issueDate' },
742
- status: { $last: '$status' },
743
- primaryIssue: { $last: '$primaryIssue' },
744
- secondaryIssue: { $last: '$secondaryIssue' },
745
- },
746
- },
747
- {
748
- $sort: {
749
- ticketId: -1,
750
- },
751
- },
752
- );
753
- if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
754
- query.push( {
755
- $sort: { [req.body.sortColumName]: req.body.sortBy },
756
- } );
757
- }
758
- if ( req.body.storeIdFilter && req.body.storeIdFilter.length > 0 ) {
759
- query.push( {
760
- $match: {
761
- storeId: { $in: req.body.storeIdFilter },
762
- },
763
- } );
764
- }
765
- if ( req.body.statusFilter && req.body.statusFilter.length > 0 ) {
766
- query.push( {
767
- $match: {
768
- status: { $in: req.body.statusFilter },
769
- },
770
- } );
771
- }
772
- if ( req.body.userFilter && req.body.userFilter.length > 0 ) {
773
- query.push( {
774
- $match: {
775
- userEmail: { $in: req.body.userFilter },
776
- },
777
- } );
778
- }
779
- let ticketList = await aggregateTangoTicket( query );
780
- let issueList = await findinfraReason( { parentId: { '$exists': false } } );
781
- const categoryCounts = {};
782
- let response;
783
- if ( ticketList.length > 0 ) {
784
- ticketList.forEach( ( item ) => {
785
- const categoryName = item.primaryIssue;
786
- if ( categoryCounts[categoryName] ) {
787
- categoryCounts[categoryName]++;
788
- } else {
789
- categoryCounts[categoryName] = 1;
790
- }
791
- } );
792
- response = issueList.map( ( category ) => ( {
793
- name: category.name,
794
- count: categoryCounts[category.name] || 0,
795
- } ) );
796
- } else {
797
- response = issueList.map( ( category ) => ( {
798
- name: category.name,
799
- count: 0,
800
- } ) );
801
- }
802
- response.push( {
803
- 'name': 'total',
804
- 'count': ticketList.length,
624
+ },
625
+ {
626
+ 'issueDate': { $lte: new Date( inputData.toDate ) },
805
627
 
806
- } );
807
- if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'total' ) {
808
- query.push( {
809
- $match: {
810
- primaryIssue: req.body.filterIssue,
811
- },
812
- } );
813
- }
628
+ },
629
+ {
630
+ 'ticketDetails.issueStatus': { $eq: 'identified' },
814
631
 
815
- if ( req.body.searchValue && req.body.searchValue != '' ) {
816
- query.push( {
817
- $match: {
818
- $or: [
819
- { storeId: { $regex: req.body.searchValue, $options: 'i' } },
820
- { storeName: { $regex: req.body.searchValue, $options: 'i' } },
821
- ],
822
- },
823
- } );
824
- }
825
- let count = await aggregateTangoTicket( query );
632
+ },
826
633
 
827
- if ( req.body.limit && req.body.offset && !req.body.export ) {
828
- query.push(
829
- { $skip: ( req.body.offset - 1 ) * req.body.limit },
830
- { $limit: Number( req.body.limit ) },
831
- );
832
- }
833
- let result = await aggregateTangoTicket( query );
834
- if ( req.body.export && result.length > 0 ) {
835
- const exportdata = [];
836
- result.forEach( ( element ) => {
837
- exportdata.push( {
838
- 'ticketId': element.ticketId,
839
- 'issueDate': dayjs( element.issueDate ).format( 'DD-MM-YYYY' ),
840
- 'storeId': element.storeId,
841
- 'storeName': element.storeName,
842
- 'clientId': element.clientId,
843
- 'clientName': element.clientName,
844
- 'userName': element.userName,
845
- 'userEmail': element.userEmail,
846
- 'Status': element.status,
847
- 'StatusDetails': element.primaryIssue,
848
- 'SubIssue': element.secondaryIssue,
849
- } );
850
- } );
851
- await download( exportdata, res );
852
- return;
853
- }
854
- res.sendSuccess( {
855
- response: response,
856
- count: count.length,
857
- result: result,
858
- } );
859
- } catch ( error ) {
860
- logger.error( { error: error, function: 'infraTable' } );
861
- return res.sendError( error, 500 );
862
- }
863
- }
864
- export async function installationTable( req, res ) {
865
- try {
866
- let query = [];
867
- let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
868
- if ( req.body.clientId && req.body.clientId.length > 0 ) {
869
- query.push( {
870
- $match: {
871
- 'basicDetails.clientId': { $in: req.body.clientId },
634
+ ],
872
635
  },
873
- } );
874
- }
875
-
876
- query.push( {
877
- $match: {
878
- $and: [
879
- { issueType: 'installation' },
880
- { createdAt: { $gte: date.start } },
881
- { createdAt: { $lte: date.end } },
882
- ],
883
636
  },
884
- },
885
- {
886
- $project: {
887
- storeId: '$basicDetails.storeId',
888
- clientId: '$basicDetails.clientId',
889
- ticketId: 1,
890
- storeName: '$basicDetails.storeName',
891
- clientName: '$basicDetails.clientName',
892
- status: 1,
893
- createdAt: 1,
894
- addressingUser: '$ticketDetails.addressingUser',
895
- installationStatus: '$ticketDetails.installationStatus',
896
- issueDate: 1,
897
- primaryIssue: {
898
- $filter: {
899
- input: '$ticketActivity',
900
- as: 'item',
901
- cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
637
+ {
638
+ $project: {
639
+ issueType: 1,
640
+ issueDate: { $dateToString: { format: '%d-%m-%Y', date: '$issueDate' } },
641
+ ticketActivity: {
642
+ $filter: {
643
+ input: '$ticketActivity',
644
+ as: 'item',
645
+ cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
646
+ },
902
647
  },
903
648
  },
904
649
  },
905
- },
906
- {
907
- $unwind: {
908
- path: '$primaryIssue', preserveNullAndEmptyArrays: true,
909
- },
910
- },
911
- {
912
- $unwind: {
913
- path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
914
- },
915
- },
916
- {
917
- $unwind: {
918
- path: '$primaryIssue.reasons.secondaryIssue', preserveNullAndEmptyArrays: true,
919
- },
920
- },
921
- {
922
- $project: {
923
- storeId: 1,
924
- clientId: 1,
925
- storeName: 1,
926
- clientName: 1,
927
- createdAt: 1,
928
- ticketId: 1,
929
- addressingUser: 1,
930
- installationStatus: { $ifNull: [ '$installationStatus', '-' ] },
931
- issueDate: { $ifNull: [ '$issueDate', '' ] },
932
- status: 1,
933
- primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
934
- secondaryIssue: { $ifNull: [ '$primaryIssue.reasons.secondaryIssue.name', '-' ] },
650
+ {
651
+ $unwind: {
652
+ path: '$ticketActivity', preserveNullAndEmptyArrays: true,
653
+ },
935
654
  },
936
- },
937
- {
938
- '$lookup': {
939
- 'from': 'users',
940
- 'let': { 'userId': '$addressingUser' },
941
- 'pipeline': [
942
- {
943
- '$match': {
944
- '$expr': {
945
- '$eq': [ '$_id', '$$userId' ],
946
- },
947
- },
948
- },
949
- {
950
- '$project': {
951
- 'userName': 1,
952
- 'email': 1,
953
- 'role': 1,
954
- },
955
- },
956
- ],
957
- 'as': 'user',
655
+ {
656
+ $unwind: {
657
+ path: '$ticketActivity.reasons', preserveNullAndEmptyArrays: true,
658
+ },
958
659
  },
959
- },
660
+ {
661
+ $group: {
662
+ _id: { reason: '$ticketActivity.reasons', issueDate: '$issueDate' },
663
+ issueDate: { $first: '$issueDate' },
664
+ primaryIssue: { $last: '$ticketActivity.reasons.primaryIssue' },
665
+ secondaryIssue: { $last: '$ticketActivity.reasons.secondaryIssue' },
960
666
 
961
- {
962
- $unwind: {
963
- path: '$user',
964
- preserveNullAndEmptyArrays: true,
965
- },
966
- },
967
- {
968
- $group: {
969
- _id: '$ticketId',
970
- storeId: { $first: '$storeId' },
971
- clientId: { $first: '$clientId' },
972
- ticketId: { $first: '$ticketId' },
973
- storeName: { $first: '$storeName' },
974
- userName: { $first: { $ifNull: [ '$user.userName', '-' ] } },
975
- userEmail: { $first: { $ifNull: [ '$user.email', '-' ] } },
976
- clientName: { $first: '$clientName' },
977
- createdAt: { $first: '$createdAt' },
978
- issueDate: { $last: '$issueDate' },
979
- installationStatus: { $last: '$installationStatus' },
980
- status: { $last: '$status' },
981
- primaryIssue: { $last: '$primaryIssue' },
982
- secondaryIssue: { $last: '$secondaryIssue' },
983
- },
984
- },
985
- {
986
- $sort: {
987
- ticketId: -1,
988
- },
989
- },
990
- );
991
- if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
992
- query.push( {
993
- $sort: { [req.body.sortColumName]: req.body.sortBy },
994
- } );
995
- }
996
- if ( req.body.storeIdFilter && req.body.storeIdFilter.length > 0 ) {
997
- query.push( {
998
- $match: {
999
- storeId: { $in: req.body.storeIdFilter },
1000
667
  },
1001
- } );
1002
- }
1003
- if ( req.body.statusFilter && req.body.statusFilter.length > 0 ) {
1004
- query.push( {
1005
- $match: {
1006
- installationStatus: { $in: req.body.statusFilter },
1007
- },
1008
- } );
1009
- }
1010
- if ( req.body.userFilter && req.body.userFilter.length > 0 ) {
1011
- query.push( {
1012
- $match: {
1013
- userEmail: { $in: req.body.userFilter },
668
+ },
669
+ {
670
+ $unwind: {
671
+ path: '$secondaryIssue', preserveNullAndEmptyArrays: true,
1014
672
  },
1015
- } );
1016
- }
1017
- let ticketList = await aggregateTangoTicket( query );
1018
- let issueList = await findinfraReason( { parentId: { '$exists': false } } );
1019
- const categoryCounts = {};
1020
- let response;
1021
- if ( ticketList.length > 0 ) {
1022
- ticketList.forEach( ( item ) => {
1023
- const categoryName = item.primaryIssue;
1024
- if ( categoryCounts[categoryName] ) {
1025
- categoryCounts[categoryName]++;
1026
- } else {
1027
- categoryCounts[categoryName] = 1;
1028
- }
1029
- } );
1030
- response = issueList.map( ( category ) => ( {
1031
- name: category.name,
1032
- count: categoryCounts[category.name] || 0,
1033
- } ) );
1034
- } else {
1035
- response = issueList.map( ( category ) => ( {
1036
- name: category.name,
1037
- count: 0,
1038
- } ) );
1039
- }
1040
- response.push( {
1041
- 'name': 'total',
1042
- 'count': ticketList.length,
673
+ },
674
+ {
675
+ $group: {
676
+ _id: { issue: '$primaryIssue', issueDate: '$issueDate' },
677
+ issueDate: { $first: '$issueDate' },
678
+ primaryIssue: { $last: '$primaryIssue' },
679
+ secondaryReason: { $push: '$secondaryIssue.name' },
1043
680
 
1044
- } );
1045
- if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'total' ) {
1046
- query.push( {
1047
- $match: {
1048
- primaryIssue: req.body.filterIssue,
1049
681
  },
1050
- } );
1051
- }
1052
- if ( req.body.searchValue && req.body.searchValue != '' ) {
1053
- query.push( {
1054
- $match: {
1055
- $or: [
1056
- { storeId: { $regex: req.body.searchValue, $options: 'i' } },
1057
- { storeName: { $regex: req.body.searchValue, $options: 'i' } },
1058
- ],
682
+ },
683
+ {
684
+ $project: {
685
+ _id: 0,
686
+ issueDate: 1,
687
+ primaryIssue: 1,
688
+ secondaryReason: 1,
1059
689
  },
1060
- } );
1061
- }
1062
- let count = await aggregateTangoTicket( query );
1063
- if ( req.body.limit && req.body.offset && !req.body.export ) {
1064
- query.push(
1065
- { $skip: ( req.body.offset - 1 ) * req.body.limit },
1066
- { $limit: Number( req.body.limit ) },
1067
- );
1068
- }
1069
- let result = await aggregateTangoTicket( query );
1070
690
 
1071
- if ( req.body.export && result.length > 0 ) {
1072
- const exportdata = [];
1073
- result.forEach( ( element ) => {
1074
- exportdata.push( {
1075
- 'ticketId': element.ticketId,
1076
- 'issueDate': dayjs( element.issueDate ).format( 'DD-MM-YYYY' ),
1077
- 'storeId': element.storeId,
1078
- 'storeName': element.storeName,
1079
- 'clientId': element.clientId,
1080
- 'clientName': element.clientName,
1081
- 'userName': element.userName,
1082
- 'userEmail': element.userEmail,
1083
- 'Status': element.installationStatus,
1084
- 'StatusDetails': element.primaryIssue,
1085
- 'SubIssue': element.secondaryIssue,
1086
- } );
1087
- } );
1088
- await download( exportdata, res );
1089
- return;
1090
- }
1091
- res.sendSuccess( {
1092
- response: response,
1093
- count: count.length,
1094
- result: result,
1095
- } );
691
+ },
692
+ ];
693
+ const result = await aggregateTangoTicket( query );
694
+ return res.sendSuccess( { result: result } );
1096
695
  } catch ( error ) {
1097
- logger.error( { error: error, function: 'installationTable' } );
696
+ logger.error( { error: error, function: 'getInfraIssues' } );
1098
697
  return res.sendError( error, 500 );
1099
698
  }
1100
699
  }
1101
- export async function matTable( req, res ) {
1102
- try {
1103
- let query = [];
1104
- let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
1105
- if ( req.body.clientId && req.body.clientId.length > 0 ) {
1106
- query.push( {
1107
- $match: {
1108
- 'basicDetails.clientId': { $in: req.body.clientId },
1109
- },
1110
- } );
1111
- }
1112
700
 
1113
- query.push( {
1114
- $match: {
1115
- $and: [
1116
- { issueType: 'mat' },
1117
- { createdAt: { $gte: date.start } },
1118
- { createdAt: { $lte: date.end } },
1119
- ],
1120
- },
1121
- },
1122
- {
1123
- $project: {
1124
- storeId: '$basicDetails.storeId',
1125
- clientId: '$basicDetails.clientId',
1126
- ticketId: 1,
1127
- storeName: '$basicDetails.storeName',
1128
- clientName: '$basicDetails.clientName',
1129
- status: 1,
1130
- createdAt: 1,
1131
- addressingUser: '$ticketDetails.addressingUser',
1132
- issueDate: 1,
1133
- },
1134
- },
1135
-
1136
- {
1137
- '$lookup': {
1138
- 'from': 'users',
1139
- 'let': { 'userId': '$addressingUser' },
1140
- 'pipeline': [
1141
- {
1142
- '$match': {
1143
- '$expr': {
1144
- '$eq': [ '$_id', '$$userId' ],
1145
- },
1146
- },
1147
- },
1148
- {
1149
- '$project': {
1150
- 'userName': 1,
1151
- 'email': 1,
1152
- 'role': 1,
1153
- },
1154
- },
1155
- ],
1156
- 'as': 'user',
1157
- },
1158
- },
1159
701
 
1160
- {
1161
- $unwind: {
1162
- path: '$user',
1163
- preserveNullAndEmptyArrays: true,
1164
- },
1165
- },
1166
- {
1167
- $group: {
1168
- _id: '$ticketId',
1169
- storeId: { $first: '$storeId' },
1170
- clientId: { $first: '$clientId' },
1171
- ticketId: { $first: '$ticketId' },
1172
- storeName: { $first: '$storeName' },
1173
- userName: { $first: { $ifNull: [ '$user.userName', '-' ] } },
1174
- userEmail: { $first: { $ifNull: [ '$user.email', '-' ] } },
1175
- clientName: { $first: '$clientName' },
1176
- createdAt: { $first: '$createdAt' },
1177
- issueDate: { $last: '$issueDate' },
1178
- status: { $last: '$status' },
1179
- },
1180
- },
1181
- );
1182
- if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
1183
- query.push( {
1184
- $sort: { [req.body.sortColumName]: req.body.sortBy },
1185
- } );
1186
- }
1187
- if ( req.body.storeIdFilter && req.body.storeIdFilter.length > 0 ) {
1188
- query.push( {
1189
- $match: {
1190
- storeId: { $in: req.body.storeIdFilter },
1191
- },
1192
- } );
1193
- }
1194
- if ( req.body.statusFilter && req.body.statusFilter.length > 0 ) {
1195
- query.push( {
1196
- $match: {
1197
- status: { $in: req.body.statusFilter },
1198
- },
1199
- } );
1200
- }
1201
- if ( req.body.userFilter && req.body.userFilter.length > 0 ) {
1202
- query.push( {
1203
- $match: {
1204
- userEmail: { $in: req.body.userFilter },
1205
- },
1206
- } );
1207
- }
1208
-
1209
- if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'total' ) {
1210
- query.push( {
1211
- $match: {
1212
- primaryIssue: req.body.filterIssue,
1213
- },
1214
- } );
1215
- }
1216
- if ( req.body.searchValue && req.body.searchValue != '' ) {
1217
- query.push( {
1218
- $match: {
1219
- $or: [
1220
- { storeId: { $regex: req.body.searchValue, $options: 'i' } },
1221
- { storeName: { $regex: req.body.searchValue, $options: 'i' } },
1222
- ],
1223
- },
1224
- } );
1225
- }
1226
- let count = await aggregateTangoTicket( query );
1227
- if ( req.body.limit && req.body.offset && !req.body.export ) {
1228
- query.push(
1229
- { $skip: ( req.body.offset - 1 ) * req.body.limit },
1230
- { $limit: Number( req.body.limit ) },
1231
- );
1232
- }
1233
- let result = await aggregateTangoTicket( query );
1234
-
1235
- if ( req.body.export && result.length > 0 ) {
1236
- const exportdata = [];
1237
- result.forEach( ( element ) => {
1238
- exportdata.push( {
1239
- 'ticketId': element.ticketId,
1240
- 'issueDate': dayjs( element.issueDate ).format( 'DD-MM-YYYY' ),
1241
- 'storeId': element.storeId,
1242
- 'storeName': element.storeName,
1243
- 'clientId': element.clientId,
1244
- 'clientName': element.clientName,
1245
- 'userName': element.userName,
1246
- 'userEmail': element.userEmail,
1247
- 'Status': element.installationStatus,
1248
- } );
1249
- } );
1250
- await download( exportdata, res );
1251
- return;
1252
- }
1253
- if ( result.length > 0 ) {
1254
- res.sendSuccess( {
1255
- count: count.length,
1256
- result: result,
1257
- } );
1258
- } else {
1259
- res.sendError( 'no data', 204 );
1260
- }
1261
- } catch ( error ) {
1262
- logger.error( { error: error, function: 'installationTable' } );
1263
- return res.sendError( error, 500 );
1264
- }
1265
- }
1266
- export async function assignTicket( req, res ) {
1267
- try {
1268
- let tickets = await updateManyTangoTicket( { ticketId: { $in: req.body.tickets } }, { 'ticketDetails.assigntoUser': true, 'ticketDetails.addressingUser': req.body.user } );
1269
- if ( tickets ) {
1270
- res.sendSuccess( 'Ticket Assigned Successfully' );
1271
- }
1272
- } catch ( error ) {
1273
- logger.error( { error: error, function: 'assignTicket' } );
1274
- return res.sendError( error, 500 );
1275
- }
1276
- }
1277
- export async function storeFilter( req, res ) {
1278
- try {
1279
- let stores = await findTangoTicket( { 'issueType': req.body.issueType, 'basicDetails.clientId': req.body.clientId, 'basicDetails.storeId': { $exists: true } }, { 'basicDetails.storeId': 1 } );
1280
- const uniqueStoreIds = [ ...new Set( stores.map( ( store ) => store.basicDetails.storeId ) ) ];
1281
- const uniqueStoreObjects = uniqueStoreIds.map( ( storeId ) => ( { 'storeId': storeId } ) );
702
+ function inWords( num ) {
703
+ let a = [ '', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ', 'nine ', 'ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', 'nineteen ' ]; let b = [ '', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety' ];
704
+ if ( ( num = num.toString() ).length > 9 ) return 'overflow';
705
+ let n = ( '000000000' + num ).substr( -9 ).match( /^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/ );
706
+ if ( !n ) return; let str = '';
707
+ str += ( n[1] != 0 ) ? ( a[Number( n[1] )] || b[n[1][0]] + ' ' + a[n[1][1]] ) + 'crore ' : '';
708
+ str += ( n[2] != 0 ) ? ( a[Number( n[2] )] || b[n[2][0]] + ' ' + a[n[2][1]] ) + 'lakh ' : '';
709
+ str += ( n[3] != 0 ) ? ( a[Number( n[3] )] || b[n[3][0]] + ' ' + a[n[3][1]] ) + 'thousand ' : '';
710
+ str += ( n[4] != 0 ) ? ( a[Number( n[4] )] || b[n[4][0]] + ' ' + a[n[4][1]] ) + 'hundred ' : '';
711
+ str += ( n[5] != 0 ) ? ( ( str != '' ) ? 'and ' : '' ) + ( a[Number( n[5] )] || b[n[5][0]] + ' ' + a[n[5][1]] ) : '';
1282
712
 
1283
- if ( uniqueStoreObjects.length>0 ) {
1284
- res.sendSuccess( { count: uniqueStoreObjects.length, data: uniqueStoreObjects } );
1285
- } else {
1286
- res.sendError( 'No data', 204 );
1287
- }
1288
- } catch ( error ) {
1289
- // console.log( error );
1290
- logger.error( { error: error, function: 'storeFilter' } );
1291
- return res.sendError( error, 500 );
1292
- }
713
+ return str.toLowerCase().split( ' ' ).map( ( word ) => word.charAt( 0 ).toUpperCase() + word.slice( 1 ) ).join( ' ' );
1293
714
  }