my-typescript-library-rahul52us 2.3.4 → 2.3.6

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.
@@ -148,779 +148,6 @@ const findOneByDocumentIdAndDelete = (data) => __awaiter(void 0, void 0, void 0,
148
148
  }
149
149
  });
150
150
  exports.findOneByDocumentIdAndDelete = findOneByDocumentIdAndDelete;
151
- // export async function getAllDocument(
152
- // workflowData: any,
153
- // noOfLevels: number,
154
- // workflow: string,
155
- // searchValue: string,
156
- // status: string,
157
- // company: string,
158
- // userId: any,
159
- // differentiateFirstLevel: any,
160
- // level: string,
161
- // sort: string | null = "1",
162
- // limit: string | null = "10",
163
- // page: string | null = "1",
164
- // exchangeType: any | null,
165
- // billType: string | null,
166
- // manual: string | null,
167
- // startDate: any,
168
- // endDate: any,
169
- // searchField: any,
170
- // dateFilterKey: string,
171
- // sortByKey: string,
172
- // additionalFiles: string[]
173
- // ) {
174
- // try {
175
- // let matchQuery: any = {};
176
- // if (searchField && searchValue?.trim()) {
177
- // matchQuery[`originalValues.${searchField}`] = {
178
- // $regex: searchValue,
179
- // $options: "i",
180
- // };
181
- // }
182
- // if (startDate) {
183
- // matchQuery[dateFilterKey] = { $gte: new Date(startDate) };
184
- // }
185
- // if (endDate) {
186
- // matchQuery[dateFilterKey] = {
187
- // ...matchQuery[dateFilterKey],
188
- // $lte: new Date(endDate),
189
- // };
190
- // }
191
- // var matchConditions: any = {
192
- // ...matchQuery,
193
- // // company: new mongoose.Types.ObjectId(company),
194
- // workflow: new mongoose.Types.ObjectId(workflow),
195
- // deleted_At: { $exists: false },
196
- // };
197
- // if (level === workflowData?.values?.approvalLevel) {
198
- // matchConditions.isguaranteed = { $eq: true };
199
- // }
200
- // if (exchangeType && Array.isArray(exchangeType)) {
201
- // exchangeType.forEach((typeObj) => {
202
- // Object.entries(typeObj).forEach(([field, value]) => {
203
- // if (!matchConditions[`originalValues.${field}`]) {
204
- // matchConditions[`originalValues.${field}`] = [];
205
- // }
206
- // matchConditions[`originalValues.${field}`].push(value);
207
- // });
208
- // });
209
- // }
210
- // Object.entries(matchConditions).forEach(([field, value]) => {
211
- // if (Array.isArray(value)) {
212
- // matchConditions[field] = { $in: value };
213
- // }
214
- // });
215
- // let pipeline: any = [];
216
- // let expr: any = {};
217
- // let levels = generateLevels(noOfLevels);
218
- // switch (level) {
219
- // case levels[0]:
220
- // switch (status) {
221
- // case "pending":
222
- // expr = {
223
- // $expr: {
224
- // $and: [
225
- // {
226
- // $and: [
227
- // {
228
- // $not: [
229
- // {
230
- // $and: [
231
- // {
232
- // $in: [
233
- // { $arrayElemAt: ["$approval.status", -1] },
234
- // ["approved", "rejected"],
235
- // ],
236
- // },
237
- // {
238
- // $in: [
239
- // { $arrayElemAt: ["$approval.level", -1] },
240
- // [levels[0]],
241
- // ],
242
- // },
243
- // ],
244
- // },
245
- // ],
246
- // },
247
- // {
248
- // $not: [
249
- // {
250
- // $and: [
251
- // {
252
- // $in: [
253
- // { $arrayElemAt: ["$approval.status", -1] },
254
- // ["approved"],
255
- // ],
256
- // },
257
- // {
258
- // $in: [
259
- // { $arrayElemAt: ["$approval.level", -1] },
260
- // [levels[levels.length - 1]],
261
- // ],
262
- // },
263
- // ],
264
- // },
265
- // ],
266
- // },
267
- // ],
268
- // },
269
- // ],
270
- // },
271
- // };
272
- // break;
273
- // case "approved":
274
- // expr = {
275
- // $expr: {
276
- // $or: [
277
- // {
278
- // $and: [
279
- // {
280
- // $in: [
281
- // { $arrayElemAt: ["$approval.status", -1] },
282
- // [status],
283
- // ],
284
- // },
285
- // {
286
- // $in: [
287
- // { $arrayElemAt: ["$approval.level", -1] },
288
- // [levels[levels.length - 1], levels[0]],
289
- // ],
290
- // },
291
- // {
292
- // $not: [{ $eq: ["$approval", []] }],
293
- // },
294
- // ],
295
- // },
296
- // ],
297
- // },
298
- // };
299
- // break;
300
- // case "rejected":
301
- // expr = {
302
- // $expr: {
303
- // $or: [
304
- // {
305
- // $and: [
306
- // {
307
- // $in: [
308
- // { $arrayElemAt: ["$approval.status", -1] },
309
- // [status],
310
- // ],
311
- // },
312
- // {
313
- // $in: [
314
- // { $arrayElemAt: ["$approval.level", -1] },
315
- // [levels[0]],
316
- // ],
317
- // },
318
- // {
319
- // $not: [{ $eq: ["$approval", []] }],
320
- // },
321
- // ],
322
- // },
323
- // ],
324
- // },
325
- // };
326
- // break;
327
- // }
328
- // pipeline = [
329
- // {
330
- // $match: {
331
- // ...matchConditions,
332
- // ...expr,
333
- // },
334
- // },
335
- // ];
336
- // break;
337
- // default:
338
- // let { approvedRoles, rejectedRoles, approvedBy, rejectedBy } =
339
- // getDynamicRoles(noOfLevels, level);
340
- // switch (status) {
341
- // case "pending":
342
- // expr = {
343
- // $expr: {
344
- // $or: [
345
- // {
346
- // $and: [
347
- // {
348
- // $and: [
349
- // {
350
- // $not: [
351
- // {
352
- // $and: [
353
- // {
354
- // $in: [
355
- // {
356
- // $arrayElemAt: ["$approval.status", -1],
357
- // },
358
- // ["approved"],
359
- // ],
360
- // },
361
- // {
362
- // $in: [
363
- // {
364
- // $arrayElemAt: ["$approval.level", -1],
365
- // },
366
- // approvedRoles,
367
- // ],
368
- // },
369
- // ],
370
- // },
371
- // ],
372
- // },
373
- // {
374
- // $not: [
375
- // {
376
- // $and: [
377
- // {
378
- // $in: [
379
- // {
380
- // $arrayElemAt: ["$approval.status", -1],
381
- // },
382
- // ["rejected"],
383
- // ],
384
- // },
385
- // {
386
- // $in: [
387
- // {
388
- // $arrayElemAt: ["$approval.level", -1],
389
- // },
390
- // rejectedRoles,
391
- // ],
392
- // },
393
- // ],
394
- // },
395
- // ],
396
- // },
397
- // level !== levels[1] && {
398
- // $and: [
399
- // {
400
- // $in: [
401
- // {
402
- // $arrayElemAt: ["$approval.status", -1],
403
- // },
404
- // ["approved"],
405
- // ],
406
- // },
407
- // {
408
- // $in: [
409
- // {
410
- // $arrayElemAt: ["$approval.level", -1],
411
- // },
412
- // approvedBy,
413
- // ],
414
- // },
415
- // ],
416
- // },
417
- // {
418
- // $not: [{ $eq: ["$approval", []] }],
419
- // },
420
- // ],
421
- // },
422
- // ],
423
- // },
424
- // level !== levels[levels.length - 1] && {
425
- // $and: [
426
- // {
427
- // $in: [
428
- // {
429
- // $arrayElemAt: ["$approval.status", -1],
430
- // },
431
- // ["rejected"],
432
- // ],
433
- // },
434
- // {
435
- // $in: [
436
- // {
437
- // $arrayElemAt: ["$approval.level", -1],
438
- // },
439
- // rejectedBy,
440
- // ],
441
- // },
442
- // ],
443
- // },
444
- // level === levels[1] && {
445
- // $and: [
446
- // {
447
- // $eq: ["$tags.extraction.type", "automatic"],
448
- // },
449
- // { $eq: ["$approval", []] },
450
- // ],
451
- // },
452
- // ],
453
- // },
454
- // };
455
- // // Only add the userId check for the first level if approval is not empty
456
- // let userIdCheck = {};
457
- // if (level === levels[1] && differentiateFirstLevel) {
458
- // userIdCheck = {
459
- // approval: {
460
- // $elemMatch: {
461
- // userId: { $in: [userId] },
462
- // level: levels[1],
463
- // },
464
- // },
465
- // };
466
- // }
467
- // pipeline = [
468
- // {
469
- // $match: {
470
- // ...matchConditions,
471
- // ...expr,
472
- // ...userIdCheck,
473
- // },
474
- // },
475
- // ];
476
- // break;
477
- // case "approved":
478
- // pipeline = [
479
- // {
480
- // $addFields: {
481
- // filteredApproval: {
482
- // $filter: {
483
- // input: "$approval",
484
- // as: "item",
485
- // cond: { $eq: ["$$item.level", level] },
486
- // },
487
- // },
488
- // },
489
- // },
490
- // {
491
- // $match: {
492
- // ...matchConditions,
493
- // $expr: {
494
- // $and: [
495
- // {
496
- // $and: [
497
- // {
498
- // $eq: [
499
- // {
500
- // $arrayElemAt: ["$filteredApproval.status", -1],
501
- // },
502
- // status,
503
- // ],
504
- // },
505
- // ],
506
- // },
507
- // {
508
- // $cond: {
509
- // if: differentiateFirstLevel,
510
- // then: {
511
- // $eq: [
512
- // {
513
- // $arrayElemAt: ["$filteredApproval.userId", -1],
514
- // },
515
- // userId,
516
- // ],
517
- // },
518
- // else: true,
519
- // },
520
- // },
521
- // {
522
- // $not: [{ $eq: ["$approval", []] }],
523
- // },
524
- // {
525
- // $not: [
526
- // {
527
- // $and: [
528
- // {
529
- // $in: [
530
- // {
531
- // $arrayElemAt: ["$approval.status", -1],
532
- // },
533
- // ["rejected"],
534
- // ],
535
- // },
536
- // {
537
- // $in: [
538
- // {
539
- // $arrayElemAt: ["$approval.level", -1],
540
- // },
541
- // rejectedBy,
542
- // ],
543
- // },
544
- // ],
545
- // },
546
- // ],
547
- // },
548
- // // {
549
- // // $not: [
550
- // // {
551
- // // $and: [
552
- // // {
553
- // // $in: [
554
- // // {
555
- // // $arrayElemAt: ["$approval.status", -1],
556
- // // },
557
- // // ["approved"],
558
- // // ],
559
- // // },
560
- // // {
561
- // // $in: [
562
- // // {
563
- // // $arrayElemAt: ["$approval.level", -1],
564
- // // },
565
- // // approvedBy,
566
- // // ],
567
- // // },
568
- // // ],
569
- // // },
570
- // // ],
571
- // // }
572
- // ],
573
- // },
574
- // },
575
- // },
576
- // ];
577
- // break;
578
- // case "rejected":
579
- // pipeline = [
580
- // {
581
- // $addFields: {
582
- // filteredApproval: {
583
- // $filter: {
584
- // input: "$approval",
585
- // as: "item",
586
- // cond: { $eq: ["$$item.level", level] },
587
- // },
588
- // },
589
- // },
590
- // },
591
- // {
592
- // $match: {
593
- // ...matchConditions,
594
- // $expr: {
595
- // $and: [
596
- // {
597
- // $and: [
598
- // {
599
- // $eq: [
600
- // {
601
- // $arrayElemAt: ["$filteredApproval.status", -1],
602
- // },
603
- // status,
604
- // ],
605
- // },
606
- // ],
607
- // },
608
- // {
609
- // $cond: {
610
- // if: differentiateFirstLevel,
611
- // then: {
612
- // $eq: [
613
- // {
614
- // $arrayElemAt: ["$filteredApproval.userId", -1],
615
- // },
616
- // userId,
617
- // ],
618
- // },
619
- // else: true,
620
- // },
621
- // },
622
- // {
623
- // $not: [{ $eq: ["$approval", []] }],
624
- // },
625
- // // {
626
- // // $not: [
627
- // // {
628
- // // $and: [
629
- // // {
630
- // // $in: [
631
- // // {
632
- // // $arrayElemAt: ["$approval.status", -1],
633
- // // },
634
- // // ["rejected"],
635
- // // ],
636
- // // },
637
- // // {
638
- // // $in: [
639
- // // {
640
- // // $arrayElemAt: ["$approval.level", -1],
641
- // // },
642
- // // rejectedBy,
643
- // // ],
644
- // // },
645
- // // ],
646
- // // },
647
- // // ],
648
- // // },
649
- // {
650
- // $not: [
651
- // {
652
- // $and: [
653
- // {
654
- // $in: [
655
- // {
656
- // $arrayElemAt: ["$approval.status", -1],
657
- // },
658
- // ["approved"],
659
- // ],
660
- // },
661
- // {
662
- // $in: [
663
- // {
664
- // $arrayElemAt: ["$approval.level", -1],
665
- // },
666
- // approvedBy,
667
- // ],
668
- // },
669
- // ],
670
- // },
671
- // ],
672
- // },
673
- // ],
674
- // },
675
- // },
676
- // },
677
- // ];
678
- // }
679
- // break;
680
- // }
681
- // if (manual && (level === levels[0] || level === levels[1])) {
682
- // pipeline = [
683
- // {
684
- // $match: {
685
- // ...matchQuery,
686
- // ...matchConditions,
687
- // "tags.extraction.type": "manual",
688
- // approval: { $eq: [] },
689
- // },
690
- // },
691
- // ];
692
- // } else if (manual) {
693
- // return {
694
- // data: [],
695
- // totalPages: 0,
696
- // };
697
- // }
698
- // const approvalStage: any = [
699
- // {
700
- // $unwind: {
701
- // path: "$approval",
702
- // preserveNullAndEmptyArrays: true,
703
- // },
704
- // },
705
- // {
706
- // $lookup: {
707
- // from: "fs.files",
708
- // localField: "approval.fileId",
709
- // foreignField: "_id",
710
- // as: "approval.fileDetails",
711
- // },
712
- // },
713
- // {
714
- // $unwind: {
715
- // path: "$approval.fileDetails",
716
- // preserveNullAndEmptyArrays: true,
717
- // },
718
- // },
719
- // {
720
- // $lookup: {
721
- // from: "accounts",
722
- // localField: "approval.userId",
723
- // foreignField: "_id",
724
- // as: "approval.userDetails",
725
- // pipeline: [
726
- // {
727
- // $project: {
728
- // _id: 1,
729
- // username: 1,
730
- // role: 1,
731
- // level: 1,
732
- // },
733
- // },
734
- // ],
735
- // },
736
- // },
737
- // {
738
- // $unwind: {
739
- // path: "$approval.userDetails",
740
- // preserveNullAndEmptyArrays: true,
741
- // },
742
- // },
743
- // {
744
- // $group: {
745
- // _id: "$_id",
746
- // document: { $first: "$$ROOT" },
747
- // approvals: {
748
- // $push: {
749
- // $mergeObjects: [
750
- // "$approval",
751
- // {
752
- // file: "$approval.fileDetails",
753
- // user: "$approval.userDetails",
754
- // },
755
- // ],
756
- // },
757
- // },
758
- // },
759
- // },
760
- // {
761
- // $addFields: {
762
- // "document.approval": {
763
- // $filter: {
764
- // input: "$approvals",
765
- // as: "approval",
766
- // cond: { $ne: ["$$approval", {}] },
767
- // },
768
- // },
769
- // },
770
- // },
771
- // {
772
- // $replaceRoot: {
773
- // newRoot: "$document",
774
- // },
775
- // },
776
- // {
777
- // $project: {
778
- // "approval.fileDetails": 0,
779
- // "approval.userDetails": 0,
780
- // },
781
- // },
782
- // ];
783
- // const lookupStages = additionalFiles.map((obj: any) => ({
784
- // $lookup: {
785
- // from: "fs.files",
786
- // localField: `additionalFiles.${obj}`,
787
- // foreignField: "_id",
788
- // as: obj,
789
- // },
790
- // }));
791
- // pipeline = [
792
- // ...pipeline,
793
- // {
794
- // $lookup: {
795
- // from: "fs.files",
796
- // localField: "file",
797
- // foreignField: "_id",
798
- // as: "file",
799
- // },
800
- // },
801
- // {
802
- // "$unwind": {
803
- // "path": "$additionalFiles",
804
- // "preserveNullAndEmptyArrays": true
805
- // }
806
- // },
807
- // {
808
- // "$lookup": {
809
- // "from": "fs.files",
810
- // "localField": "additionalFiles.fileId",
811
- // "foreignField": "_id",
812
- // "as": "lookupResult"
813
- // }
814
- // },
815
- // {
816
- // "$addFields": {
817
- // "lookupResult": {
818
- // "$cond": {
819
- // "if": { "$eq": [{ "$size": "$lookupResult" }, 0] },
820
- // "then": [{}],
821
- // "else": "$lookupResult"
822
- // }
823
- // }
824
- // }
825
- // },
826
- // {
827
- // "$group": {
828
- // "_id": "$_id",
829
- // "originalFields": { "$first": "$$ROOT" },
830
- // "additionalFilesDetails": {
831
- // "$push": {
832
- // "$mergeObjects": [
833
- // "$additionalFiles",
834
- // { "$first": "$lookupResult" }
835
- // ]
836
- // }
837
- // }
838
- // }
839
- // },
840
- // {
841
- // "$replaceRoot": {
842
- // "newRoot": {
843
- // "$mergeObjects": ["$originalFields", { "additionalFilesDetails": "$additionalFilesDetails" }]
844
- // }
845
- // }
846
- // },
847
- // {
848
- // $lookup: {
849
- // from: "fs.files",
850
- // localField: "filexls",
851
- // foreignField: "_id",
852
- // as: "filexls",
853
- // },
854
- // },
855
- // ...lookupStages,
856
- // ...approvalStage,
857
- // ];
858
- // // pipeline = [
859
- // // ...pipeline,
860
- // // {
861
- // // $lookup: {
862
- // // from: "fs.files",
863
- // // localField: "file",
864
- // // foreignField: "_id",
865
- // // as: "file",
866
- // // },
867
- // // },
868
- // // {
869
- // // $lookup: {
870
- // // from: "fs.files",
871
- // // localField: "additionalFiles",
872
- // // foreignField: "_id",
873
- // // as: "additionalFilesDetails",
874
- // // },
875
- // // },
876
- // // {
877
- // // $lookup: {
878
- // // from: "fs.files",
879
- // // localField: "filexls",
880
- // // foreignField: "_id",
881
- // // as: "filexls",
882
- // // },
883
- // // },
884
- // // // ...lookupStages,
885
- // // ...approvalStage,
886
- // // ];
887
- // if (sortByKey) {
888
- // const sortStage: any = {};
889
- // if (sortByKey === "created_At" || sortByKey === "updated_At") {
890
- // sortStage[`${sortByKey}`] = Number(sort);
891
- // } else {
892
- // sortStage[`originalValues.${sortByKey}`] = Number(sort);
893
- // }
894
- // pipeline.push({
895
- // $sort: sortStage,
896
- // });
897
- // }
898
- // let countPipeline = [
899
- // ...pipeline,
900
- // { $group: { _id: null, count: { $sum: 1 } } },
901
- // ];
902
- // if (limit && page) {
903
- // const skip = (parseInt(page) - 1) * parseInt(limit);
904
- // pipeline.push({ $skip: skip } as any, { $limit: parseInt(limit) } as any);
905
- // }
906
- // const [pendingData, totalCount]: any = await Promise.all([
907
- // Document.aggregate(pipeline),
908
- // Document.aggregate(countPipeline),
909
- // ]);
910
- // // fs.writeFileSync('aggregationResult.json', JSON.stringify(pipeline, null, 2));
911
- // let totalPages;
912
- // if (limit) {
913
- // totalPages = Math.ceil(totalCount?.[0]?.count / parseInt(limit));
914
- // }
915
- // return {
916
- // data: pendingData,
917
- // totalPages,
918
- // };
919
- // } catch (error) {
920
- // console.log(error?.message);
921
- // throw new Error(error.message);
922
- // }
923
- // }
924
151
  function getAllDocument(noOfLevels, workflow, searchValue, status, company, userId, differentiateFirstLevel, level, sort = "1", limit = "10", page = "1", exchangeType, billType, manual, startDate, endDate, searchField, dateFilterKey, sortByKey, additionalFiles) {
925
152
  var _a;
926
153
  return __awaiter(this, void 0, void 0, function* () {
@@ -1514,66 +741,6 @@ function getAllDocument(noOfLevels, workflow, searchValue, status, company, user
1514
741
  as: obj,
1515
742
  },
1516
743
  }));
