@goweekdays/core 2.2.0 → 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.";
@@ -2342,49 +2392,51 @@ import { ObjectId as ObjectId15 } from "mongodb";
2342
2392
 
2343
2393
  // src/resources/role/role.repository.ts
2344
2394
  import {
2345
- BadRequestError as BadRequestError12,
2395
+ BadRequestError as BadRequestError13,
2346
2396
  InternalServerError as InternalServerError7,
2347
2397
  useAtlas as useAtlas7,
2348
2398
  paginate as paginate4,
2349
2399
  logger as logger7,
2350
2400
  makeCacheKey as makeCacheKey6,
2351
- useCache as useCache7
2401
+ useCache as useCache7,
2402
+ AppError as AppError3
2352
2403
  } from "@goweekdays/utils";
2353
2404
 
2354
2405
  // src/resources/role/role.model.ts
2406
+ import { BadRequestError as BadRequestError12 } from "@goweekdays/utils";
2355
2407
  import Joi4 from "joi";
2356
2408
  import { ObjectId as ObjectId10 } from "mongodb";
2357
2409
  var schemaRole = Joi4.object({
2358
2410
  name: Joi4.string().required(),
2359
2411
  description: Joi4.string().max(1024).optional().allow("", null),
2360
2412
  permissions: Joi4.array().items(Joi4.string()).required(),
2361
- type: Joi4.string().required(),
2362
- org: Joi4.string().hex().optional().allow("", null)
2413
+ org: Joi4.string().hex().optional().allow("", null),
2414
+ createdBy: Joi4.string().hex().required()
2363
2415
  });
