tango-app-api-infra 3.0.15 → 3.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-infra",
3
- "version": "3.0.15",
3
+ "version": "3.0.16",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,9 +1,9 @@
1
1
 
2
- import { countDocumentsStore, findStorewithpagination } from '../services/store.service.js';
2
+ import { aggregateStore, countDocumentsStore } from '../services/store.service.js';
3
3
  import { logger, download } from 'tango-app-api-middleware';
4
4
  import { aggregateTangoTicket } from '../services/tangoTicket.service.js';
5
5
  import { findinfraReason } from '../services/infraReason.service.js';
6
- import { findClientwithpagination } from '../services/client.service.js';
6
+ import { aggregateClient } from '../services/client.service.js';
7
7
  import dayjs from 'dayjs';
8
8
  import { getOpenSearchData } from 'tango-app-api-middleware';
9
9
 
@@ -91,7 +91,7 @@ export async function infraCard( req, res ) {
91
91
  },
92
92
  },
93
93
  ];
94
- if ( req.body.filter&&req.body.filter.length>0 ) {
94
+ if ( req.body.filter && req.body.filter.length > 0 ) {
95
95
  query.push(
96
96
  {
97
97
  $match: {
@@ -336,7 +336,7 @@ export async function infraIssuesTable( req, res ) {
336
336
  );
337
337
  }
338
338
  let result = await aggregateTangoTicket( query );
339
- if ( req.body.export ) {
339
+ if ( req.body.export && result.length > 0 ) {
340
340
  const exportdata = [];
341
341
  result.forEach( ( element ) => {
342
342
  exportdata.push( {
@@ -445,13 +445,47 @@ export async function InstallationIssuesTable( req, res ) {
445
445
  export async function hourWiseDownClients( req, res ) {
446
446
  try {
447
447
  let inputData = req.body;
448
- let skip = 0;
449
- let limit = 10;
448
+
449
+ let query = [
450
+ {
451
+ $match: {
452
+ clientId: { $in: req.body.clientId },
453
+ },
454
+ },
455
+ {
456
+ $project: {
457
+ clientId: 1,
458
+ clientName: 1,
459
+ },
460
+ },
461
+ ];
462
+
463
+
464
+ if ( req.body.searchValue && req.body.searchValue !== '' ) {
465
+ query.push( {
466
+ $match: {
467
+ $or: [
468
+ { clientName: { $regex: req.body.searchValue, $options: 'i' } },
469
+ ],
470
+ },
471
+ } );
472
+ }
473
+ if ( req.body.sortColumName && req.body.sortColumName != '' && req.body.sortBy && req.body.sortBy != '' ) {
474
+ query.push( {
475
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
476
+ } );
477
+ }
478
+ let count = await aggregateClient( query );
450
479
  if ( req.body.limit && req.body.offset && !req.body.export ) {
451
- skip = ( req.body.offset - 1 ) * req.body.limit,
452
- limit = Number( req.body.limit );
480
+ query.push(
481
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
482
+ { $limit: Number( req.body.limit ) },
483
+ );
484
+ }
485
+ let clientlist = await aggregateClient( query );
486
+ if ( clientlist.length == 0 ) {
487
+ return res.sendError( 'no data', 204 );
453
488
  }
454
- let clientlist = await findClientwithpagination( { clientId: { $in: req.body.clientId } }, { clientId: 1, clientName: 1 }, skip, limit );
455
489
  let data = {};
456
490
  let result = [];
457
491
  for ( const client of clientlist ) {
@@ -460,7 +494,7 @@ export async function hourWiseDownClients( req, res ) {
460
494
  let clientdata = await livecountCheck( data, inputData );
461
495
  result.push( clientdata[0] );
462
496
  }
463
- res.sendSuccess( { result: result } );
497
+ res.sendSuccess( { count: count.length, result: result } );
464
498
  } catch ( error ) {
465
499
  logger.error( { error: error, function: 'hourWiseDownClients' } );
466
500
  return res.sendError( error, 500 );
@@ -556,13 +590,47 @@ export async function hourWiseDownstores( req, res ) {
556
590
  try {
557
591
  let inputData = req.body;
558
592
  inputData.Date = dayjs().format( 'YYYY-MM-DD' );
559
- let skip = 0;
560
- let limit = 10;
593
+
594
+ let query = [ {
595
+ $match: {
596
+ clientId: req.body.clientId,
597
+ },
598
+ },
599
+ {
600
+ $project: {
601
+ storeId: 1,
602
+ storeName: 1,
603
+ storeProfile: 1,
604
+ },
605
+ },
606
+
607
+ ];
608
+ if ( req.body.searchValue && req.body.searchValue !== '' ) {
609
+ query.push( {
610
+ $match: {
611
+ $or: [
612
+ { storeName: { $regex: req.body.searchValue, $options: 'i' } },
613
+ { storeId: { $regex: req.body.searchValue, $options: 'i' } },
614
+ ],
615
+ },
616
+ } );
617
+ }
618
+ if ( req.body.sortColumName && req.body.sortColumName != '' && req.body.sortBy && req.body.sortBy != '' ) {
619
+ query.push( {
620
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
621
+ } );
622
+ }
623
+ let count = await aggregateStore( query );
561
624
  if ( req.body.limit && req.body.offset && !req.body.export ) {
562
- skip = ( req.body.offset - 1 ) * req.body.limit,
563
- limit = Number( req.body.limit );
625
+ query.push(
626
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
627
+ { $limit: Number( req.body.limit ) },
628
+ );
629
+ }
630
+ let storeslist = await aggregateStore( query );
631
+ if ( storeslist.length == 0 ) {
632
+ return res.sendError( 'no data', 204 );
564
633
  }
565
- let storeslist = await findStorewithpagination( { clientId: req.body.clientId }, { storeId: 1, storeName: 1, storeProfile: 1 }, skip, limit );
566
634
  let data = {};
567
635
  let result = [];
568
636
  for ( const store of storeslist ) {
@@ -571,7 +639,7 @@ export async function hourWiseDownstores( req, res ) {
571
639
  let storedata = await downStoresCheck( data, inputData );
572
640
  result.push( storedata[0] );
573
641
  }
574
- res.sendSuccess( { result: result } );
642
+ res.sendSuccess( { count: count.length, result: result } );
575
643
  } catch ( error ) {
576
644
  logger.error( { error: error, function: 'hourWiseDownstores' } );
577
645
  return res.sendError( error, 500 );
@@ -2,7 +2,9 @@
2
2
 
3
3
  import { createTangoTicket, findOneTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
4
4
  import { createinfraReason, findinfraReason } from '../services/infraReason.service.js';
5
- import { logger } from 'tango-app-api-middleware';
5
+ import { updateOneStore } from '../services/store.service.js';
6
+ import { logger, fileUpload } from 'tango-app-api-middleware';
7
+ import dayjs from 'dayjs';
6
8
  export async function createTicket( req, res ) {
7
9
  try {
8
10
  req.body.issueDate = new Date( req.body.Date );
@@ -124,8 +126,30 @@ export async function AlertTicketReply( req, res ) {
124
126
  statusCheckReply: req.body.statusCheckReply,
125
127
  hibernationDays: req.body.hibernationDays,
126
128
  } );
129
+ await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketActivity': req.body.ticketActivity } );
130
+ if ( req.body.hibernationDays ) {
131
+ req.body.hibernationDays = dayjs().add( req.body.hibernationDays, 'days' ).format( 'YYYY-MM-DD' );
132
+ await updateOneStore( { storeId: req.body.basicDetails.storeId }, { 'ticketConfigs.hibernation': new Date( req.body.hibernationDays ) } );
133
+ }
134
+ res.sendSuccess( 'Updated Successfully' );
127
135
  } catch ( error ) {
128
136
  logger.error( { error: error, function: 'AlertTicketReply' } );
129
137
  return res.sendError( error, 500 );
130
138
  }
131
139
  }
140
+ export async function uploadAttachments( req, res ) {
141
+ try {
142
+ let params ={
143
+ Bucket: 'tango-brand-info-uat',
144
+ key: req.params.ticketId,
145
+ fileName: req.files[0].name,
146
+
147
+
148
+ };
149
+ let response =await fileUpload( params );
150
+ res.sendSuccess( response );
151
+ } catch ( error ) {
152
+ logger.error( { error: error, function: 'uploadAttachments' } );
153
+ return res.sendError( error, 500 );
154
+ }
155
+ }
@@ -1,6 +1,11 @@
1
1
 
2
2
  import { logger } from 'tango-app-api-middleware';
3
3
  import dayjs from 'dayjs';
4
+ import utc from 'dayjs/plugin/utc.js';
5
+ import timezone from 'dayjs/plugin/timezone.js';
6
+ import 'dayjs/locale/en.js';
7
+ dayjs.extend( utc );
8
+ dayjs.extend( timezone );
4
9
  import { createClient, findClient } from '../services/client.service.js';
5
10
  import { createStore, findStore, updateOneStore } from '../services/store.service.js';
6
11
  import { findTangoTicket, findOneTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
@@ -98,8 +103,7 @@ export async function setTicketTime( req, res ) {
98
103
 
99
104
  export async function downStoresList( req, res ) {
100
105
  try {
101
- let getCurrentHour = dayjs().startOf( 'hour' ).format( 'YYYY-MM-DDTHH:mm' );
102
- let storesList = await findStore( { 'ticketConfigs.nextTicektGenerationTime': new Date( getCurrentHour ) }, { storeId: 1, storeName: 1, storeProfile: 1, ticketConfigs: 1 } );
106
+ let storesList = await findStore( { 'ticketConfigs.hibernation': { $lt: new Date() }, 'ticketConfigs.nextTicektGenerationTime': new Date( req.body.getTime ) }, { storeId: 1, storeName: 1, storeProfile: 1, ticketConfigs: 1 } );
103
107
  if ( storesList.length > 0 ) {
104
108
  res.sendSuccess( storesList );
105
109
  } else {
@@ -139,6 +139,7 @@ export async function workHistory( req, res ) {
139
139
  $match: {
140
140
  $and: [
141
141
  { 'status': 'closed' },
142
+ { issueType: req.body.issueType },
142
143
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
143
144
  { createdAt: { $gte: new Date( req.body.fromDate ) } },
144
145
  { createdAt: { $lte: new Date( req.body.toDate ) } },
@@ -2,7 +2,7 @@
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler } from 'tango-app-api-middleware';
4
4
  import { validateDetails, validateTicket, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
- import { createTicket, updateStatus, createReason, PrimaryReasons, secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply } from '../controllers/infra.controllers.js';
5
+ import { createTicket, updateStatus, createReason, PrimaryReasons, secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply, uploadAttachments } from '../controllers/infra.controllers.js';
6
6
 
7
7
 
8
8
  export const infraRouter = express.Router();
@@ -15,5 +15,6 @@ infraRouter.post( '/secondaryReason', isAllowedSessionHandler, secondaryReason )
15
15
  infraRouter.post( '/updateTicketIssue', isAllowedSessionHandler, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert, updateTicketIssue );
16
16
  infraRouter.post( '/viewTicket', isAllowedSessionHandler, ticketExists, viewTicket );
17
17
  infraRouter.post( '/AlertTicketReply', isAllowedSessionHandler, ticketExists, AlertTicketReply );
18
+ infraRouter.put( '/uploadAttachments/:ticketId', isAllowedSessionHandler, ticketExists, uploadAttachments );
18
19
 
19
20
 
@@ -13,3 +13,6 @@ export async function findOneClient( query, project ) {
13
13
  export async function findClientwithpagination( query, project ) {
14
14
  return await dataModel.clientModel.find( query, project );
15
15
  }
16
+ export async function aggregateClient( query ) {
17
+ return await dataModel.clientModel.aggregate( query );
18
+ }
@@ -71,9 +71,10 @@ export async function validateTicket( req, res, next ) {
71
71
  };
72
72
  export async function ticketExists( req, res, next ) {
73
73
  try {
74
+ let ticketId = req.body.ticketId?req.body.ticketId:req.params.ticketId;
74
75
  let Ticket = await findOneTangoTicket(
75
76
  {
76
- ticketId: req.body.ticketId,
77
+ ticketId: ticketId,
77
78
  },
78
79
  );
79
80
  if ( !Ticket ) {