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