tango-app-api-trax 3.0.2 → 3.0.3

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-trax",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -3,6 +3,7 @@
3
3
  import { logger } from 'tango-app-api-middleware';
4
4
  import * as storeService from '../services/store.service.js';
5
5
  import * as groupService from '../services/group.service.js';
6
+ import * as clusterService from '../services/cluster.service.js';
6
7
  import * as processedchecklistconfigService from '../services/processedchecklistconfig.services.js';
7
8
  // import axios from 'axios';
8
9
  async function LamdaServiceCall( url, data ) {
@@ -29,7 +30,11 @@ async function LamdaServiceCall( url, data ) {
29
30
  export async function getchecklist( req, res ) {
30
31
  try {
31
32
  let url = JSON.parse( process.env.LAMBDAURL );
33
+ console.log( url.checklistQuestion );
34
+
32
35
  let resultData = await LamdaServiceCall( url.checklistQuestion, req.body );
36
+ console.log( resultData );
37
+
33
38
  if ( resultData ) {
34
39
  if ( resultData.status_code == '200' ) {
35
40
  return res.sendSuccess( resultData );
@@ -247,3 +252,274 @@ export const checklistDropdown = async ( req, res ) => {
247
252
  return res.sendError( { error: error }, 500 );
248
253
  }
249
254
  };
255
+
256
+ export const headerStoresV2 = async ( req, res ) => {
257
+ try {
258
+ let reqestData = req.body;
259
+ let getUserEmail = req.user.email;
260
+ let getUserType = req.user.userType;
261
+ let getRole = req.user.role;
262
+ let getClientId = reqestData.clientId;
263
+ let totalStores = await getStoresList( getUserEmail, getClientId, getUserType, getRole, req );
264
+ console.log( totalStores.length );
265
+
266
+ if ( totalStores && totalStores.length>0 ) {
267
+ let storeQuery = [];
268
+ if ( reqestData.city.length>0 && reqestData.clusters.length>0 ) {
269
+ let unqueCityStores = await getLocationStores( getClientId, reqestData.city, req );
270
+ let unqueGroupStores = await getClusterStores( getClientId, reqestData.clusters );
271
+ storeQuery = [
272
+ {
273
+ $match: {
274
+ $and: [
275
+ { storeId: { $in: totalStores } },
276
+ { storeId: { $in: unqueCityStores } },
277
+ { storeId: { $in: unqueGroupStores } },
278
+ ],
279
+ },
280
+ },
281
+ {
282
+ $project: {
283
+ _id: 0,
284
+ storeId: '$storeId',
285
+ storeName: '$storeName',
286
+ },
287
+ },
288
+ ];
289
+ } else if ( reqestData.city.length>0 ) {
290
+ let uniqueCityStores = await getLocationStores( getClientId, reqestData.city, req );
291
+ storeQuery = [
292
+ {
293
+ $match: {
294
+ $and: [
295
+ { storeId: { $in: totalStores } },
296
+ { storeId: { $in: uniqueCityStores } },
297
+ ],
298
+ },
299
+ },
300
+ {
301
+ $project: {
302
+ _id: 0,
303
+ storeId: '$storeId',
304
+ storeName: '$storeName',
305
+ },
306
+ },
307
+ ];
308
+ } else if ( reqestData.clusters.length>0 ) {
309
+ let uniqueclusterStores = await getClusterStores( getClientId, reqestData.clusters );
310
+ storeQuery = [
311
+ {
312
+ $match: {
313
+ $and: [
314
+ { storeId: { $in: totalStores } },
315
+ { storeId: { $in: uniqueclusterStores } },
316
+ ],
317
+ },
318
+ },
319
+ {
320
+ $project: {
321
+ _id: 0,
322
+ storeId: '$storeId',
323
+ storeName: '$storeName',
324
+ },
325
+ },
326
+ ];
327
+ } else {
328
+ let totalStores = await getStoresList( getUserEmail, getClientId, getUserType, getRole, req );
329
+ storeQuery = [
330
+ {
331
+ $match: {
332
+ $and: [
333
+ { storeId: { $in: totalStores } },
334
+ ],
335
+ },
336
+ },
337
+ {
338
+ $project: {
339
+ _id: 0,
340
+ storeId: '$storeId',
341
+ storeName: '$storeName',
342
+ },
343
+ },
344
+ ];
345
+ }
346
+
347
+ const storeList = await storeService.aggregate( storeQuery );
348
+ if ( storeList && storeList.length > 0 ) {
349
+ return res.sendSuccess( { storesData: storeList } );
350
+ } else {
351
+ return res.sendError( 'No Stores', 400 );
352
+ }
353
+ } else {
354
+ return res.sendError( 'No Stores', 400 );
355
+ }
356
+ } catch ( error ) {
357
+ logger.error( { error: error, message: req.query, function: 'headerStoresV2' } );
358
+ return res.sendError( { error: error }, 500 );
359
+ }
360
+ };
361
+
362
+
363
+ async function getStoresList( getUserEmail, getClientId, getUserType, getRole, req ) {
364
+ try {
365
+ if ( getUserEmail && getUserEmail !='' && getClientId && getClientId !='' && getUserType && getUserType !='' && getRole && getRole!='' ) {
366
+ let overAllStores = [];
367
+ if ( getUserType == 'tango' ) {
368
+ let getAllS = await getAssignedAllStores( getClientId );
369
+ if ( getAllS && getAllS.length >0 ) {
370
+ overAllStores = getAllS;
371
+ }
372
+ return overAllStores;
373
+ } else if ( getUserType == 'client' ) {
374
+ if ( getRole == 'superadmin' ) {
375
+ let getAllS = await getAssignedAllStores( getClientId );
376
+ if ( getAllS && getAllS.length >0 ) {
377
+ overAllStores = getAllS;
378
+ }
379
+ return overAllStores;
380
+ } else {
381
+ return req.body.assignedStores;
382
+ }
383
+ }
384
+ } else {
385
+ return false;
386
+ }
387
+ } catch ( error ) {
388
+ logger.error( { error: error, message: req.query, function: 'getAllStores' } );
389
+ }
390
+ };
391
+
392
+
393
+ async function getAssignedAllStores( userClientId ) {
394
+ try {
395
+ if ( userClientId && userClientId !='' ) {
396
+ let storeQuery = [
397
+ {
398
+ $match: {
399
+ $and: [
400
+ { clientId: { $eq: userClientId } },
401
+ ],
402
+ },
403
+ },
404
+ {
405
+ $group: {
406
+ _id: null,
407
+ stores: { $push: '$storeId' },
408
+ },
409
+ },
410
+ ];
411
+ const storeList = await storeService.aggregate( storeQuery );
412
+ if ( storeList && storeList.length>0 && storeList[0]?.stores.length > 0 ) {
413
+ let uniqueStores = [ ...new Set( storeList[0].stores ) ];
414
+ return uniqueStores;
415
+ } else {
416
+ return false;
417
+ }
418
+ } else {
419
+ return false;
420
+ }
421
+ } catch ( error ) {
422
+ logger.error( { error: error, message: data, function: 'getAssignedAllStores' } );
423
+ return false;
424
+ }
425
+ }
426
+
427
+
428
+ async function getClusterStores( userClientId, ClusterList ) {
429
+ try {
430
+ if ( userClientId && userClientId !='' && ClusterList && ClusterList.length >0 ) {
431
+ let ClusterQuery = [
432
+ {
433
+ $match: {
434
+ $and: [
435
+ { clientId: { $eq: userClientId } },
436
+ { clusterName: { $in: ClusterList } },
437
+ ],
438
+ },
439
+ },
440
+ {
441
+ $unwind: {
442
+ path: '$storeList', preserveNullAndEmptyArrays: true,
443
+ },
444
+ },
445
+ {
446
+ $group: {
447
+ _id: null,
448
+ storesList: { $push: '$stores' },
449
+ },
450
+ },
451
+ {
452
+ $project: {
453
+ storesList: {
454
+ $reduce: {
455
+ input: '$storesList', // Merge arrays using $reduce
456
+ initialValue: [],
457
+ in: { $concatArrays: [ '$$value', '$$this' ] },
458
+ },
459
+ },
460
+ },
461
+ },
462
+ ];
463
+ const clusterStoreList = await clusterService.aggregateCluster( ClusterQuery );
464
+ if ( clusterStoreList && clusterStoreList.length>0 && clusterStoreList[0]?.storesList.length > 0 ) {
465
+ let storeIds = clusterStoreList[0].storesList.map( ( data ) => data.storeId );
466
+ let uniqueStores = [ ...new Set( storeIds ) ];
467
+ return uniqueStores;
468
+ } else {
469
+ return false;
470
+ }
471
+ } else {
472
+ return false;
473
+ }
474
+ } catch ( error ) {
475
+ logger.error( { error: error, message: data, function: 'getClusterStores' } );
476
+ return false;
477
+ }
478
+ }
479
+
480
+
481
+ async function getLocationStores( userClientId, cityList, req ) {
482
+ try {
483
+ if ( userClientId && userClientId !='' && cityList && cityList.length >0 ) {
484
+ let filter = [
485
+ { clientId: { $eq: userClientId } },
486
+ { 'storeProfile.city': { $in: cityList } },
487
+ ];
488
+ if ( req.body.assignedStores&&req.body.assignedStores.length>0 ) {
489
+ filter.push( { storeId: { $in: req.body.assignedStores } } );
490
+ }
491
+
492
+ let storeQuery = [
493
+ {
494
+ $match: {
495
+ $and: filter,
496
+ },
497
+ },
498
+ {
499
+ $project: {
500
+ _id: 0,
501
+ storeId: '$storeId',
502
+ },
503
+ },
504
+ {
505
+ $group: {
506
+ _id: null,
507
+ stores: { $push: '$storeId' },
508
+ },
509
+ },
510
+ ];
511
+ const cityStoreList = await storeService.aggregate( storeQuery );
512
+ if ( cityStoreList && cityStoreList.length>0 && cityStoreList[0]?.stores.length > 0 ) {
513
+ let uniqueStores = [ ...new Set( cityStoreList[0].stores ) ];
514
+ return uniqueStores;
515
+ } else {
516
+ return [];
517
+ }
518
+ } else {
519
+ return [];
520
+ }
521
+ } catch ( error ) {
522
+ logger.error( { error: error, function: 'getLocationStores' } );
523
+ return false;
524
+ }
525
+ }
@@ -11,6 +11,15 @@ export const checklistSchema = joi.object( {
11
11
  export const checklistValidation = {
12
12
  body: checklistSchema,
13
13
  };
14
+ export const validateHeaderSchemav2 = joi.object( {
15
+ clientId: joi.string().required(),
16
+ city: joi.array().required(),
17
+ clusters: joi.array().required(),
18
+ } );
19
+ export const validateHeaderParamsv2 = {
20
+ body: validateHeaderSchemav2,
21
+ };
22
+
14
23
 
15
24
  export const checklistDetailsSchema = joi.object( {
16
25
  checkListId: joi.string().optional(),
@@ -1,10 +1,10 @@
1
1
 
2
2
 
3
- import { getchecklist, viewchecklist, getMobileUseagelist, storeOpencloselist, getcustomerunattendedlist, storesList, checklistDropdown } from '../controllers/gallery.controller.js';
3
+ import { getchecklist, viewchecklist, getMobileUseagelist, storeOpencloselist, getcustomerunattendedlist, storesList, checklistDropdown, headerStoresV2 } from '../controllers/gallery.controller.js';
4
4
  import express from 'express';
5
5
  export const galleryRouter = express.Router();
6
- import { isAllowedSessionHandler } from 'tango-app-api-middleware';
7
-
6
+ import { validate, isAllowedSessionHandler, isAllowedClient, getAssinedStore } from 'tango-app-api-middleware';
7
+ import * as validationDtos from '../dtos/validation.dtos.js';
8
8
  galleryRouter
9
9
  .post( '/getchecklist', isAllowedSessionHandler, getchecklist );
10
10
  galleryRouter
@@ -19,3 +19,5 @@ galleryRouter
19
19
  .post( '/checklistDropdown', isAllowedSessionHandler, checklistDropdown );
20
20
  galleryRouter
21
21
  .post( '/getcustomerunattendedlist', isAllowedSessionHandler, getcustomerunattendedlist );
22
+ galleryRouter
23
+ .post( '/headerStores_v2', isAllowedSessionHandler, isAllowedClient, validate( validationDtos.validateHeaderParamsv2 ), getAssinedStore, headerStoresV2 );
@@ -0,0 +1,28 @@
1
+ import clusterModel from 'tango-api-schema/schema/cluster.model.js';
2
+
3
+ export async function updateOneCluster( query, record ) {
4
+ return await clusterModel.updateOne( query, { $set: record } );
5
+ };
6
+
7
+ export async function updateCluster( query, record ) {
8
+ return await clusterModel.updateMany( query, record );
9
+ };
10
+
11
+ export async function aggregateCluster( query ) {
12
+ return await clusterModel.aggregate( query );
13
+ };
14
+
15
+ export async function findOneCluster( query ={}, field={} ) {
16
+ return await clusterModel.findOne( query, field );
17
+ };
18
+ export async function deleteCluster( query ={} ) {
19
+ return await clusterModel.deleteOne( query );
20
+ };
21
+
22
+ export async function createclusterModel( data ) {
23
+ return await clusterModel.create( data );
24
+ };
25
+
26
+ export async function findcluster( query, project ) {
27
+ return await clusterModel.find( query, project );
28
+ };