@7365admin1/core 2.73.0 → 2.74.0

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
  # @iservice365/core
2
2
 
3
+ ## 2.74.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 473d453: release changes for person api, organization api, etc
8
+
3
9
  ## 2.73.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -523,6 +523,8 @@ type TOrg = {
523
523
  busInst?: string;
524
524
  status?: string;
525
525
  defaultSite?: string;
526
+ terms?: string;
527
+ policies?: string;
526
528
  createdAt?: string | Date;
527
529
  updatedAt?: string | Date;
528
530
  deletedAt?: string | Date;
@@ -572,6 +574,7 @@ declare function useOrgRepo(): {
572
574
  pages: number;
573
575
  pageRange: string;
574
576
  }>;
577
+ getAdminOrgForResident: () => Promise<mongodb.WithId<bson.Document>>;
575
578
  };
576
579
 
577
580
  declare function useOrgController(): {
@@ -584,6 +587,7 @@ declare function useOrgController(): {
584
587
  getByEmail: (req: Request, res: Response, next: NextFunction) => Promise<void>;
585
588
  update: (req: Request, res: Response, next: NextFunction) => Promise<void>;
586
589
  getOrgsByEmail: (req: Request, res: Response, next: NextFunction) => Promise<void>;
590
+ getAdminOrgForResident: (_req: Request, res: Response, next: NextFunction) => Promise<void>;
587
591
  };
588
592
 
589
593
  /**
@@ -2641,6 +2645,7 @@ type TPerson = {
2641
2645
  platform?: string;
2642
2646
  approvedBy?: TApprover;
2643
2647
  countryCode?: string;
2648
+ callingCode?: string;
2644
2649
  createdAt?: string | Date;
2645
2650
  updatedAt?: string | Date;
2646
2651
  deletedAt?: string | Date;
@@ -2679,6 +2684,7 @@ declare function MPerson(value: TPerson): {
2679
2684
  platForm: string;
2680
2685
  approvedBy: TApprover;
2681
2686
  countryCode: string;
2687
+ callingCode: string;
2682
2688
  createdAt: string | Date;
2683
2689
  updatedAt: string | Date | undefined;
2684
2690
  deletedAt: string | Date | undefined;
package/dist/index.js CHANGED
@@ -4605,6 +4605,8 @@ var orgSchema = import_joi8.default.object({
4605
4605
  busInst: import_joi8.default.string().optional().allow("", null),
4606
4606
  status: import_joi8.default.string().optional().allow("", null),
4607
4607
  defaultSite: import_joi8.default.string().hex().optional().allow("", null),
4608
+ terms: import_joi8.default.string().optional().allow("", null),
4609
+ policies: import_joi8.default.string().optional().allow("", null),
4608
4610
  createdAt: import_joi8.default.string().optional().allow("", null),
4609
4611
  updatedAt: import_joi8.default.string().optional().allow("", null),
4610
4612
  deletedAt: import_joi8.default.string().optional().allow("", null)
@@ -4632,6 +4634,8 @@ function MOrg(value) {
4632
4634
  busInst: value.busInst,
4633
4635
  status: value.status || "active",
4634
4636
  defaultSite: value.defaultSite,
4637
+ terms: value.terms ?? "",
4638
+ policies: value.policies ?? "",
4635
4639
  createdAt: value.createdAt || /* @__PURE__ */ new Date(),
4636
4640
  updatedAt: "",
4637
4641
  deletedAt: ""
@@ -4647,6 +4651,7 @@ function useOrgRepo() {
4647
4651
  }
4648
4652
  const namespace_collection = "organizations";
4649
4653
  const collection = db.collection(namespace_collection);
4654
+ const rolesCollection = db.collection("roles");
4650
4655
  const { delNamespace, getCache, setCache } = (0, import_node_server_utils17.useCache)(namespace_collection);
4651
4656
  async function createIndex() {
4652
4657
  try {
@@ -5126,6 +5131,26 @@ function useOrgRepo() {
5126
5131
  throw error;
5127
5132
  }
5128
5133
  }
5134
+ async function getAdminOrgForResident() {
5135
+ const role = await rolesCollection.findOne({ type: "admin" });
5136
+ if (!role)
5137
+ throw new import_node_server_utils17.NotFoundError("Admin role not found.");
5138
+ let orgId;
5139
+ try {
5140
+ orgId = new import_mongodb15.ObjectId(role.org);
5141
+ } catch {
5142
+ throw new import_node_server_utils17.InternalServerError(
5143
+ "Invalid organization reference in admin role."
5144
+ );
5145
+ }
5146
+ const org = await collection.findOne(
5147
+ { _id: orgId },
5148
+ { projection: { terms: 1, policies: 1, _id: 0 } }
5149
+ );
5150
+ if (!org)
5151
+ throw new import_node_server_utils17.NotFoundError("Organization not found.");
5152
+ return org;
5153
+ }
5129
5154
  return {
5130
5155
  createIndex,
5131
5156
  createTextIndex,
@@ -5140,7 +5165,8 @@ function useOrgRepo() {
5140
5165
  updateStatusById,
5141
5166
  deleteById,
5142
5167
  getOrgsByEmail,
5143
- getOrganizationsWithSubscription
5168
+ getOrganizationsWithSubscription,
5169
+ getAdminOrgForResident
5144
5170
  };
5145
5171
  }
5146
5172
 
@@ -5745,7 +5771,7 @@ function useSiteRepo() {
5745
5771
  try {
5746
5772
  const items = await collection.aggregate([
5747
5773
  ...basePipeline,
5748
- { $project: { _id: 1, name: 1, orgId: 1 } },
5774
+ { $project: { _id: 1, name: 1, orgId: 1, category: 1 } },
5749
5775
  { $skip: page * limit },
5750
5776
  { $limit: limit }
5751
5777
  ]).toArray();
@@ -9230,7 +9256,8 @@ function useOrgController() {
9230
9256
  getAll: _getAll,
9231
9257
  add: _add,
9232
9258
  update: _update,
9233
- getOrgsByEmail: _getOrgsByEmail
9259
+ getOrgsByEmail: _getOrgsByEmail,
9260
+ getAdminOrgForResident: _getAdminOrgForResident
9234
9261
  } = useOrgRepo();
9235
9262
  async function add(req, res, next) {
9236
9263
  const validation = import_joi18.default.object({
@@ -9238,7 +9265,9 @@ function useOrgController() {
9238
9265
  type: import_joi18.default.string().required(),
9239
9266
  nature: import_joi18.default.string().valid(...allowedNatures).required(),
9240
9267
  email: import_joi18.default.string().email().optional().allow("", null),
9241
- contact: import_joi18.default.string().optional().allow("", null)
9268
+ contact: import_joi18.default.string().optional().allow("", null),
9269
+ terms: import_joi18.default.string().optional().allow("", null),
9270
+ policies: import_joi18.default.string().optional().allow("", null)
9242
9271
  });
9243
9272
  const { error } = validation.validate(req.body);
9244
9273
  if (error) {
@@ -9444,7 +9473,9 @@ function useOrgController() {
9444
9473
  type: import_joi18.default.string().optional(),
9445
9474
  nature: import_joi18.default.string().valid(...allowedNatures).optional(),
9446
9475
  email: import_joi18.default.string().email().allow("", null).optional(),
9447
- contact: import_joi18.default.string().allow("", null).optional()
9476
+ contact: import_joi18.default.string().allow("", null).optional(),
9477
+ terms: import_joi18.default.string().optional().allow("", null),
9478
+ policies: import_joi18.default.string().optional().allow("", null)
9448
9479
  });
9449
9480
  const { error } = validation.validate(req.body);
9450
9481
  if (error) {
@@ -9463,6 +9494,15 @@ function useOrgController() {
9463
9494
  next(err);
9464
9495
  }
9465
9496
  }
9497
+ async function getAdminOrgForResident(_req, res, next) {
9498
+ try {
9499
+ const data = await _getAdminOrgForResident();
9500
+ res.status(200).json(data);
9501
+ } catch (error) {
9502
+ import_node_server_utils35.logger.log({ level: "error", message: error.message });
9503
+ next(error);
9504
+ }
9505
+ }
9466
9506
  return {
9467
9507
  add,
9468
9508
  addOnboardingOrg,
@@ -9472,7 +9512,8 @@ function useOrgController() {
9472
9512
  getById,
9473
9513
  getByEmail,
9474
9514
  update,
9475
- getOrgsByEmail
9515
+ getOrgsByEmail,
9516
+ getAdminOrgForResident
9476
9517
  };
9477
9518
  }
9478
9519
 
@@ -14718,7 +14759,8 @@ var schemaPerson = import_joi36.default.object({
14718
14759
  plateNumber: import_joi36.default.string().optional().allow(null, ""),
14719
14760
  platform: import_joi36.default.string().valid("web", "mobile").optional().allow(null, ""),
14720
14761
  approvedBy: schemaApprover.optional().allow(null, ""),
14721
- countryCode: import_joi36.default.string().optional().allow(null, "")
14762
+ countryCode: import_joi36.default.string().optional().allow(null, ""),
14763
+ callingCode: import_joi36.default.string().optional().allow(null, "")
14722
14764
  });
14723
14765
  var schemaUpdatePerson = import_joi36.default.object({
14724
14766
  _id: import_joi36.default.string().hex().required(),
@@ -14742,7 +14784,8 @@ var schemaUpdatePerson = import_joi36.default.object({
14742
14784
  plateNumber: import_joi36.default.string().optional().allow(null, ""),
14743
14785
  platform: import_joi36.default.string().valid("web", "mobile").optional().allow(null, ""),
14744
14786
  approvedBy: schemaApprover.optional().allow(null, ""),
14745
- countryCode: import_joi36.default.string().optional().allow(null, "")
14787
+ countryCode: import_joi36.default.string().optional().allow(null, ""),
14788
+ callingCode: import_joi36.default.string().optional().allow(null, "")
14746
14789
  });
14747
14790
  function MPerson(value) {
14748
14791
  const { error } = schemaPerson.validate(value);
@@ -14816,6 +14859,7 @@ function MPerson(value) {
14816
14859
  platForm: value.platform ?? "",
14817
14860
  approvedBy: value.approvedBy ?? { id: "", name: "" },
14818
14861
  countryCode: value.countryCode ?? "",
14862
+ callingCode: value.callingCode ?? "",
14819
14863
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
14820
14864
  updatedAt: value.updatedAt,
14821
14865
  deletedAt: value.deletedAt
@@ -56519,6 +56563,11 @@ var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
56519
56563
  var schemaFormEntry = import_joi141.default.object({
56520
56564
  _id: import_joi141.default.string().hex().optional().allow("", null),
56521
56565
  formType: import_joi141.default.string().required(),
56566
+ block: import_joi141.default.string().optional().allow(null, ""),
56567
+ level: import_joi141.default.string().optional().allow(null, ""),
56568
+ unit: import_joi141.default.string().optional().allow(null, ""),
56569
+ name: import_joi141.default.string().optional().allow(null, ""),
56570
+ phoneNumber: import_joi141.default.string().optional().allow(null, ""),
56522
56571
  fields: import_joi141.default.object().pattern(
56523
56572
  import_joi141.default.string(),
56524
56573
  import_joi141.default.alternatives().try(
@@ -56674,15 +56723,22 @@ function useFormEntryController() {
56674
56723
  }
56675
56724
  const headerRow = worksheet.getRow(1);
56676
56725
  const headers = headerRow.values.slice(1).map((h) => String(h ?? "").trim());
56726
+ const knownKeys = ["block", "level", "unit", "name", "phoneNumber"];
56727
+ const topLevel = {};
56677
56728
  const fields = {};
56678
56729
  headers.forEach((header) => {
56679
- fields[header] = null;
56730
+ const normalized = toCamelCase(header);
56731
+ if (knownKeys.includes(normalized)) {
56732
+ topLevel[normalized] = null;
56733
+ } else {
56734
+ fields[normalized] = null;
56735
+ }
56680
56736
  });
56681
56737
  const formType = req.file.originalname.replace(/\.[^/.]+$/, "");
56682
- const normalizedFields = normalizeKeys(fields);
56683
56738
  const payload = {
56684
56739
  formType,
56685
- fields: normalizedFields,
56740
+ ...topLevel,
56741
+ fields,
56686
56742
  status: "active" /* ACTIVE */
56687
56743
  };
56688
56744
  const { error, value } = schemaFormEntry.validate(payload, {