@eeplatform/core 1.0.1 → 1.0.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,11 @@
1
1
  # @eeplatform/core
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 77ac8e2: Revise schools, members and role queries
8
+
3
9
  ## 1.0.1
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -2384,13 +2384,13 @@ declare function MSchool(value: TSchool): TSchool;
2384
2384
  declare function useSchoolRepo(): {
2385
2385
  createIndex: () => Promise<void>;
2386
2386
  add: (value: TSchool, session?: ClientSession) => Promise<ObjectId>;
2387
- getAll: ({ page, limit, sort, status, region, division, search, }?: {
2387
+ getAll: ({ page, limit, sort, status, org, app, search, }?: {
2388
2388
  page?: number | undefined;
2389
2389
  limit?: number | undefined;
2390
2390
  sort?: Record<string, number> | undefined;
2391
2391
  status?: string | undefined;
2392
- region?: string | undefined;
2393
- division?: string | undefined;
2392
+ org?: string | undefined;
2393
+ app?: string | undefined;
2394
2394
  search?: string | undefined;
2395
2395
  }) => Promise<{}>;
2396
2396
  updateStatusById: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
package/dist/index.js CHANGED
@@ -11804,10 +11804,12 @@ var MUser = class {
11804
11804
  this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
11805
11805
  this.updatedAt = value.updatedAt ?? "";
11806
11806
  this.deletedAt = value.deletedAt ?? "";
11807
- try {
11808
- value.defaultOrg = new import_mongodb3.ObjectId(value.defaultOrg);
11809
- } catch (error) {
11810
- throw new Error("Invalid defaultOrg ID.");
11807
+ if (value.defaultOrg) {
11808
+ try {
11809
+ value.defaultOrg = new import_mongodb3.ObjectId(value.defaultOrg);
11810
+ } catch (error) {
11811
+ throw new Error("Invalid defaultOrg ID.");
11812
+ }
11811
11813
  }
11812
11814
  this.defaultOrg = value.defaultOrg;
11813
11815
  }
@@ -12847,9 +12849,6 @@ function useVerificationService() {
12847
12849
  if (!metadata.app) {
12848
12850
  throw new import_nodejs_utils6.BadRequestError("App metadata is required.");
12849
12851
  }
12850
- if (!metadata.org || !metadata.orgName) {
12851
- throw new import_nodejs_utils6.BadRequestError("Organization metadata is required.");
12852
- }
12853
12852
  try {
12854
12853
  const user = await getUserByEmail(email);
12855
12854
  const dir = __dirname;
@@ -12861,7 +12860,7 @@ function useVerificationService() {
12861
12860
  context: {
12862
12861
  validity: VERIFICATION_USER_INVITE_DURATION,
12863
12862
  link: `${APP_MAIN}/verify/member-invite/${res2}`,
12864
- organization_name: metadata.orgName
12863
+ organization_name: metadata.app === "admin" ? "Admin" : metadata.orgName
12865
12864
  },
12866
12865
  filePath: filePath2
12867
12866
  });
@@ -13032,11 +13031,6 @@ function useVerificationService() {
13032
13031
  "App metadata is required for member invite."
13033
13032
  );
13034
13033
  }
13035
- if (!_id.metadata?.org || !_id.metadata?.orgName) {
13036
- throw new import_nodejs_utils6.BadRequestError(
13037
- "Organization metadata is required for member invite."
13038
- );
13039
- }
13040
13034
  if (!_id.metadata?.role || !_id.metadata?.roleName) {
13041
13035
  throw new import_nodejs_utils6.BadRequestError(
13042
13036
  "Role metadata is required for member invite."
@@ -13046,8 +13040,8 @@ function useVerificationService() {
13046
13040
  {
13047
13041
  user: user._id?.toString() ?? "",
13048
13042
  type: _id.metadata?.app,
13049
- org: _id.metadata?.org,
13050
- orgName: _id.metadata?.orgName,
13043
+ org: _id.metadata?.org ?? "",
13044
+ orgName: _id.metadata?.orgName ?? "",
13051
13045
  role: _id.metadata?.role,
13052
13046
  roleName: _id.metadata?.roleName,
13053
13047
  name: `${user.firstName} ${user.lastName}`
@@ -13166,8 +13160,8 @@ function useVerificationController() {
13166
13160
  app: import_joi2.default.string().required(),
13167
13161
  role: import_joi2.default.string().hex().required(),
13168
13162
  roleName: import_joi2.default.string().required(),
13169
- org: import_joi2.default.string().required(),
13170
- orgName: import_joi2.default.string().required()
13163
+ org: import_joi2.default.string().hex().optional().optional().allow("", null),
13164
+ orgName: import_joi2.default.string().optional().optional().allow("", null)
13171
13165
  });
13172
13166
  const { error } = validation.validate(req.body);
13173
13167
  if (error) {
@@ -17980,9 +17974,6 @@ function useUserService() {
17980
17974
  throw new import_nodejs_utils12.BadRequestError("Invitation expired.");
17981
17975
  }
17982
17976
  const email = invitation.email;
17983
- if (!invitation.metadata.org) {
17984
- throw new import_nodejs_utils12.BadRequestError("Invitation does not have an organization.");
17985
- }
17986
17977
  const _user = await getUserByEmail(invitation.email);
17987
17978
  let userId = _user?._id ?? "";
17988
17979
  if (!_user) {
@@ -18007,8 +17998,8 @@ function useUserService() {
18007
17998
  role: invitation.metadata?.role,
18008
17999
  roleName: invitation.metadata?.roleName,
18009
18000
  type: invitation.metadata?.app,
18010
- org: invitation.metadata?.org,
18011
- orgName: invitation.metadata?.orgName
18001
+ org: invitation.metadata?.org ?? "",
18002
+ orgName: invitation.metadata?.orgName ?? ""
18012
18003
  },
18013
18004
  session
18014
18005
  );
@@ -26524,8 +26515,8 @@ function useSchoolRepo() {
26524
26515
  limit = 20,
26525
26516
  sort = {},
26526
26517
  status = "active",
26527
- region = "",
26528
- division = "",
26518
+ org = "",
26519
+ app = "admin",
26529
26520
  search = ""
26530
26521
  } = {}) {
26531
26522
  page = Math.max(0, page - 1);
@@ -26543,20 +26534,12 @@ function useSchoolRepo() {
26543
26534
  query.$text = { $search: search };
26544
26535
  cacheKeyOptions.search = search;
26545
26536
  }
26546
- if (region) {
26547
- try {
26548
- query.region = new import_mongodb38.ObjectId(region);
26549
- cacheKeyOptions.region = region;
26550
- } catch (error) {
26551
- throw new import_nodejs_utils63.BadRequestError("Invalid region.");
26552
- }
26553
- }
26554
- if (division) {
26537
+ if (org) {
26555
26538
  try {
26556
- query.division = new import_mongodb38.ObjectId(division);
26557
- cacheKeyOptions.division = division;
26539
+ query[app] = new import_mongodb38.ObjectId(org);
26540
+ cacheKeyOptions[app] = org;
26558
26541
  } catch (error) {
26559
- throw new import_nodejs_utils63.BadRequestError("Invalid division.");
26542
+ throw new import_nodejs_utils63.BadRequestError("Invalid org.");
26560
26543
  }
26561
26544
  }
26562
26545
  try {
@@ -26846,8 +26829,8 @@ function useSchoolController() {
26846
26829
  sort: import_joi32.default.string().optional().allow(null, ""),
26847
26830
  sortOrder: import_joi32.default.string().optional().allow(null, ""),
26848
26831
  status: import_joi32.default.string().optional().allow(null, ""),
26849
- region: import_joi32.default.string().hex().optional().allow(null, ""),
26850
- division: import_joi32.default.string().hex().optional().allow(null, ""),
26832
+ org: import_joi32.default.string().hex().optional().allow(null, ""),
26833
+ app: import_joi32.default.string().optional().allow(null, ""),
26851
26834
  search: import_joi32.default.string().optional().allow(null, "")
26852
26835
  });
26853
26836
  const { error } = validation.validate(req.query);
@@ -26867,8 +26850,8 @@ function useSchoolController() {
26867
26850
  });
26868
26851
  }
26869
26852
  const status = req.query.status ?? "active";
26870
- const region = req.query.region ?? "";
26871
- const division = req.query.division ?? "";
26853
+ const org = req.query.org ?? "";
26854
+ const app = req.query.app ?? "admin";
26872
26855
  const search = req.query.search ?? "";
26873
26856
  try {
26874
26857
  const schools = await _getAll({
@@ -26876,8 +26859,8 @@ function useSchoolController() {
26876
26859
  limit,
26877
26860
  sort: sortObj,
26878
26861
  status,
26879
- region,
26880
- division,
26862
+ org,
26863
+ app,
26881
26864
  search
26882
26865
  });
26883
26866
  res.status(200).json(schools);