1517
- pipeline = [
1518
- ...pipeline,
1519
- {
1520
- $lookup: {
1521
- from: "fs.files",
1522
- localField: "file",
1523
- foreignField: "_id",
1524
- as: "file",
1525
- },
1526
- },
1527
- {
1528
- $addFields: {
1529
- additionalFileIds: {
1530
- $reduce: {
1531
- input: "$additionalFiles",
1532
- initialValue: [],
1533
- in: {
1534
- $concatArrays: [
1535
- "$$value",
1536
- [
1537
- {
1538
- $cond: {
1539
- if: { $isArray: "$$this" },
1540
- then: "$$this",
1541
- else: {
1542
- $let: {
1543
- vars: {
1544
- key: { $arrayElemAt: [{ $objectToArray: "$$this" }, 0] },
1545
- },
1546
- in: "$$key.v",
1547
- },
1548
- },
1549
- },
1550
- },
1551
- ],
1552
- ],
1553
- },
1554
- },
1555
- },
1556
- },
1557
- },
1558
- {
1559
- $lookup: {
1560
- from: "fs.files",
1561
- localField: "additionalFileIds",
1562
- foreignField: "_id",
1563
- as: "additionalFilesDetails",
1564
- },
1565
- },
1566
- {
1567
- $lookup: {
1568
- from: "fs.files",
1569
- localField: "filexls",
1570
- foreignField: "_id",
1571
- as: "filexls",
1572
- },
1573
- },
1574
- ...lookupStages,
1575
- ...approvalStage,
1576
- ];
1577
744
  // pipeline = [
