@7365admin1/core 3.48.1-staging.182 → 3.48.1-staging.184

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/dist/index.js CHANGED
@@ -29881,7 +29881,7 @@ function useSubscriptionService() {
29881
29881
  }
29882
29882
  const items = [];
29883
29883
  const dueInvoice = await getByDueDate(
29884
- subscription.nextBillingDate,
29884
+ new Date(subscription.nextBillingDate),
29885
29885
  "pending"
29886
29886
  );
29887
29887
  if (value.promoCode) {
@@ -30022,7 +30022,13 @@ function useSubscriptionService() {
30022
30022
  {
30023
30023
  _id: value.subscriptionId,
30024
30024
  currentSeats: value.seats,
30025
- maxSeats: 0,
30025
+ // Keep the organisation's own seat limit. It is worked out above —
30026
+ // the current limit, raised when the new seat count is larger — and
30027
+ // was then thrown away here in favour of a literal 0. Now that 0
30028
+ // means UNLIMITED, writing it handed the organisation an uncapped
30029
+ // subscription on every seat change. A plan that really is unlimited
30030
+ // is already 0 above, so it still passes through untouched.
30031
+ maxSeats,
30026
30032
  paidSeats: paidSeats > value.seats ? paidSeats : value.seats,
30027
30033
  promoCode: value.promoCode ?? "",
30028
30034
  amount: value.seats * Number(newMonthlySubscriptionPrice.toFixed(2))
@@ -33693,7 +33699,7 @@ function useBuildingUnitRepo() {
33693
33699
  ...site && { site: (0, import_node_server_utils97.toObjectId)(site) },
33694
33700
  ...building && { building: (0, import_node_server_utils97.toObjectId)(building) }
33695
33701
  };
33696
- sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
33702
+ sort = Object.keys(sort).length > 0 ? sort : { block: 1, "level.name": 1, name: 1, _id: 1 };
33697
33703
  const cacheParams = {
33698
33704
  page,
33699
33705
  limit,
@@ -33757,38 +33763,44 @@ function useBuildingUnitRepo() {
33757
33763
  }
33758
33764
  ] : []
33759
33765
  ];
33760
- const items = await collection.aggregate([
33761
- ...pipeline,
33762
- {
33763
- $lookup: {
33764
- from: "sites",
33765
- let: { siteId: "$site" },
33766
- pipeline: [
33767
- {
33768
- $match: {
33769
- $expr: { $eq: ["$_id", "$$siteId"] },
33770
- status: "active" /* ACTIVE */
33771
- }
33772
- },
33773
- {
33774
- $project: {
33775
- name: 1,
33776
- description: 1,
33777
- orgId: 1,
33778
- metadata: 1,
33779
- status: 1,
33780
- address: 1
33766
+ const items = await collection.aggregate(
33767
+ [
33768
+ ...pipeline,
33769
+ {
33770
+ $lookup: {
33771
+ from: "sites",
33772
+ let: { siteId: "$site" },
33773
+ pipeline: [
33774
+ {
33775
+ $match: {
33776
+ $expr: { $eq: ["$_id", "$$siteId"] },
33777
+ status: "active" /* ACTIVE */
33778
+ }
33779
+ },
33780
+ {
33781
+ $project: {
33782
+ name: 1,
33783
+ description: 1,
33784
+ orgId: 1,
33785
+ metadata: 1,
33786
+ status: 1,
33787
+ address: 1
33788
+ }
33781
33789
  }
33782
- }
33783
- ],
33784
- as: "site"
33785
- }
33786
- },
33787
- { $set: { site: { $first: "$site" } } },
33788
- { $sort: sort },
33789
- { $skip: page * limit },
33790
- { $limit: limit }
33791
- ]).toArray();
33790
+ ],
33791
+ as: "site"
33792
+ }
33793
+ },
33794
+ { $set: { site: { $first: "$site" } } },
33795
+ { $sort: sort },
33796
+ { $skip: page * limit },
33797
+ { $limit: limit }
33798
+ ],
33799
+ // Sort units by block, then level name (natural: Lvl 2 before Lvl 10),
33800
+ // then unit name. Skip collation when a search regex is active (Mongo
33801
+ // rejects $regex + non-simple collation); browse view is what needs it.
33802
+ searchText ? {} : { collation: { locale: "en", numericOrdering: true } }
33803
+ ).toArray();
33792
33804
  const total = await collection.aggregate([...pipeline, { $count: "length" }]).toArray();
33793
33805
  const length = total[0]?.length ?? 0;
33794
33806
  const data = (0, import_node_server_utils97.paginate)(items, page, limit, length);
@@ -33827,7 +33839,7 @@ function useBuildingUnitRepo() {
33827
33839
  ...building && { building: (0, import_node_server_utils97.toObjectId)(building) },
33828
33840
  ...level && { level: (0, import_node_server_utils97.toObjectId)(level) }
33829
33841
  };
33830
- sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
33842
+ sort = Object.keys(sort).length > 0 ? sort : { block: 1, "level.name": 1, name: 1, _id: 1 };
33831
33843
  const cacheParams = {
33832
33844
  page,
33833
33845
  limit,
@@ -33855,35 +33867,40 @@ function useBuildingUnitRepo() {
33855
33867
  });
33856
33868
  return cached;
33857
33869
  }
33858
- const items = await collection.aggregate([
33859
- { $match: query2 },
33860
- {
33861
- $project: {
33862
- site: 1,
33863
- name: 1,
33864
- building: 1,
33865
- buildingName: 1,
33866
- block: 1,
33867
- level: 1,
33868
- unitNumber: 1,
33869
- createdAt: 1,
33870
- updatedAt: 1
33871
- }
33872
- },
33873
- {
33874
- $lookup: {
33875
- from: "building-levels",
33876
- localField: "level",
33877
- foreignField: "_id",
33878
- pipeline: [{ $project: { name: 1 } }],
33879
- as: "level"
33880
- }
33881
- },
33882
- { $set: { level: { $first: "$level" } } },
33883
- { $sort: sort },
33884
- { $skip: page * limit },
33885
- { $limit: limit }
33886
- ]).toArray();
33870
+ const items = await collection.aggregate(
33871
+ [
33872
+ { $match: query2 },
33873
+ {
33874
+ $project: {
33875
+ site: 1,
33876
+ name: 1,
33877
+ building: 1,
33878
+ buildingName: 1,
33879
+ block: 1,
33880
+ level: 1,
33881
+ unitNumber: 1,
33882
+ createdAt: 1,
33883
+ updatedAt: 1
33884
+ }
33885
+ },
33886
+ {
33887
+ $lookup: {
33888
+ from: "building-levels",
33889
+ localField: "level",
33890
+ foreignField: "_id",
33891
+ pipeline: [{ $project: { name: 1 } }],
33892
+ as: "level"
33893
+ }
33894
+ },
33895
+ { $set: { level: { $first: "$level" } } },
33896
+ { $sort: sort },
33897
+ { $skip: page * limit },
33898
+ { $limit: limit }
33899
+ ],
33900
+ // Natural sort by block, level name, unit name. Skip collation when a
33901
+ // $text search is active (Mongo rejects the combo); browse view needs it.
33902
+ search ? {} : { collation: { locale: "en", numericOrdering: true } }
33903
+ ).toArray();
33887
33904
  const length = await collection.countDocuments(query2);
33888
33905
  const data = (0, import_node_server_utils97.paginate)(items, page, limit, length);
33889
33906
  setCache(cacheKey, data, 600).then(() => {
@@ -36064,7 +36081,7 @@ function useBuildingRepo() {
36064
36081
  ]
36065
36082
  }
36066
36083
  };
36067
- sort = Object.keys(sort).length ? sort : { _id: -1 };
36084
+ sort = Object.keys(sort).length ? sort : { name: 1, _id: 1 };
36068
36085
  const cacheParams = {
36069
36086
  page,
36070
36087
  limit,
@@ -36087,36 +36104,44 @@ function useBuildingRepo() {
36087
36104
  });
36088
36105
  return cached;
36089
36106
  }
36090
- const items = await collection.aggregate([
36091
- { $match: query2 },
36092
- {
36093
- $lookup: {
36094
- from: "building-levels",
36095
- let: {
36096
- buildingId: "$_id",
36097
- buildingLevelIds: { $ifNull: ["$levels", []] }
36098
- },
36099
- pipeline: [
36100
- {
36101
- $match: {
36102
- status: "active" /* ACTIVE */,
36103
- $expr: {
36104
- $or: [
36105
- { $in: ["$_id", "$$buildingLevelIds"] },
36106
- { $eq: ["$blockId", "$$buildingId"] }
36107
- ]
36108
- }
36109
- }
36107
+ const items = await collection.aggregate(
36108
+ [
36109
+ { $match: query2 },
36110
+ {
36111
+ $lookup: {
36112
+ from: "building-levels",
36113
+ let: {
36114
+ buildingId: "$_id",
36115
+ buildingLevelIds: { $ifNull: ["$levels", []] }
36110
36116
  },
36111
- { $project: { _id: 1, name: 1 } }
36112
- ],
36113
- as: "levels"
36114
- }
36115
- },
36116
- { $sort: sort },
36117
- { $skip: page * limit },
36118
- { $limit: limit }
36119
- ]).toArray();
36117
+ pipeline: [
36118
+ {
36119
+ $match: {
36120
+ status: "active" /* ACTIVE */,
36121
+ $expr: {
36122
+ $or: [
36123
+ { $in: ["$_id", "$$buildingLevelIds"] },
36124
+ { $eq: ["$blockId", "$$buildingId"] }
36125
+ ]
36126
+ }
36127
+ }
36128
+ },
36129
+ { $project: { _id: 1, name: 1 } },
36130
+ { $sort: { name: 1 } }
36131
+ ],
36132
+ as: "levels"
36133
+ }
36134
+ },
36135
+ { $sort: sort },
36136
+ { $skip: page * limit },
36137
+ { $limit: limit }
36138
+ ],
36139
+ // numericOrdering => natural order (Blk 2 < Blk 100 < Blk 165, and
36140
+ // levels Lvl 2 before Lvl 10). Skip collation when a $text search is
36141
+ // active (Mongo rejects the combo); the default browse view is what
36142
+ // needs the natural ordering.
36143
+ searchText ? {} : { collation: { locale: "en", numericOrdering: true } }
36144
+ ).toArray();
36120
36145
  const length = await collection.countDocuments(query2);
36121
36146
  const data = (0, import_node_server_utils104.paginate)(items, page, limit, length);
36122
36147
  setCache(cacheKey, data, 600).then(() => {
@@ -36465,18 +36490,25 @@ function useBuildingRepo() {
36465
36490
  const cacheOptions = { ...query2 };
36466
36491
  const cacheKey = (0, import_node_server_utils104.makeCacheKey)(buildings_namespace_collection, cacheOptions);
36467
36492
  try {
36468
- const result = await collection.aggregate([
36469
- {
36470
- $match: {
36471
- ...query2
36472
- }
36473
- },
36474
- {
36475
- $project: {
36476
- name: 1
36477
- }
36478
- }
36479
- ]).toArray();
36493
+ const result = await collection.aggregate(
36494
+ [
36495
+ {
36496
+ $match: {
36497
+ ...query2
36498
+ }
36499
+ },
36500
+ {
36501
+ $project: {
36502
+ name: 1
36503
+ }
36504
+ },
36505
+ { $sort: { name: 1, _id: 1 } }
36506
+ ],
36507
+ // numericOrdering => natural order in the block dropdowns
36508
+ // (Blk 2 < Blk 10 < Blk 165). No search branch here, so collation
36509
+ // always applies.
36510
+ { collation: { locale: "en", numericOrdering: true } }
36511
+ ).toArray();
36480
36512
  return {
36481
36513
  success: true,
36482
36514
  message: "Buildings retrieved successfully",
@@ -36641,6 +36673,9 @@ function useBuildingLevelRepo() {
36641
36673
  const { delNamespace: delBuildingNamespace } = (0, import_node_server_utils107.useCache)(
36642
36674
  buildings_namespace_collection
36643
36675
  );
36676
+ const { delNamespace: delUnitNamespace } = (0, import_node_server_utils107.useCache)(
36677
+ building_units_namespace_collection
36678
+ );
36644
36679
  async function createIndexes() {
36645
36680
  try {
36646
36681
  await collection.createIndexes([
@@ -36680,6 +36715,12 @@ function useBuildingLevelRepo() {
36680
36715
  message: `Failed to clear buildings cache: ${err.message}`
36681
36716
  });
36682
36717
  });
36718
+ delUnitNamespace().catch((err) => {
36719
+ import_node_server_utils107.logger.log({
36720
+ level: "error",
36721
+ message: `Failed to clear building-units cache: ${err.message}`
36722
+ });
36723
+ });
36683
36724
  }
36684
36725
  async function add(value, session) {
36685
36726
  try {
@@ -36742,19 +36783,25 @@ function useBuildingLevelRepo() {
36742
36783
  });
36743
36784
  return cached;
36744
36785
  }
36745
- const sortStage = Object.keys(sort).length > 0 ? { $sort: sort } : { $sort: { latestDate: -1 } };
36746
- const items = await collection.aggregate([
36747
- { $match: query2 },
36748
- {
36749
- $addFields: {
36750
- latestDate: { $max: ["$updatedAt", "$createdAt"] }
36751
- }
36752
- },
36753
- sortStage,
36754
- { $unset: "latestDate" },
36755
- { $skip: page * limit },
36756
- { $limit: limit }
36757
- ]).toArray();
36786
+ const sortStage = Object.keys(sort).length > 0 ? { $sort: sort } : { $sort: { name: 1 } };
36787
+ const items = await collection.aggregate(
36788
+ [
36789
+ { $match: query2 },
36790
+ {
36791
+ $addFields: {
36792
+ latestDate: { $max: ["$updatedAt", "$createdAt"] }
36793
+ }
36794
+ },
36795
+ sortStage,
36796
+ { $unset: "latestDate" },
36797
+ { $skip: page * limit },
36798
+ { $limit: limit }
36799
+ ],
36800
+ // numericOrdering gives natural order (Lvl 2 before Lvl 10). Skip
36801
+ // collation when a $text search is active (Mongo rejects the combo);
36802
+ // ordering matters for the default browse list.
36803
+ search ? {} : { collation: { locale: "en", numericOrdering: true } }
36804
+ ).toArray();
36758
36805
  const length = await collection.countDocuments(query2);
36759
36806
  const data = (0, import_node_server_utils107.paginate)(items, page, limit, length);
36760
36807
  setCache(cacheKey, data, 600).then(() => {
@@ -37027,18 +37074,22 @@ function useBuildingLevelRepo() {
37027
37074
  const levelIds = [
37028
37075
  ...new Set(levelsWithUnits.map((l) => l.level.toString()))
37029
37076
  ].map((id) => new import_mongodb70.ObjectId(id));
37030
- const result = await collection.aggregate([
37031
- {
37032
- $match: {
37033
- _id: { $in: levelIds }
37034
- }
37035
- },
37036
- {
37037
- $project: {
37038
- name: 1
37039
- }
37040
- }
37041
- ]).toArray();
37077
+ const result = await collection.aggregate(
37078
+ [
37079
+ {
37080
+ $match: {
37081
+ _id: { $in: levelIds }
37082
+ }
37083
+ },
37084
+ {
37085
+ $project: {
37086
+ name: 1
37087
+ }
37088
+ },
37089
+ { $sort: { name: 1 } }
37090
+ ],
37091
+ { collation: { locale: "en", numericOrdering: true } }
37092
+ ).toArray();
37042
37093
  return {
37043
37094
  success: true,
37044
37095
  message: "Building levels retrieved successfully",
@@ -37679,7 +37730,7 @@ function useBuildingController() {
37679
37730
  search: import_joi53.default.string().optional().allow("", null),
37680
37731
  site: import_joi53.default.string().hex().optional().allow("", null),
37681
37732
  status: import_joi53.default.string().valid(...Object.values(BuildingStatus)).default("active" /* ACTIVE */),
37682
- sort: import_joi53.default.string().valid(...Object.values(SortFields)).default("_id" /* ID */),
37733
+ sort: import_joi53.default.string().valid(...Object.values(SortFields)).optional(),
37683
37734
  order: import_joi53.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */)
37684
37735
  });
37685
37736
  const { error, value } = validation.validate(query2);
@@ -37694,9 +37745,7 @@ function useBuildingController() {
37694
37745
  const status = value.status;
37695
37746
  const site = value.site ?? "";
37696
37747
  const search = value.search ?? "";
37697
- const sortObj = {
37698
- [sort]: order === "asc" /* ASC */ ? 1 : -1
37699
- };
37748
+ const sortObj = sort ? { [sort]: order === "asc" /* ASC */ ? 1 : -1 } : {};
37700
37749
  try {
37701
37750
  const buildings = await _getAll({
37702
37751
  page,
@@ -38311,7 +38360,7 @@ function useBuildingUnitController() {
38311
38360
  site: import_joi54.default.string().hex().length(24).optional().allow("", null),
38312
38361
  building: import_joi54.default.string().hex().optional().allow("", null),
38313
38362
  status: import_joi54.default.string().valid(...Object.values(BuildingStatus)).default("active" /* ACTIVE */),
38314
- sort: import_joi54.default.string().valid(...Object.values(SortFields)).default("_id" /* ID */),
38363
+ sort: import_joi54.default.string().valid(...Object.values(SortFields)).optional(),
38315
38364
  order: import_joi54.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */)
38316
38365
  });
38317
38366
  const query2 = {
@@ -38332,9 +38381,7 @@ function useBuildingUnitController() {
38332
38381
  const sort = value.sort;
38333
38382
  const order = value.order;
38334
38383
  const status = value.status;
38335
- const sortObj = {
38336
- [sort]: order === "asc" /* ASC */ ? -1 : 1
38337
- };
38384
+ const sortObj = sort ? { [sort]: order === "asc" /* ASC */ ? -1 : 1 } : {};
38338
38385
  const site = value.site;
38339
38386
  const building = value.building;
38340
38387
  const search = value.search;
@@ -38477,7 +38524,7 @@ function useBuildingUnitController() {
38477
38524
  site: import_joi54.default.string().hex().length(24).optional().allow("", null),
38478
38525
  building: import_joi54.default.string().hex().optional().allow("", null),
38479
38526
  status: import_joi54.default.string().valid(...Object.values(BuildingStatus)).default("active" /* ACTIVE */),
38480
- sort: import_joi54.default.string().valid(...Object.values(SortFields)).default("_id" /* ID */),
38527
+ sort: import_joi54.default.string().valid(...Object.values(SortFields)).optional(),
38481
38528
  order: import_joi54.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
38482
38529
  level: import_joi54.default.string().hex().length(24).optional().allow(null, "")
38483
38530
  });
@@ -38499,9 +38546,7 @@ function useBuildingUnitController() {
38499
38546
  const sort = value.sort;
38500
38547
  const order = value.order;
38501
38548
  const status = value.status;
38502
- const sortObj = {
38503
- [sort]: order === "asc" /* ASC */ ? -1 : 1
38504
- };
38549
+ const sortObj = sort ? { [sort]: order === "asc" /* ASC */ ? -1 : 1 } : {};
38505
38550
  const site = value.site;
38506
38551
  const building = value.building;
38507
38552
  const search = value.search;