@goweekdays/core 2.1.4 → 2.2.1

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
@@ -833,15 +833,15 @@ function useAuthService() {
833
833
  // src/resources/auth/auth.controller.ts
834
834
  import Joi14 from "joi";
835
835
  import {
836
- AppError as AppError7,
837
- BadRequestError as BadRequestError24,
836
+ AppError as AppError8,
837
+ BadRequestError as BadRequestError25,
838
838
  InternalServerError as InternalServerError13,
839
839
  logger as logger17
840
840
  } from "@goweekdays/utils";
841
841
 
842
842
  // src/resources/user/user.service.ts
843
843
  import {
844
- BadRequestError as BadRequestError23,
844
+ BadRequestError as BadRequestError24,
845
845
  InternalServerError as InternalServerError12,
846
846
  NotFoundError as NotFoundError4,
847
847
  hashPassword,
@@ -1386,6 +1386,56 @@ function MMember(value) {
1386
1386
  deletedAt: ""
1387
1387
  };
1388
1388
  }
1389
+ var schemaMember = Joi3.object({
1390
+ org: Joi3.string().hex().optional().allow("", null),
1391
+ orgName: Joi3.string().optional().allow("", null),
1392
+ name: Joi3.string().required(),
1393
+ user: Joi3.string().hex().required(),
1394
+ role: Joi3.string().hex().required(),
1395
+ roleName: Joi3.string().optional().allow("", null),
1396
+ type: Joi3.string().required()
1397
+ });
1398
+ function modelMember(value) {
1399
+ const { error } = schemaMember.validate(value);
1400
+ if (error) {
1401
+ throw new BadRequestError9(error.message);
1402
+ }
1403
+ if (value.org) {
1404
+ try {
1405
+ value.org = new ObjectId8(value.org);
1406
+ } catch (error2) {
1407
+ throw new BadRequestError9("Invalid org ID.");
1408
+ }
1409
+ }
1410
+ if (value.user) {
1411
+ try {
1412
+ value.user = new ObjectId8(value.user);
1413
+ } catch (error2) {
1414
+ throw new BadRequestError9("Invalid user ID.");
1415
+ }
1416
+ }
1417
+ if (value.role) {
1418
+ try {
1419
+ value.role = new ObjectId8(value.role);
1420
+ } catch (error2) {
1421
+ throw new BadRequestError9("Invalid role ID.");
1422
+ }
1423
+ }
1424
+ return {
1425
+ _id: value._id,
1426
+ org: value.org ?? "",
1427
+ orgName: value.orgName ?? "",
1428
+ name: value.name,
1429
+ user: value.user,
1430
+ type: value.type,
1431
+ role: value.role,
1432
+ roleName: value.roleName ?? "",
1433
+ status: value.status ?? "active",
1434
+ createdAt: value.createdAt || /* @__PURE__ */ new Date(),
1435
+ updatedAt: "",
1436
+ deletedAt: ""
1437
+ };
1438
+ }
1389
1439
 
1390
1440
  // src/resources/member/member.repository.ts
1391
1441
  import { ObjectId as ObjectId9 } from "mongodb";
@@ -1454,7 +1504,7 @@ function useMemberRepo() {
1454
1504
  }
1455
1505
  async function add(value, session) {
1456
1506
  try {
1457
- value = MMember(value);
1507
+ value = modelMember(value);
1458
1508
  await collection.insertOne(value, { session });
1459
1509
  delCachedData();
1460
1510
  return "Successfully added member.";
@@ -1507,6 +1557,43 @@ function useMemberRepo() {
1507
1557
  );
1508
1558
  }
1509
1559
  }
1560
+ async function getByRole(role) {
1561
+ try {
1562
+ role = new ObjectId9(role);
1563
+ } catch (error) {
1564
+ throw new BadRequestError10("Invalid role ID.");
1565
+ }
1566
+ try {
1567
+ const cacheKey = makeCacheKey5(namespace_collection, {
1568
+ role: role.toString()
1569
+ });
1570
+ const cached = await getCache(cacheKey);
1571
+ if (cached) {
1572
+ logger5.log({
1573
+ level: "info",
1574
+ message: `Cache hit for getById member: ${cacheKey}`
1575
+ });
1576
+ return cached;
1577
+ }
1578
+ const data = await collection.findOne({ role });
1579
+ setCache(cacheKey, data, 300).then(() => {
1580
+ logger5.log({
1581
+ level: "info",
1582
+ message: `Cache set for member by role: ${cacheKey}`
1583
+ });
1584
+ }).catch((err) => {
1585
+ logger5.log({
1586
+ level: "error",
1587
+ message: `Failed to set cache for member by role: ${err.message}`
1588
+ });
1589
+ });
1590
+ return data;
1591
+ } catch (error) {
1592
+ throw new InternalServerError5(
1593
+ "Internal server error, failed to retrieve member."
1594
+ );
1595
+ }
1596
+ }
1510
1597
  async function getByUserId(user) {
1511
1598
  try {
1512
1599
  user = new ObjectId9(user);
@@ -1957,6 +2044,7 @@ function useMemberRepo() {
1957
2044
  createTextIndex,
1958
2045
  add,
1959
2046
  getById,
2047
+ getByRole,
1960
2048
  getAll,
1961
2049
  getOrgsByUserId,
1962
2050
  updateStatusByUserId,
@@ -2304,49 +2392,51 @@ import { ObjectId as ObjectId15 } from "mongodb";
2304
2392
 
2305
2393
  // src/resources/role/role.repository.ts
2306
2394
  import {
2307
- BadRequestError as BadRequestError12,
2395
+ BadRequestError as BadRequestError13,
2308
2396
  InternalServerError as InternalServerError7,
2309
2397
  useAtlas as useAtlas7,
2310
2398
  paginate as paginate4,
2311
2399
  logger as logger7,
2312
2400
  makeCacheKey as makeCacheKey6,
2313
- useCache as useCache7
2401
+ useCache as useCache7,
2402
+ AppError as AppError3
2314
2403
  } from "@goweekdays/utils";
2315
2404
 
2316
2405
  // src/resources/role/role.model.ts
2406
+ import { BadRequestError as BadRequestError12 } from "@goweekdays/utils";
2317
2407
  import Joi4 from "joi";
2318
2408
  import { ObjectId as ObjectId10 } from "mongodb";
2319
2409
  var schemaRole = Joi4.object({
2320
2410
  name: Joi4.string().required(),
2321
2411
  description: Joi4.string().max(1024).optional().allow("", null),
2322
2412
  permissions: Joi4.array().items(Joi4.string()).required(),
2323
- type: Joi4.string().required(),
2324
- org: Joi4.string().hex().optional().allow("", null)
2413
+ org: Joi4.string().hex().optional().allow("", null),
2414
+ createdBy: Joi4.string().hex().required()
2325
2415
  });
2326
2416
  function modelRole(value) {
2327
2417
  const { error } = schemaRole.validate(value);
2328
2418
  if (error) {
2329
- throw new Error(error.message);
2419
+ throw new BadRequestError12(error.message);
2330
2420
  }
2331
2421
  if (value._id && typeof value._id === "string") {
2332
2422
  try {
2333
2423
  value._id = new ObjectId10(value._id);
2334
2424
  } catch (error2) {
2335
- throw new Error("Invalid _id.");
2425
+ throw new BadRequestError12("Invalid _id.");
2336
2426
  }
2337
2427
  }
2338
2428
  if (value.org && typeof value.org === "string" && value.org.length === 24) {
2339
2429
  try {
2340
2430
  value.org = new ObjectId10(value.org);
2341
2431
  } catch (error2) {
2342
- throw new Error("Invalid org.");
2432
+ throw new BadRequestError12("Invalid org.");
2343
2433
  }
2344
2434
  }
2345
2435
  if (value.createdBy && typeof value.createdBy === "string" && value.createdBy.length === 24) {
2346
2436
  try {
2347
2437
  value.createdBy = new ObjectId10(value.createdBy);
2348
2438
  } catch (error2) {
2349
- throw new Error("Invalid createdBy.");
2439
+ throw new BadRequestError12("Invalid createdBy.");
2350
2440
  }
2351
2441
  }
2352
2442
  return {
@@ -2354,7 +2444,6 @@ function modelRole(value) {
2354
2444
  name: value.name,
2355
2445
  description: value.description ?? "",
2356
2446
  permissions: value.permissions,
2357
- type: value.type,
2358
2447
  org: value.org,
2359
2448
  status: value.status ?? "active",
2360
2449
  default: value.default ?? false,
@@ -2427,16 +2516,20 @@ function useRoleRepo() {
2427
2516
  logger7.log({ level: "error", message: `${error}` });
2428
2517
  const isDuplicated = error.message.includes("duplicate");
2429
2518
  if (isDuplicated) {
2430
- throw new BadRequestError12("Role already exists");
2519
+ throw new BadRequestError13("Role already exists");
2520
+ }
2521
+ if (error instanceof AppError3) {
2522
+ throw error;
2523
+ } else {
2524
+ throw new InternalServerError7("Failed to create role.");
2431
2525
  }
2432
- throw new InternalServerError7("Failed to create role.");
2433
2526
  }
2434
2527
  }
2435
2528
  async function getRoleByUserId(value) {
2436
2529
  try {
2437
2530
  value = new ObjectId11(value);
2438
2531
  } catch (error) {
2439
- throw new BadRequestError12("Invalid user ID.");
2532
+ throw new BadRequestError13("Invalid user ID.");
2440
2533
  }
2441
2534
  try {
2442
2535
  const cacheKey = makeCacheKey6(namespace_collection, {
@@ -2467,11 +2560,11 @@ function useRoleRepo() {
2467
2560
  throw new InternalServerError7("Failed to retrieve role by user ID.");
2468
2561
  }
2469
2562
  }
2470
- async function getRoleById(_id) {
2563
+ async function getById(_id) {
2471
2564
  try {
2472
2565
  _id = new ObjectId11(_id);
2473
2566
  } catch (error) {
2474
- throw new BadRequestError12("Invalid ID.");
2567
+ throw new BadRequestError13("Invalid ID.");
2475
2568
  }
2476
2569
  try {
2477
2570
  const cacheKey = makeCacheKey6(namespace_collection, {
@@ -2481,7 +2574,7 @@ function useRoleRepo() {
2481
2574
  if (cached) {
2482
2575
  logger7.log({
2483
2576
  level: "info",
2484
- message: `Cache hit for getRoleById role: ${cacheKey}`
2577
+ message: `Cache hit for getById role: ${cacheKey}`
2485
2578
  });
2486
2579
  return cached;
2487
2580
  }
@@ -2504,7 +2597,7 @@ function useRoleRepo() {
2504
2597
  }
2505
2598
  async function getRoleByName(name) {
2506
2599
  if (!name) {
2507
- throw new BadRequestError12("Role name is required.");
2600
+ throw new BadRequestError13("Role name is required.");
2508
2601
  }
2509
2602
  try {
2510
2603
  const cacheKey = makeCacheKey6(namespace_collection, {
@@ -2550,7 +2643,7 @@ function useRoleRepo() {
2550
2643
  try {
2551
2644
  id = new ObjectId11(id);
2552
2645
  } catch (error) {
2553
- throw new BadRequestError12("Invalid ID.");
2646
+ throw new BadRequestError13("Invalid ID.");
2554
2647
  }
2555
2648
  }
2556
2649
  const query = { status: "active" };
@@ -2612,12 +2705,12 @@ function useRoleRepo() {
2612
2705
  }
2613
2706
  async function updateRole(_id, value, session) {
2614
2707
  if (!_id) {
2615
- throw new BadRequestError12("Role ID is required.");
2708
+ throw new BadRequestError13("Role ID is required.");
2616
2709
  }
2617
2710
  try {
2618
2711
  _id = new ObjectId11(_id);
2619
2712
  } catch (error) {
2620
- throw new BadRequestError12("Invalid role ID.");
2713
+ throw new BadRequestError13("Invalid role ID.");
2621
2714
  }
2622
2715
  if (!value.name) {
2623
2716
  delete value.name;
@@ -2634,23 +2727,23 @@ function useRoleRepo() {
2634
2727
  throw new InternalServerError7("Failed to update role.");
2635
2728
  }
2636
2729
  } else {
2637
- throw new BadRequestError12("No fields to update.");
2730
+ throw new BadRequestError13("No fields to update.");
2638
2731
  }
2639
2732
  }
2640
2733
  async function updatePermissionsById(_id, permissions, session) {
2641
2734
  if (!_id) {
2642
- throw new BadRequestError12("Role ID is required.");
2735
+ throw new BadRequestError13("Role ID is required.");
2643
2736
  }
2644
2737
  try {
2645
2738
  _id = new ObjectId11(_id);
2646
2739
  } catch (error) {
2647
- throw new BadRequestError12("Invalid role ID.");
2740
+ throw new BadRequestError13("Invalid role ID.");
2648
2741
  }
2649
2742
  if (!permissions) {
2650
- throw new BadRequestError12("Permissions are required.");
2743
+ throw new BadRequestError13("Permissions are required.");
2651
2744
  }
2652
2745
  if (permissions.length === 0) {
2653
- throw new BadRequestError12("Permissions cannot be empty.");
2746
+ throw new BadRequestError13("Permissions cannot be empty.");
2654
2747
  }
2655
2748
  try {
2656
2749
  await collection.updateOne(
@@ -2664,11 +2757,11 @@ function useRoleRepo() {
2664
2757
  throw new InternalServerError7("Failed to update role permissions.");
2665
2758
  }
2666
2759
  }
2667
- async function deleteRole(_id, session) {
2760
+ async function deleteById(_id, session) {
2668
2761
  try {
2669
2762
  _id = new ObjectId11(_id);
2670
2763
  } catch (error) {
2671
- throw new BadRequestError12("Invalid ID.");
2764
+ throw new BadRequestError13("Invalid ID.");
2672
2765
  }
2673
2766
  try {
2674
2767
  await collection.deleteOne(
@@ -2690,17 +2783,17 @@ function useRoleRepo() {
2690
2783
  addRole,
2691
2784
  getRoles,
2692
2785
  getRoleByUserId,
2693
- getRoleById,
2786
+ getById,
2694
2787
  getRoleByName,
2695
2788
  updateRole,
2696
- deleteRole,
2789
+ deleteById,
2697
2790
  updatePermissionsById,
2698
2791
  delCachedData
2699
2792
  };
2700
2793
  }
2701
2794
 
2702
2795
  // src/resources/permission/permission.model.ts
2703
- import { BadRequestError as BadRequestError13 } from "@goweekdays/utils";
2796
+ import { BadRequestError as BadRequestError14 } from "@goweekdays/utils";
2704
2797
  import Joi5 from "joi";
2705
2798
  var schemaPermission = Joi5.object({
2706
2799
  app: Joi5.string().required(),
@@ -2719,7 +2812,7 @@ var schemaPermissionUpdate = Joi5.object({
2719
2812
  function modelPermission(value) {
2720
2813
  const { error } = schemaPermission.validate(value);
2721
2814
  if (error) {
2722
- throw new BadRequestError13(error.message);
2815
+ throw new BadRequestError14(error.message);
2723
2816
  }
2724
2817
  return {
2725
2818
  _id: value._id,
@@ -2738,8 +2831,8 @@ function modelPermission(value) {
2738
2831
 
2739
2832
  // src/resources/permission/permission.repository.ts
2740
2833
  import {
2741
- AppError as AppError3,
2742
- BadRequestError as BadRequestError14,
2834
+ AppError as AppError4,
2835
+ BadRequestError as BadRequestError15,
2743
2836
  InternalServerError as InternalServerError8,
2744
2837
  logger as logger8,
2745
2838
  makeCacheKey as makeCacheKey7,
@@ -2798,12 +2891,12 @@ function usePermissionRepo() {
2798
2891
  level: "error",
2799
2892
  message: error.message
2800
2893
  });
2801
- if (error instanceof AppError3) {
2894
+ if (error instanceof AppError4) {
2802
2895
  throw error;
2803
2896
  } else {
2804
2897
  const isDuplicated = error.message.includes("duplicate");
2805
2898
  if (isDuplicated) {
2806
- throw new BadRequestError14("Permission already exists.");
2899
+ throw new BadRequestError15("Permission already exists.");
2807
2900
  }
2808
2901
  throw new Error("Failed to create permission.");
2809
2902
  }
@@ -2813,11 +2906,11 @@ function usePermissionRepo() {
2813
2906
  try {
2814
2907
  _id = new ObjectId12(_id);
2815
2908
  } catch (error2) {
2816
- throw new BadRequestError14("Invalid ID.");
2909
+ throw new BadRequestError15("Invalid ID.");
2817
2910
  }
2818
2911
  const { error } = schemaPermissionUpdate.validate(value);
2819
2912
  if (error) {
2820
- throw new BadRequestError14(`Invalid data: ${error.message}`);
2913
+ throw new BadRequestError15(`Invalid data: ${error.message}`);
2821
2914
  }
2822
2915
  try {
2823
2916
  const res = await collection.updateOne(
@@ -2832,7 +2925,7 @@ function usePermissionRepo() {
2832
2925
  level: "error",
2833
2926
  message: error2.message
2834
2927
  });
2835
- if (error2 instanceof AppError3) {
2928
+ if (error2 instanceof AppError4) {
2836
2929
  throw error2;
2837
2930
  } else {
2838
2931
  throw new Error("Failed to update permission.");
@@ -2908,7 +3001,7 @@ function usePermissionRepo() {
2908
3001
  try {
2909
3002
  _id = new ObjectId12(_id);
2910
3003
  } catch (error) {
2911
- throw new BadRequestError14("Invalid ID.");
3004
+ throw new BadRequestError15("Invalid ID.");
2912
3005
  }
2913
3006
  const cacheKey = makeCacheKey7(namespace_collection, { _id: String(_id) });
2914
3007
  try {
@@ -2936,7 +3029,7 @@ function usePermissionRepo() {
2936
3029
  });
2937
3030
  return result;
2938
3031
  } catch (error) {
2939
- if (error instanceof AppError3) {
3032
+ if (error instanceof AppError4) {
2940
3033
  throw error;
2941
3034
  } else {
2942
3035
  throw new InternalServerError8("Failed to get permission.");
@@ -2951,7 +3044,7 @@ function usePermissionRepo() {
2951
3044
  });
2952
3045
  const { error } = validation.validate({ key, group });
2953
3046
  if (error) {
2954
- throw new BadRequestError14(`Invalid data: ${error.message}`);
3047
+ throw new BadRequestError15(`Invalid data: ${error.message}`);
2955
3048
  }
2956
3049
  const query = {};
2957
3050
  const cacheKeyOptions = {};
@@ -2989,7 +3082,7 @@ function usePermissionRepo() {
2989
3082
  });
2990
3083
  return result;
2991
3084
  } catch (error2) {
2992
- if (error2 instanceof AppError3) {
3085
+ if (error2 instanceof AppError4) {
2993
3086
  throw error2;
2994
3087
  } else {
2995
3088
  throw new InternalServerError8("Failed to get permission.");
@@ -3026,7 +3119,7 @@ function usePermissionRepo() {
3026
3119
  });
3027
3120
  return result;
3028
3121
  } catch (error) {
3029
- if (error instanceof AppError3) {
3122
+ if (error instanceof AppError4) {
3030
3123
  throw error;
3031
3124
  } else {
3032
3125
  throw new InternalServerError8("Failed to count permission by group.");
@@ -3037,7 +3130,7 @@ function usePermissionRepo() {
3037
3130
  try {
3038
3131
  _id = new ObjectId12(_id);
3039
3132
  } catch (error) {
3040
- throw new BadRequestError14("Invalid ID.");
3133
+ throw new BadRequestError15("Invalid ID.");
3041
3134
  }
3042
3135
  try {
3043
3136
  const res = await collection.updateOne(
@@ -3051,7 +3144,7 @@ function usePermissionRepo() {
3051
3144
  level: "error",
3052
3145
  message: error.message
3053
3146
  });
3054
- if (error instanceof AppError3) {
3147
+ if (error instanceof AppError4) {
3055
3148
  throw error;
3056
3149
  } else {
3057
3150
  throw new InternalServerError8("Failed to delete permission.");
@@ -3104,7 +3197,7 @@ function usePermissionService() {
3104
3197
  }
3105
3198
 
3106
3199
  // src/resources/permission/permission.controller.ts
3107
- import { BadRequestError as BadRequestError15, logger as logger9 } from "@goweekdays/utils";
3200
+ import { BadRequestError as BadRequestError16, logger as logger9 } from "@goweekdays/utils";
3108
3201
  import Joi7 from "joi";
3109
3202
  function usePermissionController() {
3110
3203
  const {
@@ -3118,7 +3211,7 @@ function usePermissionController() {
3118
3211
  const value = req.body;
3119
3212
  const { error } = schemaPermission.validate(value);
3120
3213
  if (error) {
3121
- next(new BadRequestError15(error.message));
3214
+ next(new BadRequestError16(error.message));
3122
3215
  logger9.info(`Controller: ${error.message}`);
3123
3216
  return;
3124
3217
  }
@@ -3141,7 +3234,7 @@ function usePermissionController() {
3141
3234
  });
3142
3235
  const { error } = validation.validate(query);
3143
3236
  if (error) {
3144
- next(new BadRequestError15(error.message));
3237
+ next(new BadRequestError16(error.message));
3145
3238
  return;
3146
3239
  }
3147
3240
  const page = parseInt(req.query.page) ?? 1;
@@ -3180,7 +3273,7 @@ function usePermissionController() {
3180
3273
  });
3181
3274
  const { error } = validation.validate({ id });
3182
3275
  if (error) {
3183
- next(new BadRequestError15(error.message));
3276
+ next(new BadRequestError16(error.message));
3184
3277
  return;
3185
3278
  }
3186
3279
  try {
@@ -3201,7 +3294,7 @@ function usePermissionController() {
3201
3294
  });
3202
3295
  const { error } = validation.validate({ id });
3203
3296
  if (error) {
3204
- next(new BadRequestError15(error.message));
3297
+ next(new BadRequestError16(error.message));
3205
3298
  return;
3206
3299
  }
3207
3300
  try {
@@ -3216,13 +3309,13 @@ function usePermissionController() {
3216
3309
  const id = req.params.id;
3217
3310
  const { error: errorId } = Joi7.string().hex().required().validate(id);
3218
3311
  if (errorId) {
3219
- next(new BadRequestError15(errorId.message));
3312
+ next(new BadRequestError16(errorId.message));
3220
3313
  return;
3221
3314
  }
3222
3315
  const payload = req.body;
3223
3316
  const { error } = schemaPermissionUpdate.validate(payload);
3224
3317
  if (error) {
3225
- next(new BadRequestError15(error.message));
3318
+ next(new BadRequestError16(error.message));
3226
3319
  return;
3227
3320
  }
3228
3321
  try {
@@ -3243,7 +3336,7 @@ function usePermissionController() {
3243
3336
  }
3244
3337
 
3245
3338
  // src/resources/permission/permission.group.model.ts
3246
- import { BadRequestError as BadRequestError16 } from "@goweekdays/utils";
3339
+ import { BadRequestError as BadRequestError17 } from "@goweekdays/utils";
3247
3340
  import Joi8 from "joi";
3248
3341
  var schemaPermissionGroup = Joi8.object({
3249
3342
  app: Joi8.string().required(),
@@ -3259,7 +3352,7 @@ var schemaPermissionGroupUpdate = Joi8.object({
3259
3352
  function modelPermissionGroup(value) {
3260
3353
  const { error } = schemaPermissionGroup.validate(value);
3261
3354
  if (error) {
3262
- throw new BadRequestError16(error.message);
3355
+ throw new BadRequestError17(error.message);
3263
3356
  }
3264
3357
  return {
3265
3358
  _id: value._id,
@@ -3276,8 +3369,8 @@ function modelPermissionGroup(value) {
3276
3369
 
3277
3370
  // src/resources/permission/permission.group.repository.ts
3278
3371
  import {
3279
- AppError as AppError4,
3280
- BadRequestError as BadRequestError17,
3372
+ AppError as AppError5,
3373
+ BadRequestError as BadRequestError18,
3281
3374
  InternalServerError as InternalServerError9,
3282
3375
  logger as logger10,
3283
3376
  makeCacheKey as makeCacheKey8,
@@ -3336,12 +3429,12 @@ function usePermissionGroupRepo() {
3336
3429
  level: "error",
3337
3430
  message: error.message
3338
3431
  });
3339
- if (error instanceof AppError4) {
3432
+ if (error instanceof AppError5) {
3340
3433
  throw error;
3341
3434
  } else {
3342
3435
  const isDuplicated = error.message.includes("duplicate");
3343
3436
  if (isDuplicated) {
3344
- throw new BadRequestError17("Permission group already exists.");
3437
+ throw new BadRequestError18("Permission group already exists.");
3345
3438
  }
3346
3439
  throw new Error("Failed to create permission group.");
3347
3440
  }
@@ -3351,11 +3444,11 @@ function usePermissionGroupRepo() {
3351
3444
  try {
3352
3445
  _id = new ObjectId13(_id);
3353
3446
  } catch (error2) {
3354
- throw new BadRequestError17("Invalid ID.");
3447
+ throw new BadRequestError18("Invalid ID.");
3355
3448
  }
3356
3449
  const { error } = schemaPermissionGroupUpdate.validate(value);
3357
3450
  if (error) {
3358
- throw new BadRequestError17(`Invalid data: ${error.message}`);
3451
+ throw new BadRequestError18(`Invalid data: ${error.message}`);
3359
3452
  }
3360
3453
  try {
3361
3454
  const res = await collection.updateOne(
@@ -3370,7 +3463,7 @@ function usePermissionGroupRepo() {
3370
3463
  level: "error",
3371
3464
  message: error2.message
3372
3465
  });
3373
- if (error2 instanceof AppError4) {
3466
+ if (error2 instanceof AppError5) {
3374
3467
  throw error2;
3375
3468
  } else {
3376
3469
  throw new Error("Failed to update permission group.");
@@ -3446,7 +3539,7 @@ function usePermissionGroupRepo() {
3446
3539
  try {
3447
3540
  _id = new ObjectId13(_id);
3448
3541
  } catch (error) {
3449
- throw new BadRequestError17("Invalid ID.");
3542
+ throw new BadRequestError18("Invalid ID.");
3450
3543
  }
3451
3544
  const cacheKey = makeCacheKey8(namespace_collection, { _id: String(_id) });
3452
3545
  try {
@@ -3474,7 +3567,7 @@ function usePermissionGroupRepo() {
3474
3567
  });
3475
3568
  return result;
3476
3569
  } catch (error) {
3477
- if (error instanceof AppError4) {
3570
+ if (error instanceof AppError5) {
3478
3571
  throw error;
3479
3572
  } else {
3480
3573
  throw new InternalServerError9("Failed to get permission group.");
@@ -3488,7 +3581,7 @@ function usePermissionGroupRepo() {
3488
3581
  });
3489
3582
  const { error } = validation.validate({ key, app });
3490
3583
  if (error) {
3491
- throw new BadRequestError17("Invalid key.");
3584
+ throw new BadRequestError18("Invalid key.");
3492
3585
  }
3493
3586
  const query = { key };
3494
3587
  const cacheKeyOptions = { key, tag: "byKey" };
@@ -3520,7 +3613,7 @@ function usePermissionGroupRepo() {
3520
3613
  });
3521
3614
  return result;
3522
3615
  } catch (error2) {
3523
- if (error2 instanceof AppError4) {
3616
+ if (error2 instanceof AppError5) {
3524
3617
  throw error2;
3525
3618
  } else {
3526
3619
  throw new InternalServerError9("Failed to get permission group.");
@@ -3531,7 +3624,7 @@ function usePermissionGroupRepo() {
3531
3624
  try {
3532
3625
  _id = new ObjectId13(_id);
3533
3626
  } catch (error) {
3534
- throw new BadRequestError17("Invalid ID.");
3627
+ throw new BadRequestError18("Invalid ID.");
3535
3628
  }
3536
3629
  try {
3537
3630
  const res = await collection.updateOne(
@@ -3545,7 +3638,7 @@ function usePermissionGroupRepo() {
3545
3638
  level: "error",
3546
3639
  message: error.message
3547
3640
  });
3548
- if (error instanceof AppError4) {
3641
+ if (error instanceof AppError5) {
3549
3642
  throw error;
3550
3643
  } else {
3551
3644
  throw new InternalServerError9("Failed to delete permission group.");
@@ -3578,15 +3671,15 @@ function usePermissionGroupRepo() {
3578
3671
 
3579
3672
  // src/resources/permission/permission.group.service.ts
3580
3673
  import {
3581
- AppError as AppError6,
3582
- BadRequestError as BadRequestError21,
3674
+ AppError as AppError7,
3675
+ BadRequestError as BadRequestError22,
3583
3676
  InternalServerError as InternalServerError11,
3584
3677
  logger as logger14,
3585
3678
  useAtlas as useAtlas12
3586
3679
  } from "@goweekdays/utils";
3587
3680
 
3588
3681
  // src/resources/app/app.model.ts
3589
- import { BadRequestError as BadRequestError18 } from "@goweekdays/utils";
3682
+ import { BadRequestError as BadRequestError19 } from "@goweekdays/utils";
3590
3683
  import Joi10 from "joi";
3591
3684
  var schemaApp = Joi10.object({
3592
3685
  code: Joi10.string().alphanum().max(20).required(),
@@ -3602,7 +3695,7 @@ var schemaAppUpdate = Joi10.object({
3602
3695
  function modelApp(value) {
3603
3696
  const { error } = schemaApp.validate(value);
3604
3697
  if (error) {
3605
- throw new BadRequestError18(error.message);
3698
+ throw new BadRequestError19(error.message);
3606
3699
  }
3607
3700
  return {
3608
3701
  _id: value._id,
@@ -3619,8 +3712,8 @@ function modelApp(value) {
3619
3712
 
3620
3713
  // src/resources/app/app.repository.ts
3621
3714
  import {
3622
- AppError as AppError5,
3623
- BadRequestError as BadRequestError19,
3715
+ AppError as AppError6,
3716
+ BadRequestError as BadRequestError20,
3624
3717
  InternalServerError as InternalServerError10,
3625
3718
  logger as logger11,
3626
3719
  makeCacheKey as makeCacheKey9,
@@ -3682,12 +3775,12 @@ function useAppRepo() {
3682
3775
  level: "error",
3683
3776
  message: error.message
3684
3777
  });
3685
- if (error instanceof AppError5) {
3778
+ if (error instanceof AppError6) {
3686
3779
  throw error;
3687
3780
  } else {
3688
3781
  const isDuplicated = error.message.includes("duplicate");
3689
3782
  if (isDuplicated) {
3690
- throw new BadRequestError19("App already exists.");
3783
+ throw new BadRequestError20("App already exists.");
3691
3784
  }
3692
3785
  throw new Error("Failed to create app.");
3693
3786
  }
@@ -3697,7 +3790,7 @@ function useAppRepo() {
3697
3790
  try {
3698
3791
  _id = new ObjectId14(_id);
3699
3792
  } catch (error) {
3700
- throw new BadRequestError19("Invalid ID.");
3793
+ throw new BadRequestError20("Invalid ID.");
3701
3794
  }
3702
3795
  try {
3703
3796
  const res = await collection.updateOne(
@@ -3712,7 +3805,7 @@ function useAppRepo() {
3712
3805
  level: "error",
3713
3806
  message: error.message
3714
3807
  });
3715
- if (error instanceof AppError5) {
3808
+ if (error instanceof AppError6) {
3716
3809
  throw error;
3717
3810
  } else {
3718
3811
  throw new Error("Failed to update app.");
@@ -3793,7 +3886,7 @@ function useAppRepo() {
3793
3886
  try {
3794
3887
  _id = new ObjectId14(_id);
3795
3888
  } catch (error) {
3796
- throw new BadRequestError19("Invalid ID.");
3889
+ throw new BadRequestError20("Invalid ID.");
3797
3890
  }
3798
3891
  const cacheKey = makeCacheKey9(namespace_collection, { _id: String(_id) });
3799
3892
  try {
@@ -3821,7 +3914,7 @@ function useAppRepo() {
3821
3914
  });
3822
3915
  return result;
3823
3916
  } catch (error) {
3824
- if (error instanceof AppError5) {
3917
+ if (error instanceof AppError6) {
3825
3918
  throw error;
3826
3919
  } else {
3827
3920
  throw new InternalServerError10("Failed to get app.");
@@ -3832,7 +3925,7 @@ function useAppRepo() {
3832
3925
  const validate = Joi11.string().required();
3833
3926
  const { error } = validate.validate(code);
3834
3927
  if (error) {
3835
- throw new BadRequestError19("Invalid code.");
3928
+ throw new BadRequestError20("Invalid code.");
3836
3929
  }
3837
3930
  const cacheKey = makeCacheKey9(namespace_collection, {
3838
3931
  code,
@@ -3863,7 +3956,7 @@ function useAppRepo() {
3863
3956
  });
3864
3957
  return result;
3865
3958
  } catch (error2) {
3866
- if (error2 instanceof AppError5) {
3959
+ if (error2 instanceof AppError6) {
3867
3960
  throw error2;
3868
3961
  } else {
3869
3962
  throw new InternalServerError10("Failed to get app.");
@@ -3874,7 +3967,7 @@ function useAppRepo() {
3874
3967
  try {
3875
3968
  _id = new ObjectId14(_id);
3876
3969
  } catch (error) {
3877
- throw new BadRequestError19("Invalid ID.");
3970
+ throw new BadRequestError20("Invalid ID.");
3878
3971
  }
3879
3972
  try {
3880
3973
  const res = await collection.updateOne(
@@ -3888,7 +3981,7 @@ function useAppRepo() {
3888
3981
  level: "error",
3889
3982
  message: error.message
3890
3983
  });
3891
- if (error instanceof AppError5) {
3984
+ if (error instanceof AppError6) {
3892
3985
  throw error;
3893
3986
  } else {
3894
3987
  throw new InternalServerError10("Failed to delete app.");
@@ -3937,6 +4030,12 @@ function useAppService() {
3937
4030
  description: "Administrative application.",
3938
4031
  type: "default"
3939
4032
  },
4033
+ {
4034
+ code: "org",
4035
+ name: "Organization",
4036
+ description: "Organization application.",
4037
+ type: "standard"
4038
+ },
3940
4039
  {
3941
4040
  code: "marketplace",
3942
4041
  name: "Marketplace",
@@ -4008,7 +4107,7 @@ function useAppService() {
4008
4107
  }
4009
4108
 
4010
4109
  // src/resources/app/app.controller.ts
4011
- import { BadRequestError as BadRequestError20 } from "@goweekdays/utils";
4110
+ import { BadRequestError as BadRequestError21 } from "@goweekdays/utils";
4012
4111
  import Joi12 from "joi";
4013
4112
  function useAppController() {
4014
4113
  const {
@@ -4022,7 +4121,7 @@ function useAppController() {
4022
4121
  const value = req.body;
4023
4122
  const { error } = schemaApp.validate(value);
4024
4123
  if (error) {
4025
- next(new BadRequestError20(error.message));
4124
+ next(new BadRequestError21(error.message));
4026
4125
  return;
4027
4126
  }
4028
4127
  try {
@@ -4037,13 +4136,13 @@ function useAppController() {
4037
4136
  const id = req.params.id ?? "";
4038
4137
  const { error: errorId } = Joi12.string().hex().required().validate(id);
4039
4138
  if (errorId) {
4040
- next(new BadRequestError20(errorId.message));
4139
+ next(new BadRequestError21(errorId.message));
4041
4140
  return;
4042
4141
  }
4043
4142
  const value = req.body;
4044
4143
  const { error } = schemaAppUpdate.validate(value);
4045
4144
  if (error) {
4046
- next(new BadRequestError20(error.message));
4145
+ next(new BadRequestError21(error.message));
4047
4146
  return;
4048
4147
  }
4049
4148
  try {
@@ -4065,7 +4164,7 @@ function useAppController() {
4065
4164
  });
4066
4165
  const { error } = validation.validate(query);
4067
4166
  if (error) {
4068
- next(new BadRequestError20(error.message));
4167
+ next(new BadRequestError21(error.message));
4069
4168
  return;
4070
4169
  }
4071
4170
  const page = parseInt(req.query.page) ?? 1;
@@ -4104,7 +4203,7 @@ function useAppController() {
4104
4203
  });
4105
4204
  const { error } = validation.validate({ id });
4106
4205
  if (error) {
4107
- next(new BadRequestError20(error.message));
4206
+ next(new BadRequestError21(error.message));
4108
4207
  return;
4109
4208
  }
4110
4209
  try {
@@ -4125,7 +4224,7 @@ function useAppController() {
4125
4224
  });
4126
4225
  const { error } = validation.validate({ id });
4127
4226
  if (error) {
4128
- next(new BadRequestError20(error.message));
4227
+ next(new BadRequestError21(error.message));
4129
4228
  return;
4130
4229
  }
4131
4230
  try {
@@ -4525,7 +4624,7 @@ function usePermissionGroupService() {
4525
4624
  }
4526
4625
  const associatedPermissionsCount = await countByGroup(permission.key);
4527
4626
  if (associatedPermissionsCount > 0) {
4528
- throw new BadRequestError21(
4627
+ throw new BadRequestError22(
4529
4628
  "Cannot delete Permission Group with associated Permissions."
4530
4629
  );
4531
4630
  }
@@ -4533,7 +4632,7 @@ function usePermissionGroupService() {
4533
4632
  await _deleteById(id);
4534
4633
  return "Permission deleted successfully.";
4535
4634
  } catch (error) {
4536
- if (error instanceof AppError6) {
4635
+ if (error instanceof AppError7) {
4537
4636
  throw error;
4538
4637
  } else {
4539
4638
  throw new InternalServerError11("Failed to delete Permission Group.");
@@ -4547,7 +4646,7 @@ function usePermissionGroupService() {
4547
4646
  }
4548
4647
 
4549
4648
  // src/resources/permission/permission.group.controller.ts
4550
- import { BadRequestError as BadRequestError22, logger as logger15 } from "@goweekdays/utils";
4649
+ import { BadRequestError as BadRequestError23, logger as logger15 } from "@goweekdays/utils";
4551
4650
  import Joi13 from "joi";
4552
4651
  function usePermissionGroupController() {
4553
4652
  const {
@@ -4561,7 +4660,7 @@ function usePermissionGroupController() {
4561
4660
  const value = req.body;
4562
4661
  const { error } = schemaPermissionGroup.validate(value);
4563
4662
  if (error) {
4564
- next(new BadRequestError22(error.message));
4663
+ next(new BadRequestError23(error.message));
4565
4664
  logger15.info(`Controller: ${error.message}`);
4566
4665
  return;
4567
4666
  }
@@ -4584,7 +4683,7 @@ function usePermissionGroupController() {
4584
4683
  });
4585
4684
  const { error } = validation.validate(query);
4586
4685
  if (error) {
4587
- next(new BadRequestError22(error.message));
4686
+ next(new BadRequestError23(error.message));
4588
4687
  return;
4589
4688
  }
4590
4689
  const page = parseInt(req.query.page) ?? 1;
@@ -4623,7 +4722,7 @@ function usePermissionGroupController() {
4623
4722
  });
4624
4723
  const { error } = validation.validate({ id });
4625
4724
  if (error) {
4626
- next(new BadRequestError22(error.message));
4725
+ next(new BadRequestError23(error.message));
4627
4726
  return;
4628
4727
  }
4629
4728
  try {
@@ -4644,7 +4743,7 @@ function usePermissionGroupController() {
4644
4743
  });
4645
4744
  const { error } = validation.validate({ id });
4646
4745
  if (error) {
4647
- next(new BadRequestError22(error.message));
4746
+ next(new BadRequestError23(error.message));
4648
4747
  return;
4649
4748
  }
4650
4749
  try {
@@ -4659,13 +4758,13 @@ function usePermissionGroupController() {
4659
4758
  const id = req.params.id;
4660
4759
  const { error: errorId } = Joi13.string().hex().required().validate(id);
4661
4760
  if (errorId) {
4662
- next(new BadRequestError22(errorId.message));
4761
+ next(new BadRequestError23(errorId.message));
4663
4762
  return;
4664
4763
  }
4665
4764
  const payload = req.body;
4666
4765
  const { error } = schemaPermissionGroupUpdate.validate(payload);
4667
4766
  if (error) {
4668
- next(new BadRequestError22(error.message));
4767
+ next(new BadRequestError23(error.message));
4669
4768
  return;
4670
4769
  }
4671
4770
  try {
@@ -4705,7 +4804,7 @@ function useUserService() {
4705
4804
  session?.startTransaction();
4706
4805
  const _user = await getUserByEmail(DEFAULT_USER_EMAIL);
4707
4806
  if (_user) {
4708
- throw new BadRequestError23(
4807
+ throw new BadRequestError24(
4709
4808
  `User already exists: ${DEFAULT_USER_EMAIL}.`
4710
4809
  );
4711
4810
  }
@@ -4775,7 +4874,7 @@ function useUserService() {
4775
4874
  try {
4776
4875
  const _user = await getUserByEmail(value.email);
4777
4876
  if (_user) {
4778
- throw new BadRequestError23(`User already exists: ${value.email}.`);
4877
+ throw new BadRequestError24(`User already exists: ${value.email}.`);
4779
4878
  }
4780
4879
  const hashedPassword = await hashPassword(value.password);
4781
4880
  const userId = new ObjectId15();
@@ -4814,14 +4913,14 @@ function useUserService() {
4814
4913
  try {
4815
4914
  const invitation = await _getVerificationById(id);
4816
4915
  if (!invitation || !invitation.metadata?.app || !invitation.metadata?.role) {
4817
- throw new BadRequestError23("Invalid invitation.");
4916
+ throw new BadRequestError24("Invalid invitation.");
4818
4917
  }
4819
4918
  if (invitation.status === "complete") {
4820
- throw new BadRequestError23("Invitation already used.");
4919
+ throw new BadRequestError24("Invitation already used.");
4821
4920
  }
4822
4921
  const expired = new Date(invitation.expireAt) < /* @__PURE__ */ new Date();
4823
4922
  if (invitation.status === "expired" || expired) {
4824
- throw new BadRequestError23("Invitation expired.");
4923
+ throw new BadRequestError24("Invitation expired.");
4825
4924
  }
4826
4925
  const email = invitation.email;
4827
4926
  const _user = await getUserByEmail(invitation.email);
@@ -4873,21 +4972,21 @@ function useUserService() {
4873
4972
  try {
4874
4973
  const signUp = await _getVerificationById(id);
4875
4974
  if (!signUp) {
4876
- throw new BadRequestError23("Invalid sign up link.");
4975
+ throw new BadRequestError24("Invalid sign up link.");
4877
4976
  }
4878
4977
  if (signUp.status === "complete") {
4879
- throw new BadRequestError23(
4978
+ throw new BadRequestError24(
4880
4979
  "You have already an account created using this link."
4881
4980
  );
4882
4981
  }
4883
4982
  const expired = new Date(signUp.expireAt) < /* @__PURE__ */ new Date();
4884
4983
  if (signUp.status === "expired" || expired) {
4885
- throw new BadRequestError23("Sign up link expired.");
4984
+ throw new BadRequestError24("Sign up link expired.");
4886
4985
  }
4887
4986
  const email = signUp.email;
4888
4987
  const _user = await getUserByEmail(signUp.email);
4889
4988
  if (_user) {
4890
- throw new BadRequestError23(`User already exists: ${email}.`);
4989
+ throw new BadRequestError24(`User already exists: ${email}.`);
4891
4990
  }
4892
4991
  const hashedPassword = await hashPassword(password);
4893
4992
  const userId = new ObjectId15();
@@ -4921,7 +5020,7 @@ function useUserService() {
4921
5020
  throw error;
4922
5021
  }
4923
5022
  if (newPassword !== passwordConfirmation) {
4924
- throw new BadRequestError23("Passwords do not match.");
5023
+ throw new BadRequestError24("Passwords do not match.");
4925
5024
  }
4926
5025
  let hashedPassword = "";
4927
5026
  try {
@@ -4935,7 +5034,7 @@ function useUserService() {
4935
5034
  throw new NotFoundError4("You are using an invalid reset link.");
4936
5035
  }
4937
5036
  if (otpDoc.status === "used") {
4938
- throw new BadRequestError23("This link has already been invalidated.");
5037
+ throw new BadRequestError24("This link has already been invalidated.");
4939
5038
  }
4940
5039
  await updateStatusById(id, "used");
4941
5040
  return "Successfully reset password.";
@@ -4946,13 +5045,13 @@ function useUserService() {
4946
5045
  const { updateName: updateMemberName } = useMemberRepo();
4947
5046
  async function updateName(_id, firstName, lastName) {
4948
5047
  if (!_id) {
4949
- throw new BadRequestError23("Invalid user ID");
5048
+ throw new BadRequestError24("Invalid user ID");
4950
5049
  }
4951
5050
  if (!firstName) {
4952
- throw new BadRequestError23("Invalid firstName");
5051
+ throw new BadRequestError24("Invalid firstName");
4953
5052
  }
4954
5053
  if (!lastName) {
4955
- throw new BadRequestError23("Invalid lastName");
5054
+ throw new BadRequestError24("Invalid lastName");
4956
5055
  }
4957
5056
  const session = useAtlas13.getClient()?.startSession();
4958
5057
  session?.startTransaction();
@@ -4979,16 +5078,16 @@ function useUserService() {
4979
5078
  }
4980
5079
  async function updateBirthday(_id, month, day, year) {
4981
5080
  if (!_id) {
4982
- throw new BadRequestError23("Invalid user ID");
5081
+ throw new BadRequestError24("Invalid user ID");
4983
5082
  }
4984
5083
  if (!month) {
4985
- throw new BadRequestError23("Invalid birth month.");
5084
+ throw new BadRequestError24("Invalid birth month.");
4986
5085
  }
4987
5086
  if (!day) {
4988
- throw new BadRequestError23("Invalid birthday.");
5087
+ throw new BadRequestError24("Invalid birthday.");
4989
5088
  }
4990
5089
  if (!year) {
4991
- throw new BadRequestError23("Invalid birth year.");
5090
+ throw new BadRequestError24("Invalid birth year.");
4992
5091
  }
4993
5092
  try {
4994
5093
  await _updateBirthday({ _id, month, day, year });
@@ -5069,7 +5168,7 @@ function useAuthController() {
5069
5168
  });
5070
5169
  const { error } = validation.validate({ email, password });
5071
5170
  if (error) {
5072
- next(new BadRequestError24(error.message));
5171
+ next(new BadRequestError25(error.message));
5073
5172
  return;
5074
5173
  }
5075
5174
  try {
@@ -5089,7 +5188,7 @@ function useAuthController() {
5089
5188
  level: "error",
5090
5189
  message: `Error during login: ${error2.message}`
5091
5190
  });
5092
- if (error2 instanceof AppError7) {
5191
+ if (error2 instanceof AppError8) {
5093
5192
  next(error2);
5094
5193
  } else {
5095
5194
  next(new InternalServerError13("An unexpected error occurred"));
@@ -5100,14 +5199,14 @@ function useAuthController() {
5100
5199
  async function logout(req, res, next) {
5101
5200
  const sid = req.headers["authorization"] ?? "";
5102
5201
  if (!sid) {
5103
- next(new BadRequestError24("Session ID is required"));
5202
+ next(new BadRequestError25("Session ID is required"));
5104
5203
  return;
5105
5204
  }
5106
5205
  try {
5107
5206
  await useAuthService().logout(sid);
5108
5207
  res.json({ message: "Logged out successfully" });
5109
5208
  } catch (error) {
5110
- if (error instanceof AppError7) {
5209
+ if (error instanceof AppError8) {
5111
5210
  next(error);
5112
5211
  } else {
5113
5212
  next(new InternalServerError13("An unexpected error occurred"));
@@ -5129,7 +5228,7 @@ function useAuthController() {
5129
5228
  passwordConfirmation
5130
5229
  });
5131
5230
  if (error) {
5132
- next(new BadRequestError24(error.message));
5231
+ next(new BadRequestError25(error.message));
5133
5232
  return;
5134
5233
  }
5135
5234
  try {
@@ -5153,7 +5252,7 @@ function useAuthController() {
5153
5252
  });
5154
5253
  const { error } = validation.validate({ email, referralCode });
5155
5254
  if (error) {
5156
- next(new BadRequestError24(error.message));
5255
+ next(new BadRequestError25(error.message));
5157
5256
  return;
5158
5257
  }
5159
5258
  try {
@@ -5178,7 +5277,7 @@ function useAuthController() {
5178
5277
  }
5179
5278
 
5180
5279
  // src/resources/building/building.model.ts
5181
- import { BadRequestError as BadRequestError25, logger as logger18 } from "@goweekdays/utils";
5280
+ import { BadRequestError as BadRequestError26, logger as logger18 } from "@goweekdays/utils";
5182
5281
  import Joi15 from "joi";
5183
5282
  import { ObjectId as ObjectId16 } from "mongodb";
5184
5283
  var schemaBuilding = Joi15.object({
@@ -5223,19 +5322,19 @@ function MBuilding(value) {
5223
5322
  const { error } = schemaBuilding.validate(value);
5224
5323
  if (error) {
5225
5324
  logger18.info(`Building Model: ${error.message}`);
5226
- throw new BadRequestError25(error.message);
5325
+ throw new BadRequestError26(error.message);
5227
5326
  }
5228
5327
  if (value._id && typeof value._id === "string") {
5229
5328
  try {
5230
5329
  value._id = new ObjectId16(value._id);
5231
5330
  } catch (error2) {
5232
- throw new BadRequestError25("Invalid _id format");
5331
+ throw new BadRequestError26("Invalid _id format");
5233
5332
  }
5234
5333
  }
5235
5334
  try {
5236
5335
  value.school = new ObjectId16(value.school);
5237
5336
  } catch (error2) {
5238
- throw new BadRequestError25("Invalid school format");
5337
+ throw new BadRequestError26("Invalid school format");
5239
5338
  }
5240
5339
  return {
5241
5340
  _id: value._id ?? void 0,
@@ -5253,24 +5352,24 @@ function MBuildingUnit(value) {
5253
5352
  const { error } = schemaBuildingUnit.validate(value);
5254
5353
  if (error) {
5255
5354
  logger18.info(`Building Unit Model: ${error.message}`);
5256
- throw new BadRequestError25(error.message);
5355
+ throw new BadRequestError26(error.message);
5257
5356
  }
5258
5357
  if (value._id && typeof value._id === "string") {
5259
5358
  try {
5260
5359
  value._id = new ObjectId16(value._id);
5261
5360
  } catch (error2) {
5262
- throw new BadRequestError25("Invalid ID");
5361
+ throw new BadRequestError26("Invalid ID");
5263
5362
  }
5264
5363
  }
5265
5364
  try {
5266
5365
  value.school = new ObjectId16(value.school);
5267
5366
  } catch (error2) {
5268
- throw new BadRequestError25("Invalid school ID");
5367
+ throw new BadRequestError26("Invalid school ID");
5269
5368
  }
5270
5369
  try {
5271
5370
  value.building = new ObjectId16(value.building);
5272
5371
  } catch (error2) {
5273
- throw new BadRequestError25("Invalid building ID");
5372
+ throw new BadRequestError26("Invalid building ID");
5274
5373
  }
5275
5374
  return {
5276
5375
  _id: value._id ?? void 0,
@@ -5295,8 +5394,8 @@ function MBuildingUnit(value) {
5295
5394
 
5296
5395
  // src/resources/building/building.repository.ts
5297
5396
  import {
5298
- AppError as AppError8,
5299
- BadRequestError as BadRequestError26,
5397
+ AppError as AppError9,
5398
+ BadRequestError as BadRequestError27,
5300
5399
  InternalServerError as InternalServerError14,
5301
5400
  logger as logger19,
5302
5401
  makeCacheKey as makeCacheKey11,
@@ -5338,12 +5437,12 @@ function useBuildingRepo() {
5338
5437
  level: "error",
5339
5438
  message: error.message
5340
5439
  });
5341
- if (error instanceof AppError8) {
5440
+ if (error instanceof AppError9) {
5342
5441
  throw error;
5343
5442
  } else {
5344
5443
  const isDuplicated = error.message.includes("duplicate");
5345
5444
  if (isDuplicated) {
5346
- throw new BadRequestError26("Building already exists.");
5445
+ throw new BadRequestError27("Building already exists.");
5347
5446
  }
5348
5447
  throw new Error("Failed to create building.");
5349
5448
  }
@@ -5353,7 +5452,7 @@ function useBuildingRepo() {
5353
5452
  try {
5354
5453
  _id = new ObjectId17(_id);
5355
5454
  } catch (error) {
5356
- throw new BadRequestError26("Invalid ID.");
5455
+ throw new BadRequestError27("Invalid ID.");
5357
5456
  }
5358
5457
  try {
5359
5458
  const res = await collection.updateOne(
@@ -5368,7 +5467,7 @@ function useBuildingRepo() {
5368
5467
  level: "error",
5369
5468
  message: error.message
5370
5469
  });
5371
- if (error instanceof AppError8) {
5470
+ if (error instanceof AppError9) {
5372
5471
  throw error;
5373
5472
  } else {
5374
5473
  throw new Error("Failed to update building.");
@@ -5395,7 +5494,7 @@ function useBuildingRepo() {
5395
5494
  try {
5396
5495
  query.school = new ObjectId17(school);
5397
5496
  } catch (error) {
5398
- throw new BadRequestError26("Invalid school ID.");
5497
+ throw new BadRequestError27("Invalid school ID.");
5399
5498
  }
5400
5499
  }
5401
5500
  const cacheParams = {
@@ -5452,7 +5551,7 @@ function useBuildingRepo() {
5452
5551
  try {
5453
5552
  _id = new ObjectId17(_id);
5454
5553
  } catch (error) {
5455
- throw new BadRequestError26("Invalid ID.");
5554
+ throw new BadRequestError27("Invalid ID.");
5456
5555
  }
5457
5556
  const cacheKey = makeCacheKey11(namespace_collection, { _id: String(_id) });
5458
5557
  try {
@@ -5480,7 +5579,7 @@ function useBuildingRepo() {
5480
5579
  });
5481
5580
  return result;
5482
5581
  } catch (error) {
5483
- if (error instanceof AppError8) {
5582
+ if (error instanceof AppError9) {
5484
5583
  throw error;
5485
5584
  } else {
5486
5585
  throw new InternalServerError14("Failed to get building.");
@@ -5491,7 +5590,7 @@ function useBuildingRepo() {
5491
5590
  try {
5492
5591
  _id = new ObjectId17(_id);
5493
5592
  } catch (error) {
5494
- throw new BadRequestError26("Invalid ID.");
5593
+ throw new BadRequestError27("Invalid ID.");
5495
5594
  }
5496
5595
  try {
5497
5596
  const res = await collection.updateOne(
@@ -5505,7 +5604,7 @@ function useBuildingRepo() {
5505
5604
  level: "error",
5506
5605
  message: error.message
5507
5606
  });
5508
- if (error instanceof AppError8) {
5607
+ if (error instanceof AppError9) {
5509
5608
  throw error;
5510
5609
  } else {
5511
5610
  throw new InternalServerError14("Failed to delete building.");
@@ -5536,12 +5635,12 @@ function useBuildingRepo() {
5536
5635
  }
5537
5636
 
5538
5637
  // src/resources/building/building.service.ts
5539
- import { BadRequestError as BadRequestError28, NotFoundError as NotFoundError5, useAtlas as useAtlas16 } from "@goweekdays/utils";
5638
+ import { BadRequestError as BadRequestError29, NotFoundError as NotFoundError5, useAtlas as useAtlas16 } from "@goweekdays/utils";
5540
5639
 
5541
5640
  // src/resources/building/building-unit.repository.ts
5542
5641
  import {
5543
- AppError as AppError9,
5544
- BadRequestError as BadRequestError27,
5642
+ AppError as AppError10,
5643
+ BadRequestError as BadRequestError28,
5545
5644
  InternalServerError as InternalServerError15,
5546
5645
  logger as logger20,
5547
5646
  makeCacheKey as makeCacheKey12,
@@ -5607,7 +5706,7 @@ function useBuildingUnitRepo() {
5607
5706
  level: "error",
5608
5707
  message: error.message
5609
5708
  });
5610
- if (error instanceof AppError9) {
5709
+ if (error instanceof AppError10) {
5611
5710
  throw error;
5612
5711
  } else {
5613
5712
  throw new Error("Failed to create building unit.");
@@ -5617,12 +5716,12 @@ function useBuildingUnitRepo() {
5617
5716
  async function updateById(_id, value, session) {
5618
5717
  const { error } = schemaUpdateOptions.validate(value);
5619
5718
  if (error) {
5620
- throw new BadRequestError27(error.message);
5719
+ throw new BadRequestError28(error.message);
5621
5720
  }
5622
5721
  try {
5623
5722
  _id = new ObjectId18(_id);
5624
5723
  } catch (error2) {
5625
- throw new BadRequestError27("Invalid ID.");
5724
+ throw new BadRequestError28("Invalid ID.");
5626
5725
  }
5627
5726
  try {
5628
5727
  const res = await collection.updateOne(
@@ -5637,7 +5736,7 @@ function useBuildingUnitRepo() {
5637
5736
  level: "error",
5638
5737
  message: error2.message
5639
5738
  });
5640
- if (error2 instanceof AppError9) {
5739
+ if (error2 instanceof AppError10) {
5641
5740
  throw error2;
5642
5741
  } else {
5643
5742
  throw new Error("Failed to create building unit.");
@@ -5647,12 +5746,12 @@ function useBuildingUnitRepo() {
5647
5746
  async function updateByBuildingId(building, value, session) {
5648
5747
  const { error } = schemaUpdateOptions.validate(value);
5649
5748
  if (error) {
5650
- throw new BadRequestError27(error.message);
5749
+ throw new BadRequestError28(error.message);
5651
5750
  }
5652
5751
  try {
5653
5752
  building = new ObjectId18(building);
5654
5753
  } catch (error2) {
5655
- throw new BadRequestError27("Invalid building ID.");
5754
+ throw new BadRequestError28("Invalid building ID.");
5656
5755
  }
5657
5756
  try {
5658
5757
  const res = await collection.updateMany(
@@ -5667,7 +5766,7 @@ function useBuildingUnitRepo() {
5667
5766
  level: "error",
5668
5767
  message: error2.message
5669
5768
  });
5670
- if (error2 instanceof AppError9) {
5769
+ if (error2 instanceof AppError10) {
5671
5770
  throw error2;
5672
5771
  } else {
5673
5772
  throw new Error("Failed to update building unit.");
@@ -5696,14 +5795,14 @@ function useBuildingUnitRepo() {
5696
5795
  try {
5697
5796
  query.school = new ObjectId18(school);
5698
5797
  } catch (error) {
5699
- throw new BadRequestError27("Invalid school ID.");
5798
+ throw new BadRequestError28("Invalid school ID.");
5700
5799
  }
5701
5800
  }
5702
5801
  if (building) {
5703
5802
  try {
5704
5803
  query.building = new ObjectId18(building);
5705
5804
  } catch (error) {
5706
- throw new BadRequestError27("Invalid building ID.");
5805
+ throw new BadRequestError28("Invalid building ID.");
5707
5806
  }
5708
5807
  }
5709
5808
  const cacheParams = {
@@ -5762,7 +5861,7 @@ function useBuildingUnitRepo() {
5762
5861
  try {
5763
5862
  _id = new ObjectId18(_id);
5764
5863
  } catch (error) {
5765
- throw new BadRequestError27("Invalid ID.");
5864
+ throw new BadRequestError28("Invalid ID.");
5766
5865
  }
5767
5866
  const cacheKey = makeCacheKey12(namespace_collection, { _id: String(_id) });
5768
5867
  try {
@@ -5779,7 +5878,7 @@ function useBuildingUnitRepo() {
5779
5878
  deletedAt: { $in: ["", null] }
5780
5879
  });
5781
5880
  if (!result) {
5782
- throw new BadRequestError27("Building unit not found.");
5881
+ throw new BadRequestError28("Building unit not found.");
5783
5882
  }
5784
5883
  setCache(cacheKey, result, 300).then(() => {
5785
5884
  logger20.log({
@@ -5794,7 +5893,7 @@ function useBuildingUnitRepo() {
5794
5893
  });
5795
5894
  return result;
5796
5895
  } catch (error) {
5797
- if (error instanceof AppError9) {
5896
+ if (error instanceof AppError10) {
5798
5897
  throw error;
5799
5898
  } else {
5800
5899
  throw new InternalServerError15("Failed to get building unit.");
@@ -5805,7 +5904,7 @@ function useBuildingUnitRepo() {
5805
5904
  try {
5806
5905
  building = new ObjectId18(building);
5807
5906
  } catch (error) {
5808
- throw new BadRequestError27("Invalid building ID.");
5907
+ throw new BadRequestError28("Invalid building ID.");
5809
5908
  }
5810
5909
  const cacheKey = makeCacheKey12(namespace_collection, {
5811
5910
  building: String(building),
@@ -5838,7 +5937,7 @@ function useBuildingUnitRepo() {
5838
5937
  });
5839
5938
  return result;
5840
5939
  } catch (error) {
5841
- if (error instanceof AppError9) {
5940
+ if (error instanceof AppError10) {
5842
5941
  throw error;
5843
5942
  } else {
5844
5943
  throw new InternalServerError15("Failed to get building unit.");
@@ -5849,7 +5948,7 @@ function useBuildingUnitRepo() {
5849
5948
  try {
5850
5949
  building = new ObjectId18(building);
5851
5950
  } catch (error) {
5852
- throw new BadRequestError27("Invalid building ID.");
5951
+ throw new BadRequestError28("Invalid building ID.");
5853
5952
  }
5854
5953
  const cacheKey = makeCacheKey12(namespace_collection, {
5855
5954
  building: String(building)
@@ -5880,7 +5979,7 @@ function useBuildingUnitRepo() {
5880
5979
  });
5881
5980
  return result;
5882
5981
  } catch (error) {
5883
- if (error instanceof AppError9) {
5982
+ if (error instanceof AppError10) {
5884
5983
  throw error;
5885
5984
  } else {
5886
5985
  throw new InternalServerError15("Failed to get building unit.");
@@ -5891,7 +5990,7 @@ function useBuildingUnitRepo() {
5891
5990
  try {
5892
5991
  _id = new ObjectId18(_id);
5893
5992
  } catch (error) {
5894
- throw new BadRequestError27("Invalid ID.");
5993
+ throw new BadRequestError28("Invalid ID.");
5895
5994
  }
5896
5995
  try {
5897
5996
  const res = await collection.updateOne(
@@ -5906,7 +6005,7 @@ function useBuildingUnitRepo() {
5906
6005
  level: "error",
5907
6006
  message: error.message
5908
6007
  });
5909
- if (error instanceof AppError9) {
6008
+ if (error instanceof AppError10) {
5910
6009
  throw error;
5911
6010
  } else {
5912
6011
  throw new Error("Failed to deleted room/facility.");
@@ -5945,7 +6044,7 @@ function useBuildingService() {
5945
6044
  if (data.levels < building.levels) {
5946
6045
  const unit = await getByBuildingLevel(id, building.levels);
5947
6046
  if (unit) {
5948
- throw new BadRequestError28(
6047
+ throw new BadRequestError29(
5949
6048
  "Cannot reduce floors, there are existing building units at higher floors."
5950
6049
  );
5951
6050
  }
@@ -5967,7 +6066,7 @@ function useBuildingService() {
5967
6066
  async function deleteById(id) {
5968
6067
  const building = await getByBuilding(id);
5969
6068
  if (building) {
5970
- throw new BadRequestError28(
6069
+ throw new BadRequestError29(
5971
6070
  "Cannot delete building with existing room/facility. Please delete room/facility first."
5972
6071
  );
5973
6072
  }
@@ -5985,7 +6084,7 @@ function useBuildingService() {
5985
6084
  }
5986
6085
 
5987
6086
  // src/resources/building/building.controller.ts
5988
- import { BadRequestError as BadRequestError29, logger as logger21 } from "@goweekdays/utils";
6087
+ import { BadRequestError as BadRequestError30, logger as logger21 } from "@goweekdays/utils";
5989
6088
  import Joi16 from "joi";
5990
6089
  function useBuildingController() {
5991
6090
  const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
@@ -6001,7 +6100,7 @@ function useBuildingController() {
6001
6100
  });
6002
6101
  const { error } = validation.validate(value);
6003
6102
  if (error) {
6004
- next(new BadRequestError29(error.message));
6103
+ next(new BadRequestError30(error.message));
6005
6104
  logger21.info(`Controller: ${error.message}`);
6006
6105
  return;
6007
6106
  }
@@ -6026,7 +6125,7 @@ function useBuildingController() {
6026
6125
  });
6027
6126
  const { error } = validation.validate({ id, value });
6028
6127
  if (error) {
6029
- next(new BadRequestError29(error.message));
6128
+ next(new BadRequestError30(error.message));
6030
6129
  logger21.info(`Controller: ${error.message}`);
6031
6130
  return;
6032
6131
  }
@@ -6049,7 +6148,7 @@ function useBuildingController() {
6049
6148
  });
6050
6149
  const { error } = validation.validate(query);
6051
6150
  if (error) {
6052
- next(new BadRequestError29(error.message));
6151
+ next(new BadRequestError30(error.message));
6053
6152
  return;
6054
6153
  }
6055
6154
  const page = parseInt(req.query.page) ?? 1;
@@ -6088,7 +6187,7 @@ function useBuildingController() {
6088
6187
  });
6089
6188
  const { error } = validation.validate({ id });
6090
6189
  if (error) {
6091
- next(new BadRequestError29(error.message));
6190
+ next(new BadRequestError30(error.message));
6092
6191
  return;
6093
6192
  }
6094
6193
  try {
@@ -6109,7 +6208,7 @@ function useBuildingController() {
6109
6208
  });
6110
6209
  const { error } = validation.validate({ id });
6111
6210
  if (error) {
6112
- next(new BadRequestError29(error.message));
6211
+ next(new BadRequestError30(error.message));
6113
6212
  return;
6114
6213
  }
6115
6214
  try {
@@ -6161,7 +6260,7 @@ function useBuildingUnitService() {
6161
6260
  }
6162
6261
 
6163
6262
  // src/resources/building/building-unit.controller.ts
6164
- import { BadRequestError as BadRequestError30 } from "@goweekdays/utils";
6263
+ import { BadRequestError as BadRequestError31 } from "@goweekdays/utils";
6165
6264
  import Joi17 from "joi";
6166
6265
  function useBuildingUnitController() {
6167
6266
  const {
@@ -6193,7 +6292,7 @@ function useBuildingUnitController() {
6193
6292
  });
6194
6293
  const { error } = validation.validate(data);
6195
6294
  if (error) {
6196
- next(new BadRequestError30(error.message));
6295
+ next(new BadRequestError31(error.message));
6197
6296
  return;
6198
6297
  }
6199
6298
  try {
@@ -6215,7 +6314,7 @@ function useBuildingUnitController() {
6215
6314
  });
6216
6315
  const { error } = validation.validate({ id, value: data });
6217
6316
  if (error) {
6218
- next(new BadRequestError30(error.message));
6317
+ next(new BadRequestError31(error.message));
6219
6318
  return;
6220
6319
  }
6221
6320
  try {
@@ -6240,7 +6339,7 @@ function useBuildingUnitController() {
6240
6339
  });
6241
6340
  const { error } = validation.validate(query);
6242
6341
  if (error) {
6243
- next(new BadRequestError30(error.message));
6342
+ next(new BadRequestError31(error.message));
6244
6343
  return;
6245
6344
  }
6246
6345
  const page = parseInt(req.query.page) ?? 1;
@@ -6281,7 +6380,7 @@ function useBuildingUnitController() {
6281
6380
  });
6282
6381
  const { error } = validation.validate({ id });
6283
6382
  if (error) {
6284
- next(new BadRequestError30(error.message));
6383
+ next(new BadRequestError31(error.message));
6285
6384
  return;
6286
6385
  }
6287
6386
  try {
@@ -6302,7 +6401,7 @@ function useBuildingUnitController() {
6302
6401
  });
6303
6402
  const { error } = validation.validate({ id });
6304
6403
  if (error) {
6305
- next(new BadRequestError30(error.message));
6404
+ next(new BadRequestError31(error.message));
6306
6405
  return;
6307
6406
  }
6308
6407
  try {
@@ -6323,7 +6422,7 @@ function useBuildingUnitController() {
6323
6422
  }
6324
6423
 
6325
6424
  // src/resources/counter/counter.model.ts
6326
- import { BadRequestError as BadRequestError31 } from "@goweekdays/utils";
6425
+ import { BadRequestError as BadRequestError32 } from "@goweekdays/utils";
6327
6426
  import { ObjectId as ObjectId19 } from "mongodb";
6328
6427
  import { z } from "zod";
6329
6428
  var TCounter = z.object({
@@ -6343,7 +6442,7 @@ function useCounterModel(db) {
6343
6442
  try {
6344
6443
  return TCounter.parse(value);
6345
6444
  } catch (error) {
6346
- throw new BadRequestError31(error.issues[0].message);
6445
+ throw new BadRequestError32(error.issues[0].message);
6347
6446
  }
6348
6447
  }
6349
6448
  function validateCounter(data) {
@@ -6560,8 +6659,8 @@ function useFileService() {
6560
6659
 
6561
6660
  // src/resources/file/file.controller.ts
6562
6661
  import {
6563
- AppError as AppError10,
6564
- BadRequestError as BadRequestError32,
6662
+ AppError as AppError11,
6663
+ BadRequestError as BadRequestError33,
6565
6664
  InternalServerError as InternalServerError16
6566
6665
  } from "@goweekdays/utils";
6567
6666
  import Joi18 from "joi";
@@ -6577,7 +6676,7 @@ function useFileController() {
6577
6676
  res.json({ message: "Successfully uploaded file", id });
6578
6677
  return;
6579
6678
  } catch (error) {
6580
- if (error instanceof AppError10) {
6679
+ if (error instanceof AppError11) {
6581
6680
  next(error);
6582
6681
  } else {
6583
6682
  next(new InternalServerError16(error));
@@ -6589,14 +6688,14 @@ function useFileController() {
6589
6688
  const validation = Joi18.string().required();
6590
6689
  const { error } = validation.validate(id);
6591
6690
  if (error) {
6592
- next(new BadRequestError32(error.message));
6691
+ next(new BadRequestError33(error.message));
6593
6692
  }
6594
6693
  try {
6595
6694
  const message = await _deleteFile(id);
6596
6695
  res.json({ message });
6597
6696
  return;
6598
6697
  } catch (error2) {
6599
- if (error2 instanceof AppError10) {
6698
+ if (error2 instanceof AppError11) {
6600
6699
  next(error2);
6601
6700
  } else {
6602
6701
  next(new InternalServerError16(error2));
@@ -6611,7 +6710,7 @@ function useFileController() {
6611
6710
 
6612
6711
  // src/resources/member/member.controller.ts
6613
6712
  import Joi19 from "joi";
6614
- import { BadRequestError as BadRequestError33 } from "@goweekdays/utils";
6713
+ import { BadRequestError as BadRequestError34 } from "@goweekdays/utils";
6615
6714
  function useMemberController() {
6616
6715
  const {
6617
6716
  getByUserId: _getByUserId,
@@ -6627,7 +6726,7 @@ function useMemberController() {
6627
6726
  });
6628
6727
  const { error } = validation.validate({ id: userId });
6629
6728
  if (error) {
6630
- next(new BadRequestError33(error.message));
6729
+ next(new BadRequestError34(error.message));
6631
6730
  return;
6632
6731
  }
6633
6732
  try {
@@ -6649,7 +6748,7 @@ function useMemberController() {
6649
6748
  });
6650
6749
  const { error } = validation.validate({ ...req.params, ...req.query });
6651
6750
  if (error) {
6652
- next(new BadRequestError33(error.message));
6751
+ next(new BadRequestError34(error.message));
6653
6752
  return;
6654
6753
  }
6655
6754
  const orgId = req.query.org;
@@ -6693,7 +6792,7 @@ function useMemberController() {
6693
6792
  status
6694
6793
  });
6695
6794
  if (error) {
6696
- next(new BadRequestError33(error.message));
6795
+ next(new BadRequestError34(error.message));
6697
6796
  return;
6698
6797
  }
6699
6798
  try {
@@ -6730,7 +6829,7 @@ function useMemberController() {
6730
6829
  limit
6731
6830
  });
6732
6831
  if (error) {
6733
- next(new BadRequestError33(error.message));
6832
+ next(new BadRequestError34(error.message));
6734
6833
  }
6735
6834
  try {
6736
6835
  const items = await _getOrgsByMembership({
@@ -6752,7 +6851,7 @@ function useMemberController() {
6752
6851
  });
6753
6852
  const { error } = validation.validate(req.params);
6754
6853
  if (error) {
6755
- next(new BadRequestError33(error.message));
6854
+ next(new BadRequestError34(error.message));
6756
6855
  return;
6757
6856
  }
6758
6857
  const id = req.params.id;
@@ -6774,42 +6873,32 @@ function useMemberController() {
6774
6873
  }
6775
6874
 
6776
6875
  // src/resources/organization/organization.model.ts
6777
- import { BadRequestError as BadRequestError34 } from "@goweekdays/utils";
6876
+ import { BadRequestError as BadRequestError35 } from "@goweekdays/utils";
6778
6877
  import Joi20 from "joi";
6779
6878
  import { ObjectId as ObjectId20 } from "mongodb";
6780
- var OrgTypes = [
6781
- "marketplace",
6782
- "stay",
6783
- "eat",
6784
- "service",
6785
- "ride",
6786
- "experience"
6787
- ];
6788
6879
  var schemaOrg = Joi20.object({
6789
6880
  name: Joi20.string().max(255).required(),
6790
6881
  description: Joi20.string().max(1024).optional().allow("", null),
6791
- type: Joi20.string().allow(...OrgTypes).required(),
6792
6882
  email: Joi20.string().email().max(255).optional().allow("", null),
6793
6883
  contact: Joi20.string().max(50).optional().allow("", null),
6794
6884
  createdBy: Joi20.string().hex().required()
6795
6885
  });
6796
- function MOrg(value) {
6886
+ function modelOrg(value) {
6797
6887
  const { error } = schemaOrg.validate(value);
6798
6888
  if (error) {
6799
- throw new BadRequestError34(error.message);
6889
+ throw new BadRequestError35(error.message);
6800
6890
  }
6801
6891
  if (value.createdBy && typeof value.createdBy === "string") {
6802
6892
  try {
6803
6893
  value.createdBy = new ObjectId20(value.createdBy);
6804
6894
  } catch (error2) {
6805
- throw new BadRequestError34("Invalid createdBy ObjectId");
6895
+ throw new BadRequestError35("Invalid createdBy ObjectId");
6806
6896
  }
6807
6897
  }
6808
6898
  return {
6809
6899
  _id: value._id,
6810
6900
  name: value.name,
6811
- description: value.description,
6812
- type: value.type,
6901
+ description: value.description ?? "",
6813
6902
  email: value.email,
6814
6903
  contact: value.contact,
6815
6904
  createdBy: value.createdBy,
@@ -6822,8 +6911,8 @@ function MOrg(value) {
6822
6911
 
6823
6912
  // src/resources/organization/organization.repository.ts
6824
6913
  import {
6825
- AppError as AppError11,
6826
- BadRequestError as BadRequestError35,
6914
+ AppError as AppError12,
6915
+ BadRequestError as BadRequestError36,
6827
6916
  InternalServerError as InternalServerError17,
6828
6917
  logger as logger24,
6829
6918
  makeCacheKey as makeCacheKey14,
@@ -6872,7 +6961,7 @@ function useOrgRepo() {
6872
6961
  }
6873
6962
  async function add(value, session) {
6874
6963
  try {
6875
- value = MOrg(value);
6964
+ value = modelOrg(value);
6876
6965
  const res = await collection.insertOne(value, { session });
6877
6966
  delCachedData();
6878
6967
  return res.insertedId;
@@ -6881,12 +6970,12 @@ function useOrgRepo() {
6881
6970
  level: "error",
6882
6971
  message: error.message
6883
6972
  });
6884
- if (error instanceof AppError11) {
6973
+ if (error instanceof AppError12) {
6885
6974
  throw error;
6886
6975
  } else {
6887
6976
  const isDuplicated = error.message.includes("duplicate");
6888
6977
  if (isDuplicated) {
6889
- throw new BadRequestError35("Organization already exist.");
6978
+ throw new BadRequestError36("Organization already exist.");
6890
6979
  }
6891
6980
  throw new Error("Failed to create organization.");
6892
6981
  }
@@ -6963,7 +7052,7 @@ function useOrgRepo() {
6963
7052
  try {
6964
7053
  _id = new ObjectId21(_id);
6965
7054
  } catch (error) {
6966
- throw new BadRequestError35("Invalid ID.");
7055
+ throw new BadRequestError36("Invalid ID.");
6967
7056
  }
6968
7057
  const cacheKey = makeCacheKey14(namespace_collection, { _id: String(_id) });
6969
7058
  try {
@@ -6977,7 +7066,7 @@ function useOrgRepo() {
6977
7066
  }
6978
7067
  const result = await collection.findOne({ _id });
6979
7068
  if (!result) {
6980
- throw new BadRequestError35("Organization not found.");
7069
+ throw new BadRequestError36("Organization not found.");
6981
7070
  }
6982
7071
  setCache(cacheKey, result, 300).then(() => {
6983
7072
  logger24.log({
@@ -6992,7 +7081,7 @@ function useOrgRepo() {
6992
7081
  });
6993
7082
  return result;
6994
7083
  } catch (error) {
6995
- if (error instanceof AppError11) {
7084
+ if (error instanceof AppError12) {
6996
7085
  throw error;
6997
7086
  } else {
6998
7087
  throw new InternalServerError17("Failed to get organization.");
@@ -7012,7 +7101,7 @@ function useOrgRepo() {
7012
7101
  }
7013
7102
  const result = await collection.findOne({ name });
7014
7103
  if (!result) {
7015
- throw new BadRequestError35("Organization not found.");
7104
+ throw new BadRequestError36("Organization not found.");
7016
7105
  }
7017
7106
  setCache(cacheKey, result, 300).then(() => {
7018
7107
  logger24.log({
@@ -7027,7 +7116,7 @@ function useOrgRepo() {
7027
7116
  });
7028
7117
  return result;
7029
7118
  } catch (error) {
7030
- if (error instanceof AppError11) {
7119
+ if (error instanceof AppError12) {
7031
7120
  throw error;
7032
7121
  } else {
7033
7122
  throw new InternalServerError17("Failed to get organization.");
@@ -7037,14 +7126,14 @@ function useOrgRepo() {
7037
7126
  async function updateFieldById({ _id, field, value } = {}, session) {
7038
7127
  const allowedFields = ["name", "description"];
7039
7128
  if (!allowedFields.includes(field)) {
7040
- throw new BadRequestError35(
7129
+ throw new BadRequestError36(
7041
7130
  `Field "${field}" is not allowed to be updated.`
7042
7131
  );
7043
7132
  }
7044
7133
  try {
7045
7134
  _id = new ObjectId21(_id);
7046
7135
  } catch (error) {
7047
- throw new BadRequestError35("Invalid ID.");
7136
+ throw new BadRequestError36("Invalid ID.");
7048
7137
  }
7049
7138
  try {
7050
7139
  await collection.updateOne(
@@ -7063,7 +7152,7 @@ function useOrgRepo() {
7063
7152
  try {
7064
7153
  _id = new ObjectId21(_id);
7065
7154
  } catch (error) {
7066
- throw new BadRequestError35("Invalid ID.");
7155
+ throw new BadRequestError36("Invalid ID.");
7067
7156
  }
7068
7157
  try {
7069
7158
  await collection.updateOne(
@@ -7088,12 +7177,12 @@ function useOrgRepo() {
7088
7177
  }
7089
7178
 
7090
7179
  // src/resources/organization/organization.service.ts
7091
- import { BadRequestError as BadRequestError37, useAtlas as useAtlas21 } from "@goweekdays/utils";
7180
+ import { BadRequestError as BadRequestError38, useAtlas as useAtlas21 } from "@goweekdays/utils";
7092
7181
 
7093
7182
  // src/resources/user/user.controller.ts
7094
7183
  import {
7095
- AppError as AppError12,
7096
- BadRequestError as BadRequestError36,
7184
+ AppError as AppError13,
7185
+ BadRequestError as BadRequestError37,
7097
7186
  InternalServerError as InternalServerError18
7098
7187
  } from "@goweekdays/utils";
7099
7188
  import Joi21 from "joi";
@@ -7119,7 +7208,7 @@ function useUserController() {
7119
7208
  });
7120
7209
  const { error } = validation.validate({ status, search, page });
7121
7210
  if (error) {
7122
- next(new BadRequestError36(error.message));
7211
+ next(new BadRequestError37(error.message));
7123
7212
  return;
7124
7213
  }
7125
7214
  try {
@@ -7134,12 +7223,12 @@ function useUserController() {
7134
7223
  const id = req.params.id || "";
7135
7224
  const validation = Joi21.string().hex().validate(id);
7136
7225
  if (validation.error) {
7137
- throw new BadRequestError36("Invalid id.");
7226
+ throw new BadRequestError37("Invalid id.");
7138
7227
  }
7139
7228
  try {
7140
7229
  const user = await _getUserById(id);
7141
7230
  if (!user) {
7142
- throw new BadRequestError36("User not found.");
7231
+ throw new BadRequestError37("User not found.");
7143
7232
  }
7144
7233
  res.json(user);
7145
7234
  } catch (error) {
@@ -7156,7 +7245,7 @@ function useUserController() {
7156
7245
  });
7157
7246
  const { error } = validation.validate({ firstName, lastName });
7158
7247
  if (error) {
7159
- next(new BadRequestError36(error.message));
7248
+ next(new BadRequestError37(error.message));
7160
7249
  return;
7161
7250
  }
7162
7251
  try {
@@ -7179,7 +7268,7 @@ function useUserController() {
7179
7268
  });
7180
7269
  const { error } = validation.validate({ month, day, year });
7181
7270
  if (error) {
7182
- next(new BadRequestError36(error.message));
7271
+ next(new BadRequestError37(error.message));
7183
7272
  return;
7184
7273
  }
7185
7274
  try {
@@ -7204,7 +7293,7 @@ function useUserController() {
7204
7293
  });
7205
7294
  const { error } = validation.validate({ _id, field, value });
7206
7295
  if (error) {
7207
- next(new BadRequestError36(error.message));
7296
+ next(new BadRequestError37(error.message));
7208
7297
  return;
7209
7298
  }
7210
7299
  try {
@@ -7225,7 +7314,7 @@ function useUserController() {
7225
7314
  });
7226
7315
  const { error } = validation.validate({ previousProfile });
7227
7316
  if (error) {
7228
- next(new BadRequestError36(error.message));
7317
+ next(new BadRequestError37(error.message));
7229
7318
  return;
7230
7319
  }
7231
7320
  const user = req.headers["user"] ?? "";
@@ -7238,7 +7327,7 @@ function useUserController() {
7238
7327
  res.json({ message: "Successfully updated profile picture." });
7239
7328
  return;
7240
7329
  } catch (error2) {
7241
- if (error2 instanceof AppError12) {
7330
+ if (error2 instanceof AppError13) {
7242
7331
  next(error2);
7243
7332
  } else {
7244
7333
  next(new InternalServerError18(error2));
@@ -7266,7 +7355,7 @@ function useUserController() {
7266
7355
  type
7267
7356
  });
7268
7357
  if (error) {
7269
- next(new BadRequestError36(error.message));
7358
+ next(new BadRequestError37(error.message));
7270
7359
  return;
7271
7360
  }
7272
7361
  try {
@@ -7307,11 +7396,14 @@ function useOrgService() {
7307
7396
  const { getUserById } = useUserRepo();
7308
7397
  async function add(value) {
7309
7398
  const session = useAtlas21.getClient()?.startSession();
7310
- session?.startTransaction();
7399
+ if (!session) {
7400
+ throw new BadRequestError38("Unable to start database session.");
7401
+ }
7311
7402
  try {
7403
+ session?.startTransaction();
7312
7404
  const org = await addOrg(value, session);
7313
7405
  const allPermissions = await getAllPermission({
7314
- app: value.type,
7406
+ app: "org",
7315
7407
  limit: 100
7316
7408
  });
7317
7409
  let permissions = [];
@@ -7321,39 +7413,41 @@ function useOrgService() {
7321
7413
  if (permissions.length === 0) {
7322
7414
  throw new Error("No permissions found for the organization type.");
7323
7415
  }
7416
+ const createdBy = String(value.createdBy);
7324
7417
  const role = await addRole(
7325
7418
  {
7326
- id: org,
7419
+ org: String(org),
7327
7420
  name: "Owner",
7328
7421
  description: "Owner of the organization",
7329
- permissions
7422
+ permissions,
7423
+ createdBy
7330
7424
  },
7331
7425
  session
7332
7426
  );
7333
7427
  if (!role) {
7334
- throw new BadRequestError37("Role is required to create org member.");
7428
+ throw new BadRequestError38("Role is required to create org member.");
7335
7429
  }
7336
- const user = await getUserById(value.createdBy);
7430
+ const user = await getUserById(createdBy);
7337
7431
  if (!user) {
7338
- throw new BadRequestError37("User is required to create org member.");
7432
+ throw new BadRequestError38("User is required to create org member.");
7339
7433
  }
7340
7434
  await addMember(
7341
7435
  {
7342
7436
  role: String(role),
7343
7437
  org: String(org),
7344
7438
  name: `${user.firstName} ${user.lastName}`,
7345
- user: value.createdBy,
7346
- type: "owner"
7439
+ user: createdBy,
7440
+ type: "org"
7347
7441
  },
7348
7442
  session
7349
7443
  );
7350
- session?.commitTransaction();
7351
- return "Organization created successfully.";
7444
+ await session?.commitTransaction();
7445
+ return String(org);
7352
7446
  } catch (error) {
7353
- session?.abortTransaction();
7447
+ await session?.abortTransaction();
7354
7448
  throw error;
7355
7449
  } finally {
7356
- session?.endSession();
7450
+ await session?.endSession();
7357
7451
  }
7358
7452
  }
7359
7453
  return {
@@ -7362,7 +7456,7 @@ function useOrgService() {
7362
7456
  }
7363
7457
 
7364
7458
  // src/resources/organization/organization.controller.ts
7365
- import { BadRequestError as BadRequestError38 } from "@goweekdays/utils";
7459
+ import { BadRequestError as BadRequestError39 } from "@goweekdays/utils";
7366
7460
  import Joi22 from "joi";
7367
7461
  function useOrgController() {
7368
7462
  const { add: _add } = useOrgService();
@@ -7372,16 +7466,19 @@ function useOrgController() {
7372
7466
  getAll: getAllOrg,
7373
7467
  getById: _getById
7374
7468
  } = useOrgRepo();
7375
- async function createOrg(req, res, next) {
7469
+ async function add(req, res, next) {
7376
7470
  const value = req.body;
7377
7471
  const { error } = schemaOrg.validate(value);
7378
7472
  if (error) {
7379
- next(new BadRequestError38(error.message));
7473
+ next(new BadRequestError39(error.message));
7380
7474
  return;
7381
7475
  }
7382
7476
  try {
7383
- const message = await _add(value);
7384
- res.json({ message });
7477
+ const org = await _add(value);
7478
+ res.json({
7479
+ message: "Organization created successfully.",
7480
+ data: { org }
7481
+ });
7385
7482
  return;
7386
7483
  } catch (error2) {
7387
7484
  next(error2);
@@ -7394,12 +7491,12 @@ function useOrgController() {
7394
7491
  const user = req.params.user ?? "";
7395
7492
  const isPageNumber = isFinite(page);
7396
7493
  if (!isPageNumber) {
7397
- next(new BadRequestError38("Invalid page number."));
7494
+ next(new BadRequestError39("Invalid page number."));
7398
7495
  return;
7399
7496
  }
7400
7497
  const isLimitNumber = isFinite(limit);
7401
7498
  if (!isLimitNumber) {
7402
- next(new BadRequestError38("Invalid limit number."));
7499
+ next(new BadRequestError39("Invalid limit number."));
7403
7500
  return;
7404
7501
  }
7405
7502
  const validation = Joi22.object({
@@ -7410,7 +7507,7 @@ function useOrgController() {
7410
7507
  });
7411
7508
  const { error } = validation.validate({ user, page, limit, search });
7412
7509
  if (error) {
7413
- next(new BadRequestError38(error.message));
7510
+ next(new BadRequestError39(error.message));
7414
7511
  return;
7415
7512
  }
7416
7513
  try {
@@ -7436,16 +7533,16 @@ function useOrgController() {
7436
7533
  const status = req.query.status ?? "active";
7437
7534
  const isPageNumber = isFinite(page);
7438
7535
  if (!isPageNumber) {
7439
- next(new BadRequestError38("Invalid page number."));
7536
+ next(new BadRequestError39("Invalid page number."));
7440
7537
  return;
7441
7538
  }
7442
7539
  const isLimitNumber = isFinite(limit);
7443
7540
  if (!isLimitNumber) {
7444
- next(new BadRequestError38("Invalid limit number."));
7541
+ next(new BadRequestError39("Invalid limit number."));
7445
7542
  return;
7446
7543
  }
7447
7544
  if (error) {
7448
- next(new BadRequestError38(error.message));
7545
+ next(new BadRequestError39(error.message));
7449
7546
  return;
7450
7547
  }
7451
7548
  try {
@@ -7463,7 +7560,7 @@ function useOrgController() {
7463
7560
  });
7464
7561
  const { error } = validation.validate({ name });
7465
7562
  if (error) {
7466
- next(new BadRequestError38(error.message));
7563
+ next(new BadRequestError39(error.message));
7467
7564
  return;
7468
7565
  }
7469
7566
  try {
@@ -7481,7 +7578,7 @@ function useOrgController() {
7481
7578
  });
7482
7579
  const { error } = validation.validate({ id });
7483
7580
  if (error) {
7484
- next(new BadRequestError38(error.message));
7581
+ next(new BadRequestError39(error.message));
7485
7582
  return;
7486
7583
  }
7487
7584
  try {
@@ -7493,7 +7590,7 @@ function useOrgController() {
7493
7590
  }
7494
7591
  }
7495
7592
  return {
7496
- createOrg,
7593
+ add,
7497
7594
  getOrgsByUserId,
7498
7595
  getByName,
7499
7596
  getAll,
@@ -7522,8 +7619,8 @@ function modelPSGC(data) {
7522
7619
 
7523
7620
  // src/resources/psgc/psgc.repository.ts
7524
7621
  import {
7525
- AppError as AppError13,
7526
- BadRequestError as BadRequestError39,
7622
+ AppError as AppError14,
7623
+ BadRequestError as BadRequestError40,
7527
7624
  InternalServerError as InternalServerError19,
7528
7625
  logger as logger25,
7529
7626
  makeCacheKey as makeCacheKey15,
@@ -7575,12 +7672,12 @@ function usePSGCRepo() {
7575
7672
  level: "error",
7576
7673
  message: error.message
7577
7674
  });
7578
- if (error instanceof AppError13) {
7675
+ if (error instanceof AppError14) {
7579
7676
  throw error;
7580
7677
  } else {
7581
7678
  const isDuplicated = error.message.includes("duplicate");
7582
7679
  if (isDuplicated) {
7583
- throw new BadRequestError39("Region already exists.");
7680
+ throw new BadRequestError40("Region already exists.");
7584
7681
  }
7585
7682
  throw new Error("Failed to create PSGC.");
7586
7683
  }
@@ -7659,7 +7756,7 @@ function usePSGCRepo() {
7659
7756
  try {
7660
7757
  _id = new ObjectId22(_id);
7661
7758
  } catch (error) {
7662
- throw new BadRequestError39("Invalid ID.");
7759
+ throw new BadRequestError40("Invalid ID.");
7663
7760
  }
7664
7761
  const cacheKey = makeCacheKey15(namespace_collection, { _id: String(_id) });
7665
7762
  try {
@@ -7676,7 +7773,7 @@ function usePSGCRepo() {
7676
7773
  deletedAt: { $in: ["", null] }
7677
7774
  });
7678
7775
  if (!result) {
7679
- throw new BadRequestError39("Region not found.");
7776
+ throw new BadRequestError40("Region not found.");
7680
7777
  }
7681
7778
  setCache(cacheKey, result, 300).then(() => {
7682
7779
  logger25.log({
@@ -7691,7 +7788,7 @@ function usePSGCRepo() {
7691
7788
  });
7692
7789
  return result;
7693
7790
  } catch (error) {
7694
- if (error instanceof AppError13) {
7791
+ if (error instanceof AppError14) {
7695
7792
  throw error;
7696
7793
  } else {
7697
7794
  throw new InternalServerError19("Failed to get PSGC.");
@@ -7746,7 +7843,7 @@ function usePSGCRepo() {
7746
7843
  });
7747
7844
  return result;
7748
7845
  } catch (error) {
7749
- if (error instanceof AppError13) {
7846
+ if (error instanceof AppError14) {
7750
7847
  throw error;
7751
7848
  } else {
7752
7849
  throw new InternalServerError19("Failed to get PSGC.");
@@ -7756,14 +7853,14 @@ function usePSGCRepo() {
7756
7853
  async function updateFieldById({ _id, field, value } = {}, session) {
7757
7854
  const allowedFields = ["name"];
7758
7855
  if (!allowedFields.includes(field)) {
7759
- throw new BadRequestError39(
7856
+ throw new BadRequestError40(
7760
7857
  `Field "${field}" is not allowed to be updated.`
7761
7858
  );
7762
7859
  }
7763
7860
  try {
7764
7861
  _id = new ObjectId22(_id);
7765
7862
  } catch (error) {
7766
- throw new BadRequestError39("Invalid ID.");
7863
+ throw new BadRequestError40("Invalid ID.");
7767
7864
  }
7768
7865
  try {
7769
7866
  await collection.updateOne(
@@ -7781,7 +7878,7 @@ function usePSGCRepo() {
7781
7878
  try {
7782
7879
  _id = new ObjectId22(_id);
7783
7880
  } catch (error) {
7784
- throw new BadRequestError39("Invalid ID.");
7881
+ throw new BadRequestError40("Invalid ID.");
7785
7882
  }
7786
7883
  try {
7787
7884
  await collection.updateOne(
@@ -7806,7 +7903,7 @@ function usePSGCRepo() {
7806
7903
  }
7807
7904
 
7808
7905
  // src/resources/psgc/psgc.controller.ts
7809
- import { BadRequestError as BadRequestError40 } from "@goweekdays/utils";
7906
+ import { BadRequestError as BadRequestError41 } from "@goweekdays/utils";
7810
7907
  import Joi24 from "joi";
7811
7908
  function usePSGCController() {
7812
7909
  const {
@@ -7821,7 +7918,7 @@ function usePSGCController() {
7821
7918
  const value = req.body;
7822
7919
  const { error } = schemaPSGC.validate(value);
7823
7920
  if (error) {
7824
- next(new BadRequestError40(error.message));
7921
+ next(new BadRequestError41(error.message));
7825
7922
  return;
7826
7923
  }
7827
7924
  try {
@@ -7852,16 +7949,16 @@ function usePSGCController() {
7852
7949
  const prefix = req.query.prefix ? String(req.query.prefix) : "";
7853
7950
  const isPageNumber = isFinite(page);
7854
7951
  if (!isPageNumber) {
7855
- next(new BadRequestError40("Invalid page number."));
7952
+ next(new BadRequestError41("Invalid page number."));
7856
7953
  return;
7857
7954
  }
7858
7955
  const isLimitNumber = isFinite(limit);
7859
7956
  if (!isLimitNumber) {
7860
- next(new BadRequestError40("Invalid limit number."));
7957
+ next(new BadRequestError41("Invalid limit number."));
7861
7958
  return;
7862
7959
  }
7863
7960
  if (error) {
7864
- next(new BadRequestError40(error.message));
7961
+ next(new BadRequestError41(error.message));
7865
7962
  return;
7866
7963
  }
7867
7964
  try {
@@ -7885,7 +7982,7 @@ function usePSGCController() {
7885
7982
  });
7886
7983
  const { error } = validation.validate({ id });
7887
7984
  if (error) {
7888
- next(new BadRequestError40(error.message));
7985
+ next(new BadRequestError41(error.message));
7889
7986
  return;
7890
7987
  }
7891
7988
  try {
@@ -7906,7 +8003,7 @@ function usePSGCController() {
7906
8003
  });
7907
8004
  const { error } = validation.validate({ name });
7908
8005
  if (error) {
7909
- next(new BadRequestError40(error.message));
8006
+ next(new BadRequestError41(error.message));
7910
8007
  return;
7911
8008
  }
7912
8009
  try {
@@ -7930,7 +8027,7 @@ function usePSGCController() {
7930
8027
  });
7931
8028
  const { error } = validation.validate({ _id, field, value });
7932
8029
  if (error) {
7933
- next(new BadRequestError40(error.message));
8030
+ next(new BadRequestError41(error.message));
7934
8031
  return;
7935
8032
  }
7936
8033
  try {
@@ -7948,7 +8045,7 @@ function usePSGCController() {
7948
8045
  });
7949
8046
  const { error } = validation.validate({ _id });
7950
8047
  if (error) {
7951
- next(new BadRequestError40(error.message));
8048
+ next(new BadRequestError41(error.message));
7952
8049
  return;
7953
8050
  }
7954
8051
  try {
@@ -7969,24 +8066,53 @@ function usePSGCController() {
7969
8066
  };
7970
8067
  }
7971
8068
 
8069
+ // src/resources/role/role.service.ts
8070
+ import {
8071
+ AppError as AppError15,
8072
+ BadRequestError as BadRequestError42,
8073
+ InternalServerError as InternalServerError20
8074
+ } from "@goweekdays/utils";
8075
+ function useRoleService() {
8076
+ const { getByRole } = useMemberRepo();
8077
+ const { deleteById: _deleteById } = useRoleRepo();
8078
+ async function deleteById(id) {
8079
+ try {
8080
+ const role = await getByRole(id);
8081
+ if (role) {
8082
+ throw new BadRequestError42("Cannot delete role assigned to members.");
8083
+ }
8084
+ await _deleteById(id);
8085
+ } catch (error) {
8086
+ if (error instanceof AppError15) {
8087
+ throw error;
8088
+ } else {
8089
+ throw new InternalServerError20("Failed to delete role.");
8090
+ }
8091
+ }
8092
+ }
8093
+ return {
8094
+ deleteById
8095
+ };
8096
+ }
8097
+
7972
8098
  // src/resources/role/role.controller.ts
7973
8099
  import Joi25 from "joi";
7974
- import { BadRequestError as BadRequestError41 } from "@goweekdays/utils";
8100
+ import { BadRequestError as BadRequestError43 } from "@goweekdays/utils";
7975
8101
  function useRoleController() {
7976
8102
  const {
7977
8103
  addRole: _createRole,
7978
- getRoleById: _getRoleById,
8104
+ getById,
7979
8105
  getRoleByUserId: _getRoleByUserId,
7980
8106
  getRoles: _getRoles,
7981
8107
  updateRole: _updateRole,
7982
- deleteRole: _deleteRole,
7983
8108
  updatePermissionsById: _updatePermissionsById
7984
8109
  } = useRoleRepo();
8110
+ const { deleteById: _deleteById } = useRoleService();
7985
8111
  async function createRole(req, res, next) {
7986
8112
  const payload = req.body;
7987
8113
  const { error } = schemaRole.validate(payload);
7988
8114
  if (error) {
7989
- next(new BadRequestError41(error.message));
8115
+ next(new BadRequestError43(error.message));
7990
8116
  return;
7991
8117
  }
7992
8118
  try {
@@ -8012,7 +8138,7 @@ function useRoleController() {
8012
8138
  });
8013
8139
  const { error } = validation.validate({ search, page, limit, type, id });
8014
8140
  if (error) {
8015
- next(new BadRequestError41(error.message));
8141
+ next(new BadRequestError43(error.message));
8016
8142
  return;
8017
8143
  }
8018
8144
  try {
@@ -8030,7 +8156,7 @@ function useRoleController() {
8030
8156
  });
8031
8157
  const { error } = validation.validate({ userId });
8032
8158
  if (error) {
8033
- next(new BadRequestError41(error.message));
8159
+ next(new BadRequestError43(error.message));
8034
8160
  return;
8035
8161
  }
8036
8162
  try {
@@ -8048,11 +8174,11 @@ function useRoleController() {
8048
8174
  });
8049
8175
  const { error } = validation.validate({ _id });
8050
8176
  if (error) {
8051
- next(new BadRequestError41(error.message));
8177
+ next(new BadRequestError43(error.message));
8052
8178
  return;
8053
8179
  }
8054
8180
  try {
8055
- const data = await _getRoleById(_id);
8181
+ const data = await getById(_id);
8056
8182
  res.json(data);
8057
8183
  return;
8058
8184
  } catch (error2) {
@@ -8070,7 +8196,7 @@ function useRoleController() {
8070
8196
  });
8071
8197
  const { error } = validation.validate({ _id, name, permissions });
8072
8198
  if (error) {
8073
- next(new BadRequestError41(error.message));
8199
+ next(new BadRequestError43(error.message));
8074
8200
  return;
8075
8201
  }
8076
8202
  try {
@@ -8090,7 +8216,7 @@ function useRoleController() {
8090
8216
  });
8091
8217
  const { error } = validation.validate({ _id, permissions });
8092
8218
  if (error) {
8093
- next(new BadRequestError41(error.message));
8219
+ next(new BadRequestError43(error.message));
8094
8220
  return;
8095
8221
  }
8096
8222
  try {
@@ -8108,11 +8234,11 @@ function useRoleController() {
8108
8234
  });
8109
8235
  const { error } = validation.validate({ _id });
8110
8236
  if (error) {
8111
- next(new BadRequestError41(error.message));
8237
+ next(new BadRequestError43(error.message));
8112
8238
  return;
8113
8239
  }
8114
8240
  try {
8115
- const message = await _deleteRole(_id);
8241
+ const message = await _deleteById(_id);
8116
8242
  res.json({ message });
8117
8243
  return;
8118
8244
  } catch (error2) {
@@ -8131,7 +8257,7 @@ function useRoleController() {
8131
8257
  }
8132
8258
 
8133
8259
  // src/resources/utils/github.service.ts
8134
- import { AppError as AppError14, BadRequestError as BadRequestError42 } from "@goweekdays/utils";
8260
+ import { AppError as AppError16, BadRequestError as BadRequestError44 } from "@goweekdays/utils";
8135
8261
  import { Octokit } from "@octokit/rest";
8136
8262
  import _sodium from "libsodium-wrappers";
8137
8263
  function useGitHubService() {
@@ -8145,23 +8271,23 @@ function useGitHubService() {
8145
8271
  try {
8146
8272
  const { data: repoData } = await octokit.repos.get({ owner, repo });
8147
8273
  if (!repoData.permissions?.admin) {
8148
- throw new BadRequestError42(
8274
+ throw new BadRequestError44(
8149
8275
  "You do not have admin access to this repository."
8150
8276
  );
8151
8277
  }
8152
8278
  } catch (error) {
8153
8279
  if (error.status === 404) {
8154
- throw new BadRequestError42(
8280
+ throw new BadRequestError44(
8155
8281
  "Repository not found or you don't have access to it."
8156
8282
  );
8157
8283
  } else if (error.status === 401) {
8158
- throw new BadRequestError42(
8284
+ throw new BadRequestError44(
8159
8285
  "Invalid GitHub token or insufficient permissions."
8160
8286
  );
8161
8287
  } else if (error.message.includes("admin access")) {
8162
8288
  throw error;
8163
8289
  } else {
8164
- throw new BadRequestError42(
8290
+ throw new BadRequestError44(
8165
8291
  `Failed to check repository permissions: ${error.message}`
8166
8292
  );
8167
8293
  }
@@ -8210,7 +8336,7 @@ function useGitHubService() {
8210
8336
  key_id: publicKeyRes.key_id
8211
8337
  });
8212
8338
  } catch (encryptionError) {
8213
- throw new BadRequestError42(
8339
+ throw new BadRequestError44(
8214
8340
  `Failed to encrypt secret '${key}': ${encryptionError.message}`
8215
8341
  );
8216
8342
  }
@@ -8240,22 +8366,22 @@ function useGitHubService() {
8240
8366
  }
8241
8367
  return `Successfully set ${lines.length} ${type} variables/secrets in environment '${environment}'`;
8242
8368
  } catch (error) {
8243
- if (error instanceof AppError14)
8369
+ if (error instanceof AppError16)
8244
8370
  throw error;
8245
8371
  if (error.status === 422) {
8246
- throw new BadRequestError42(
8372
+ throw new BadRequestError44(
8247
8373
  `GitHub API validation error: ${error.message}`
8248
8374
  );
8249
8375
  } else if (error.status === 404) {
8250
- throw new BadRequestError42("Environment or repository not found.");
8376
+ throw new BadRequestError44("Environment or repository not found.");
8251
8377
  } else if (error.status === 403) {
8252
- throw new BadRequestError42(
8378
+ throw new BadRequestError44(
8253
8379
  "Forbidden: Insufficient permissions or rate limit exceeded."
8254
8380
  );
8255
8381
  } else if (error.message.includes("admin access") || error.message.includes("permissions")) {
8256
8382
  throw error;
8257
8383
  } else {
8258
- throw new BadRequestError42(
8384
+ throw new BadRequestError44(
8259
8385
  `Failed to set GitHub variables: ${error.message}`
8260
8386
  );
8261
8387
  }
@@ -8269,9 +8395,9 @@ function useGitHubService() {
8269
8395
  // src/resources/utils/util.controller.ts
8270
8396
  import Joi26 from "joi";
8271
8397
  import {
8272
- AppError as AppError15,
8273
- BadRequestError as BadRequestError43,
8274
- InternalServerError as InternalServerError21,
8398
+ AppError as AppError17,
8399
+ BadRequestError as BadRequestError45,
8400
+ InternalServerError as InternalServerError22,
8275
8401
  logger as logger26
8276
8402
  } from "@goweekdays/utils";
8277
8403
  function useUtilController() {
@@ -8290,7 +8416,7 @@ function useUtilController() {
8290
8416
  });
8291
8417
  } catch (error) {
8292
8418
  logger26.error("Health check failed", { error: error.message });
8293
- next(new InternalServerError21("Health check failed"));
8419
+ next(new InternalServerError22("Health check failed"));
8294
8420
  }
8295
8421
  }
8296
8422
  async function setGitHubVariables(req, res, next) {
@@ -8327,13 +8453,13 @@ function useUtilController() {
8327
8453
  keyValues
8328
8454
  });
8329
8455
  if (error) {
8330
- next(new BadRequestError43(error.message));
8456
+ next(new BadRequestError45(error.message));
8331
8457
  return;
8332
8458
  }
8333
8459
  const repoUrlPattern = /github\.com[:\/]([^\/]+)\/(.+)\.git$/;
8334
8460
  if (!repoUrlPattern.test(repoUrl)) {
8335
8461
  next(
8336
- new BadRequestError43(
8462
+ new BadRequestError45(
8337
8463
  "Invalid GitHub repository URL format. Expected format: https://github.com/owner/repo.git"
8338
8464
  )
8339
8465
  );
@@ -8345,7 +8471,7 @@ function useUtilController() {
8345
8471
  );
8346
8472
  if (invalidLines.length > 0) {
8347
8473
  next(
8348
- new BadRequestError43(
8474
+ new BadRequestError45(
8349
8475
  "Invalid key-value format. Each pair should be in format: KEY=value. Pairs should be separated by semicolons."
8350
8476
  )
8351
8477
  );
@@ -8380,11 +8506,11 @@ function useUtilController() {
8380
8506
  error: error.message,
8381
8507
  stack: error.stack
8382
8508
  });
8383
- if (error instanceof AppError15) {
8509
+ if (error instanceof AppError17) {
8384
8510
  next(error);
8385
8511
  } else {
8386
8512
  next(
8387
- new InternalServerError21(
8513
+ new InternalServerError22(
8388
8514
  `Failed to set GitHub variables: ${error.message}`
8389
8515
  )
8390
8516
  );
@@ -8422,9 +8548,9 @@ var transactionSchema = Joi27.object({
8422
8548
 
8423
8549
  // src/resources/verification/verification.controller.ts
8424
8550
  import {
8425
- AppError as AppError16,
8426
- BadRequestError as BadRequestError44,
8427
- InternalServerError as InternalServerError22
8551
+ AppError as AppError18,
8552
+ BadRequestError as BadRequestError46,
8553
+ InternalServerError as InternalServerError23
8428
8554
  } from "@goweekdays/utils";
8429
8555
  import Joi28 from "joi";
8430
8556
  function useVerificationController() {
@@ -8446,7 +8572,7 @@ function useVerificationController() {
8446
8572
  });
8447
8573
  const { error } = validation.validate(req.body);
8448
8574
  if (error) {
8449
- next(new BadRequestError44(error.message));
8575
+ next(new BadRequestError46(error.message));
8450
8576
  return;
8451
8577
  }
8452
8578
  const email = req.body.email ?? "";
@@ -8477,7 +8603,7 @@ function useVerificationController() {
8477
8603
  const validation = Joi28.string().email().required();
8478
8604
  const { error } = validation.validate(email);
8479
8605
  if (error) {
8480
- next(new BadRequestError44(error.message));
8606
+ next(new BadRequestError46(error.message));
8481
8607
  return;
8482
8608
  }
8483
8609
  try {
@@ -8487,10 +8613,10 @@ function useVerificationController() {
8487
8613
  });
8488
8614
  return;
8489
8615
  } catch (error2) {
8490
- if (error2 instanceof AppError16) {
8616
+ if (error2 instanceof AppError18) {
8491
8617
  next(error2);
8492
8618
  } else {
8493
- next(new InternalServerError22("An unexpected error occurred"));
8619
+ next(new InternalServerError23("An unexpected error occurred"));
8494
8620
  }
8495
8621
  }
8496
8622
  }
@@ -8505,7 +8631,7 @@ function useVerificationController() {
8505
8631
  });
8506
8632
  const { error } = validation.validate(req.query);
8507
8633
  if (error) {
8508
- next(new BadRequestError44(error.message));
8634
+ next(new BadRequestError46(error.message));
8509
8635
  return;
8510
8636
  }
8511
8637
  const status = req.query.status ?? "";
@@ -8539,7 +8665,7 @@ function useVerificationController() {
8539
8665
  const validation = Joi28.string().hex().required();
8540
8666
  const { error } = validation.validate(id);
8541
8667
  if (error) {
8542
- next(new BadRequestError44(error.message));
8668
+ next(new BadRequestError46(error.message));
8543
8669
  return;
8544
8670
  }
8545
8671
  try {
@@ -8555,7 +8681,7 @@ function useVerificationController() {
8555
8681
  const validation = Joi28.string().hex().required();
8556
8682
  const { error } = validation.validate(otpId);
8557
8683
  if (error) {
8558
- next(new BadRequestError44(error.message));
8684
+ next(new BadRequestError46(error.message));
8559
8685
  return;
8560
8686
  }
8561
8687
  try {
@@ -8597,11 +8723,9 @@ export {
8597
8723
  MMember,
8598
8724
  MONGO_DB,
8599
8725
  MONGO_URI,
8600
- MOrg,
8601
8726
  MUser,
8602
8727
  MUserRole,
8603
8728
  MVerification,
8604
- OrgTypes,
8605
8729
  PAYPAL_API_URL,
8606
8730
  PAYPAL_CLIENT_ID,
8607
8731
  PAYPAL_CLIENT_SECRET,
@@ -8624,6 +8748,8 @@ export {
8624
8748
  addressSchema,
8625
8749
  isDev,
8626
8750
  modelApp,
8751
+ modelMember,
8752
+ modelOrg,
8627
8753
  modelPSGC,
8628
8754
  modelPermission,
8629
8755
  modelPermissionGroup,
@@ -8632,6 +8758,7 @@ export {
8632
8758
  schemaAppUpdate,
8633
8759
  schemaBuilding,
8634
8760
  schemaBuildingUnit,
8761
+ schemaMember,
8635
8762
  schemaOrg,
8636
8763
  schemaPSGC,
8637
8764
  schemaPermission,
@@ -8675,6 +8802,7 @@ export {
8675
8802
  usePermissionService,
8676
8803
  useRoleController,
8677
8804
  useRoleRepo,
8805
+ useRoleService,
8678
8806
  useUserController,
8679
8807
  useUserRepo,
8680
8808
  useUserService,