@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/dist/index.mjs CHANGED
@@ -4193,6 +4193,8 @@ var orgSchema = Joi8.object({
4193
4193
  busInst: Joi8.string().optional().allow("", null),
4194
4194
  status: Joi8.string().optional().allow("", null),
4195
4195
  defaultSite: Joi8.string().hex().optional().allow("", null),
4196
+ terms: Joi8.string().optional().allow("", null),
4197
+ policies: Joi8.string().optional().allow("", null),
4196
4198
  createdAt: Joi8.string().optional().allow("", null),
4197
4199
  updatedAt: Joi8.string().optional().allow("", null),
4198
4200
  deletedAt: Joi8.string().optional().allow("", null)
@@ -4220,6 +4222,8 @@ function MOrg(value) {
4220
4222
  busInst: value.busInst,
4221
4223
  status: value.status || "active",
4222
4224
  defaultSite: value.defaultSite,
4225
+ terms: value.terms ?? "",
4226
+ policies: value.policies ?? "",
4223
4227
  createdAt: value.createdAt || /* @__PURE__ */ new Date(),
4224
4228
  updatedAt: "",
4225
4229
  deletedAt: ""
@@ -4235,6 +4239,7 @@ function useOrgRepo() {
4235
4239
  }
4236
4240
  const namespace_collection = "organizations";
4237
4241
  const collection = db.collection(namespace_collection);
4242
+ const rolesCollection = db.collection("roles");
4238
4243
  const { delNamespace, getCache, setCache } = useCache9(namespace_collection);
4239
4244
  async function createIndex() {
4240
4245
  try {
@@ -4714,6 +4719,26 @@ function useOrgRepo() {
4714
4719
  throw error;
4715
4720
  }
4716
4721
  }
4722
+ async function getAdminOrgForResident() {
4723
+ const role = await rolesCollection.findOne({ type: "admin" });
4724
+ if (!role)
4725
+ throw new NotFoundError7("Admin role not found.");
4726
+ let orgId;
4727
+ try {
4728
+ orgId = new ObjectId15(role.org);
4729
+ } catch {
4730
+ throw new InternalServerError9(
4731
+ "Invalid organization reference in admin role."
4732
+ );
4733
+ }
4734
+ const org = await collection.findOne(
4735
+ { _id: orgId },
4736
+ { projection: { terms: 1, policies: 1, _id: 0 } }
4737
+ );
4738
+ if (!org)
4739
+ throw new NotFoundError7("Organization not found.");
4740
+ return org;
4741
+ }
4717
4742
  return {
4718
4743
  createIndex,
4719
4744
  createTextIndex,
@@ -4728,7 +4753,8 @@ function useOrgRepo() {
4728
4753
  updateStatusById,
4729
4754
  deleteById,
4730
4755
  getOrgsByEmail,
4731
- getOrganizationsWithSubscription
4756
+ getOrganizationsWithSubscription,
4757
+ getAdminOrgForResident
4732
4758
  };
4733
4759
  }
4734
4760
 
@@ -5347,7 +5373,7 @@ function useSiteRepo() {
5347
5373
  try {
5348
5374
  const items = await collection.aggregate([
5349
5375
  ...basePipeline,
5350
- { $project: { _id: 1, name: 1, orgId: 1 } },
5376
+ { $project: { _id: 1, name: 1, orgId: 1, category: 1 } },
5351
5377
  { $skip: page * limit },
5352
5378
  { $limit: limit }
5353
5379
  ]).toArray();
@@ -8870,7 +8896,8 @@ function useOrgController() {
8870
8896
  getAll: _getAll,
8871
8897
  add: _add,
8872
8898
  update: _update,
8873
- getOrgsByEmail: _getOrgsByEmail
8899
+ getOrgsByEmail: _getOrgsByEmail,
8900
+ getAdminOrgForResident: _getAdminOrgForResident
8874
8901
  } = useOrgRepo();
8875
8902
  async function add(req, res, next) {
8876
8903
  const validation = Joi18.object({
@@ -8878,7 +8905,9 @@ function useOrgController() {
8878
8905
  type: Joi18.string().required(),
8879
8906
  nature: Joi18.string().valid(...allowedNatures).required(),
8880
8907
  email: Joi18.string().email().optional().allow("", null),
8881
- contact: Joi18.string().optional().allow("", null)
8908
+ contact: Joi18.string().optional().allow("", null),
8909
+ terms: Joi18.string().optional().allow("", null),
8910
+ policies: Joi18.string().optional().allow("", null)
8882
8911
  });
8883
8912
  const { error } = validation.validate(req.body);
8884
8913
  if (error) {
@@ -9084,7 +9113,9 @@ function useOrgController() {
9084
9113
  type: Joi18.string().optional(),
9085
9114
  nature: Joi18.string().valid(...allowedNatures).optional(),
9086
9115
  email: Joi18.string().email().allow("", null).optional(),
9087
- contact: Joi18.string().allow("", null).optional()
9116
+ contact: Joi18.string().allow("", null).optional(),
9117
+ terms: Joi18.string().optional().allow("", null),
9118
+ policies: Joi18.string().optional().allow("", null)
9088
9119
  });
9089
9120
  const { error } = validation.validate(req.body);
9090
9121
  if (error) {
@@ -9103,6 +9134,15 @@ function useOrgController() {
9103
9134
  next(err);
9104
9135
  }
9105
9136
  }
9137
+ async function getAdminOrgForResident(_req, res, next) {
9138
+ try {
9139
+ const data = await _getAdminOrgForResident();
9140
+ res.status(200).json(data);
9141
+ } catch (error) {
9142
+ logger25.log({ level: "error", message: error.message });
9143
+ next(error);
9144
+ }
9145
+ }
9106
9146
  return {
9107
9147
  add,
9108
9148
  addOnboardingOrg,
@@ -9112,7 +9152,8 @@ function useOrgController() {
9112
9152
  getById,
9113
9153
  getByEmail,
9114
9154
  update,
9115
- getOrgsByEmail
9155
+ getOrgsByEmail,
9156
+ getAdminOrgForResident
9116
9157
  };
9117
9158
  }
9118
9159
 
@@ -14431,7 +14472,8 @@ var schemaPlate = Joi36.object({
14431
14472
  });
14432
14473
  var schemaFiles = Joi36.object({
14433
14474
  id: Joi36.string().hex().required(),
14434
- name: Joi36.string().optional().allow(null, "")
14475
+ name: Joi36.string().optional().allow(null, ""),
14476
+ mimeType: Joi36.string().optional().allow(null, "")
14435
14477
  });
14436
14478
  var schemaApprover = Joi36.object({
14437
14479
  id: Joi36.string().hex().required(),
@@ -14463,7 +14505,8 @@ var schemaPerson = Joi36.object({
14463
14505
  plateNumber: Joi36.string().optional().allow(null, ""),
14464
14506
  platform: Joi36.string().valid("web", "mobile").optional().allow(null, ""),
14465
14507
  approvedBy: schemaApprover.optional().allow(null, ""),
14466
- countryCode: Joi36.string().optional().allow(null, "")
14508
+ countryCode: Joi36.string().optional().allow(null, ""),
14509
+ callingCode: Joi36.string().optional().allow(null, "")
14467
14510
  });
14468
14511
  var schemaUpdatePerson = Joi36.object({
14469
14512
  _id: Joi36.string().hex().required(),
@@ -14479,6 +14522,9 @@ var schemaUpdatePerson = Joi36.object({
14479
14522
  email: Joi36.string().email().optional().allow(null, ""),
14480
14523
  nric: Joi36.string().optional().allow(null, ""),
14481
14524
  remarks: Joi36.string().optional().allow(null, ""),
14525
+ type: Joi36.string().valid(...PERSON_TYPES).optional().allow(null, ""),
14526
+ org: Joi36.string().hex().optional().allow(null, ""),
14527
+ site: Joi36.string().hex().optional().allow(null, ""),
14482
14528
  companyName: Joi36.array().items(Joi36.string()).optional().allow(null, ""),
14483
14529
  plates: Joi36.array().items(schemaFiles).optional().allow(null, ""),
14484
14530
  isOwner: Joi36.boolean().optional().allow(null, ""),
@@ -14487,7 +14533,8 @@ var schemaUpdatePerson = Joi36.object({
14487
14533
  plateNumber: Joi36.string().optional().allow(null, ""),
14488
14534
  platform: Joi36.string().valid("web", "mobile").optional().allow(null, ""),
14489
14535
  approvedBy: schemaApprover.optional().allow(null, ""),
14490
- countryCode: Joi36.string().optional().allow(null, "")
14536
+ countryCode: Joi36.string().optional().allow(null, ""),
14537
+ callingCode: Joi36.string().optional().allow(null, "")
14491
14538
  });
14492
14539
  function MPerson(value) {
14493
14540
  const { error } = schemaPerson.validate(value);
@@ -14561,6 +14608,7 @@ function MPerson(value) {
14561
14608
  platForm: value.platform ?? "",
14562
14609
  approvedBy: value.approvedBy ?? { id: "", name: "" },
14563
14610
  countryCode: value.countryCode ?? "",
14611
+ callingCode: value.callingCode ?? "",
14564
14612
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
14565
14613
  updatedAt: value.updatedAt,
14566
14614
  deletedAt: value.deletedAt
@@ -56788,6 +56836,11 @@ var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
56788
56836
  var schemaFormEntry = Joi141.object({
56789
56837
  _id: Joi141.string().hex().optional().allow("", null),
56790
56838
  formType: Joi141.string().required(),
56839
+ block: Joi141.string().optional().allow(null, ""),
56840
+ level: Joi141.string().optional().allow(null, ""),
56841
+ unit: Joi141.string().optional().allow(null, ""),
56842
+ name: Joi141.string().optional().allow(null, ""),
56843
+ phoneNumber: Joi141.string().optional().allow(null, ""),
56791
56844
  fields: Joi141.object().pattern(
56792
56845
  Joi141.string(),
56793
56846
  Joi141.alternatives().try(
@@ -56949,15 +57002,22 @@ function useFormEntryController() {
56949
57002
  }
56950
57003
  const headerRow = worksheet.getRow(1);
56951
57004
  const headers = headerRow.values.slice(1).map((h) => String(h ?? "").trim());
57005
+ const knownKeys = ["block", "level", "unit", "name", "phoneNumber"];
57006
+ const topLevel = {};
56952
57007
  const fields = {};
56953
57008
  headers.forEach((header) => {
56954
- fields[header] = null;
57009
+ const normalized = toCamelCase(header);
57010
+ if (knownKeys.includes(normalized)) {
57011
+ topLevel[normalized] = null;
57012
+ } else {
57013
+ fields[normalized] = null;
57014
+ }
56955
57015
  });
56956
57016
  const formType = req.file.originalname.replace(/\.[^/.]+$/, "");
56957
- const normalizedFields = normalizeKeys(fields);
56958
57017
  const payload = {
56959
57018
  formType,
56960
- fields: normalizedFields,
57019
+ ...topLevel,
57020
+ fields,
56961
57021
  status: "active" /* ACTIVE */
56962
57022
  };
56963
57023
  const { error, value } = schemaFormEntry.validate(payload, {