@7365admin1/core 2.73.0 → 2.75.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,17 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 2.75.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ba3e599: release latest changes for person API, preloved API, etc.
8
+
9
+ ## 2.74.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 473d453: release changes for person api, organization api, etc
14
+
3
15
  ## 2.73.0
4
16
 
5
17
  ### 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
  /**
@@ -2608,6 +2612,7 @@ declare enum PersonStatus {
2608
2612
  type TFiles = {
2609
2613
  id: string | ObjectId;
2610
2614
  name: string;
2615
+ mimeType?: string;
2611
2616
  };
2612
2617
  type TApprover = {
2613
2618
  id: string | ObjectId;
@@ -2641,6 +2646,7 @@ type TPerson = {
2641
2646
  platform?: string;
2642
2647
  approvedBy?: TApprover;
2643
2648
  countryCode?: string;
2649
+ callingCode?: string;
2644
2650
  createdAt?: string | Date;
2645
2651
  updatedAt?: string | Date;
2646
2652
  deletedAt?: string | Date;
@@ -2679,6 +2685,7 @@ declare function MPerson(value: TPerson): {
2679
2685
  platForm: string;
2680
2686
  approvedBy: TApprover;
2681
2687
  countryCode: string;
2688
+ callingCode: string;
2682
2689
  createdAt: string | Date;
2683
2690
  updatedAt: string | Date | undefined;
2684
2691
  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
 
@@ -14686,7 +14727,8 @@ var schemaPlate = import_joi36.default.object({
14686
14727
  });
14687
14728
  var schemaFiles = import_joi36.default.object({
14688
14729
  id: import_joi36.default.string().hex().required(),
14689
- name: import_joi36.default.string().optional().allow(null, "")
14730
+ name: import_joi36.default.string().optional().allow(null, ""),
14731
+ mimeType: import_joi36.default.string().optional().allow(null, "")
14690
14732
  });
14691
14733
  var schemaApprover = import_joi36.default.object({
14692
14734
  id: import_joi36.default.string().hex().required(),
@@ -14718,7 +14760,8 @@ var schemaPerson = import_joi36.default.object({
14718
14760
  plateNumber: import_joi36.default.string().optional().allow(null, ""),
14719
14761
  platform: import_joi36.default.string().valid("web", "mobile").optional().allow(null, ""),
14720
14762
  approvedBy: schemaApprover.optional().allow(null, ""),
14721
- countryCode: import_joi36.default.string().optional().allow(null, "")
14763
+ countryCode: import_joi36.default.string().optional().allow(null, ""),
14764
+ callingCode: import_joi36.default.string().optional().allow(null, "")
14722
14765
  });
14723
14766
  var schemaUpdatePerson = import_joi36.default.object({
14724
14767
  _id: import_joi36.default.string().hex().required(),
@@ -14734,6 +14777,9 @@ var schemaUpdatePerson = import_joi36.default.object({
14734
14777
  email: import_joi36.default.string().email().optional().allow(null, ""),
14735
14778
  nric: import_joi36.default.string().optional().allow(null, ""),
14736
14779
  remarks: import_joi36.default.string().optional().allow(null, ""),
14780
+ type: import_joi36.default.string().valid(...PERSON_TYPES).optional().allow(null, ""),
14781
+ org: import_joi36.default.string().hex().optional().allow(null, ""),
14782
+ site: import_joi36.default.string().hex().optional().allow(null, ""),
14737
14783
  companyName: import_joi36.default.array().items(import_joi36.default.string()).optional().allow(null, ""),
14738
14784
  plates: import_joi36.default.array().items(schemaFiles).optional().allow(null, ""),
14739
14785
  isOwner: import_joi36.default.boolean().optional().allow(null, ""),
@@ -14742,7 +14788,8 @@ var schemaUpdatePerson = import_joi36.default.object({
14742
14788
  plateNumber: import_joi36.default.string().optional().allow(null, ""),
14743
14789
  platform: import_joi36.default.string().valid("web", "mobile").optional().allow(null, ""),
14744
14790
  approvedBy: schemaApprover.optional().allow(null, ""),
14745
- countryCode: import_joi36.default.string().optional().allow(null, "")
14791
+ countryCode: import_joi36.default.string().optional().allow(null, ""),
14792
+ callingCode: import_joi36.default.string().optional().allow(null, "")
14746
14793
  });
14747
14794
  function MPerson(value) {
14748
14795
  const { error } = schemaPerson.validate(value);
@@ -14816,6 +14863,7 @@ function MPerson(value) {
14816
14863
  platForm: value.platform ?? "",
14817
14864
  approvedBy: value.approvedBy ?? { id: "", name: "" },
14818
14865
  countryCode: value.countryCode ?? "",
14866
+ callingCode: value.callingCode ?? "",
14819
14867
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
14820
14868
  updatedAt: value.updatedAt,
14821
14869
  deletedAt: value.deletedAt
@@ -56519,6 +56567,11 @@ var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
56519
56567
  var schemaFormEntry = import_joi141.default.object({
56520
56568
  _id: import_joi141.default.string().hex().optional().allow("", null),
56521
56569
  formType: import_joi141.default.string().required(),
56570
+ block: import_joi141.default.string().optional().allow(null, ""),
56571
+ level: import_joi141.default.string().optional().allow(null, ""),
56572
+ unit: import_joi141.default.string().optional().allow(null, ""),
56573
+ name: import_joi141.default.string().optional().allow(null, ""),
56574
+ phoneNumber: import_joi141.default.string().optional().allow(null, ""),
56522
56575
  fields: import_joi141.default.object().pattern(
56523
56576
  import_joi141.default.string(),
56524
56577
  import_joi141.default.alternatives().try(
@@ -56674,15 +56727,22 @@ function useFormEntryController() {
56674
56727
  }
56675
56728
  const headerRow = worksheet.getRow(1);
56676
56729
  const headers = headerRow.values.slice(1).map((h) => String(h ?? "").trim());
56730
+ const knownKeys = ["block", "level", "unit", "name", "phoneNumber"];
56731
+ const topLevel = {};
56677
56732
  const fields = {};
56678
56733
  headers.forEach((header) => {
56679
- fields[header] = null;
56734
+ const normalized = toCamelCase(header);
56735
+ if (knownKeys.includes(normalized)) {
56736
+ topLevel[normalized] = null;
56737
+ } else {
56738
+ fields[normalized] = null;
56739
+ }
56680
56740
  });
56681
56741
  const formType = req.file.originalname.replace(/\.[^/.]+$/, "");
56682
- const normalizedFields = normalizeKeys(fields);
56683
56742
  const payload = {
56684
56743
  formType,
56685
- fields: normalizedFields,
56744
+ ...topLevel,
56745
+ fields,
56686
56746
  status: "active" /* ACTIVE */
56687
56747
  };
56688
56748
  const { error, value } = schemaFormEntry.validate(payload, {