tango-app-api-client 3.0.46-dev → 3.0.47-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
|
@@ -83,7 +83,7 @@ export async function create( req, res ) {
|
|
|
83
83
|
|
|
84
84
|
await createGroupModel( defaultGroup );
|
|
85
85
|
|
|
86
|
-
const createdGroup = await findOneGroup( { clientId: insertedClientRecord.clientId, isDefault: true }, {
|
|
86
|
+
const createdGroup = await findOneGroup( { clientId: insertedClientRecord.clientId, isDefault: true }, {} );
|
|
87
87
|
|
|
88
88
|
let oldGroup = {
|
|
89
89
|
'_id': createdGroup._id,
|
|
@@ -318,10 +318,12 @@ export async function getClients( req, res ) {
|
|
|
318
318
|
assignedType: { $eq: 'client' },
|
|
319
319
|
$expr: {
|
|
320
320
|
$cond: {
|
|
321
|
-
if: {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
321
|
+
if: {
|
|
322
|
+
$and: [
|
|
323
|
+
{ $eq: [ '$userType', 'tango' ] },
|
|
324
|
+
{ $eq: [ '$tangoUserType', 'csm' ] },
|
|
325
|
+
],
|
|
326
|
+
},
|
|
325
327
|
then: { $eq: [ '$isClientApproved', true ] },
|
|
326
328
|
else: true,
|
|
327
329
|
},
|
|
@@ -459,18 +461,30 @@ export async function detailedAllClientCount( req, res ) {
|
|
|
459
461
|
{
|
|
460
462
|
$project: {
|
|
461
463
|
activeClient: { $cond: [ { $eq: [ '$status', 'active' ] }, 1, 0 ] },
|
|
462
|
-
paidClient: {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
464
|
+
paidClient: {
|
|
465
|
+
$cond: [ {
|
|
466
|
+
$and: [
|
|
467
|
+
{ $eq: [ '$status', 'active' ] },
|
|
468
|
+
{ $in: [ '$planDetails.paymentStatus', [ 'paid', 'unbilled', 'due' ] ] },
|
|
469
|
+
],
|
|
470
|
+
}, 1, 0 ],
|
|
471
|
+
},
|
|
472
|
+
trialClient: {
|
|
473
|
+
$cond: [ {
|
|
474
|
+
$and: [
|
|
475
|
+
{ $eq: [ '$status', 'active' ] },
|
|
476
|
+
{ $eq: [ '$planDetails.paymentStatus', 'trial' ] },
|
|
477
|
+
],
|
|
478
|
+
}, 1, 0 ],
|
|
479
|
+
},
|
|
480
|
+
|
|
481
|
+
freeClient: {
|
|
482
|
+
$cond: [ {
|
|
483
|
+
$and: [
|
|
484
|
+
{ $eq: [ '$status', 'active' ] }, { $eq: [ '$planDetails.paymentStatus', 'free' ] },
|
|
485
|
+
],
|
|
486
|
+
}, 1, 0 ],
|
|
487
|
+
},
|
|
474
488
|
holdClient: { $cond: [ { $eq: [ '$status', 'hold' ] }, 1, 0 ] },
|
|
475
489
|
suspendClient: { $cond: [ { $eq: [ '$status', 'suspended' ] }, 1, 0 ] },
|
|
476
490
|
deactiveClient: { $cond: [ { $eq: [ '$status', 'deactive' ] }, 1, 0 ] },
|
|
@@ -1103,9 +1117,11 @@ export async function clientList( req, res ) {
|
|
|
1103
1117
|
userType: 'tango',
|
|
1104
1118
|
$expr: {
|
|
1105
1119
|
$cond: {
|
|
1106
|
-
if: {
|
|
1107
|
-
|
|
1108
|
-
|
|
1120
|
+
if: {
|
|
1121
|
+
$and: [
|
|
1122
|
+
{ $eq: [ '$tangoUserType', 'csm' ] },
|
|
1123
|
+
],
|
|
1124
|
+
},
|
|
1109
1125
|
then: { $eq: [ '$isClientApproved', true ] },
|
|
1110
1126
|
else: true,
|
|
1111
1127
|
},
|
|
@@ -1122,7 +1138,7 @@ export async function clientList( req, res ) {
|
|
|
1122
1138
|
];
|
|
1123
1139
|
const clientIdList = await aggregateUserAssignedStore( query );
|
|
1124
1140
|
logger.info( { message: clientIdList, value: 'clientIdList' } );
|
|
1125
|
-
if ( clientIdList.length ==0 ) {
|
|
1141
|
+
if ( clientIdList.length == 0 ) {
|
|
1126
1142
|
return res.sendError( 'No Data Found', 204 );
|
|
1127
1143
|
}
|
|
1128
1144
|
|
|
@@ -1391,7 +1407,7 @@ export async function clientList( req, res ) {
|
|
|
1391
1407
|
'client Id': chunk[i]?.clientId,
|
|
1392
1408
|
'Installation Stores Count': chunk[i]?.installedStores || 0,
|
|
1393
1409
|
'Onboarded Stores Count': chunk[i]?.totalStores,
|
|
1394
|
-
'Store Progress': chunk[i]?.installedStores? `${
|
|
1410
|
+
'Store Progress': chunk[i]?.installedStores ? `${( ( chunk[i]?.installedStores / chunk[i]?.totalStores ) * 100 ).toFixed( 0 )}%` : '0%',
|
|
1395
1411
|
'Active Store': chunk[i]?.activeStoreCount || 0,
|
|
1396
1412
|
'Active Camera': chunk[i]?.activeCameraCount && chunk[i]?.activeCameraCount != undefined ? chunk[i]?.activeCameraCount : 0,
|
|
1397
1413
|
'Pending Stores': chunk[i]?.pendingStores || 0,
|
|
@@ -1414,7 +1430,242 @@ export async function clientList( req, res ) {
|
|
|
1414
1430
|
return res.sendError( 'Internal Server Error', 500 );
|
|
1415
1431
|
}
|
|
1416
1432
|
}
|
|
1433
|
+
export async function clientListV1( req, res ) {
|
|
1434
|
+
try {
|
|
1435
|
+
const inputData = req.body;
|
|
1436
|
+
let clientQuery = [];
|
|
1437
|
+
logger.info( { message: req?.user?.role } );
|
|
1438
|
+
if ( req?.user?.role !== 'superadmin' ) {
|
|
1439
|
+
const query = [
|
|
1440
|
+
{
|
|
1441
|
+
$match: {
|
|
1442
|
+
userEmail: { $eq: req?.user?.email },
|
|
1443
|
+
userType: 'tango',
|
|
1444
|
+
$expr: {
|
|
1445
|
+
$cond: {
|
|
1446
|
+
if: {
|
|
1447
|
+
$and: [
|
|
1448
|
+
{ $eq: [ '$tangoUserType', 'csm' ] },
|
|
1449
|
+
],
|
|
1450
|
+
},
|
|
1451
|
+
then: { $eq: [ '$isClientApproved', true ] },
|
|
1452
|
+
else: true,
|
|
1453
|
+
},
|
|
1454
|
+
},
|
|
1417
1455
|
|
|
1456
|
+
},
|
|
1457
|
+
},
|
|
1458
|
+
{
|
|
1459
|
+
$group: {
|
|
1460
|
+
_id: null,
|
|
1461
|
+
clientList: { $push: '$assignedValue' },
|
|
1462
|
+
},
|
|
1463
|
+
},
|
|
1464
|
+
];
|
|
1465
|
+
const clientIdList = await aggregateUserAssignedStore( query );
|
|
1466
|
+
logger.info( { message: clientIdList, value: 'clientIdList' } );
|
|
1467
|
+
if ( clientIdList.length == 0 ) {
|
|
1468
|
+
return res.sendError( 'No Data Found', 204 );
|
|
1469
|
+
}
|
|
1470
|
+
clientQuery.push(
|
|
1471
|
+
{
|
|
1472
|
+
$match: {
|
|
1473
|
+
clientId: { $in: clientIdList[0].clientList },
|
|
1474
|
+
},
|
|
1475
|
+
},
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
clientQuery.push(
|
|
1479
|
+
{
|
|
1480
|
+
$project: {
|
|
1481
|
+
status: 1,
|
|
1482
|
+
clientName: 1,
|
|
1483
|
+
clientId: 1,
|
|
1484
|
+
subscriptionType: '$planDetails.subscriptionType',
|
|
1485
|
+
PaymentPlan: '$planDetails.paymentStatus',
|
|
1486
|
+
},
|
|
1487
|
+
},
|
|
1488
|
+
);
|
|
1489
|
+
if ( inputData.searchValue && inputData.searchValue != '' ) {
|
|
1490
|
+
clientQuery.push( {
|
|
1491
|
+
$match: {
|
|
1492
|
+
$or: [
|
|
1493
|
+
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1494
|
+
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1495
|
+
{ subscriptionType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1496
|
+
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1497
|
+
],
|
|
1498
|
+
},
|
|
1499
|
+
} );
|
|
1500
|
+
}
|
|
1501
|
+
clientQuery.push( {
|
|
1502
|
+
$lookup: {
|
|
1503
|
+
from: 'stores',
|
|
1504
|
+
let: { clientId: '$clientId' },
|
|
1505
|
+
pipeline: [
|
|
1506
|
+
{
|
|
1507
|
+
$match: {
|
|
1508
|
+
$expr: {
|
|
1509
|
+
$and: [
|
|
1510
|
+
{ $eq: [ '$clientId', '$$clientId' ] },
|
|
1511
|
+
],
|
|
1512
|
+
},
|
|
1513
|
+
},
|
|
1514
|
+
},
|
|
1515
|
+
{
|
|
1516
|
+
$project: {
|
|
1517
|
+
edge: 1,
|
|
1518
|
+
status: 1,
|
|
1519
|
+
clientId: 1,
|
|
1520
|
+
storeId: 1,
|
|
1521
|
+
},
|
|
1522
|
+
},
|
|
1523
|
+
], as: 'stores',
|
|
1524
|
+
},
|
|
1525
|
+
},
|
|
1526
|
+
|
|
1527
|
+
{
|
|
1528
|
+
$unwind: { path: '$stores', preserveNullAndEmptyArrays: true },
|
|
1529
|
+
},
|
|
1530
|
+
{
|
|
1531
|
+
$project: {
|
|
1532
|
+
clientId: 1,
|
|
1533
|
+
status: 1,
|
|
1534
|
+
clientName: 1,
|
|
1535
|
+
subscriptionType: 1,
|
|
1536
|
+
PaymentPlan: 1,
|
|
1537
|
+
installed: {
|
|
1538
|
+
$cond: [ { $and: [ { $eq: [ '$stores.edge.firstFile', true ] } ] }, 1, 0,
|
|
1539
|
+
],
|
|
1540
|
+
},
|
|
1541
|
+
activeStores: {
|
|
1542
|
+
$cond: [ { $and: [ { $eq: [ '$stores.status', 'active' ] }, { $eq: [ '$stores.edge.firstFile', true ] } ] }, 1, 0,
|
|
1543
|
+
],
|
|
1544
|
+
},
|
|
1545
|
+
},
|
|
1546
|
+
},
|
|
1547
|
+
{
|
|
1548
|
+
$group: {
|
|
1549
|
+
_id: '$clientId',
|
|
1550
|
+
clientId: { $first: '$clientId' },
|
|
1551
|
+
onboardedStores: { $sum: 1 },
|
|
1552
|
+
installedStore: { $sum: '$installed' },
|
|
1553
|
+
activeStores: { $sum: '$activeStores' },
|
|
1554
|
+
ProcessingStatus: { $first: '$status' },
|
|
1555
|
+
clientName: { $first: '$clientName' },
|
|
1556
|
+
subscriptionPlan: { $first: '$subscriptionType' },
|
|
1557
|
+
PaymentPlan: { $first: '$PaymentPlan' },
|
|
1558
|
+
},
|
|
1559
|
+
},
|
|
1560
|
+
{
|
|
1561
|
+
$lookup: {
|
|
1562
|
+
from: 'tangoTicket',
|
|
1563
|
+
let: { clientId: '$clientId' },
|
|
1564
|
+
pipeline: [
|
|
1565
|
+
{
|
|
1566
|
+
$match: {
|
|
1567
|
+
$expr: {
|
|
1568
|
+
$and: [
|
|
1569
|
+
{ $eq: [ '$issueType', 'installation' ] },
|
|
1570
|
+
{ $eq: [ '$basicDetails.clientId', '$$clientId' ] },
|
|
1571
|
+
],
|
|
1572
|
+
},
|
|
1573
|
+
},
|
|
1574
|
+
|
|
1575
|
+
},
|
|
1576
|
+
{
|
|
1577
|
+
$project: {
|
|
1578
|
+
ticketDetails: 1,
|
|
1579
|
+
status: 1,
|
|
1580
|
+
basicDetails: 1,
|
|
1581
|
+
},
|
|
1582
|
+
},
|
|
1583
|
+
], as: 'ticket',
|
|
1584
|
+
},
|
|
1585
|
+
},
|
|
1586
|
+
{
|
|
1587
|
+
$unwind: { path: '$ticket', preserveNullAndEmptyArrays: true },
|
|
1588
|
+
},
|
|
1589
|
+
{
|
|
1590
|
+
$project: {
|
|
1591
|
+
clientId: 1,
|
|
1592
|
+
ProcessingStatus: 1,
|
|
1593
|
+
onboardedStores: 1,
|
|
1594
|
+
clientName: 1,
|
|
1595
|
+
PaymentPlan: 1,
|
|
1596
|
+
subscriptionPlan: 1,
|
|
1597
|
+
installedStore: 1,
|
|
1598
|
+
activeStores: 1,
|
|
1599
|
+
installedPending: {
|
|
1600
|
+
$cond: [ { $and: [ { $ne: [ '$ticket.status', 'closed' ] } ] }, 1, 0 ],
|
|
1601
|
+
},
|
|
1602
|
+
installedFailed: {
|
|
1603
|
+
$cond: [ { $and: [ { $ne: [ '$ticket.status', 'closed' ] }, { $eq: [ '$ticket.ticketDetails.issueStatus', 'identified' ] } ] }, 1, 0 ],
|
|
1604
|
+
},
|
|
1605
|
+
},
|
|
1606
|
+
},
|
|
1607
|
+
{
|
|
1608
|
+
$group: {
|
|
1609
|
+
_id: '$clientId',
|
|
1610
|
+
clientId: { $first: '$clientId' },
|
|
1611
|
+
onboardedStores: { $first: '$onboardedStores' },
|
|
1612
|
+
installedStore: { $first: '$installedStore' },
|
|
1613
|
+
activeStores: { $first: '$activeStores' },
|
|
1614
|
+
ProcessingStatus: { $first: '$ProcessingStatus' },
|
|
1615
|
+
clientName: { $first: '$clientName' },
|
|
1616
|
+
subscriptionPlan: { $first: '$subscriptionPlan' },
|
|
1617
|
+
PaymentPlan: { $first: '$PaymentPlan' },
|
|
1618
|
+
installedPending: { $sum: '$installedPending' },
|
|
1619
|
+
installedFailed: { $sum: '$installedFailed' },
|
|
1620
|
+
},
|
|
1621
|
+
},
|
|
1622
|
+
);
|
|
1623
|
+
|
|
1624
|
+
const clientCount = await aggregateClient( clientQuery );
|
|
1625
|
+
if ( clientCount.length == 0 ) {
|
|
1626
|
+
return res.sendError( 'No Data Found', 204 );
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
if ( inputData.sortColumName ) {
|
|
1630
|
+
clientQuery.push( {
|
|
1631
|
+
$sort: { [req.body.sortColumName]: req.body.sortBy },
|
|
1632
|
+
},
|
|
1633
|
+
);
|
|
1634
|
+
}
|
|
1635
|
+
if ( req.body.limit && req.body.offset && !req.body.isExport ) {
|
|
1636
|
+
clientQuery.push(
|
|
1637
|
+
{ $skip: ( req.body.offset - 1 ) * req.body.limit },
|
|
1638
|
+
{ $limit: Number( req.body.limit ) },
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1641
|
+
const clientList = await aggregateClient( clientQuery );
|
|
1642
|
+
|
|
1643
|
+
if ( inputData.isExport ) {
|
|
1644
|
+
const exportResult = [];
|
|
1645
|
+
for ( let client of clientList ) {
|
|
1646
|
+
exportResult.push( {
|
|
1647
|
+
'client Name': client.clientName,
|
|
1648
|
+
'client Id': client.clientId,
|
|
1649
|
+
'Installation Stores Count': client.installedStore || 0,
|
|
1650
|
+
'Onboarded Stores Count': client.onboardedStores,
|
|
1651
|
+
'Store Progress': client.onboardedStores ? `${Math.round( ( client.onboardedStores / client.installedStore ) * 100 )}%` : '0%',
|
|
1652
|
+
'Active Store': client.activeStores || 0,
|
|
1653
|
+
'installedPending Stores': client.installedPending || 0,
|
|
1654
|
+
'installedFailed Stores': client.installedFailed || 0,
|
|
1655
|
+
'PaymentPlan': client.PaymentPlan,
|
|
1656
|
+
'subscriptionPlan': client.subscriptionPlan,
|
|
1657
|
+
'ProcessingStatus': client.ProcessingStatus,
|
|
1658
|
+
} );
|
|
1659
|
+
}
|
|
1660
|
+
await download( exportResult, res );
|
|
1661
|
+
return;
|
|
1662
|
+
}
|
|
1663
|
+
return res.sendSuccess( { result: clientList, count: clientCount.length } );
|
|
1664
|
+
} catch ( error ) {
|
|
1665
|
+
logger.error( { error: error, function: 'clientList' } );
|
|
1666
|
+
return res.sendError( 'Internal Server Error', 500 );
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1418
1669
|
export async function getOpsUsers( req, res ) {
|
|
1419
1670
|
try {
|
|
1420
1671
|
const users = await OpsUsersGet();
|
|
@@ -5,7 +5,7 @@ import { auditConfiguration, changeStatus, clientCsmAssignAction, clientDetails,
|
|
|
5
5
|
import { authorize, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
6
6
|
import { clientListValid, detailedClientCountValid } from '../dtos/client.dtos.js';
|
|
7
7
|
import { isclientIdExists, isclientNameExists } from '../validations/client.validations.js';
|
|
8
|
-
import { detailedAllClientCount, detailedClientCount, clientList } from '../controllers/client.controllers.js';
|
|
8
|
+
import { detailedAllClientCount, detailedClientCount, clientList, clientListV1 } from '../controllers/client.controllers.js';
|
|
9
9
|
|
|
10
10
|
export const clientRouter = express.Router();
|
|
11
11
|
|
|
@@ -83,7 +83,9 @@ clientRouter.get( '/detailed-all-client-count', isAllowedSessionHandler,
|
|
|
83
83
|
clientRouter.post( '/client-list', isAllowedSessionHandler,
|
|
84
84
|
authorize( { userType: [ 'tango' ], access: [ { featureName: 'manage', name: 'brands', permissions: [ 'isView' ] } ] } ),
|
|
85
85
|
validate( clientListValid ), clientList );
|
|
86
|
-
|
|
86
|
+
clientRouter.post( '/client-list_v1', isAllowedSessionHandler,
|
|
87
|
+
authorize( { userType: [ 'tango' ], access: [ { featureName: 'manage', name: 'brands', permissions: [ 'isView' ] } ] } ),
|
|
88
|
+
validate( clientListValid ), clientListV1 );
|
|
87
89
|
clientRouter.get( '/detailed-client-count', isAllowedSessionHandler,
|
|
88
90
|
authorize( { userType: [ 'tango', 'client' ] } ),
|
|
89
91
|
validate( detailedClientCountValid ), isclientIdExists, detailedClientCount );
|