1578
745
  // ...pipeline,
1579
746
  // {
@@ -1585,59 +752,50 @@ function getAllDocument(noOfLevels, workflow, searchValue, status, company, user
1585
752
  // },
1586
753
  // },
1587
754
  // {
1588
- // $unwind: {
1589
- // path: "$additionalFiles",
1590
- // preserveNullAndEmptyArrays: true,
1591
- // },
755
+ // "$unwind": {
756
+ // "path": "$additionalFiles",
757
+ // "preserveNullAndEmptyArrays": true
758
+ // }
1592
759
  // },
1593
760
  // {
1594
- // $lookup: {
1595
- // from: "fs.files",
1596
- // localField: "additionalFiles.fileId",
1597
- // foreignField: "_id",
1598
- // as: "lookupResult",
1599
- // },
761
+ // "$lookup": {
762
+ // "from": "fs.files",
763
+ // "localField": "additionalFiles.fileId",
764
+ // "foreignField": "_id",
765
+ // "as": "lookupResult"
766
+ // }
1600
767
  // },
1601
768
  // {
1602
- // $addFields: {
1603
- // lookupResult: {
1604
- // $cond: {
1605
- // if: { $eq: [{ $size: "$lookupResult" }, 0] },
1606
- // then: [{}],
1607
- // else: "$lookupResult",
1608
- // },
1609
- // },
1610
- // },
769
+ // "$addFields": {
770
+ // "lookupResult": {
771
+ // "$cond": {
772
+ // "if": { "$eq": [{ "$size": "$lookupResult" }, 0] },
773
+ // "then": [{}],
774
+ // "else": "$lookupResult"
775
+ // }
776
+ // }
777
+ // }
1611
778
  // },
1612
779
  // {
1613
- // $group: {
1614
- // _id: "$_id",
1615
- // originalFields: { $first: "$$ROOT" },
1616
- // additionalFilesDetails: {
1617
- // $push: {
1618
- // $cond: {
1619
- // if: { $or: [{ $eq: ["$additionalFiles", null] }, { $eq: ["$additionalFiles", {}] }] },
1620
- // then: {},
1621
- // else: {
1622
- // $mergeObjects: [
1623
- // { fileId: "$additionalFiles.fileId" },
1624
- // { $first: "$lookupResult" },
1625
- // ],
1626
- // },
1627
- // },
1628
- // },
1629
- // },
1630
- // },
780
+ // "$group": {
781
+ // "_id": "$_id",
782
+ // "originalFields": { "$first": "$$ROOT" },
783
+ // "additionalFilesDetails": {
784
+ // "$push": {
785
+ // "$mergeObjects": [
786
+ // "$additionalFiles",
787
+ // { "$first": "$lookupResult" }
788
+ // ]
789
+ // }
790
+ // }
791
+ // }
1631
792
  // },
1632
793
  // {
1633
- // $replaceRoot: {
1634
- // newRoot: {
1635
- // $mergeObjects: [
1636
- // "$originalFields",
1637
- // { additionalFilesDetails: "$additionalFilesDetails" },
1638
- // ],
1639
- // },
1640
- // },
794
+ // "$replaceRoot": {
795
+ // "newRoot": {
796
+ // "$mergeObjects": ["$originalFields", { "additionalFilesDetails": "$additionalFilesDetails" }]
797
+ // }
798
+ // }
1641
799
  // },
1642
800
  // {
1643
801
  // $lookup: {
@@ -1650,35 +808,35 @@ function getAllDocument(noOfLevels, workflow, searchValue, status, company, user
1650
808
  // ...lookupStages,
1651
809
  // ...approvalStage,
1652
810
  // ];
1653
- // pipeline = [
1654
- // ...pipeline,
1655
- // {
1656
- // $lookup: {
1657
- // from: "fs.files",
1658
- // localField: "file",
1659
- // foreignField: "_id",
1660
- // as: "file",
1661
- // },
1662
- // },
1663
- // {
1664
- // $lookup: {
1665
- // from: "fs.files",
1666
- // localField: "additionalFiles",
1667
- // foreignField: "_id",
1668
- // as: "additionalFilesDetails",
1669
- // },
1670
- // },
1671
- // {
1672
- // $lookup: {
1673
- // from: "fs.files",
1674
- // localField: "filexls",
1675
- // foreignField: "_id",
1676
- // as: "filexls",
1677
- // },
1678
- // },
1679
- // // ...lookupStages,
1680
- // ...approvalStage,
1681
- // ];
811
+ pipeline = [
812
+ // ...pipeline,
813
+ // {
814
+ // $lookup: {
815
+ // from: "fs.files",
816
+ // localField: "file",
817
+ // foreignField: "_id",
818
+ // as: "file",
819
+ // },
820
+ // },
821
+ // {
822
+ // $lookup: {
823
+ // from: "fs.files",
824
+ // localField: "additionalFiles",
825
+ // foreignField: "_id",
826
+ // as: "additionalFilesDetails",
827
+ // },
828
+ // },
829
+ // {
830
+ // $lookup: {
831
+ // from: "fs.files",
832
+ // localField: "filexls",
833
+ // foreignField: "_id",
834
+ // as: "filexls",
835
+ // },
836
+ // },
837
+ ...lookupStages,
838
+ // ...approvalStage,
839
+ ];
1682
840
  if (sortByKey) {
1683
841
  const sortStage = {};
1684
842
  if (sortByKey === "created_At" || sortByKey === "updated_At") {