2364
2416
  function modelRole(value) {
2365
2417
  const { error } = schemaRole.validate(value);
2366
2418
  if (error) {
2367
- throw new Error(error.message);
2419
+ throw new BadRequestError12(error.message);
2368
2420
  }
2369
2421
  if (value._id && typeof value._id === "string") {
2370
2422
  try {
2371
2423
  value._id = new ObjectId10(value._id);
2372
2424
  } catch (error2) {
2373
- throw new Error("Invalid _id.");
2425
+ throw new BadRequestError12("Invalid _id.");
2374
2426
  }
2375
2427
  }
2376
2428
  if (value.org && typeof value.org === "string" && value.org.length === 24) {
2377
2429
  try {
2378
2430
  value.org = new ObjectId10(value.org);
2379
2431
  } catch (error2) {
2380
- throw new Error("Invalid org.");
2432
+ throw new BadRequestError12("Invalid org.");
2381
2433
  }
2382
2434
  }
2383
2435
  if (value.createdBy && typeof value.createdBy === "string" && value.createdBy.length === 24) {
2384
2436
  try {
2385
2437
  value.createdBy = new ObjectId10(value.createdBy);
2386
2438
  } catch (error2) {
2387
- throw new Error("Invalid createdBy.");
2439
+ throw new BadRequestError12("Invalid createdBy.");
2388
2440
  }
2389
2441
  }
2390
2442
  return {
@@ -2392,7 +2444,6 @@ function modelRole(value) {
2392
2444
  name: value.name,
2393
2445
  description: value.description ?? "",
2394
2446
  permissions: value.permissions,
2395
- type: value.type,
2396
2447
  org: value.org,
2397
2448
  status: value.status ?? "active",
2398
2449
  default: value.default ?? false,
@@ -2465,16 +2516,20 @@ function useRoleRepo() {
2465
2516
  logger7.log({ level: "error", message: `${error}` });
2466
2517
  const isDuplicated = error.message.includes("duplicate");
2467
2518
  if (isDuplicated) {
2468
- 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.");
2469
2525
  }
2470
- throw new InternalServerError7("Failed to create role.");
2471
2526
  }
2472
2527
  }
2473
2528
  async function getRoleByUserId(value) {
2474
2529
  try {
2475
2530
  value = new ObjectId11(value);
2476
2531
  } catch (error) {
2477
- throw new BadRequestError12("Invalid user ID.");
2532
+ throw new BadRequestError13("Invalid user ID.");
2478
2533
  }
2479
2534
  try {
2480
2535
  const cacheKey = makeCacheKey6(namespace_collection, {
@@ -2509,7 +2564,7 @@ function useRoleRepo() {
2509
2564
  try {
2510
2565
  _id = new ObjectId11(_id);
2511
2566
  } catch (error) {
2512
- throw new BadRequestError12("Invalid ID.");
2567
+ throw new BadRequestError13("Invalid ID.");
2513
2568
  }
2514
2569
  try {
2515
2570
  const cacheKey = makeCacheKey6(namespace_collection, {
@@ -2542,7 +2597,7 @@ function useRoleRepo() {
2542
2597
  }
2543
2598
  async function getRoleByName(name) {
2544
2599
  if (!name) {
2545
- throw new BadRequestError12("Role name is required.");
2600
+ throw new BadRequestError13("Role name is required.");
2546
2601
  }
2547
2602
  try {
2548
2603
  const cacheKey = makeCacheKey6(namespace_collection, {
@@ -2588,7 +2643,7 @@ function useRoleRepo() {
2588
2643
  try {
2589
2644
  id = new ObjectId11(id);
2590
2645
  } catch (error) {
2591
- throw new BadRequestError12("Invalid ID.");
2646
+ throw new BadRequestError13("Invalid ID.");
2592
2647
  }
2593
2648
  }
2594
2649
  const query = { status: "active" };
@@ -2650,12 +2705,12 @@ function useRoleRepo() {
2650
2705
  }
2651
2706
  async function updateRole(_id, value, session) {
2652
2707
  if (!_id) {
2653
- throw new BadRequestError12("Role ID is required.");
2708
+ throw new BadRequestError13("Role ID is required.");
2654
2709
  }
2655
2710
  try {
2656
2711
  _id = new ObjectId11(_id);
2657
2712
  } catch (error) {
2658
- throw new BadRequestError12("Invalid role ID.");
2713
+ throw new BadRequestError13("Invalid role ID.");
2659
2714
  }
2660
2715
  if (!value.name) {
2661
2716
  delete value.name;
@@ -2672,23 +2727,23 @@ function useRoleRepo() {
2672
2727
  throw new InternalServerError7("Failed to update role.");
2673
2728
  }
2674
2729
  } else {
2675
- throw new BadRequestError12("No fields to update.");
2730
+ throw new BadRequestError13("No fields to update.");
2676
2731
  }
2677
2732
  }
2678
2733
  async function updatePermissionsById(_id, permissions, session) {
2679
2734
  if (!_id) {
2680
- throw new BadRequestError12("Role ID is required.");
2735
+ throw new BadRequestError13("Role ID is required.");
2681
2736
  }
2682
2737
  try {
2683
2738
  _id = new ObjectId11(_id);
2684
2739
  } catch (error) {
2685
- throw new BadRequestError12("Invalid role ID.");
2740
+ throw new BadRequestError13("Invalid role ID.");
2686
2741
  }
2687
2742
  if (!permissions) {
2688
- throw new BadRequestError12("Permissions are required.");
2743
+ throw new BadRequestError13("Permissions are required.");
2689
2744
  }
2690
2745
  if (permissions.length === 0) {
2691
- throw new BadRequestError12("Permissions cannot be empty.");
2746
+ throw new BadRequestError13("Permissions cannot be empty.");
2692
2747
  }
2693
2748
  try {
2694
2749
  await collection.updateOne(
@@ -2706,7 +2761,7 @@ function useRoleRepo() {
2706
2761
  try {
2707
2762
  _id = new ObjectId11(_id);
2708
2763
  } catch (error) {
2709
- throw new BadRequestError12("Invalid ID.");
2764
+ throw new BadRequestError13("Invalid ID.");
2710
2765
  }
2711
2766
  try {
2712
2767
  await collection.deleteOne(
@@ -2738,7 +2793,7 @@ function useRoleRepo() {
2738
2793
  }
2739
2794
 
2740
2795
  // src/resources/permission/permission.model.ts
2741
- import { BadRequestError as BadRequestError13 } from "@goweekdays/utils";
2796
+ import { BadRequestError as BadRequestError14 } from "@goweekdays/utils";
2742
2797
  import Joi5 from "joi";
2743
2798
  var schemaPermission = Joi5.object({
2744
2799
  app: Joi5.string().required(),
@@ -2757,7 +2812,7 @@ var schemaPermissionUpdate = Joi5.object({
2757
2812
  function modelPermission(value) {
2758
2813
  const { error } = schemaPermission.validate(value);
2759
2814
  if (error) {
2760
- throw new BadRequestError13(error.message);
2815
+ throw new BadRequestError14(error.message);
2761
2816
  }
2762
2817
  return {
2763
2818
  _id: value._id,
@@ -2776,8 +2831,8 @@ function modelPermission(value) {
2776
2831
 
2777
2832
  // src/resources/permission/permission.repository.ts
2778
2833
  import {
2779
- AppError as AppError3,
2780
- BadRequestError as BadRequestError14,
2834
+ AppError as AppError4,
2835
+ BadRequestError as BadRequestError15,
2781
2836
  InternalServerError as InternalServerError8,
2782
2837
  logger as logger8,
2783
2838
  makeCacheKey as makeCacheKey7,
@@ -2836,12 +2891,12 @@ function usePermissionRepo() {
2836
2891
  level: "error",
2837
2892
  message: error.message
2838
2893
  });
2839
- if (error instanceof AppError3) {
2894
+ if (error instanceof AppError4) {
2840
2895
  throw error;
2841
2896
  } else {
2842
2897
  const isDuplicated = error.message.includes("duplicate");
2843
2898
  if (isDuplicated) {
2844
- throw new BadRequestError14("Permission already exists.");
2899
+ throw new BadRequestError15("Permission already exists.");
2845
2900
  }
2846
2901
  throw new Error("Failed to create permission.");
2847
2902
  }
@@ -2851,11 +2906,11 @@ function usePermissionRepo() {
2851
2906
  try {
2852
2907
  _id = new ObjectId12(_id);
2853
2908
  } catch (error2) {
2854
- throw new BadRequestError14("Invalid ID.");
2909
+ throw new BadRequestError15("Invalid ID.");
2855
2910
  }
2856
2911
  const { error } = schemaPermissionUpdate.validate(value);
2857
2912
  if (error) {
2858
- throw new BadRequestError14(`Invalid data: ${error.message}`);
2913
+ throw new BadRequestError15(`Invalid data: ${error.message}`);
2859
2914
  }
2860
2915
  try {
2861
2916
  const res = await collection.updateOne(
@@ -2870,7 +2925,7 @@ function usePermissionRepo() {
2870
2925
  level: "error",
2871
2926
  message: error2.message
2872
2927
  });
2873
- if (error2 instanceof AppError3) {
2928
+ if (error2 instanceof AppError4) {
2874
2929
  throw error2;
2875
2930
  } else {
2876
2931
  throw new Error("Failed to update permission.");
@@ -2946,7 +3001,7 @@ function usePermissionRepo() {
2946
3001
  try {
2947
3002
  _id = new ObjectId12(_id);
2948
3003
  } catch (error) {
2949
- throw new BadRequestError14("Invalid ID.");
3004
+ throw new BadRequestError15("Invalid ID.");
2950
3005
  }
2951
3006
  const cacheKey = makeCacheKey7(namespace_collection, { _id: String(_id) });
2952
3007
  try {
@@ -2974,7 +3029,7 @@ function usePermissionRepo() {
2974
3029
  });
2975
3030
  return result;
2976
3031
  } catch (error) {
2977
- if (error instanceof AppError3) {
3032
+ if (error instanceof AppError4) {
2978
3033
  throw error;
2979
3034
  } else {
2980
3035
  throw new InternalServerError8("Failed to get permission.");
@@ -2989,7 +3044,7 @@ function usePermissionRepo() {
2989
3044
  });
2990
3045
  const { error } = validation.validate({ key, group });
2991
3046
  if (error) {
2992
- throw new BadRequestError14(`Invalid data: ${error.message}`);
3047
+ throw new BadRequestError15(`Invalid data: ${error.message}`);
2993
3048
  }
2994
3049
  const query = {};
2995
3050
  const cacheKeyOptions = {};
@@ -3027,7 +3082,7 @@ function usePermissionRepo() {
3027
3082
  });
3028
3083
  return result;
3029
3084
  } catch (error2) {
3030
- if (error2 instanceof AppError3) {
3085
+ if (error2 instanceof AppError4) {
3031
3086
  throw error2;
3032
3087
  } else {
3033
3088
  throw new InternalServerError8("Failed to get permission.");
@@ -3064,7 +3119,7 @@ function usePermissionRepo() {
3064
3119
  });
3065
3120
  return result;
3066
3121
  } catch (error) {
3067
- if (error instanceof AppError3) {
3122
+ if (error instanceof AppError4) {
3068
3123
  throw error;
3069
3124
  } else {
3070
3125
  throw new InternalServerError8("Failed to count permission by group.");
@@ -3075,7 +3130,7 @@ function usePermissionRepo() {
3075
3130
  try {
3076
3131
  _id = new ObjectId12(_id);
3077
3132
  } catch (error) {
3078
- throw new BadRequestError14("Invalid ID.");
3133
+ throw new BadRequestError15("Invalid ID.");
3079
3134
  }
3080
3135
  try {
3081
3136
  const res = await collection.updateOne(
@@ -3089,7 +3144,7 @@ function usePermissionRepo() {
3089
3144
  level: "error",
3090
3145
  message: error.message
3091
3146
  });
3092
- if (error instanceof AppError3) {
3147
+ if (error instanceof AppError4) {
3093
3148
  throw error;
3094
3149
  } else {
3095
3150
  throw new InternalServerError8("Failed to delete permission.");
@@ -3142,7 +3197,7 @@ function usePermissionService() {
3142
3197
  }
3143
3198
 
3144
3199
  // src/resources/permission/permission.controller.ts
3145
- import { BadRequestError as BadRequestError15, logger as logger9 } from "@goweekdays/utils";
3200
+ import { BadRequestError as BadRequestError16, logger as logger9 } from "@goweekdays/utils";
3146
3201
  import Joi7 from "joi";
3147
3202
  function usePermissionController() {
3148
3203
  const {
@@ -3156,7 +3211,7 @@ function usePermissionController() {
3156
3211
  const value = req.body;
3157
3212
  const { error } = schemaPermission.validate(value);
3158
3213
  if (error) {
3159
- next(new BadRequestError15(error.message));
3214
+ next(new BadRequestError16(error.message));
3160
3215
  logger9.info(`Controller: ${error.message}`);
3161
3216
  return;
3162
3217
  }
@@ -3179,7 +3234,7 @@ function usePermissionController() {
3179
3234
  });
3180
3235
  const { error } = validation.validate(query);
3181
3236
  if (error) {
3182
- next(new BadRequestError15(error.message));
3237
+ next(new BadRequestError16(error.message));
3183
3238
  return;
3184
3239
  }
3185
3240
  const page = parseInt(req.query.page) ?? 1;
@@ -3218,7 +3273,7 @@ function usePermissionController() {
3218
3273
  });
3219
3274
  const { error } = validation.validate({ id });
3220
3275
  if (error) {
3221
- next(new BadRequestError15(error.message));
3276
+ next(new BadRequestError16(error.message));
3222
3277
  return;
3223
3278
  }
3224
3279
  try {
@@ -3239,7 +3294,7 @@ function usePermissionController() {
3239
3294
  });
3240
3295
  const { error } = validation.validate({ id });
3241
3296
  if (error) {
3242
- next(new BadRequestError15(error.message));
3297
+ next(new BadRequestError16(error.message));
3243
3298
  return;
3244
3299
  }
3245
3300
  try {
@@ -3254,13 +3309,13 @@ function usePermissionController() {
3254
3309
  const id = req.params.id;
3255
3310
  const { error: errorId } = Joi7.string().hex().required().validate(id);
3256
3311
  if (errorId) {
3257
- next(new BadRequestError15(errorId.message));
3312
+ next(new BadRequestError16(errorId.message));
3258
3313
  return;
3259
3314
  }
3260
3315
  const payload = req.body;
3261
3316
  const { error } = schemaPermissionUpdate.validate(payload);
3262
3317
  if (error) {
3263
- next(new BadRequestError15(error.message));
3318
+ next(new BadRequestError16(error.message));
3264
3319
  return;
3265
3320
  }
3266
3321
  try {
@@ -3281,7 +3336,7 @@ function usePermissionController() {
3281
3336
  }
3282
3337
 
3283
3338
  // src/resources/permission/permission.group.model.ts
3284
- import { BadRequestError as BadRequestError16 } from "@goweekdays/utils";
3339
+ import { BadRequestError as BadRequestError17 } from "@goweekdays/utils";
3285
3340
  import Joi8 from "joi";
3286
3341
  var schemaPermissionGroup = Joi8.object({
3287
3342
  app: Joi8.string().required(),
@@ -3297,7 +3352,7 @@ var schemaPermissionGroupUpdate = Joi8.object({
3297
3352
  function modelPermissionGroup(value) {
3298
3353
  const { error } = schemaPermissionGroup.validate(value);
3299
3354
  if (error) {
3300
- throw new BadRequestError16(error.message);
3355
+ throw new BadRequestError17(error.message);
3301
3356
  }
3302
3357
  return {
3303
3358
  _id: value._id,
@@ -3314,8 +3369,8 @@ function modelPermissionGroup(value) {
3314
3369
 
3315
3370
  // src/resources/permission/permission.group.repository.ts
3316
3371
  import {
3317
- AppError as AppError4,
3318
- BadRequestError as BadRequestError17,
3372
+ AppError as AppError5,
3373
+ BadRequestError as BadRequestError18,
3319
3374
  InternalServerError as InternalServerError9,
3320
3375
  logger as logger10,
3321
3376
  makeCacheKey as makeCacheKey8,
@@ -3374,12 +3429,12 @@ function usePermissionGroupRepo() {
3374
3429
  level: "error",
3375
3430
  message: error.message
3376
3431
  });
3377
- if (error instanceof AppError4) {
3432
+ if (error instanceof AppError5) {
3378
3433
  throw error;
3379
3434
  } else {
3380
3435
  const isDuplicated = error.message.includes("duplicate");
3381
3436
  if (isDuplicated) {
3382
- throw new BadRequestError17("Permission group already exists.");
3437
+ throw new BadRequestError18("Permission group already exists.");
3383
3438
  }
3384
3439
  throw new Error("Failed to create permission group.");
3385
3440
  }
@@ -3389,11 +3444,11 @@ function usePermissionGroupRepo() {
3389
3444
  try {
3390
3445
  _id = new ObjectId13(_id);
3391
3446
  } catch (error2) {
3392
- throw new BadRequestError17("Invalid ID.");
3447
+ throw new BadRequestError18("Invalid ID.");
3393
3448
  }
3394
3449
  const { error } = schemaPermissionGroupUpdate.validate(value);
3395
3450
  if (error) {
3396
- throw new BadRequestError17(`Invalid data: ${error.message}`);
3451
+ throw new BadRequestError18(`Invalid data: ${error.message}`);
3397
3452
  }
3398
3453
  try {
3399
3454
  const res = await collection.updateOne(
@@ -3408,7 +3463,7 @@ function usePermissionGroupRepo() {
3408
3463
  level: "error",
3409
3464
  message: error2.message
3410
3465
  });
3411
- if (error2 instanceof AppError4) {
3466
+ if (error2 instanceof AppError5) {
3412
3467
  throw error2;
3413
3468
  } else {
3414
3469
  throw new Error("Failed to update permission group.");
@@ -3484,7 +3539,7 @@ function usePermissionGroupRepo() {
3484
3539
  try {
3485
3540
  _id = new ObjectId13(_id);
3486
3541
  } catch (error) {
3487
- throw new BadRequestError17("Invalid ID.");
3542
+ throw new BadRequestError18("Invalid ID.");
3488
3543
  }
3489
3544
  const cacheKey = makeCacheKey8(namespace_collection, { _id: String(_id) });
3490
3545
  try {
@@ -3512,7 +3567,7 @@ function usePermissionGroupRepo() {
3512
3567
  });
3513
3568
  return result;
3514
3569
  } catch (error) {
3515
- if (error instanceof AppError4) {
3570
+ if (error instanceof AppError5) {
3516
3571
  throw error;
3517
3572
  } else {
3518
3573
  throw new InternalServerError9("Failed to get permission group.");
@@ -3526,7 +3581,7 @@ function usePermissionGroupRepo() {
3526
3581
  });
3527
3582
  const { error } = validation.validate({ key, app });
3528
3583
  if (error) {
3529
- throw new BadRequestError17("Invalid key.");
3584
+ throw new BadRequestError18("Invalid key.");
3530
3585
  }
3531
3586
  const query = { key };
3532
3587
  const cacheKeyOptions = { key, tag: "byKey" };
@@ -3558,7 +3613,7 @@ function usePermissionGroupRepo() {
3558
3613
  });
3559
3614
  return result;
3560
3615
  } catch (error2) {
3561
- if (error2 instanceof AppError4) {
3616
+ if (error2 instanceof AppError5) {
3562
3617
  throw error2;
3563
3618
  } else {
3564
3619
  throw new InternalServerError9("Failed to get permission group.");
@@ -3569,7 +3624,7 @@ function usePermissionGroupRepo() {
3569
3624
  try {
3570
3625
  _id = new ObjectId13(_id);
3571
3626
  } catch (error) {
3572
- throw new BadRequestError17("Invalid ID.");
3627
+ throw new BadRequestError18("Invalid ID.");
3573
3628
  }
3574
3629
  try {
3575
3630
  const res = await collection.updateOne(
@@ -3583,7 +3638,7 @@ function usePermissionGroupRepo() {
3583
3638
  level: "error",
3584
3639
  message: error.message
3585
3640
  });
3586
- if (error instanceof AppError4) {
3641
+ if (error instanceof AppError5) {
3587
3642
  throw error;
3588
3643
  } else {
3589
3644
  throw new InternalServerError9("Failed to delete permission group.");
@@ -3616,15 +3671,15 @@ function usePermissionGroupRepo() {
3616
3671
 
3617
3672
  // src/resources/permission/permission.group.service.ts
3618
3673
  import {
3619
- AppError as AppError6,
3620
- BadRequestError as BadRequestError21,
3674
+ AppError as AppError7,
3675
+ BadRequestError as BadRequestError22,
3621
3676
  InternalServerError as InternalServerError11,
3622
3677
  logger as logger14,
3623
3678
  useAtlas as useAtlas12
3624
3679
  } from "@goweekdays/utils";
3625
3680
 
3626
3681
  // src/resources/app/app.model.ts
3627
- import { BadRequestError as BadRequestError18 } from "@goweekdays/utils";
3682
+ import { BadRequestError as BadRequestError19 } from "@goweekdays/utils";
3628
3683
  import Joi10 from "joi";
3629
3684
  var schemaApp = Joi10.object({
3630
3685
  code: Joi10.string().alphanum().max(20).required(),
@@ -3640,7 +3695,7 @@ var schemaAppUpdate = Joi10.object({
3640
3695
  function modelApp(value) {
3641
3696
  const { error } = schemaApp.validate(value);
3642
3697
  if (error) {
3643
- throw new BadRequestError18(error.message);
3698
+ throw new BadRequestError19(error.message);
3644
3699
  }
3645
3700
  return {
3646
3701
  _id: value._id,
@@ -3657,8 +3712,8 @@ function modelApp(value) {
3657
3712
 
3658
3713
  // src/resources/app/app.repository.ts
3659
3714
  import {
3660
- AppError as AppError5,
3661
- BadRequestError as BadRequestError19,
3715
+ AppError as AppError6,
3716
+ BadRequestError as BadRequestError20,
3662
3717
  InternalServerError as InternalServerError10,
3663
3718
  logger as logger11,
3664
3719
  makeCacheKey as makeCacheKey9,
@@ -3720,12 +3775,12 @@ function useAppRepo() {
3720
3775
  level: "error",
3721
3776
  message: error.message
3722
3777
  });
3723
- if (error instanceof AppError5) {
3778
+ if (error instanceof AppError6) {
3724
3779
  throw error;
3725
3780
  } else {
3726
3781
  const isDuplicated = error.message.includes("duplicate");
3727
3782
  if (isDuplicated) {
3728
- throw new BadRequestError19("App already exists.");
3783
+ throw new BadRequestError20("App already exists.");
3729
3784
  }
3730
3785
  throw new Error("Failed to create app.");
3731
3786
  }
@@ -3735,7 +3790,7 @@ function useAppRepo() {
3735
3790
  try {
3736
3791
  _id = new ObjectId14(_id);
3737
3792
  } catch (error) {
3738
- throw new BadRequestError19("Invalid ID.");
3793
+ throw new BadRequestError20("Invalid ID.");
3739
3794
  }
3740
3795
  try {
3741
3796
  const res = await collection.updateOne(
@@ -3750,7 +3805,7 @@ function useAppRepo() {
3750
3805
  level: "error",
3751
3806
  message: error.message
3752
3807
  });
3753
- if (error instanceof AppError5) {
3808
+ if (error instanceof AppError6) {
3754
3809
  throw error;
3755
3810
  } else {
3756
3811
  throw new Error("Failed to update app.");
@@ -3831,7 +3886,7 @@ function useAppRepo() {
3831
3886
  try {
3832
3887
  _id = new ObjectId14(_id);
3833
3888
  } catch (error) {
3834
- throw new BadRequestError19("Invalid ID.");
3889
+ throw new BadRequestError20("Invalid ID.");
3835
3890
  }
3836
3891
  const cacheKey = makeCacheKey9(namespace_collection, { _id: String(_id) });
3837
3892
  try {
@@ -3859,7 +3914,7 @@ function useAppRepo() {
3859
3914
  });
3860
3915
  return result;
3861
3916
  } catch (error) {
3862
- if (error instanceof AppError5) {
3917
+ if (error instanceof AppError6) {
3863
3918
  throw error;
3864
3919
  } else {
3865
3920
  throw new InternalServerError10("Failed to get app.");
@@ -3870,7 +3925,7 @@ function useAppRepo() {
3870
3925
  const validate = Joi11.string().required();
3871
3926
  const { error } = validate.validate(code);
3872
3927
  if (error) {
3873
- throw new BadRequestError19("Invalid code.");
3928
+ throw new BadRequestError20("Invalid code.");
3874
3929
  }
3875
3930
  const cacheKey = makeCacheKey9(namespace_collection, {
3876
3931
  code,
@@ -3901,7 +3956,7 @@ function useAppRepo() {
3901
3956
  });
3902
3957
  return result;
3903
3958
  } catch (error2) {
3904
- if (error2 instanceof AppError5) {
3959
+ if (error2 instanceof AppError6) {
3905
3960
  throw error2;
3906
3961
  } else {
3907
3962
  throw new InternalServerError10("Failed to get app.");
@@ -3912,7 +3967,7 @@ function useAppRepo() {
3912
3967
  try {
3913
3968
  _id = new ObjectId14(_id);
3914
3969
  } catch (error) {
3915
- throw new BadRequestError19("Invalid ID.");
3970
+ throw new BadRequestError20("Invalid ID.");
3916
3971
  }
3917
3972
  try {
3918
3973
  const res = await collection.updateOne(
@@ -3926,7 +3981,7 @@ function useAppRepo() {
3926
3981
  level: "error",
3927
3982
  message: error.message
3928
3983
  });
3929
- if (error instanceof AppError5) {
3984
+ if (error instanceof AppError6) {
3930
3985
  throw error;
3931
3986
  } else {
3932
3987
  throw new InternalServerError10("Failed to delete app.");
@@ -4052,7 +4107,7 @@ function useAppService() {
4052
4107
  }
4053
4108
 
4054
4109
  // src/resources/app/app.controller.ts
4055
- import { BadRequestError as BadRequestError20 } from "@goweekdays/utils";
4110
+ import { BadRequestError as BadRequestError21 } from "@goweekdays/utils";
4056
4111
  import Joi12 from "joi";
4057
4112
  function useAppController() {
4058
4113
  const {
@@ -4066,7 +4121,7 @@ function useAppController() {
4066
4121
  const value = req.body;
4067
4122
  const { error } = schemaApp.validate(value);
4068
4123
  if (error) {
4069
- next(new BadRequestError20(error.message));
4124
+ next(new BadRequestError21(error.message));
4070
4125
  return;
4071
4126
  }
4072
4127
  try {
@@ -4081,13 +4136,13 @@ function useAppController() {
4081
4136
  const id = req.params.id ?? "";
4082
4137
  const { error: errorId } = Joi12.string().hex().required().validate(id);
4083
4138
  if (errorId) {
4084
- next(new BadRequestError20(errorId.message));
4139
+ next(new BadRequestError21(errorId.message));
4085
4140
  return;
4086
4141
  }
4087
4142
  const value = req.body;
4088
4143
  const { error } = schemaAppUpdate.validate(value);
4089
4144
  if (error) {
4090
- next(new BadRequestError20(error.message));
4145
+ next(new BadRequestError21(error.message));
4091
4146
  return;
4092
4147
  }
4093
4148
  try {
@@ -4109,7 +4164,7 @@ function useAppController() {
4109
4164
  });
4110
4165
  const { error } = validation.validate(query);
4111
4166
  if (error) {
4112
- next(new BadRequestError20(error.message));
4167
+ next(new BadRequestError21(error.message));
4113
4168
  return;
4114
4169
  }
4115
4170
  const page = parseInt(req.query.page) ?? 1;
@@ -4148,7 +4203,7 @@ function useAppController() {
4148
4203
  });
4149
4204
  const { error } = validation.validate({ id });
4150
4205
  if (error) {
4151
- next(new BadRequestError20(error.message));
4206
+ next(new BadRequestError21(error.message));
4152
4207
  return;
4153
4208
  }
4154
4209
  try {
@@ -4169,7 +4224,7 @@ function useAppController() {
4169
4224
  });
4170
4225
  const { error } = validation.validate({ id });
4171
4226
  if (error) {
4172
- next(new BadRequestError20(error.message));
4227
+ next(new BadRequestError21(error.message));
4173
4228
  return;
4174
4229
  }
4175
4230
  try {
@@ -4569,7 +4624,7 @@ function usePermissionGroupService() {
4569
4624
  }
4570
4625
  const associatedPermissionsCount = await countByGroup(permission.key);
4571
4626
  if (associatedPermissionsCount > 0) {
4572
- throw new BadRequestError21(
4627
+ throw new BadRequestError22(
4573
4628
  "Cannot delete Permission Group with associated Permissions."
4574
4629
  );
4575
4630
  }
@@ -4577,7 +4632,7 @@ function usePermissionGroupService() {
4577
4632
  await _deleteById(id);
4578
4633
  return "Permission deleted successfully.";
4579
4634
  } catch (error) {
4580
- if (error instanceof AppError6) {
4635
+ if (error instanceof AppError7) {
4581
4636
  throw error;
4582
4637
  } else {
4583
4638
  throw new InternalServerError11("Failed to delete Permission Group.");
@@ -4591,7 +4646,7 @@ function usePermissionGroupService() {
4591
4646
  }
4592
4647
 
4593
4648
  // src/resources/permission/permission.group.controller.ts
4594
- import { BadRequestError as BadRequestError22, logger as logger15 } from "@goweekdays/utils";
4649
+ import { BadRequestError as BadRequestError23, logger as logger15 } from "@goweekdays/utils";
4595
4650
  import Joi13 from "joi";
4596
4651
  function usePermissionGroupController() {
4597
4652
  const {
@@ -4605,7 +4660,7 @@ function usePermissionGroupController() {
4605
4660
  const value = req.body;
4606
4661
  const { error } = schemaPermissionGroup.validate(value);
4607
4662
  if (error) {
4608
- next(new BadRequestError22(error.message));
4663
+ next(new BadRequestError23(error.message));
4609
4664
  logger15.info(`Controller: ${error.message}`);
4610
4665
  return;
4611
4666
  }
@@ -4628,7 +4683,7 @@ function usePermissionGroupController() {
4628
4683
  });
4629
4684
  const { error } = validation.validate(query);
4630
4685
  if (error) {
4631
- next(new BadRequestError22(error.message));
4686
+ next(new BadRequestError23(error.message));
4632
4687
  return;
4633
4688
  }
4634
4689
  const page = parseInt(req.query.page) ?? 1;
@@ -4667,7 +4722,7 @@ function usePermissionGroupController() {
4667
4722
  });
4668
4723
  const { error } = validation.validate({ id });
4669
4724
  if (error) {
4670
- next(new BadRequestError22(error.message));
4725
+ next(new BadRequestError23(error.message));
4671
4726
  return;
4672
4727
  }
4673
4728
  try {
@@ -4688,7 +4743,7 @@ function usePermissionGroupController() {
4688
4743
  });
4689
4744
  const { error } = validation.validate({ id });
4690
4745
  if (error) {
4691
- next(new BadRequestError22(error.message));
4746
+ next(new BadRequestError23(error.message));
4692
4747
  return;
4693
4748
  }
4694
4749
  try {
@@ -4703,13 +4758,13 @@ function usePermissionGroupController() {
4703
4758
  const id = req.params.id;
4704
4759
  const { error: errorId } = Joi13.string().hex().required().validate(id);
4705
4760
  if (errorId) {
4706
- next(new BadRequestError22(errorId.message));
4761
+ next(new BadRequestError23(errorId.message));
4707
4762
  return;
4708
4763
  }
4709
4764
  const payload = req.body;
4710
4765
  const { error } = schemaPermissionGroupUpdate.validate(payload);
4711
4766
  if (error) {
4712
- next(new BadRequestError22(error.message));
4767
+ next(new BadRequestError23(error.message));
4713
4768
  return;
4714
4769
  }
4715
4770
  try {
@@ -4749,7 +4804,7 @@ function useUserService() {
4749
4804
  session?.startTransaction();
4750
4805
  const _user = await getUserByEmail(DEFAULT_USER_EMAIL);
4751
4806
  if (_user) {
4752
- throw new BadRequestError23(
4807
+ throw new BadRequestError24(
4753
4808
  `User already exists: ${DEFAULT_USER_EMAIL}.`
4754
4809
  );
4755
4810
  }
@@ -4819,7 +4874,7 @@ function useUserService() {
4819
4874
  try {
4820
4875
  const _user = await getUserByEmail(value.email);
4821
4876
  if (_user) {
4822
- throw new BadRequestError23(`User already exists: ${value.email}.`);
4877
+ throw new BadRequestError24(`User already exists: ${value.email}.`);
4823
4878
  }
4824
4879
  const hashedPassword = await hashPassword(value.password);
4825
4880
  const userId = new ObjectId15();
@@ -4858,14 +4913,14 @@ function useUserService() {
4858
4913
  try {
4859
4914
  const invitation = await _getVerificationById(id);
4860
4915
  if (!invitation || !invitation.metadata?.app || !invitation.metadata?.role) {
4861
- throw new BadRequestError23("Invalid invitation.");
4916
+ throw new BadRequestError24("Invalid invitation.");
4862
4917
  }
4863
4918
  if (invitation.status === "complete") {
4864
- throw new BadRequestError23("Invitation already used.");
4919
+ throw new BadRequestError24("Invitation already used.");
4865
4920
  }
4866
4921
  const expired = new Date(invitation.expireAt) < /* @__PURE__ */ new Date();
4867
4922
  if (invitation.status === "expired" || expired) {
4868
- throw new BadRequestError23("Invitation expired.");
4923
+ throw new BadRequestError24("Invitation expired.");
4869
4924
  }
4870
4925
  const email = invitation.email;
4871
4926
  const _user = await getUserByEmail(invitation.email);
@@ -4917,21 +4972,21 @@ function useUserService() {
4917
4972
  try {
4918
4973
  const signUp = await _getVerificationById(id);
4919
4974
  if (!signUp) {
4920
- throw new BadRequestError23("Invalid sign up link.");
4975
+ throw new BadRequestError24("Invalid sign up link.");
4921
4976
  }
4922
4977
  if (signUp.status === "complete") {
4923
- throw new BadRequestError23(
4978
+ throw new BadRequestError24(
4924
4979
  "You have already an account created using this link."
4925
4980
  );
4926
4981
  }
4927
4982
  const expired = new Date(signUp.expireAt) < /* @__PURE__ */ new Date();
4928
4983
  if (signUp.status === "expired" || expired) {
4929
- throw new BadRequestError23("Sign up link expired.");
4984
+ throw new BadRequestError24("Sign up link expired.");
4930
4985
  }
4931
4986
  const email = signUp.email;
4932
4987
  const _user = await getUserByEmail(signUp.email);
4933
4988
  if (_user) {
4934
- throw new BadRequestError23(`User already exists: ${email}.`);
4989
+ throw new BadRequestError24(`User already exists: ${email}.`);
4935
4990
  }
4936
4991
  const hashedPassword = await hashPassword(password);
4937
4992
  const userId = new ObjectId15();
@@ -4965,7 +5020,7 @@ function useUserService() {
4965
5020
  throw error;
4966
5021
  }
4967
5022
  if (newPassword !== passwordConfirmation) {
4968
- throw new BadRequestError23("Passwords do not match.");
5023
+ throw new BadRequestError24("Passwords do not match.");
4969
5024
  }
4970
5025
  let hashedPassword = "";
4971
5026
  try {
@@ -4979,7 +5034,7 @@ function useUserService() {
4979
5034
  throw new NotFoundError4("You are using an invalid reset link.");
4980
5035
  }
4981
5036
  if (otpDoc.status === "used") {
4982
- throw new BadRequestError23("This link has already been invalidated.");
5037
+ throw new BadRequestError24("This link has already been invalidated.");
4983
5038
  }
4984
5039
  await updateStatusById(id, "used");
4985
5040
  return "Successfully reset password.";
@@ -4990,13 +5045,13 @@ function useUserService() {
4990
5045
  const { updateName: updateMemberName } = useMemberRepo();
4991
5046
  async function updateName(_id, firstName, lastName) {
4992
5047
  if (!_id) {
4993
- throw new BadRequestError23("Invalid user ID");
5048
+ throw new BadRequestError24("Invalid user ID");
4994
5049
  }
4995
5050
  if (!firstName) {
4996
- throw new BadRequestError23("Invalid firstName");
5051
+ throw new BadRequestError24("Invalid firstName");
4997
5052
  }
4998
5053
  if (!lastName) {
4999
- throw new BadRequestError23("Invalid lastName");
5054
+ throw new BadRequestError24("Invalid lastName");
5000
5055
  }
5001
5056
  const session = useAtlas13.getClient()?.startSession();
5002
5057
  session?.startTransaction();
@@ -5023,16 +5078,16 @@ function useUserService() {
5023
5078
  }
5024
5079
  async function updateBirthday(_id, month, day, year) {
5025
5080
  if (!_id) {
5026
- throw new BadRequestError23("Invalid user ID");
5081
+ throw new BadRequestError24("Invalid user ID");
5027
5082
  }
5028
5083
  if (!month) {
5029
- throw new BadRequestError23("Invalid birth month.");
5084
+ throw new BadRequestError24("Invalid birth month.");
5030
5085
  }
5031
5086
  if (!day) {
5032
- throw new BadRequestError23("Invalid birthday.");
5087
+ throw new BadRequestError24("Invalid birthday.");
5033
5088
  }
5034
5089
  if (!year) {
5035
- throw new BadRequestError23("Invalid birth year.");
5090
+ throw new BadRequestError24("Invalid birth year.");
5036
5091
  }
5037
5092
  try {
5038
5093
  await _updateBirthday({ _id, month, day, year });
@@ -5113,7 +5168,7 @@ function useAuthController() {
5113
5168
  });
5114
5169
  const { error } = validation.validate({ email, password });
5115
5170
  if (error) {
5116
- next(new BadRequestError24(error.message));
5171
+ next(new BadRequestError25(error.message));
5117
5172
  return;
5118
5173
  }
5119
5174
  try {
@@ -5133,7 +5188,7 @@ function useAuthController() {
5133
5188
  level: "error",
5134
5189
  message: `Error during login: ${error2.message}`
5135
5190
  });
5136
- if (error2 instanceof AppError7) {
5191
+ if (error2 instanceof AppError8) {
5137
5192
  next(error2);
5138
5193
  } else {
5139
5194
  next(new InternalServerError13("An unexpected error occurred"));
@@ -5144,14 +5199,14 @@ function useAuthController() {
5144
5199
  async function logout(req, res, next) {
5145
5200
  const sid = req.headers["authorization"] ?? "";
5146
5201
  if (!sid) {
5147
- next(new BadRequestError24("Session ID is required"));
5202
+ next(new BadRequestError25("Session ID is required"));
5148
5203
  return;
5149
5204
  }
5150
5205
  try {
5151
5206
  await useAuthService().logout(sid);
5152
5207
  res.json({ message: "Logged out successfully" });
5153
5208
  } catch (error) {
5154
- if (error instanceof AppError7) {
5209
+ if (error instanceof AppError8) {
5155
5210
  next(error);
5156
5211
  } else {
5157
5212
  next(new InternalServerError13("An unexpected error occurred"));
@@ -5173,7 +5228,7 @@ function useAuthController() {
5173
5228
  passwordConfirmation
5174
5229
  });
5175
5230
  if (error) {
5176
- next(new BadRequestError24(error.message));
5231
+ next(new BadRequestError25(error.message));
5177
5232
  return;
5178
5233
  }
5179
5234
  try {
@@ -5197,7 +5252,7 @@ function useAuthController() {
5197
5252
  });
5198
5253
  const { error } = validation.validate({ email, referralCode });
5199
5254
  if (error) {
5200
- next(new BadRequestError24(error.message));
5255
+ next(new BadRequestError25(error.message));
5201
5256
  return;
5202
5257
  }
5203
5258
  try {
@@ -5222,7 +5277,7 @@ function useAuthController() {
5222
5277
  }
5223
5278
 
5224
5279
  // src/resources/building/building.model.ts
5225
- import { BadRequestError as BadRequestError25, logger as logger18 } from "@goweekdays/utils";
5280
+ import { BadRequestError as BadRequestError26, logger as logger18 } from "@goweekdays/utils";
5226
5281
  import Joi15 from "joi";
5227
5282
  import { ObjectId as ObjectId16 } from "mongodb";
5228
5283
  var schemaBuilding = Joi15.object({
@@ -5267,19 +5322,19 @@ function MBuilding(value) {
5267
5322
  const { error } = schemaBuilding.validate(value);
5268
5323
  if (error) {
5269
5324
  logger18.info(`Building Model: ${error.message}`);
5270
- throw new BadRequestError25(error.message);
5325
+ throw new BadRequestError26(error.message);
5271
5326
  }
5272
5327
  if (value._id && typeof value._id === "string") {
5273
5328
  try {
5274
5329
  value._id = new ObjectId16(value._id);
5275
5330
  } catch (error2) {
5276
- throw new BadRequestError25("Invalid _id format");
5331
+ throw new BadRequestError26("Invalid _id format");
5277
5332
  }
5278
5333
  }
5279
5334
  try {
5280
5335
  value.school = new ObjectId16(value.school);
5281
5336
  } catch (error2) {
5282
- throw new BadRequestError25("Invalid school format");
5337
+ throw new BadRequestError26("Invalid school format");
5283
5338
  }
5284
5339
  return {
5285
5340
  _id: value._id ?? void 0,
@@ -5297,24 +5352,24 @@ function MBuildingUnit(value) {
5297
5352
  const { error } = schemaBuildingUnit.validate(value);
5298
5353
  if (error) {
5299
5354
  logger18.info(`Building Unit Model: ${error.message}`);
5300
- throw new BadRequestError25(error.message);
5355
+ throw new BadRequestError26(error.message);
5301
5356
  }
5302
5357
  if (value._id && typeof value._id === "string") {
5303
5358
  try {
5304
5359
  value._id = new ObjectId16(value._id);
5305
5360
  } catch (error2) {
5306
- throw new BadRequestError25("Invalid ID");
5361
+ throw new BadRequestError26("Invalid ID");
5307
5362
  }
5308
5363
  }
5309
5364
  try {
5310
5365
  value.school = new ObjectId16(value.school);
5311
5366
  } catch (error2) {
5312
- throw new BadRequestError25("Invalid school ID");
5367
+ throw new BadRequestError26("Invalid school ID");
5313
5368
  }
5314
5369
  try {
5315
5370
  value.building = new ObjectId16(value.building);
5316
5371
  } catch (error2) {
5317
- throw new BadRequestError25("Invalid building ID");
5372
+ throw new BadRequestError26("Invalid building ID");
5318
5373
  }
5319
5374
  return {
5320
5375
  _id: value._id ?? void 0,
@@ -5339,8 +5394,8 @@ function MBuildingUnit(value) {
5339
5394
 
5340
5395
  // src/resources/building/building.repository.ts
5341
5396
  import {
5342
- AppError as AppError8,
5343
- BadRequestError as BadRequestError26,
5397
+ AppError as AppError9,
5398
+ BadRequestError as BadRequestError27,
5344
5399
  InternalServerError as InternalServerError14,
5345
5400
  logger as logger19,
5346
5401
  makeCacheKey as makeCacheKey11,
@@ -5382,12 +5437,12 @@ function useBuildingRepo() {
5382
5437
  level: "error",
5383
5438
  message: error.message
5384
5439
  });
5385
- if (error instanceof AppError8) {
5440
+ if (error instanceof AppError9) {
5386
5441
  throw error;
5387
5442
  } else {
5388
5443
  const isDuplicated = error.message.includes("duplicate");
5389
5444
  if (isDuplicated) {
5390
- throw new BadRequestError26("Building already exists.");
5445
+ throw new BadRequestError27("Building already exists.");
5391
5446
  }
5392
5447
  throw new Error("Failed to create building.");
5393
5448
  }
@@ -5397,7 +5452,7 @@ function useBuildingRepo() {
5397
5452
  try {
5398
5453
  _id = new ObjectId17(_id);
5399
5454
  } catch (error) {
5400
- throw new BadRequestError26("Invalid ID.");
5455
+ throw new BadRequestError27("Invalid ID.");
5401
5456
  }
5402
5457
  try {
5403
5458
  const res = await collection.updateOne(
@@ -5412,7 +5467,7 @@ function useBuildingRepo() {
5412
5467
  level: "error",
5413
5468
  message: error.message
5414
5469
  });
5415
- if (error instanceof AppError8) {
5470
+ if (error instanceof AppError9) {
5416
5471
  throw error;
5417
5472
  } else {
5418
5473
  throw new Error("Failed to update building.");
@@ -5439,7 +5494,7 @@ function useBuildingRepo() {
5439
5494
  try {
5440
5495
  query.school = new ObjectId17(school);
5441
5496
  } catch (error) {
5442
- throw new BadRequestError26("Invalid school ID.");
5497
+ throw new BadRequestError27("Invalid school ID.");
5443
5498
  }
5444
5499
  }
5445
5500
  const cacheParams = {
@@ -5496,7 +5551,7 @@ function useBuildingRepo() {
5496
5551
  try {
5497
5552
  _id = new ObjectId17(_id);
5498
5553
  } catch (error) {
5499
- throw new BadRequestError26("Invalid ID.");
5554
+ throw new BadRequestError27("Invalid ID.");
5500
5555
  }
5501
5556
  const cacheKey = makeCacheKey11(namespace_collection, { _id: String(_id) });
5502
5557
  try {
@@ -5524,7 +5579,7 @@ function useBuildingRepo() {
5524
5579
  });
5525
5580
  return result;
5526
5581
  } catch (error) {
5527
- if (error instanceof AppError8) {
5582
+ if (error instanceof AppError9) {
5528
5583
  throw error;
5529
5584
  } else {
5530
5585
  throw new InternalServerError14("Failed to get building.");
@@ -5535,7 +5590,7 @@ function useBuildingRepo() {
5535
5590
  try {
5536
5591
  _id = new ObjectId17(_id);
5537
5592
  } catch (error) {
5538
- throw new BadRequestError26("Invalid ID.");
5593
+ throw new BadRequestError27("Invalid ID.");
5539
5594
  }
5540
5595
  try {
5541
5596
  const res = await collection.updateOne(
@@ -5549,7 +5604,7 @@ function useBuildingRepo() {
5549
5604
  level: "error",
5550
5605
  message: error.message
5551
5606
  });
5552
- if (error instanceof AppError8) {
5607
+ if (error instanceof AppError9) {
5553
5608
  throw error;
5554
5609
  } else {
5555
5610
  throw new InternalServerError14("Failed to delete building.");
@@ -5580,12 +5635,12 @@ function useBuildingRepo() {
5580
5635
  }
5581
5636
 
5582
5637
  // src/resources/building/building.service.ts
5583
- 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";
5584
5639
 
5585
5640
  // src/resources/building/building-unit.repository.ts
5586
5641
  import {
5587
- AppError as AppError9,
5588
- BadRequestError as BadRequestError27,
5642
+ AppError as AppError10,
5643
+ BadRequestError as BadRequestError28,
5589
5644
  InternalServerError as InternalServerError15,
5590
5645
  logger as logger20,
5591
5646
  makeCacheKey as makeCacheKey12,
@@ -5651,7 +5706,7 @@ function useBuildingUnitRepo() {
5651
5706
  level: "error",
5652
5707
  message: error.message
5653
5708
  });
5654
- if (error instanceof AppError9) {
5709
+ if (error instanceof AppError10) {
5655
5710
  throw error;
5656
5711
  } else {
5657
5712
  throw new Error("Failed to create building unit.");
@@ -5661,12 +5716,12 @@ function useBuildingUnitRepo() {
5661
5716
  async function updateById(_id, value, session) {
5662
5717
  const { error } = schemaUpdateOptions.validate(value);
5663
5718
  if (error) {
5664
- throw new BadRequestError27(error.message);
5719
+ throw new BadRequestError28(error.message);
5665
5720
  }
5666
5721
  try {
5667
5722
  _id = new ObjectId18(_id);
5668
5723
  } catch (error2) {
5669
- throw new BadRequestError27("Invalid ID.");
5724
+ throw new BadRequestError28("Invalid ID.");
5670
5725
  }
5671
5726
  try {
5672
5727
  const res = await collection.updateOne(
@@ -5681,7 +5736,7 @@ function useBuildingUnitRepo() {
5681
5736
  level: "error",
5682
5737
  message: error2.message
5683
5738
  });
5684
- if (error2 instanceof AppError9) {
5739
+ if (error2 instanceof AppError10) {
5685
5740
  throw error2;
5686
5741
  } else {
5687
5742
  throw new Error("Failed to create building unit.");
@@ -5691,12 +5746,12 @@ function useBuildingUnitRepo() {
5691
5746
  async function updateByBuildingId(building, value, session) {
5692
5747
  const { error } = schemaUpdateOptions.validate(value);
5693
5748
  if (error) {
5694
- throw new BadRequestError27(error.message);
5749
+ throw new BadRequestError28(error.message);
5695
5750
  }
5696
5751
  try {
5697
5752
  building = new ObjectId18(building);
5698
5753
  } catch (error2) {
5699
- throw new BadRequestError27("Invalid building ID.");
5754
+ throw new BadRequestError28("Invalid building ID.");
5700
5755
  }
5701
5756
  try {
5702
5757
  const res = await collection.updateMany(
@@ -5711,7 +5766,7 @@ function useBuildingUnitRepo() {
5711
5766
  level: "error",
5712
5767
  message: error2.message
5713
5768
  });
5714
- if (error2 instanceof AppError9) {
5769
+ if (error2 instanceof AppError10) {
5715
5770
  throw error2;
5716
5771
  } else {
5717
5772
  throw new Error("Failed to update building unit.");
@@ -5740,14 +5795,14 @@ function useBuildingUnitRepo() {
5740
5795
  try {
5741
5796
  query.school = new ObjectId18(school);
5742
5797
  } catch (error) {
5743
- throw new BadRequestError27("Invalid school ID.");
5798
+ throw new BadRequestError28("Invalid school ID.");
5744
5799
  }
5745
5800
  }
5746
5801
  if (building) {
5747
5802
  try {
5748
5803
  query.building = new ObjectId18(building);
5749
5804
  } catch (error) {
5750
- throw new BadRequestError27("Invalid building ID.");
5805
+ throw new BadRequestError28("Invalid building ID.");
5751
5806
  }
5752
5807
  }
5753
5808
  const cacheParams = {
@@ -5806,7 +5861,7 @@ function useBuildingUnitRepo() {
5806
5861
  try {
5807
5862
  _id = new ObjectId18(_id);
5808
5863
  } catch (error) {
5809
- throw new BadRequestError27("Invalid ID.");
5864
+ throw new BadRequestError28("Invalid ID.");
5810
5865
  }
5811
5866
  const cacheKey = makeCacheKey12(namespace_collection, { _id: String(_id) });
5812
5867
  try {
@@ -5823,7 +5878,7 @@ function useBuildingUnitRepo() {
5823
5878
  deletedAt: { $in: ["", null] }
5824
5879
  });
5825
5880
  if (!result) {
5826
- throw new BadRequestError27("Building unit not found.");
5881
+ throw new BadRequestError28("Building unit not found.");
5827
5882
  }
5828
5883
  setCache(cacheKey, result, 300).then(() => {
5829
5884
  logger20.log({
@@ -5838,7 +5893,7 @@ function useBuildingUnitRepo() {
5838
5893
  });
5839
5894
  return result;
5840
5895
  } catch (error) {
5841
- if (error instanceof AppError9) {
5896
+ if (error instanceof AppError10) {
5842
5897
  throw error;
5843
5898
  } else {
5844
5899
  throw new InternalServerError15("Failed to get building unit.");
@@ -5849,7 +5904,7 @@ function useBuildingUnitRepo() {
5849
5904
  try {
5850
5905
  building = new ObjectId18(building);
5851
5906
  } catch (error) {
5852
- throw new BadRequestError27("Invalid building ID.");
5907
+ throw new BadRequestError28("Invalid building ID.");
5853
5908
  }
5854
5909
  const cacheKey = makeCacheKey12(namespace_collection, {
5855
5910
  building: String(building),
@@ -5882,7 +5937,7 @@ function useBuildingUnitRepo() {
5882
5937
  });
5883
5938
  return result;
5884
5939
  } catch (error) {
5885
- if (error instanceof AppError9) {
5940
+ if (error instanceof AppError10) {
5886
5941
  throw error;
5887
5942
  } else {
5888
5943
  throw new InternalServerError15("Failed to get building unit.");
@@ -5893,7 +5948,7 @@ function useBuildingUnitRepo() {
5893
5948
  try {
5894
5949
  building = new ObjectId18(building);
5895
5950
  } catch (error) {
5896
- throw new BadRequestError27("Invalid building ID.");
5951
+ throw new BadRequestError28("Invalid building ID.");
5897
5952
  }
5898
5953
  const cacheKey = makeCacheKey12(namespace_collection, {
5899
5954
  building: String(building)
@@ -5924,7 +5979,7 @@ function useBuildingUnitRepo() {
5924
5979
  });
5925
5980
  return result;
5926
5981
  } catch (error) {
5927
- if (error instanceof AppError9) {
5982
+ if (error instanceof AppError10) {
5928
5983
  throw error;
5929
5984
  } else {
5930
5985
  throw new InternalServerError15("Failed to get building unit.");
@@ -5935,7 +5990,7 @@ function useBuildingUnitRepo() {
5935
5990
  try {
5936
5991
  _id = new ObjectId18(_id);
5937
5992
  } catch (error) {
5938
- throw new BadRequestError27("Invalid ID.");
5993
+ throw new BadRequestError28("Invalid ID.");
5939
5994
  }
5940
5995
  try {
5941
5996
  const res = await collection.updateOne(
@@ -5950,7 +6005,7 @@ function useBuildingUnitRepo() {
5950
6005
  level: "error",
5951
6006
  message: error.message
5952
6007
  });
5953
- if (error instanceof AppError9) {
6008
+ if (error instanceof AppError10) {
5954
6009
  throw error;
5955
6010
  } else {
5956
6011
  throw new Error("Failed to deleted room/facility.");
@@ -5989,7 +6044,7 @@ function useBuildingService() {
5989
6044
  if (data.levels < building.levels) {
5990
6045
  const unit = await getByBuildingLevel(id, building.levels);
5991
6046
  if (unit) {
5992
- throw new BadRequestError28(
6047
+ throw new BadRequestError29(
5993
6048
  "Cannot reduce floors, there are existing building units at higher floors."
5994
6049
  );
5995
6050
  }
@@ -6011,7 +6066,7 @@ function useBuildingService() {
6011
6066
  async function deleteById(id) {
6012
6067
  const building = await getByBuilding(id);
6013
6068
  if (building) {
6014
- throw new BadRequestError28(
6069
+ throw new BadRequestError29(
6015
6070
  "Cannot delete building with existing room/facility. Please delete room/facility first."
6016
6071
  );
6017
6072
  }
@@ -6029,7 +6084,7 @@ function useBuildingService() {
6029
6084
  }
6030
6085
 
6031
6086
  // src/resources/building/building.controller.ts
6032
- import { BadRequestError as BadRequestError29, logger as logger21 } from "@goweekdays/utils";
6087
+ import { BadRequestError as BadRequestError30, logger as logger21 } from "@goweekdays/utils";
6033
6088
  import Joi16 from "joi";
6034
6089
  function useBuildingController() {
6035
6090
  const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
@@ -6045,7 +6100,7 @@ function useBuildingController() {
6045
6100
  });
6046
6101
  const { error } = validation.validate(value);
6047
6102
  if (error) {
6048
- next(new BadRequestError29(error.message));
6103
+ next(new BadRequestError30(error.message));
6049
6104
  logger21.info(`Controller: ${error.message}`);
6050
6105
  return;
6051
6106
  }
@@ -6070,7 +6125,7 @@ function useBuildingController() {
6070
6125
  });
6071
6126
  const { error } = validation.validate({ id, value });
6072
6127
  if (error) {
6073
- next(new BadRequestError29(error.message));
6128
+ next(new BadRequestError30(error.message));
6074
6129
  logger21.info(`Controller: ${error.message}`);
6075
6130
  return;
6076
6131
  }
@@ -6093,7 +6148,7 @@ function useBuildingController() {
6093
6148
  });
6094
6149
  const { error } = validation.validate(query);
6095
6150
  if (error) {
6096
- next(new BadRequestError29(error.message));
6151
+ next(new BadRequestError30(error.message));
6097
6152
  return;
6098
6153
  }
6099
6154
  const page = parseInt(req.query.page) ?? 1;
@@ -6132,7 +6187,7 @@ function useBuildingController() {
6132
6187
  });
6133
6188
  const { error } = validation.validate({ id });
6134
6189
  if (error) {
6135
- next(new BadRequestError29(error.message));
6190
+ next(new BadRequestError30(error.message));
6136
6191
  return;
6137
6192
  }
6138
6193
  try {
@@ -6153,7 +6208,7 @@ function useBuildingController() {
6153
6208
  });
6154
6209
  const { error } = validation.validate({ id });
6155
6210
  if (error) {
6156
- next(new BadRequestError29(error.message));
6211
+ next(new BadRequestError30(error.message));
6157
6212
  return;
6158
6213
  }
6159
6214
  try {
@@ -6205,7 +6260,7 @@ function useBuildingUnitService() {
6205
6260
  }
6206
6261
 
6207
6262
  // src/resources/building/building-unit.controller.ts
6208
- import { BadRequestError as BadRequestError30 } from "@goweekdays/utils";
6263
+ import { BadRequestError as BadRequestError31 } from "@goweekdays/utils";
6209
6264
  import Joi17 from "joi";
6210
6265
  function useBuildingUnitController() {
6211
6266
  const {
@@ -6237,7 +6292,7 @@ function useBuildingUnitController() {
6237
6292
  });
6238
6293
  const { error } = validation.validate(data);
6239
6294
  if (error) {
6240
- next(new BadRequestError30(error.message));
6295
+ next(new BadRequestError31(error.message));
6241
6296
  return;
6242
6297
  }
6243
6298
  try {
@@ -6259,7 +6314,7 @@ function useBuildingUnitController() {
6259
6314
  });
6260
6315
  const { error } = validation.validate({ id, value: data });
6261
6316
  if (error) {
6262
- next(new BadRequestError30(error.message));
6317
+ next(new BadRequestError31(error.message));
6263
6318
  return;
6264
6319
  }
6265
6320
  try {
@@ -6284,7 +6339,7 @@ function useBuildingUnitController() {
6284
6339
  });
6285
6340
  const { error } = validation.validate(query);
6286
6341
  if (error) {
6287
- next(new BadRequestError30(error.message));
6342
+ next(new BadRequestError31(error.message));
6288
6343
  return;
6289
6344
  }
6290
6345
  const page = parseInt(req.query.page) ?? 1;
@@ -6325,7 +6380,7 @@ function useBuildingUnitController() {
6325
6380
  });
6326
6381
  const { error } = validation.validate({ id });
6327
6382
  if (error) {
6328
- next(new BadRequestError30(error.message));
6383
+ next(new BadRequestError31(error.message));
6329
6384
  return;
6330
6385
  }
6331
6386
  try {
@@ -6346,7 +6401,7 @@ function useBuildingUnitController() {
6346
6401
  });
6347
6402
  const { error } = validation.validate({ id });
6348
6403
  if (error) {
6349
- next(new BadRequestError30(error.message));
6404
+ next(new BadRequestError31(error.message));
6350
6405
  return;
6351
6406
  }
6352
6407
  try {
@@ -6367,7 +6422,7 @@ function useBuildingUnitController() {
6367
6422
  }
6368
6423
 
6369
6424
  // src/resources/counter/counter.model.ts
6370
- import { BadRequestError as BadRequestError31 } from "@goweekdays/utils";
6425
+ import { BadRequestError as BadRequestError32 } from "@goweekdays/utils";
6371
6426
  import { ObjectId as ObjectId19 } from "mongodb";
6372
6427
  import { z } from "zod";
6373
6428
  var TCounter = z.object({
@@ -6387,7 +6442,7 @@ function useCounterModel(db) {
6387
6442
  try {
6388
6443
  return TCounter.parse(value);
6389
6444
  } catch (error) {
6390
- throw new BadRequestError31(error.issues[0].message);
6445
+ throw new BadRequestError32(error.issues[0].message);
6391
6446
  }
6392
6447
  }
6393
6448
  function validateCounter(data) {
@@ -6604,8 +6659,8 @@ function useFileService() {
6604
6659
 
6605
6660
  // src/resources/file/file.controller.ts
6606
6661
  import {
6607
- AppError as AppError10,
6608
- BadRequestError as BadRequestError32,
6662
+ AppError as AppError11,
6663
+ BadRequestError as BadRequestError33,
6609
6664
  InternalServerError as InternalServerError16
6610
6665
  } from "@goweekdays/utils";
6611
6666
  import Joi18 from "joi";
@@ -6621,7 +6676,7 @@ function useFileController() {
6621
6676
  res.json({ message: "Successfully uploaded file", id });
6622
6677
  return;
6623
6678
  } catch (error) {
6624
- if (error instanceof AppError10) {
6679
+ if (error instanceof AppError11) {
6625
6680
  next(error);
6626
6681
  } else {
6627
6682
  next(new InternalServerError16(error));
@@ -6633,14 +6688,14 @@ function useFileController() {
6633
6688
  const validation = Joi18.string().required();
6634
6689
  const { error } = validation.validate(id);
6635
6690
  if (error) {
6636
- next(new BadRequestError32(error.message));
6691
+ next(new BadRequestError33(error.message));
6637
6692
  }
6638
6693
  try {
6639
6694
  const message = await _deleteFile(id);
6640
6695
  res.json({ message });
6641
6696
  return;
6642
6697
  } catch (error2) {
6643
- if (error2 instanceof AppError10) {
6698
+ if (error2 instanceof AppError11) {
6644
6699
  next(error2);
6645
6700
  } else {
6646
6701
  next(new InternalServerError16(error2));
@@ -6655,7 +6710,7 @@ function useFileController() {
6655
6710
 
6656
6711
  // src/resources/member/member.controller.ts
6657
6712
  import Joi19 from "joi";
6658
- import { BadRequestError as BadRequestError33 } from "@goweekdays/utils";
6713
+ import { BadRequestError as BadRequestError34 } from "@goweekdays/utils";
6659
6714
  function useMemberController() {
6660
6715
  const {
6661
6716
  getByUserId: _getByUserId,
@@ -6671,7 +6726,7 @@ function useMemberController() {
6671
6726
  });
6672
6727
  const { error } = validation.validate({ id: userId });
6673
6728
  if (error) {
6674
- next(new BadRequestError33(error.message));
6729
+ next(new BadRequestError34(error.message));
6675
6730
  return;
6676
6731
  }
6677
6732
  try {
@@ -6693,7 +6748,7 @@ function useMemberController() {
6693
6748
  });
6694
6749
  const { error } = validation.validate({ ...req.params, ...req.query });
6695
6750
  if (error) {
6696
- next(new BadRequestError33(error.message));
6751
+ next(new BadRequestError34(error.message));
6697
6752
  return;
6698
6753
  }
6699
6754
  const orgId = req.query.org;
@@ -6737,7 +6792,7 @@ function useMemberController() {
6737
6792
  status
6738
6793
  });
6739
6794
  if (error) {
6740
- next(new BadRequestError33(error.message));
6795
+ next(new BadRequestError34(error.message));
6741
6796
  return;
6742
6797
  }
6743
6798
  try {
@@ -6774,7 +6829,7 @@ function useMemberController() {
6774
6829
  limit
6775
6830
  });
6776
6831
  if (error) {
6777
- next(new BadRequestError33(error.message));
6832
+ next(new BadRequestError34(error.message));
6778
6833
  }
6779
6834
  try {
6780
6835
  const items = await _getOrgsByMembership({
@@ -6796,7 +6851,7 @@ function useMemberController() {
6796
6851
  });
6797
6852
  const { error } = validation.validate(req.params);
6798
6853
  if (error) {
6799
- next(new BadRequestError33(error.message));
6854
+ next(new BadRequestError34(error.message));
6800
6855
  return;
6801
6856
  }
6802
6857
  const id = req.params.id;
@@ -6818,42 +6873,32 @@ function useMemberController() {
6818
6873
  }
6819
6874
 
6820
6875
  // src/resources/organization/organization.model.ts
6821
- import { BadRequestError as BadRequestError34 } from "@goweekdays/utils";
6876
+ import { BadRequestError as BadRequestError35 } from "@goweekdays/utils";
6822
6877
  import Joi20 from "joi";
6823
6878
  import { ObjectId as ObjectId20 } from "mongodb";
6824
- var OrgTypes = [
6825
- "marketplace",
6826
- "stay",
6827
- "eat",
6828
- "service",
6829
- "ride",
6830
- "experience"
6831
- ];
6832
6879
  var schemaOrg = Joi20.object({
6833
6880
  name: Joi20.string().max(255).required(),
6834
6881
  description: Joi20.string().max(1024).optional().allow("", null),
6835
- type: Joi20.string().allow(...OrgTypes).required(),
6836
6882
  email: Joi20.string().email().max(255).optional().allow("", null),
6837
6883
  contact: Joi20.string().max(50).optional().allow("", null),
6838
6884
  createdBy: Joi20.string().hex().required()
6839
6885
  });
6840
- function MOrg(value) {
6886
+ function modelOrg(value) {
6841
6887
  const { error } = schemaOrg.validate(value);
6842
6888
  if (error) {
6843
- throw new BadRequestError34(error.message);
6889
+ throw new BadRequestError35(error.message);
6844
6890
  }
6845
6891
  if (value.createdBy && typeof value.createdBy === "string") {
6846
6892
  try {
6847
6893
  value.createdBy = new ObjectId20(value.createdBy);
6848
6894
  } catch (error2) {
6849
- throw new BadRequestError34("Invalid createdBy ObjectId");
6895
+ throw new BadRequestError35("Invalid createdBy ObjectId");
6850
6896
  }
6851
6897
  }
6852
6898
  return {
6853
6899
  _id: value._id,
6854
6900
  name: value.name,
6855
- description: value.description,
6856
- type: value.type,
6901
+ description: value.description ?? "",
6857
6902
  email: value.email,
6858
6903
  contact: value.contact,
6859
6904
  createdBy: value.createdBy,
@@ -6866,8 +6911,8 @@ function MOrg(value) {
6866
6911
 
6867
6912
  // src/resources/organization/organization.repository.ts
6868
6913
  import {
6869
- AppError as AppError11,
6870
- BadRequestError as BadRequestError35,
6914
+ AppError as AppError12,
6915
+ BadRequestError as BadRequestError36,
6871
6916
  InternalServerError as InternalServerError17,
6872
6917
  logger as logger24,
6873
6918
  makeCacheKey as makeCacheKey14,
@@ -6916,7 +6961,7 @@ function useOrgRepo() {
6916
6961
  }
6917
6962
  async function add(value, session) {
6918
6963
  try {
6919
- value = MOrg(value);
6964
+ value = modelOrg(value);
6920
6965
  const res = await collection.insertOne(value, { session });
6921
6966
  delCachedData();
6922
6967
  return res.insertedId;
@@ -6925,12 +6970,12 @@ function useOrgRepo() {
6925
6970
  level: "error",
6926
6971
  message: error.message
6927
6972
  });
6928
- if (error instanceof AppError11) {
6973
+ if (error instanceof AppError12) {
6929
6974
  throw error;
6930
6975
  } else {
6931
6976
  const isDuplicated = error.message.includes("duplicate");
6932
6977
  if (isDuplicated) {
6933
- throw new BadRequestError35("Organization already exist.");
6978
+ throw new BadRequestError36("Organization already exist.");
6934
6979
  }
6935
6980
  throw new Error("Failed to create organization.");
6936
6981
  }
@@ -7007,7 +7052,7 @@ function useOrgRepo() {
7007
7052
  try {
7008
7053
  _id = new ObjectId21(_id);
7009
7054
  } catch (error) {
7010
- throw new BadRequestError35("Invalid ID.");
7055
+ throw new BadRequestError36("Invalid ID.");
7011
7056
  }
7012
7057
  const cacheKey = makeCacheKey14(namespace_collection, { _id: String(_id) });
7013
7058
  try {
@@ -7021,7 +7066,7 @@ function useOrgRepo() {
7021
7066
  }
7022
7067
  const result = await collection.findOne({ _id });
7023
7068
  if (!result) {
7024
- throw new BadRequestError35("Organization not found.");
7069
+ throw new BadRequestError36("Organization not found.");
7025
7070
  }
7026
7071
  setCache(cacheKey, result, 300).then(() => {
7027
7072
  logger24.log({
@@ -7036,7 +7081,7 @@ function useOrgRepo() {
7036
7081
  });
7037
7082
  return result;
7038
7083
  } catch (error) {
7039
- if (error instanceof AppError11) {
7084
+ if (error instanceof AppError12) {
7040
7085
  throw error;
7041
7086
  } else {
7042
7087
  throw new InternalServerError17("Failed to get organization.");
@@ -7056,7 +7101,7 @@ function useOrgRepo() {
7056
7101
  }
7057
7102
  const result = await collection.findOne({ name });
7058
7103
  if (!result) {
7059
- throw new BadRequestError35("Organization not found.");
7104
+ throw new BadRequestError36("Organization not found.");
7060
7105
  }
7061
7106
  setCache(cacheKey, result, 300).then(() => {
7062
7107
  logger24.log({
@@ -7071,7 +7116,7 @@ function useOrgRepo() {
7071
7116
  });
7072
7117
  return result;
7073
7118
  } catch (error) {
7074
- if (error instanceof AppError11) {
7119
+ if (error instanceof AppError12) {
7075
7120
  throw error;
7076
7121
  } else {
7077
7122
  throw new InternalServerError17("Failed to get organization.");
@@ -7081,14 +7126,14 @@ function useOrgRepo() {
7081
7126
  async function updateFieldById({ _id, field, value } = {}, session) {
7082
7127
  const allowedFields = ["name", "description"];
7083
7128
  if (!allowedFields.includes(field)) {
7084
- throw new BadRequestError35(
7129
+ throw new BadRequestError36(
7085
7130
  `Field "${field}" is not allowed to be updated.`
7086
7131
  );
7087
7132
  }
7088
7133
  try {
7089
7134
  _id = new ObjectId21(_id);
7090
7135
  } catch (error) {
7091
- throw new BadRequestError35("Invalid ID.");
7136
+ throw new BadRequestError36("Invalid ID.");
7092
7137
  }
7093
7138
  try {
7094
7139
  await collection.updateOne(
@@ -7107,7 +7152,7 @@ function useOrgRepo() {
7107
7152
  try {
7108
7153
  _id = new ObjectId21(_id);
7109
7154
  } catch (error) {
7110
- throw new BadRequestError35("Invalid ID.");
7155
+ throw new BadRequestError36("Invalid ID.");
7111
7156
  }
7112
7157
  try {
7113
7158
  await collection.updateOne(
@@ -7132,12 +7177,12 @@ function useOrgRepo() {
7132
7177
  }
7133
7178
 
7134
7179
  // src/resources/organization/organization.service.ts
7135
- import { BadRequestError as BadRequestError37, useAtlas as useAtlas21 } from "@goweekdays/utils";
7180
+ import { BadRequestError as BadRequestError38, useAtlas as useAtlas21 } from "@goweekdays/utils";
7136
7181
 
7137
7182
  // src/resources/user/user.controller.ts
7138
7183
  import {
7139
- AppError as AppError12,
7140
- BadRequestError as BadRequestError36,
7184
+ AppError as AppError13,
7185
+ BadRequestError as BadRequestError37,
7141
7186
  InternalServerError as InternalServerError18
7142
7187
  } from "@goweekdays/utils";
7143
7188
  import Joi21 from "joi";
@@ -7163,7 +7208,7 @@ function useUserController() {
7163
7208
  });
7164
7209
  const { error } = validation.validate({ status, search, page });
7165
7210
  if (error) {
7166
- next(new BadRequestError36(error.message));
7211
+ next(new BadRequestError37(error.message));
7167
7212
  return;
7168
7213
  }
7169
7214
  try {
@@ -7178,12 +7223,12 @@ function useUserController() {
7178
7223
  const id = req.params.id || "";
7179
7224
  const validation = Joi21.string().hex().validate(id);
7180
7225
  if (validation.error) {
7181
- throw new BadRequestError36("Invalid id.");
7226
+ throw new BadRequestError37("Invalid id.");
7182
7227
  }
7183
7228
  try {
7184
7229
  const user = await _getUserById(id);
7185
7230
  if (!user) {
7186
- throw new BadRequestError36("User not found.");
7231
+ throw new BadRequestError37("User not found.");
7187
7232
  }
7188
7233
  res.json(user);
7189
7234
  } catch (error) {
@@ -7200,7 +7245,7 @@ function useUserController() {
7200
7245
  });
7201
7246
  const { error } = validation.validate({ firstName, lastName });
7202
7247
  if (error) {
7203
- next(new BadRequestError36(error.message));
7248
+ next(new BadRequestError37(error.message));
7204
7249
  return;
7205
7250
  }
7206
7251
  try {
@@ -7223,7 +7268,7 @@ function useUserController() {
7223
7268
  });
7224
7269
  const { error } = validation.validate({ month, day, year });
7225
7270
  if (error) {
7226
- next(new BadRequestError36(error.message));
7271
+ next(new BadRequestError37(error.message));
7227
7272
  return;
7228
7273
  }
7229
7274
  try {
@@ -7248,7 +7293,7 @@ function useUserController() {
7248
7293
  });
7249
7294
  const { error } = validation.validate({ _id, field, value });
7250
7295
  if (error) {
7251
- next(new BadRequestError36(error.message));
7296
+ next(new BadRequestError37(error.message));
7252
7297
  return;
7253
7298
  }
7254
7299
  try {
@@ -7269,7 +7314,7 @@ function useUserController() {
7269
7314
  });
7270
7315
  const { error } = validation.validate({ previousProfile });
7271
7316
  if (error) {
7272
- next(new BadRequestError36(error.message));
7317
+ next(new BadRequestError37(error.message));
7273
7318
  return;
7274
7319
  }
7275
7320
  const user = req.headers["user"] ?? "";
@@ -7282,7 +7327,7 @@ function useUserController() {
7282
7327
  res.json({ message: "Successfully updated profile picture." });
7283
7328
  return;
7284
7329
  } catch (error2) {
7285
- if (error2 instanceof AppError12) {
7330
+ if (error2 instanceof AppError13) {
7286
7331
  next(error2);
7287
7332
  } else {
7288
7333
  next(new InternalServerError18(error2));
@@ -7310,7 +7355,7 @@ function useUserController() {
7310
7355
  type
7311
7356
  });
7312
7357
  if (error) {
7313
- next(new BadRequestError36(error.message));
7358
+ next(new BadRequestError37(error.message));
7314
7359
  return;
7315
7360
  }
7316
7361
  try {
@@ -7351,8 +7396,11 @@ function useOrgService() {
7351
7396
  const { getUserById } = useUserRepo();
7352
7397
  async function add(value) {
7353
7398
  const session = useAtlas21.getClient()?.startSession();
7354
- session?.startTransaction();
7399
+ if (!session) {
7400
+ throw new BadRequestError38("Unable to start database session.");
7401
+ }
7355
7402
  try {
7403
+ session?.startTransaction();
7356
7404
  const org = await addOrg(value, session);
7357
7405
  const allPermissions = await getAllPermission({
7358
7406
  app: "org",
@@ -7365,39 +7413,41 @@ function useOrgService() {
7365
7413
  if (permissions.length === 0) {
7366
7414
  throw new Error("No permissions found for the organization type.");
7367
7415
  }
7416
+ const createdBy = String(value.createdBy);
7368
7417
  const role = await addRole(
7369
7418
  {
7370
- id: org,
7419
+ org: String(org),
7371
7420
  name: "Owner",
7372
7421
  description: "Owner of the organization",
7373
- permissions
7422
+ permissions,
7423
+ createdBy
7374
7424
  },
7375
7425
  session
7376
7426
  );
7377
7427
  if (!role) {
7378
- throw new BadRequestError37("Role is required to create org member.");
7428
+ throw new BadRequestError38("Role is required to create org member.");
7379
7429
  }
7380
- const user = await getUserById(value.createdBy);
7430
+ const user = await getUserById(createdBy);
7381
7431
  if (!user) {
7382
- throw new BadRequestError37("User is required to create org member.");
7432
+ throw new BadRequestError38("User is required to create org member.");
7383
7433
  }
7384
7434
  await addMember(
7385
7435
  {
7386
7436
  role: String(role),
7387
7437
  org: String(org),
7388
7438
  name: `${user.firstName} ${user.lastName}`,
7389
- user: value.createdBy,
7390
- type: "owner"
7439
+ user: createdBy,
7440
+ type: "org"
7391
7441
  },
7392
7442
  session
7393
7443
  );
7394
- session?.commitTransaction();
7395
- return "Organization created successfully.";
7444
+ await session?.commitTransaction();
7445
+ return String(org);
7396
7446
  } catch (error) {
7397
- session?.abortTransaction();
7447
+ await session?.abortTransaction();
7398
7448
  throw error;
7399
7449
  } finally {
7400
- session?.endSession();
7450
+ await session?.endSession();
7401
7451
  }
7402
7452
  }
7403
7453
  return {
@@ -7406,7 +7456,7 @@ function useOrgService() {
7406
7456
  }
7407
7457
 
7408
7458
  // src/resources/organization/organization.controller.ts
7409
- import { BadRequestError as BadRequestError38 } from "@goweekdays/utils";
7459
+ import { BadRequestError as BadRequestError39 } from "@goweekdays/utils";
7410
7460
  import Joi22 from "joi";
7411
7461
  function useOrgController() {
7412
7462
  const { add: _add } = useOrgService();
@@ -7416,16 +7466,19 @@ function useOrgController() {
7416
7466
  getAll: getAllOrg,
7417
7467
  getById: _getById
7418
7468
  } = useOrgRepo();
7419
- async function createOrg(req, res, next) {
7469
+ async function add(req, res, next) {
7420
7470
  const value = req.body;
7421
7471
  const { error } = schemaOrg.validate(value);
7422
7472
  if (error) {
7423
- next(new BadRequestError38(error.message));
7473
+ next(new BadRequestError39(error.message));
7424
7474
  return;
7425
7475
  }
7426
7476
  try {
7427
- const message = await _add(value);
7428
- res.json({ message });
7477
+ const org = await _add(value);
7478
+ res.json({
7479
+ message: "Organization created successfully.",
7480
+ data: { org }
7481
+ });
7429
7482
  return;
7430
7483
  } catch (error2) {
7431
7484
  next(error2);
@@ -7438,12 +7491,12 @@ function useOrgController() {
7438
7491
  const user = req.params.user ?? "";
7439
7492
  const isPageNumber = isFinite(page);
7440
7493
  if (!isPageNumber) {
7441
- next(new BadRequestError38("Invalid page number."));
7494
+ next(new BadRequestError39("Invalid page number."));
7442
7495
  return;
7443
7496
  }
7444
7497
  const isLimitNumber = isFinite(limit);
7445
7498
  if (!isLimitNumber) {
7446
- next(new BadRequestError38("Invalid limit number."));
7499
+ next(new BadRequestError39("Invalid limit number."));
7447
7500
  return;
7448
7501
  }
7449
7502
  const validation = Joi22.object({
@@ -7454,7 +7507,7 @@ function useOrgController() {
7454
7507
  });
7455
7508
  const { error } = validation.validate({ user, page, limit, search });
7456
7509
  if (error) {
7457
- next(new BadRequestError38(error.message));
7510
+ next(new BadRequestError39(error.message));
7458
7511
  return;
7459
7512
  }
7460
7513
  try {
@@ -7480,16 +7533,16 @@ function useOrgController() {
7480
7533
  const status = req.query.status ?? "active";
7481
7534
  const isPageNumber = isFinite(page);
7482
7535
  if (!isPageNumber) {
7483
- next(new BadRequestError38("Invalid page number."));
7536
+ next(new BadRequestError39("Invalid page number."));
7484
7537
  return;
7485
7538
  }
7486
7539
  const isLimitNumber = isFinite(limit);
7487
7540
  if (!isLimitNumber) {
7488
- next(new BadRequestError38("Invalid limit number."));
7541
+ next(new BadRequestError39("Invalid limit number."));
7489
7542
  return;
7490
7543
  }
7491
7544
  if (error) {
7492
- next(new BadRequestError38(error.message));
7545
+ next(new BadRequestError39(error.message));
7493
7546
  return;
7494
7547
  }
7495
7548
  try {
@@ -7507,7 +7560,7 @@ function useOrgController() {
7507
7560
  });
7508
7561
  const { error } = validation.validate({ name });
7509
7562
  if (error) {
7510
- next(new BadRequestError38(error.message));
7563
+ next(new BadRequestError39(error.message));
7511
7564
  return;
7512
7565
  }
7513
7566
  try {
@@ -7525,7 +7578,7 @@ function useOrgController() {
7525
7578
  });
7526
7579
  const { error } = validation.validate({ id });
7527
7580
  if (error) {
7528
- next(new BadRequestError38(error.message));
7581
+ next(new BadRequestError39(error.message));
7529
7582
  return;
7530
7583
  }
7531
7584
  try {
@@ -7537,7 +7590,7 @@ function useOrgController() {
7537
7590
  }
7538
7591
  }
7539
7592
  return {
7540
- createOrg,
7593
+ add,
7541
7594
  getOrgsByUserId,
7542
7595
  getByName,
7543
7596
  getAll,
@@ -7566,8 +7619,8 @@ function modelPSGC(data) {
7566
7619
 
7567
7620
  // src/resources/psgc/psgc.repository.ts
7568
7621
  import {
7569
- AppError as AppError13,
7570
- BadRequestError as BadRequestError39,
7622
+ AppError as AppError14,
7623
+ BadRequestError as BadRequestError40,
7571
7624
  InternalServerError as InternalServerError19,
7572
7625
  logger as logger25,
7573
7626
  makeCacheKey as makeCacheKey15,
@@ -7619,12 +7672,12 @@ function usePSGCRepo() {
7619
7672
  level: "error",
7620
7673
  message: error.message
7621
7674
  });
7622
- if (error instanceof AppError13) {
7675
+ if (error instanceof AppError14) {
7623
7676
  throw error;
7624
7677
  } else {
7625
7678
  const isDuplicated = error.message.includes("duplicate");
7626
7679
  if (isDuplicated) {
7627
- throw new BadRequestError39("Region already exists.");
7680
+ throw new BadRequestError40("Region already exists.");
7628
7681
  }
7629
7682
  throw new Error("Failed to create PSGC.");
7630
7683
  }
@@ -7703,7 +7756,7 @@ function usePSGCRepo() {
7703
7756
  try {
7704
7757
  _id = new ObjectId22(_id);
7705
7758
  } catch (error) {
7706
- throw new BadRequestError39("Invalid ID.");
7759
+ throw new BadRequestError40("Invalid ID.");
7707
7760
  }
7708
7761
  const cacheKey = makeCacheKey15(namespace_collection, { _id: String(_id) });
7709
7762
  try {
@@ -7720,7 +7773,7 @@ function usePSGCRepo() {
7720
7773
  deletedAt: { $in: ["", null] }
7721
7774
  });
7722
7775
  if (!result) {
7723
- throw new BadRequestError39("Region not found.");
7776
+ throw new BadRequestError40("Region not found.");
7724
7777
  }
7725
7778
  setCache(cacheKey, result, 300).then(() => {
7726
7779
  logger25.log({
@@ -7735,7 +7788,7 @@ function usePSGCRepo() {
7735
7788
  });
7736
7789
  return result;
7737
7790
  } catch (error) {
7738
- if (error instanceof AppError13) {
7791
+ if (error instanceof AppError14) {
7739
7792
  throw error;
7740
7793
  } else {
7741
7794
  throw new InternalServerError19("Failed to get PSGC.");
@@ -7790,7 +7843,7 @@ function usePSGCRepo() {
7790
7843
  });
7791
7844
  return result;
7792
7845
  } catch (error) {
7793
- if (error instanceof AppError13) {
7846
+ if (error instanceof AppError14) {
7794
7847
  throw error;
7795
7848
  } else {
7796
7849
  throw new InternalServerError19("Failed to get PSGC.");
@@ -7800,14 +7853,14 @@ function usePSGCRepo() {
7800
7853
  async function updateFieldById({ _id, field, value } = {}, session) {
7801
7854
  const allowedFields = ["name"];
7802
7855
  if (!allowedFields.includes(field)) {
7803
- throw new BadRequestError39(
7856
+ throw new BadRequestError40(
7804
7857
  `Field "${field}" is not allowed to be updated.`
7805
7858
  );
7806
7859
  }
7807
7860
  try {
7808
7861
  _id = new ObjectId22(_id);
7809
7862
  } catch (error) {
7810
- throw new BadRequestError39("Invalid ID.");
7863
+ throw new BadRequestError40("Invalid ID.");
7811
7864
  }
7812
7865
  try {
7813
7866
  await collection.updateOne(
@@ -7825,7 +7878,7 @@ function usePSGCRepo() {
7825
7878
  try {
7826
7879
  _id = new ObjectId22(_id);
7827
7880
  } catch (error) {
7828
- throw new BadRequestError39("Invalid ID.");
7881
+ throw new BadRequestError40("Invalid ID.");
7829
7882
  }
7830
7883
  try {
7831
7884
  await collection.updateOne(
@@ -7850,7 +7903,7 @@ function usePSGCRepo() {
7850
7903
  }
7851
7904
 
7852
7905
  // src/resources/psgc/psgc.controller.ts
7853
- import { BadRequestError as BadRequestError40 } from "@goweekdays/utils";
7906
+ import { BadRequestError as BadRequestError41 } from "@goweekdays/utils";
7854
7907
  import Joi24 from "joi";
7855
7908
  function usePSGCController() {
7856
7909
  const {
@@ -7865,7 +7918,7 @@ function usePSGCController() {
7865
7918
  const value = req.body;
7866
7919
  const { error } = schemaPSGC.validate(value);
7867
7920
  if (error) {
7868
- next(new BadRequestError40(error.message));
7921
+ next(new BadRequestError41(error.message));
7869
7922
  return;
7870
7923
  }
7871
7924
  try {
@@ -7896,16 +7949,16 @@ function usePSGCController() {
7896
7949
  const prefix = req.query.prefix ? String(req.query.prefix) : "";
7897
7950
  const isPageNumber = isFinite(page);
7898
7951
  if (!isPageNumber) {
7899
- next(new BadRequestError40("Invalid page number."));
7952
+ next(new BadRequestError41("Invalid page number."));
7900
7953
  return;
7901
7954
  }
7902
7955
  const isLimitNumber = isFinite(limit);
7903
7956
  if (!isLimitNumber) {
7904
- next(new BadRequestError40("Invalid limit number."));
7957
+ next(new BadRequestError41("Invalid limit number."));
7905
7958
  return;
7906
7959
  }
7907
7960
  if (error) {
7908
- next(new BadRequestError40(error.message));
7961
+ next(new BadRequestError41(error.message));
7909
7962
  return;
7910
7963
  }
7911
7964
  try {
@@ -7929,7 +7982,7 @@ function usePSGCController() {
7929
7982
  });
7930
7983
  const { error } = validation.validate({ id });
7931
7984
  if (error) {
7932
- next(new BadRequestError40(error.message));
7985
+ next(new BadRequestError41(error.message));
7933
7986
  return;
7934
7987
  }
7935
7988
  try {
@@ -7950,7 +8003,7 @@ function usePSGCController() {
7950
8003
  });
7951
8004
  const { error } = validation.validate({ name });
7952
8005
  if (error) {
7953
- next(new BadRequestError40(error.message));
8006
+ next(new BadRequestError41(error.message));
7954
8007
  return;
7955
8008
  }
7956
8009
  try {
@@ -7974,7 +8027,7 @@ function usePSGCController() {
7974
8027
  });
7975
8028
  const { error } = validation.validate({ _id, field, value });
7976
8029
  if (error) {
7977
- next(new BadRequestError40(error.message));
8030
+ next(new BadRequestError41(error.message));
7978
8031
  return;
7979
8032
  }
7980
8033
  try {
@@ -7992,7 +8045,7 @@ function usePSGCController() {
7992
8045
  });
7993
8046
  const { error } = validation.validate({ _id });
7994
8047
  if (error) {
7995
- next(new BadRequestError40(error.message));
8048
+ next(new BadRequestError41(error.message));
7996
8049
  return;
7997
8050
  }
7998
8051
  try {
@@ -8015,8 +8068,8 @@ function usePSGCController() {
8015
8068
 
8016
8069
  // src/resources/role/role.service.ts
8017
8070
  import {
8018
- AppError as AppError14,
8019
- BadRequestError as BadRequestError41,
8071
+ AppError as AppError15,
8072
+ BadRequestError as BadRequestError42,
8020
8073
  InternalServerError as InternalServerError20
8021
8074
  } from "@goweekdays/utils";
8022
8075
  function useRoleService() {
@@ -8026,11 +8079,11 @@ function useRoleService() {
8026
8079
  try {
8027
8080
  const role = await getByRole(id);
8028
8081
  if (role) {
8029
- throw new BadRequestError41("Cannot delete role assigned to members.");
8082
+ throw new BadRequestError42("Cannot delete role assigned to members.");
8030
8083
  }
8031
8084
  await _deleteById(id);
8032
8085
  } catch (error) {
8033
- if (error instanceof AppError14) {
8086
+ if (error instanceof AppError15) {
8034
8087
  throw error;
8035
8088
  } else {
8036
8089
  throw new InternalServerError20("Failed to delete role.");
@@ -8044,7 +8097,7 @@ function useRoleService() {
8044
8097
 
8045
8098
  // src/resources/role/role.controller.ts
8046
8099
  import Joi25 from "joi";
8047
- import { BadRequestError as BadRequestError42 } from "@goweekdays/utils";
8100
+ import { BadRequestError as BadRequestError43 } from "@goweekdays/utils";
8048
8101
  function useRoleController() {
8049
8102
  const {
8050
8103
  addRole: _createRole,
@@ -8059,7 +8112,7 @@ function useRoleController() {
8059
8112
  const payload = req.body;
8060
8113
  const { error } = schemaRole.validate(payload);
8061
8114
  if (error) {
8062
- next(new BadRequestError42(error.message));
8115
+ next(new BadRequestError43(error.message));
8063
8116
  return;
8064
8117
  }
8065
8118
  try {
@@ -8085,7 +8138,7 @@ function useRoleController() {
8085
8138
  });
8086
8139
  const { error } = validation.validate({ search, page, limit, type, id });
8087
8140
  if (error) {
8088
- next(new BadRequestError42(error.message));
8141
+ next(new BadRequestError43(error.message));
8089
8142
  return;
8090
8143
  }
8091
8144
  try {
@@ -8103,7 +8156,7 @@ function useRoleController() {
8103
8156
  });
8104
8157
  const { error } = validation.validate({ userId });
8105
8158
  if (error) {
8106
- next(new BadRequestError42(error.message));
8159
+ next(new BadRequestError43(error.message));
8107
8160
  return;
8108
8161
  }
8109
8162
  try {
@@ -8121,7 +8174,7 @@ function useRoleController() {
8121
8174
  });
8122
8175
  const { error } = validation.validate({ _id });
8123
8176
  if (error) {
8124
- next(new BadRequestError42(error.message));
8177
+ next(new BadRequestError43(error.message));
8125
8178
  return;
8126
8179
  }
8127
8180
  try {
@@ -8143,7 +8196,7 @@ function useRoleController() {
8143
8196
  });
8144
8197
  const { error } = validation.validate({ _id, name, permissions });
8145
8198
  if (error) {
8146
- next(new BadRequestError42(error.message));
8199
+ next(new BadRequestError43(error.message));
8147
8200
  return;
8148
8201
  }
8149
8202
  try {
@@ -8163,7 +8216,7 @@ function useRoleController() {
8163
8216
  });
8164
8217
  const { error } = validation.validate({ _id, permissions });
8165
8218
  if (error) {
8166
- next(new BadRequestError42(error.message));
8219
+ next(new BadRequestError43(error.message));
8167
8220
  return;
8168
8221
  }
8169
8222
  try {
@@ -8181,7 +8234,7 @@ function useRoleController() {
8181
8234
  });
8182
8235
  const { error } = validation.validate({ _id });
8183
8236
  if (error) {
8184
- next(new BadRequestError42(error.message));
8237
+ next(new BadRequestError43(error.message));
8185
8238
  return;
8186
8239
  }
8187
8240
  try {
@@ -8204,7 +8257,7 @@ function useRoleController() {
8204
8257
  }
8205
8258
 
8206
8259
  // src/resources/utils/github.service.ts
8207
- import { AppError as AppError15, BadRequestError as BadRequestError43 } from "@goweekdays/utils";
8260
+ import { AppError as AppError16, BadRequestError as BadRequestError44 } from "@goweekdays/utils";
8208
8261
  import { Octokit } from "@octokit/rest";
8209
8262
  import _sodium from "libsodium-wrappers";
8210
8263
  function useGitHubService() {
@@ -8218,23 +8271,23 @@ function useGitHubService() {
8218
8271
  try {
8219
8272
  const { data: repoData } = await octokit.repos.get({ owner, repo });
8220
8273
  if (!repoData.permissions?.admin) {
8221
- throw new BadRequestError43(
8274
+ throw new BadRequestError44(
8222
8275
  "You do not have admin access to this repository."
8223
8276
  );
8224
8277
  }
8225
8278
  } catch (error) {
8226
8279
  if (error.status === 404) {
8227
- throw new BadRequestError43(
8280
+ throw new BadRequestError44(
8228
8281
  "Repository not found or you don't have access to it."
8229
8282
  );
8230
8283
  } else if (error.status === 401) {
8231
- throw new BadRequestError43(
8284
+ throw new BadRequestError44(
8232
8285
  "Invalid GitHub token or insufficient permissions."
8233
8286
  );
8234
8287
  } else if (error.message.includes("admin access")) {
8235
8288
  throw error;
8236
8289
  } else {
8237
- throw new BadRequestError43(
8290
+ throw new BadRequestError44(
8238
8291
  `Failed to check repository permissions: ${error.message}`
8239
8292
  );
8240
8293
  }
@@ -8283,7 +8336,7 @@ function useGitHubService() {
8283
8336
  key_id: publicKeyRes.key_id
8284
8337
  });
8285
8338
  } catch (encryptionError) {
8286
- throw new BadRequestError43(
8339
+ throw new BadRequestError44(
8287
8340
  `Failed to encrypt secret '${key}': ${encryptionError.message}`
8288
8341
  );
8289
8342
  }
@@ -8313,22 +8366,22 @@ function useGitHubService() {
8313
8366
  }
8314
8367
  return `Successfully set ${lines.length} ${type} variables/secrets in environment '${environment}'`;
8315
8368
  } catch (error) {
8316
- if (error instanceof AppError15)
8369
+ if (error instanceof AppError16)
8317
8370
  throw error;
8318
8371
  if (error.status === 422) {
8319
- throw new BadRequestError43(
8372
+ throw new BadRequestError44(
8320
8373
  `GitHub API validation error: ${error.message}`
8321
8374
  );
8322
8375
  } else if (error.status === 404) {
8323
- throw new BadRequestError43("Environment or repository not found.");
8376
+ throw new BadRequestError44("Environment or repository not found.");
8324
8377
  } else if (error.status === 403) {
8325
- throw new BadRequestError43(
8378
+ throw new BadRequestError44(
8326
8379
  "Forbidden: Insufficient permissions or rate limit exceeded."
8327
8380
  );
8328
8381
  } else if (error.message.includes("admin access") || error.message.includes("permissions")) {
8329
8382
  throw error;
8330
8383
  } else {
8331
- throw new BadRequestError43(
8384
+ throw new BadRequestError44(
8332
8385
  `Failed to set GitHub variables: ${error.message}`
8333
8386
  );
8334
8387
  }
@@ -8342,8 +8395,8 @@ function useGitHubService() {
8342
8395
  // src/resources/utils/util.controller.ts
8343
8396
  import Joi26 from "joi";
8344
8397
  import {
8345
- AppError as AppError16,
8346
- BadRequestError as BadRequestError44,
8398
+ AppError as AppError17,
8399
+ BadRequestError as BadRequestError45,
8347
8400
  InternalServerError as InternalServerError22,
8348
8401
  logger as logger26
8349
8402
  } from "@goweekdays/utils";
@@ -8400,13 +8453,13 @@ function useUtilController() {
8400
8453
  keyValues
8401
8454
  });
8402
8455
  if (error) {
8403
- next(new BadRequestError44(error.message));
8456
+ next(new BadRequestError45(error.message));
8404
8457
  return;
8405
8458
  }
8406
8459
  const repoUrlPattern = /github\.com[:\/]([^\/]+)\/(.+)\.git$/;
8407
8460
  if (!repoUrlPattern.test(repoUrl)) {
8408
8461
  next(
8409
- new BadRequestError44(
8462
+ new BadRequestError45(
8410
8463
  "Invalid GitHub repository URL format. Expected format: https://github.com/owner/repo.git"
8411
8464
  )
8412
8465
  );
@@ -8418,7 +8471,7 @@ function useUtilController() {
8418
8471
  );
8419
8472
  if (invalidLines.length > 0) {
8420
8473
  next(
8421
- new BadRequestError44(
8474
+ new BadRequestError45(
8422
8475
  "Invalid key-value format. Each pair should be in format: KEY=value. Pairs should be separated by semicolons."
8423
8476
  )
8424
8477
  );
@@ -8453,7 +8506,7 @@ function useUtilController() {
8453
8506
  error: error.message,
8454
8507
  stack: error.stack
8455
8508
  });
8456
- if (error instanceof AppError16) {
8509
+ if (error instanceof AppError17) {
8457
8510
  next(error);
8458
8511
  } else {
8459
8512
  next(
@@ -8495,8 +8548,8 @@ var transactionSchema = Joi27.object({
8495
8548
 
8496
8549
  // src/resources/verification/verification.controller.ts
8497
8550
  import {
8498
- AppError as AppError17,
8499
- BadRequestError as BadRequestError45,
8551
+ AppError as AppError18,
8552
+ BadRequestError as BadRequestError46,
8500
8553
  InternalServerError as InternalServerError23
8501
8554
  } from "@goweekdays/utils";
8502
8555
  import Joi28 from "joi";
@@ -8519,7 +8572,7 @@ function useVerificationController() {
8519
8572
  });
8520
8573
  const { error } = validation.validate(req.body);
8521
8574
  if (error) {
8522
- next(new BadRequestError45(error.message));
8575
+ next(new BadRequestError46(error.message));
8523
8576
  return;
8524
8577
  }
8525
8578
  const email = req.body.email ?? "";
@@ -8550,7 +8603,7 @@ function useVerificationController() {
8550
8603
  const validation = Joi28.string().email().required();
8551
8604
  const { error } = validation.validate(email);
8552
8605
  if (error) {
8553
- next(new BadRequestError45(error.message));
8606
+ next(new BadRequestError46(error.message));
8554
8607
  return;
8555
8608
  }
8556
8609
  try {
@@ -8560,7 +8613,7 @@ function useVerificationController() {
8560
8613
  });
8561
8614
  return;
8562
8615
  } catch (error2) {
8563
- if (error2 instanceof AppError17) {
8616
+ if (error2 instanceof AppError18) {
8564
8617
  next(error2);
8565
8618
  } else {
8566
8619
  next(new InternalServerError23("An unexpected error occurred"));
@@ -8578,7 +8631,7 @@ function useVerificationController() {
8578
8631
  });
8579
8632
  const { error } = validation.validate(req.query);
8580
8633
  if (error) {
8581
- next(new BadRequestError45(error.message));
8634
+ next(new BadRequestError46(error.message));
8582
8635
  return;
8583
8636
  }
8584
8637
  const status = req.query.status ?? "";
@@ -8612,7 +8665,7 @@ function useVerificationController() {
8612
8665
  const validation = Joi28.string().hex().required();
8613
8666
  const { error } = validation.validate(id);
8614
8667
  if (error) {
8615
- next(new BadRequestError45(error.message));
8668
+ next(new BadRequestError46(error.message));
8616
8669
  return;
8617
8670
  }
8618
8671
  try {
@@ -8628,7 +8681,7 @@ function useVerificationController() {
8628
8681
  const validation = Joi28.string().hex().required();
8629
8682
  const { error } = validation.validate(otpId);
8630
8683
  if (error) {
8631
- next(new BadRequestError45(error.message));
8684
+ next(new BadRequestError46(error.message));
8632
8685
  return;
8633
8686
  }
8634
8687
  try {
@@ -8670,11 +8723,9 @@ export {
8670
8723
  MMember,
8671
8724
  MONGO_DB,
8672
8725
  MONGO_URI,
8673
- MOrg,
8674
8726
  MUser,
8675
8727
  MUserRole,
8676
8728
  MVerification,
8677
- OrgTypes,
8678
8729
  PAYPAL_API_URL,
8679
8730
  PAYPAL_CLIENT_ID,
8680
8731
  PAYPAL_CLIENT_SECRET,
@@ -8697,6 +8748,8 @@ export {
8697
8748
  addressSchema,
8698
8749
  isDev,
8699
8750
  modelApp,
8751
+ modelMember,
8752
+ modelOrg,
8700
8753
  modelPSGC,
8701
8754
  modelPermission,
8702
8755
  modelPermissionGroup,
@@ -8705,6 +8758,7 @@ export {
8705
8758
  schemaAppUpdate,
8706
8759
  schemaBuilding,
8707
8760
  schemaBuildingUnit,
8761
+ schemaMember,
8708
8762
  schemaOrg,
8709
8763
  schemaPSGC,
8710
8764
  schemaPermission,