@7365admin1/core 3.64.1 → 3.64.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 3.64.2
4
+
5
+ ### Patch Changes
6
+
7
+ - f90c6f0: Return one row per site from `/api/customer-sites`, named by the site.
8
+
9
+ `getAll` grouped by `{ name, site }`. A customer-sites row is an ENGAGEMENT and
10
+ one site can carry more than one, so two rows for the same site with different
11
+ names both survived as "distinct" — a provider's site list showed four entries
12
+ for three sites, and the site switcher ticked two at once.
13
+
14
+ `name` is also a snapshot from when the engagement was created and goes stale
15
+ when the site is renamed; recency is no guide, since the newer row held the
16
+ staler name. The site is now looked up and its live name projected over the
17
+ snapshot, with the stored name kept as a fallback.
18
+
19
+ The search and the sort both run after the rename, so a site is found and
20
+ ordered by the name it actually has, and the count is derived from the same
21
+ pipeline.
22
+
3
23
  ## 3.64.1
4
24
 
5
25
  ### Patch Changes
package/dist/index.js CHANGED
@@ -14145,7 +14145,6 @@ function useCustomerSiteRepo() {
14145
14145
  cacheOptions.siteScope = scoped.length ? [...scoped].sort().join(",") : "no-site";
14146
14146
  }
14147
14147
  if (search) {
14148
- query2.$or = [{ name: { $regex: search, $options: "i" } }];
14149
14148
  cacheOptions.search = search;
14150
14149
  }
14151
14150
  const cacheKey = (0, import_node_server_utils26.makeCacheKey)(namespace_collection2, cacheOptions);
@@ -14158,8 +14157,20 @@ function useCustomerSiteRepo() {
14158
14157
  const distinctPipeline = [
14159
14158
  { $match: query2 },
14160
14159
  { $sort: sort },
14161
- { $group: { _id: { name: "$name", site: "$site" }, doc: { $first: "$$ROOT" } } },
14160
+ { $group: { _id: "$site", doc: { $first: "$$ROOT" } } },
14162
14161
  { $replaceRoot: { newRoot: "$doc" } },
14162
+ {
14163
+ $lookup: {
14164
+ from: "sites",
14165
+ localField: "site",
14166
+ foreignField: "_id",
14167
+ as: "_liveSite"
14168
+ }
14169
+ },
14170
+ { $unwind: { path: "$_liveSite", preserveNullAndEmptyArrays: true } },
14171
+ { $set: { name: { $ifNull: ["$_liveSite.name", "$name"] } } },
14172
+ { $unset: "_liveSite" },
14173
+ ...search ? [{ $match: { name: { $regex: search, $options: "i" } } }] : [],
14163
14174
  { $sort: sort }
14164
14175
  ];
14165
14176
  const items = await collection.aggregate(
@@ -14170,14 +14181,7 @@ function useCustomerSiteRepo() {
14170
14181
  ],
14171
14182
  { session }
14172
14183
  ).toArray();
14173
- const countResult = await collection.aggregate(
14174
- [
14175
- { $match: query2 },
14176
- { $group: { _id: { name: "$name", site: "$site" } } },
14177
- { $count: "total" }
14178
- ],
14179
- { session }
14180
- ).toArray();
14184
+ const countResult = await collection.aggregate([...distinctPipeline, { $count: "total" }], { session }).toArray();
14181
14185
  const length = countResult[0]?.total ?? 0;
14182
14186
  const data = (0, import_node_server_utils26.paginate)(items, page, limit, length);
14183
14187
  setCache(cacheKey, data, 15 * 60).then(() => {