@7365admin1/core 3.52.14 → 3.52.15-staging.264

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.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@7365admin1/core": patch
3
+ ---
4
+
5
+ Scope `GET /api/post-preloved` to the caller's entitled sites, stop a caller-supplied `status` from returning soft-deleted posts, and authorise the `org` on `GET /api/customers`.
package/dist/index.d.ts CHANGED
@@ -10909,7 +10909,7 @@ declare function MPost(value: TPost): {
10909
10909
  declare function usePostPrelovedRepo(): {
10910
10910
  add: (value: TPost, session?: any) => Promise<ObjectId>;
10911
10911
  getById: (_id: string | ObjectId, userId?: string | ObjectId) => Promise<bson.Document>;
10912
- getAll: ({ search, page, limit, filter, site, status, category, subcategory, userId, }: {
10912
+ getAll: ({ search, page, limit, filter, site, status, category, subcategory, userId, siteScope, }: {
10913
10913
  search?: string | undefined;
10914
10914
  page?: number | undefined;
10915
10915
  limit?: number | undefined;
@@ -10919,6 +10919,12 @@ declare function usePostPrelovedRepo(): {
10919
10919
  category?: string | ObjectId | undefined;
10920
10920
  subcategory?: (string | ObjectId)[] | undefined;
10921
10921
  userId?: string | undefined;
10922
+ /**
10923
+ * The sites this caller may be shown, or `null` for no restriction. Set
10924
+ * only when the request named NO site - see `entitledSites`. Same
10925
+ * parameter, same meaning, as `vehicle.repo.ts`.
10926
+ */
10927
+ siteScope?: string[] | null | undefined;
10922
10928
  }, session?: any) => Promise<{
10923
10929
  items: any[];
10924
10930
  pages: number;
package/dist/index.js CHANGED
@@ -34435,6 +34435,7 @@ function useCustomerController() {
34435
34435
  }
34436
34436
  });
34437
34437
  try {
34438
+ await requireOrgReach(req, org);
34438
34439
  const data = await _getAll({
34439
34440
  search,
34440
34441
  page,
@@ -86827,7 +86828,8 @@ function usePostPrelovedRepo() {
86827
86828
  status,
86828
86829
  category,
86829
86830
  subcategory,
86830
- userId
86831
+ userId,
86832
+ siteScope = null
86831
86833
  }, session) {
86832
86834
  page = page > 0 ? page - 1 : 0;
86833
86835
  if (site) {
@@ -86856,7 +86858,15 @@ function usePostPrelovedRepo() {
86856
86858
  }
86857
86859
  }
86858
86860
  const query2 = {
86859
- status: { $ne: "deleted" /* DELETED */ },
86861
+ // `$ne` and `$in` are both operators on the SAME field, so Mongo ANDs
86862
+ // them: a caller-supplied `status` narrows the answer but can never
86863
+ // widen it back to deleted rows. Written as one object rather than two
86864
+ // spreads because the second spread REPLACED the key - `?status=deleted`
86865
+ // listed every soft-deleted post the noticeboard had hidden.
86866
+ status: {
86867
+ $ne: "deleted" /* DELETED */,
86868
+ ...status && { $in: Array.isArray(status) ? status : [status] }
86869
+ },
86860
86870
  ...site && { site },
86861
86871
  ...search && {
86862
86872
  $or: [
@@ -86864,9 +86874,16 @@ function usePostPrelovedRepo() {
86864
86874
  { description: { $regex: search, $options: "i" } }
86865
86875
  ]
86866
86876
  },
86867
- ...status && {
86868
- status: { $in: Array.isArray(status) ? status : [status] }
86869
- },
86877
+ // The sites this caller may be shown, set only when the request named NO
86878
+ // site - see `entitledSites`. Applied inside the query so the page counts
86879
+ // describe what the caller can actually see. An EMPTY array is a real
86880
+ // answer: `$in: []` matches nothing, which is the fail-closed side, so it
86881
+ // is deliberately not collapsed into the falsy branch alongside `null`.
86882
+ ...siteScope ? {
86883
+ site: {
86884
+ $in: siteScope.filter((id) => import_mongodb166.ObjectId.isValid(id)).map((id) => new import_mongodb166.ObjectId(id))
86885
+ }
86886
+ } : {},
86870
86887
  ...categoryId && { category: categoryId },
86871
86888
  ...subcategoryIds && { subcategory: { $in: subcategoryIds } }
86872
86889
  };
@@ -86979,7 +86996,14 @@ function usePostPrelovedRepo() {
86979
86996
  });
86980
86997
  }
86981
86998
  const query2 = {
86982
- status: { $ne: "deleted" /* DELETED */ },
86999
+ // Same merge as `getAll` above, and for the same reason: the second
87000
+ // spread replaced the key, so `?status=deleted` returned this owner's
87001
+ // soft-deleted posts. Scope is unchanged here - the list is already
87002
+ // bounded to one `createdBy`.
87003
+ status: {
87004
+ $ne: "deleted" /* DELETED */,
87005
+ ...status && { $in: Array.isArray(status) ? status : [status] }
87006
+ },
86983
87007
  createdBy: ownerObjectId,
86984
87008
  ...site && { site },
86985
87009
  ...search && {
@@ -86988,9 +87012,6 @@ function usePostPrelovedRepo() {
86988
87012
  { description: { $regex: search, $options: "i" } }
86989
87013
  ]
86990
87014
  },
86991
- ...status && {
86992
- status: { $in: Array.isArray(status) ? status : [status] }
86993
- },
86994
87015
  ...categoryIds && { category: { $in: categoryIds } }
86995
87016
  };
86996
87017
  const sortObj = buildSortObj(filter);
@@ -87391,12 +87412,16 @@ function usePostPrelovedController() {
87391
87412
  userId
87392
87413
  } = value;
87393
87414
  try {
87415
+ const siteScope = site ? null : await entitledSites(req);
87416
+ if (site)
87417
+ await requireSiteReach(req, site);
87394
87418
  const data = await _getAll({
87395
87419
  page,
87396
87420
  limit,
87397
87421
  search,
87398
87422
  filter,
87399
87423
  site,
87424
+ siteScope,
87400
87425
  status: status ? Array.isArray(status) ? status : [status] : void 0,
87401
87426
  category: category ?? void 0,
87402
87427
  subcategory: subcategory ? Array.isArray(subcategory) ? subcategory : [subcategory] : void 0,