@goweekdays/core 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +125 -3
- package/dist/index.js +2004 -722
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2005 -715
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/tsconfig.json +1 -1
package/dist/index.js
CHANGED
|
@@ -70,6 +70,7 @@ __export(src_exports, {
|
|
|
70
70
|
XENDIT_BASE_URL: () => XENDIT_BASE_URL,
|
|
71
71
|
XENDIT_SECRET_KEY: () => XENDIT_SECRET_KEY,
|
|
72
72
|
addressSchema: () => addressSchema,
|
|
73
|
+
currencies: () => currencies,
|
|
73
74
|
isDev: () => isDev,
|
|
74
75
|
modelApp: () => modelApp,
|
|
75
76
|
modelMember: () => modelMember,
|
|
@@ -77,7 +78,10 @@ __export(src_exports, {
|
|
|
77
78
|
modelPSGC: () => modelPSGC,
|
|
78
79
|
modelPermission: () => modelPermission,
|
|
79
80
|
modelPermissionGroup: () => modelPermissionGroup,
|
|
81
|
+
modelPlan: () => modelPlan,
|
|
80
82
|
modelRole: () => modelRole,
|
|
83
|
+
modelSubscription: () => modelSubscription,
|
|
84
|
+
modelSubscriptionTransaction: () => modelSubscriptionTransaction,
|
|
81
85
|
modelUser: () => modelUser,
|
|
82
86
|
modelVerification: () => modelVerification,
|
|
83
87
|
schemaApp: () => schemaApp,
|
|
@@ -89,13 +93,20 @@ __export(src_exports, {
|
|
|
89
93
|
schemaMemberRole: () => schemaMemberRole,
|
|
90
94
|
schemaMemberStatus: () => schemaMemberStatus,
|
|
91
95
|
schemaOrg: () => schemaOrg,
|
|
96
|
+
schemaOrgAdd: () => schemaOrgAdd,
|
|
97
|
+
schemaOrgUpdate: () => schemaOrgUpdate,
|
|
92
98
|
schemaPSGC: () => schemaPSGC,
|
|
93
99
|
schemaPermission: () => schemaPermission,
|
|
94
100
|
schemaPermissionGroup: () => schemaPermissionGroup,
|
|
95
101
|
schemaPermissionGroupUpdate: () => schemaPermissionGroupUpdate,
|
|
96
102
|
schemaPermissionUpdate: () => schemaPermissionUpdate,
|
|
103
|
+
schemaPlan: () => schemaPlan,
|
|
97
104
|
schemaRole: () => schemaRole,
|
|
98
105
|
schemaRoleUpdate: () => schemaRoleUpdate,
|
|
106
|
+
schemaSubscription: () => schemaSubscription,
|
|
107
|
+
schemaSubscriptionSeats: () => schemaSubscriptionSeats,
|
|
108
|
+
schemaSubscriptionTransaction: () => schemaSubscriptionTransaction,
|
|
109
|
+
schemaSubscriptionUpdate: () => schemaSubscriptionUpdate,
|
|
99
110
|
schemaUpdateOptions: () => schemaUpdateOptions,
|
|
100
111
|
schemaUser: () => schemaUser,
|
|
101
112
|
schemaVerification: () => schemaVerification,
|
|
@@ -132,9 +143,16 @@ __export(src_exports, {
|
|
|
132
143
|
usePermissionGroupService: () => usePermissionGroupService,
|
|
133
144
|
usePermissionRepo: () => usePermissionRepo,
|
|
134
145
|
usePermissionService: () => usePermissionService,
|
|
146
|
+
usePlanController: () => usePlanController,
|
|
147
|
+
usePlanRepo: () => usePlanRepo,
|
|
148
|
+
usePlanService: () => usePlanService,
|
|
135
149
|
useRoleController: () => useRoleController,
|
|
136
150
|
useRoleRepo: () => useRoleRepo,
|
|
137
151
|
useRoleService: () => useRoleService,
|
|
152
|
+
useSubscriptionController: () => useSubscriptionController,
|
|
153
|
+
useSubscriptionRepo: () => useSubscriptionRepo,
|
|
154
|
+
useSubscriptionTransactionController: () => useSubscriptionTransactionController,
|
|
155
|
+
useSubscriptionTransactionRepo: () => useSubscriptionTransactionRepo,
|
|
138
156
|
useUserController: () => useUserController,
|
|
139
157
|
useUserRepo: () => useUserRepo,
|
|
140
158
|
useUserService: () => useUserService,
|
|
@@ -933,11 +951,11 @@ function useAuthService() {
|
|
|
933
951
|
}
|
|
934
952
|
|
|
935
953
|
// src/resources/auth/auth.controller.ts
|
|
936
|
-
var
|
|
937
|
-
var
|
|
954
|
+
var import_joi32 = __toESM(require("joi"));
|
|
955
|
+
var import_utils44 = require("@goweekdays/utils");
|
|
938
956
|
|
|
939
957
|
// src/resources/verification/verification.service.ts
|
|
940
|
-
var
|
|
958
|
+
var import_utils43 = require("@goweekdays/utils");
|
|
941
959
|
|
|
942
960
|
// src/resources/verification/verification.model.ts
|
|
943
961
|
var import_utils6 = require("@goweekdays/utils");
|
|
@@ -1330,7 +1348,7 @@ var XENDIT_BASE_URL = process.env.XENDIT_BASE_URL ?? "https://api.xendit.co";
|
|
|
1330
1348
|
var DOMAIN = process.env.DOMAIN || "localhost";
|
|
1331
1349
|
|
|
1332
1350
|
// src/resources/user/user.service.ts
|
|
1333
|
-
var
|
|
1351
|
+
var import_utils41 = require("@goweekdays/utils");
|
|
1334
1352
|
|
|
1335
1353
|
// src/resources/file/file.repository.ts
|
|
1336
1354
|
var import_utils8 = require("@goweekdays/utils");
|
|
@@ -4188,6 +4206,33 @@ function usePermissionGroupService() {
|
|
|
4188
4206
|
description: "Allow user to revoke invitations"
|
|
4189
4207
|
}
|
|
4190
4208
|
]
|
|
4209
|
+
},
|
|
4210
|
+
{
|
|
4211
|
+
key: "billing",
|
|
4212
|
+
label: "Billing",
|
|
4213
|
+
permissions: [
|
|
4214
|
+
{
|
|
4215
|
+
key: "billing.view",
|
|
4216
|
+
name: "View Billing",
|
|
4217
|
+
description: "Allow user to view billing"
|
|
4218
|
+
}
|
|
4219
|
+
]
|
|
4220
|
+
},
|
|
4221
|
+
{
|
|
4222
|
+
key: "setting",
|
|
4223
|
+
label: "Setting",
|
|
4224
|
+
permissions: [
|
|
4225
|
+
{
|
|
4226
|
+
key: "setting.view",
|
|
4227
|
+
name: "View Setting",
|
|
4228
|
+
description: "Allow user to view setting"
|
|
4229
|
+
},
|
|
4230
|
+
{
|
|
4231
|
+
key: "setting.edit.details",
|
|
4232
|
+
name: "Edit Setting Details",
|
|
4233
|
+
description: "Allow user to edit setting details"
|
|
4234
|
+
}
|
|
4235
|
+
]
|
|
4191
4236
|
}
|
|
4192
4237
|
];
|
|
4193
4238
|
for (const app of apps.items) {
|
|
@@ -4622,13 +4667,25 @@ function usePermissionGroupController() {
|
|
|
4622
4667
|
var import_utils24 = require("@goweekdays/utils");
|
|
4623
4668
|
var import_joi17 = __toESM(require("joi"));
|
|
4624
4669
|
var import_mongodb15 = require("mongodb");
|
|
4625
|
-
var
|
|
4670
|
+
var schema = {
|
|
4626
4671
|
name: import_joi17.default.string().max(255).required(),
|
|
4627
4672
|
description: import_joi17.default.string().max(1024).optional().allow("", null),
|
|
4628
|
-
email: import_joi17.default.string().email().max(255).
|
|
4629
|
-
contact: import_joi17.default.string().max(50).optional().allow("", null)
|
|
4673
|
+
email: import_joi17.default.string().email().max(255).required(),
|
|
4674
|
+
contact: import_joi17.default.string().max(50).optional().allow("", null)
|
|
4675
|
+
};
|
|
4676
|
+
var schemaOrg = import_joi17.default.object({
|
|
4677
|
+
...schema,
|
|
4630
4678
|
createdBy: import_joi17.default.string().hex().required()
|
|
4631
4679
|
});
|
|
4680
|
+
var schemaOrgAdd = import_joi17.default.object({
|
|
4681
|
+
...schema,
|
|
4682
|
+
createdBy: import_joi17.default.string().hex().required(),
|
|
4683
|
+
seats: import_joi17.default.number().required()
|
|
4684
|
+
});
|
|
4685
|
+
var schemaOrgUpdate = import_joi17.default.object({
|
|
4686
|
+
...schema,
|
|
4687
|
+
_id: import_joi17.default.string().hex().required()
|
|
4688
|
+
});
|
|
4632
4689
|
function modelOrg(value) {
|
|
4633
4690
|
const { error } = schemaOrg.validate(value);
|
|
4634
4691
|
if (error) {
|
|
@@ -4902,6 +4959,30 @@ function useOrgRepo() {
|
|
|
4902
4959
|
throw new import_utils25.InternalServerError("Failed to delete organization.");
|
|
4903
4960
|
}
|
|
4904
4961
|
}
|
|
4962
|
+
async function updateById(_id, options) {
|
|
4963
|
+
const { error } = schemaOrgUpdate.validate({ ...options, _id });
|
|
4964
|
+
if (error) {
|
|
4965
|
+
throw new import_utils25.BadRequestError(error.message);
|
|
4966
|
+
}
|
|
4967
|
+
try {
|
|
4968
|
+
_id = new import_mongodb16.ObjectId(_id);
|
|
4969
|
+
} catch (error2) {
|
|
4970
|
+
throw new import_utils25.BadRequestError("Invalid org ID.");
|
|
4971
|
+
}
|
|
4972
|
+
try {
|
|
4973
|
+
await collection.updateOne(
|
|
4974
|
+
{ _id },
|
|
4975
|
+
{ $set: { ...options, updatedAt: /* @__PURE__ */ new Date() } }
|
|
4976
|
+
);
|
|
4977
|
+
delCachedData();
|
|
4978
|
+
} catch (error2) {
|
|
4979
|
+
const isDuplicated = error2.message.includes("duplicate");
|
|
4980
|
+
if (isDuplicated) {
|
|
4981
|
+
throw new import_utils25.BadRequestError("Organization name already exist.");
|
|
4982
|
+
}
|
|
4983
|
+
throw new import_utils25.InternalServerError("Failed to update org info.");
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4905
4986
|
return {
|
|
4906
4987
|
createIndexes,
|
|
4907
4988
|
add,
|
|
@@ -4909,12 +4990,13 @@ function useOrgRepo() {
|
|
|
4909
4990
|
getById,
|
|
4910
4991
|
updateFieldById,
|
|
4911
4992
|
deleteById,
|
|
4912
|
-
getByName
|
|
4993
|
+
getByName,
|
|
4994
|
+
updateById
|
|
4913
4995
|
};
|
|
4914
4996
|
}
|
|
4915
4997
|
|
|
4916
4998
|
// src/resources/organization/organization.service.ts
|
|
4917
|
-
var
|
|
4999
|
+
var import_utils39 = require("@goweekdays/utils");
|
|
4918
5000
|
|
|
4919
5001
|
// src/resources/member/member.controller.ts
|
|
4920
5002
|
var import_joi20 = __toESM(require("joi"));
|
|
@@ -5431,180 +5513,1345 @@ function useMemberController() {
|
|
|
5431
5513
|
};
|
|
5432
5514
|
}
|
|
5433
5515
|
|
|
5434
|
-
// src/resources/
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5516
|
+
// src/resources/subscription/subscription.model.ts
|
|
5517
|
+
var import_utils30 = require("@goweekdays/utils");
|
|
5518
|
+
var import_joi21 = __toESM(require("joi"));
|
|
5519
|
+
var import_mongodb17 = require("mongodb");
|
|
5520
|
+
var schema2 = {
|
|
5521
|
+
seats: import_joi21.default.number().integer().min(1).required(),
|
|
5522
|
+
paidSeats: import_joi21.default.number().integer().min(0).required(),
|
|
5523
|
+
amount: import_joi21.default.number().positive().required(),
|
|
5524
|
+
promoCode: import_joi21.default.string().optional().allow("", null),
|
|
5525
|
+
nextBillingDate: import_joi21.default.date().optional().allow("", null)
|
|
5526
|
+
};
|
|
5527
|
+
var schemaSubscription = import_joi21.default.object({
|
|
5528
|
+
...schema2,
|
|
5529
|
+
org: import_joi21.default.string().hex().length(24).required(),
|
|
5530
|
+
currency: import_joi21.default.string().length(3).required(),
|
|
5531
|
+
billingCycle: import_joi21.default.string().valid("monthly", "yearly").required()
|
|
5532
|
+
});
|
|
5533
|
+
var schemaSubscriptionUpdate = import_joi21.default.object({
|
|
5534
|
+
...schema2,
|
|
5535
|
+
status: import_joi21.default.string().optional().allow("", null)
|
|
5536
|
+
});
|
|
5537
|
+
var schemaSubscriptionSeats = import_joi21.default.object({
|
|
5538
|
+
id: import_joi21.default.string().hex().length(24).required(),
|
|
5539
|
+
seats: import_joi21.default.number().integer().min(1).required(),
|
|
5540
|
+
amount: import_joi21.default.number().positive().optional().allow(null, 0),
|
|
5541
|
+
user: import_joi21.default.string().hex().length(24).required()
|
|
5542
|
+
});
|
|
5543
|
+
function modelSubscription(data) {
|
|
5544
|
+
const { error } = schemaSubscription.validate(data);
|
|
5545
|
+
if (error) {
|
|
5546
|
+
throw new import_utils30.BadRequestError(`Invalid subscription data: ${error.message}`);
|
|
5547
|
+
}
|
|
5548
|
+
if (data._id && typeof data._id === "string") {
|
|
5446
5549
|
try {
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
app: "org",
|
|
5451
|
-
limit: 100
|
|
5452
|
-
});
|
|
5453
|
-
let permissions = [];
|
|
5454
|
-
if (allPermissions && allPermissions.items && allPermissions.items.length) {
|
|
5455
|
-
permissions = allPermissions.items.map((perm) => perm.key);
|
|
5456
|
-
}
|
|
5457
|
-
if (permissions.length === 0) {
|
|
5458
|
-
throw new Error("No permissions found for the organization type.");
|
|
5459
|
-
}
|
|
5460
|
-
const createdBy = String(value.createdBy);
|
|
5461
|
-
const roleData = {
|
|
5462
|
-
org: String(org),
|
|
5463
|
-
name: "Owner",
|
|
5464
|
-
description: "Owner of the organization",
|
|
5465
|
-
permissions,
|
|
5466
|
-
createdBy,
|
|
5467
|
-
app: "org"
|
|
5468
|
-
};
|
|
5469
|
-
const role = await addRole(roleData, session);
|
|
5470
|
-
if (!role) {
|
|
5471
|
-
throw new import_utils30.BadRequestError("Role is required to create org member.");
|
|
5472
|
-
}
|
|
5473
|
-
const user = await getUserById(createdBy);
|
|
5474
|
-
if (!user) {
|
|
5475
|
-
throw new import_utils30.BadRequestError("User is required to create org member.");
|
|
5476
|
-
}
|
|
5477
|
-
await addMember(
|
|
5478
|
-
{
|
|
5479
|
-
role: String(role),
|
|
5480
|
-
roleName: roleData.name,
|
|
5481
|
-
org: String(org),
|
|
5482
|
-
name: `${user.firstName} ${user.lastName}`,
|
|
5483
|
-
user: createdBy,
|
|
5484
|
-
app: "org"
|
|
5485
|
-
},
|
|
5486
|
-
session
|
|
5487
|
-
);
|
|
5488
|
-
await session?.commitTransaction();
|
|
5489
|
-
return String(org);
|
|
5490
|
-
} catch (error) {
|
|
5491
|
-
await session?.abortTransaction();
|
|
5492
|
-
throw error;
|
|
5493
|
-
} finally {
|
|
5494
|
-
await session?.endSession();
|
|
5550
|
+
data._id = new import_mongodb17.ObjectId(data._id);
|
|
5551
|
+
} catch (error2) {
|
|
5552
|
+
throw new import_utils30.BadRequestError("Invalid subscription ID.");
|
|
5495
5553
|
}
|
|
5496
5554
|
}
|
|
5555
|
+
try {
|
|
5556
|
+
data.org = new import_mongodb17.ObjectId(data.org);
|
|
5557
|
+
} catch (error2) {
|
|
5558
|
+
throw new import_utils30.BadRequestError("Invalid organization ID.");
|
|
5559
|
+
}
|
|
5497
5560
|
return {
|
|
5498
|
-
|
|
5561
|
+
_id: data._id,
|
|
5562
|
+
org: data.org,
|
|
5563
|
+
seats: data.seats,
|
|
5564
|
+
paidSeats: data.paidSeats,
|
|
5565
|
+
amount: data.amount,
|
|
5566
|
+
currency: data.currency,
|
|
5567
|
+
billingCycle: data.billingCycle,
|
|
5568
|
+
promoCode: data.promoCode,
|
|
5569
|
+
status: data.status ?? "active",
|
|
5570
|
+
nextBillingDate: data.nextBillingDate,
|
|
5571
|
+
createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
|
|
5572
|
+
updatedAt: data.updatedAt ?? ""
|
|
5499
5573
|
};
|
|
5500
5574
|
}
|
|
5501
5575
|
|
|
5502
|
-
// src/resources/
|
|
5576
|
+
// src/resources/subscription/subscription.repository.ts
|
|
5503
5577
|
var import_utils31 = require("@goweekdays/utils");
|
|
5504
|
-
var
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
const
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
}
|
|
5520
|
-
try {
|
|
5521
|
-
const org = await _add(value);
|
|
5522
|
-
res.json({
|
|
5523
|
-
message: "Organization created successfully.",
|
|
5524
|
-
data: { org }
|
|
5578
|
+
var import_joi22 = __toESM(require("joi"));
|
|
5579
|
+
var import_mongodb18 = require("mongodb");
|
|
5580
|
+
function useSubscriptionRepo() {
|
|
5581
|
+
const db = import_utils31.useAtlas.getDb();
|
|
5582
|
+
if (!db) {
|
|
5583
|
+
throw new import_utils31.InternalServerError("Unable to connect to server.");
|
|
5584
|
+
}
|
|
5585
|
+
const namespace_collection = "subscriptions";
|
|
5586
|
+
const collection = db.collection(namespace_collection);
|
|
5587
|
+
const { getCache, setCache, delNamespace } = (0, import_utils31.useCache)(namespace_collection);
|
|
5588
|
+
function delCachedData() {
|
|
5589
|
+
delNamespace().then(() => {
|
|
5590
|
+
import_utils31.logger.log({
|
|
5591
|
+
level: "info",
|
|
5592
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
5525
5593
|
});
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5594
|
+
}).catch((err) => {
|
|
5595
|
+
import_utils31.logger.log({
|
|
5596
|
+
level: "error",
|
|
5597
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
5598
|
+
});
|
|
5599
|
+
});
|
|
5530
5600
|
}
|
|
5531
|
-
async function
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5601
|
+
async function createIndexes() {
|
|
5602
|
+
try {
|
|
5603
|
+
await collection.createIndexes([
|
|
5604
|
+
{
|
|
5605
|
+
key: {
|
|
5606
|
+
org: 1
|
|
5607
|
+
},
|
|
5608
|
+
name: "org_index"
|
|
5609
|
+
},
|
|
5610
|
+
{
|
|
5611
|
+
key: { org: 1, status: 1 },
|
|
5612
|
+
name: "org_status_index"
|
|
5613
|
+
}
|
|
5614
|
+
]);
|
|
5615
|
+
} catch (error) {
|
|
5545
5616
|
}
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5617
|
+
}
|
|
5618
|
+
createIndexes().catch((error) => {
|
|
5619
|
+
import_utils31.logger.log({
|
|
5620
|
+
level: "error",
|
|
5621
|
+
message: `Failed to create indexes for subscriptions collection: ${error.message}`
|
|
5551
5622
|
});
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
next(new import_utils31.BadRequestError(error.message));
|
|
5555
|
-
return;
|
|
5556
|
-
}
|
|
5623
|
+
});
|
|
5624
|
+
async function add(value, session) {
|
|
5557
5625
|
try {
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5626
|
+
value = modelSubscription(value);
|
|
5627
|
+
const result = await collection.insertOne(value, { session });
|
|
5628
|
+
delCachedData();
|
|
5629
|
+
return result.insertedId.toString();
|
|
5630
|
+
} catch (error) {
|
|
5631
|
+
import_utils31.logger.log({
|
|
5632
|
+
level: "error",
|
|
5633
|
+
message: `${error}`
|
|
5634
|
+
});
|
|
5635
|
+
if (error instanceof import_utils31.AppError) {
|
|
5636
|
+
throw error;
|
|
5637
|
+
}
|
|
5638
|
+
throw new import_utils31.InternalServerError("Failed to add subscription.");
|
|
5563
5639
|
}
|
|
5564
5640
|
}
|
|
5565
|
-
async function getAll(
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
}
|
|
5573
|
-
const
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5641
|
+
async function getAll({
|
|
5642
|
+
page = 1,
|
|
5643
|
+
limit = 10,
|
|
5644
|
+
search = "",
|
|
5645
|
+
status = "active"
|
|
5646
|
+
} = {}) {
|
|
5647
|
+
page = page < 1 ? page - 1 : page;
|
|
5648
|
+
const query = { status };
|
|
5649
|
+
const cacheKeyOptions = {
|
|
5650
|
+
page,
|
|
5651
|
+
limit,
|
|
5652
|
+
search,
|
|
5653
|
+
status,
|
|
5654
|
+
tag: "getAll"
|
|
5655
|
+
};
|
|
5656
|
+
if (search) {
|
|
5657
|
+
query.$text = { $search: search };
|
|
5582
5658
|
}
|
|
5583
|
-
const
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5659
|
+
const cacheKey = (0, import_utils31.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
5660
|
+
try {
|
|
5661
|
+
const cachedData = await getCache(cacheKey);
|
|
5662
|
+
if (cachedData) {
|
|
5663
|
+
return cachedData;
|
|
5664
|
+
}
|
|
5665
|
+
const items = await collection.aggregate([
|
|
5666
|
+
{ $match: query },
|
|
5667
|
+
{ $skip: page * limit },
|
|
5668
|
+
{ $limit: limit }
|
|
5669
|
+
]).toArray();
|
|
5670
|
+
const length = await collection.countDocuments(query);
|
|
5671
|
+
const data = (0, import_utils31.paginate)(
|
|
5672
|
+
items,
|
|
5673
|
+
page,
|
|
5674
|
+
limit,
|
|
5675
|
+
length
|
|
5676
|
+
);
|
|
5677
|
+
setCache(cacheKey, data).then(() => {
|
|
5678
|
+
import_utils31.logger.log({
|
|
5679
|
+
level: "info",
|
|
5680
|
+
message: `Cache set for getAll subscription: ${cacheKey}`
|
|
5681
|
+
});
|
|
5682
|
+
}).catch((err) => {
|
|
5683
|
+
import_utils31.logger.log({
|
|
5684
|
+
level: "error",
|
|
5685
|
+
message: `Failed to set cache for getAll subscription: ${err.message}`
|
|
5686
|
+
});
|
|
5687
|
+
});
|
|
5688
|
+
return data;
|
|
5689
|
+
} catch (error) {
|
|
5690
|
+
throw new import_utils31.InternalServerError("Failed to get subscriptions.");
|
|
5587
5691
|
}
|
|
5692
|
+
}
|
|
5693
|
+
async function getByOrg(org) {
|
|
5694
|
+
const { error } = import_joi22.default.string().hex().length(24).required().validate(org);
|
|
5588
5695
|
if (error) {
|
|
5589
|
-
|
|
5590
|
-
return;
|
|
5696
|
+
throw new Error(`Invalid org ID: ${error.message}`);
|
|
5591
5697
|
}
|
|
5592
5698
|
try {
|
|
5593
|
-
|
|
5594
|
-
res.json(orgs);
|
|
5595
|
-
return;
|
|
5699
|
+
org = new import_mongodb18.ObjectId(org);
|
|
5596
5700
|
} catch (error2) {
|
|
5597
|
-
|
|
5701
|
+
throw new import_utils31.BadRequestError("Invalid org ID.");
|
|
5598
5702
|
}
|
|
5599
|
-
|
|
5703
|
+
try {
|
|
5704
|
+
const cacheKey = (0, import_utils31.makeCacheKey)(namespace_collection, {
|
|
5705
|
+
org: String(org),
|
|
5706
|
+
tag: "getByOrg"
|
|
5707
|
+
});
|
|
5708
|
+
const cachedData = await getCache(cacheKey);
|
|
5709
|
+
if (cachedData) {
|
|
5710
|
+
return cachedData;
|
|
5711
|
+
}
|
|
5712
|
+
const data = await collection.findOne({
|
|
5713
|
+
org,
|
|
5714
|
+
status: { $ne: "deleted" }
|
|
5715
|
+
});
|
|
5716
|
+
setCache(cacheKey, data).then(() => {
|
|
5717
|
+
import_utils31.logger.log({
|
|
5718
|
+
level: "info",
|
|
5719
|
+
message: `Cache set for getByOrg subscription: ${cacheKey}`
|
|
5720
|
+
});
|
|
5721
|
+
}).catch((err) => {
|
|
5722
|
+
import_utils31.logger.log({
|
|
5723
|
+
level: "error",
|
|
5724
|
+
message: `Failed to set cache for getByOrg subscription: ${err.message}`
|
|
5725
|
+
});
|
|
5726
|
+
});
|
|
5727
|
+
return data;
|
|
5728
|
+
} catch (error2) {
|
|
5729
|
+
throw new import_utils31.InternalServerError("Failed to get subscription.");
|
|
5730
|
+
}
|
|
5731
|
+
}
|
|
5732
|
+
async function getById(_id) {
|
|
5733
|
+
const { error } = import_joi22.default.string().hex().length(24).required().validate(_id);
|
|
5734
|
+
if (error) {
|
|
5735
|
+
throw new Error(`Invalid subscription ID: ${error.message}`);
|
|
5736
|
+
}
|
|
5737
|
+
try {
|
|
5738
|
+
_id = new import_mongodb18.ObjectId(_id);
|
|
5739
|
+
} catch (error2) {
|
|
5740
|
+
throw new import_utils31.BadRequestError("Invalid subscription ID.");
|
|
5741
|
+
}
|
|
5742
|
+
try {
|
|
5743
|
+
const cacheKey = (0, import_utils31.makeCacheKey)(namespace_collection, {
|
|
5744
|
+
_id: String(_id),
|
|
5745
|
+
tag: "getById"
|
|
5746
|
+
});
|
|
5747
|
+
const cachedData = await getCache(cacheKey);
|
|
5748
|
+
if (cachedData) {
|
|
5749
|
+
return cachedData;
|
|
5750
|
+
}
|
|
5751
|
+
const data = await collection.findOne({
|
|
5752
|
+
_id,
|
|
5753
|
+
status: { $ne: "deleted" }
|
|
5754
|
+
});
|
|
5755
|
+
setCache(cacheKey, data).then(() => {
|
|
5756
|
+
import_utils31.logger.log({
|
|
5757
|
+
level: "info",
|
|
5758
|
+
message: `Cache set for getById subscription: ${cacheKey}`
|
|
5759
|
+
});
|
|
5760
|
+
}).catch((err) => {
|
|
5761
|
+
import_utils31.logger.log({
|
|
5762
|
+
level: "error",
|
|
5763
|
+
message: `Failed to set cache for getById subscription: ${err.message}`
|
|
5764
|
+
});
|
|
5765
|
+
});
|
|
5766
|
+
return data;
|
|
5767
|
+
} catch (error2) {
|
|
5768
|
+
throw new import_utils31.InternalServerError("Failed to get subscription.");
|
|
5769
|
+
}
|
|
5770
|
+
}
|
|
5771
|
+
async function deleteById(_id) {
|
|
5772
|
+
const { error } = import_joi22.default.string().hex().length(24).required().validate(_id);
|
|
5773
|
+
if (error) {
|
|
5774
|
+
throw new Error(`Invalid subscription ID: ${error.message}`);
|
|
5775
|
+
}
|
|
5776
|
+
try {
|
|
5777
|
+
_id = new import_mongodb18.ObjectId(_id);
|
|
5778
|
+
} catch (error2) {
|
|
5779
|
+
throw new import_utils31.BadRequestError("Invalid subscription ID.");
|
|
5780
|
+
}
|
|
5781
|
+
try {
|
|
5782
|
+
const result = await collection.updateOne(
|
|
5783
|
+
{ _id },
|
|
5784
|
+
{ $set: { status: "deleted" } }
|
|
5785
|
+
);
|
|
5786
|
+
if (result.modifiedCount === 0) {
|
|
5787
|
+
throw new import_utils31.InternalServerError("Failed to delete subscription.");
|
|
5788
|
+
}
|
|
5789
|
+
delCachedData();
|
|
5790
|
+
return "Successfully deleted subscription.";
|
|
5791
|
+
} catch (error2) {
|
|
5792
|
+
if (error2 instanceof import_utils31.AppError) {
|
|
5793
|
+
throw error2;
|
|
5794
|
+
}
|
|
5795
|
+
throw new import_utils31.InternalServerError("Failed to delete subscription.");
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
async function updateById(_id, options, session) {
|
|
5799
|
+
const { error: errorId } = import_joi22.default.string().hex().length(24).required().validate(_id);
|
|
5800
|
+
if (errorId) {
|
|
5801
|
+
throw new Error(`Invalid subscription ID: ${errorId.message}`);
|
|
5802
|
+
}
|
|
5803
|
+
const { error } = schemaSubscriptionUpdate.validate(options);
|
|
5804
|
+
if (error) {
|
|
5805
|
+
throw new import_utils31.BadRequestError(
|
|
5806
|
+
`Invalid subscription update data: ${error.message}`
|
|
5807
|
+
);
|
|
5808
|
+
}
|
|
5809
|
+
try {
|
|
5810
|
+
_id = new import_mongodb18.ObjectId(_id);
|
|
5811
|
+
} catch (error2) {
|
|
5812
|
+
throw new import_utils31.BadRequestError("Invalid subscription ID.");
|
|
5813
|
+
}
|
|
5814
|
+
try {
|
|
5815
|
+
const result = await collection.updateOne(
|
|
5816
|
+
{ _id },
|
|
5817
|
+
{ $set: { ...options, updatedAt: /* @__PURE__ */ new Date() } },
|
|
5818
|
+
{ session }
|
|
5819
|
+
);
|
|
5820
|
+
if (result.modifiedCount === 0) {
|
|
5821
|
+
throw new import_utils31.InternalServerError("Failed to update subscription.");
|
|
5822
|
+
}
|
|
5823
|
+
delCachedData();
|
|
5824
|
+
return "Successfully updated subscription.";
|
|
5825
|
+
} catch (error2) {
|
|
5826
|
+
if (error2 instanceof import_utils31.AppError) {
|
|
5827
|
+
throw error2;
|
|
5828
|
+
}
|
|
5829
|
+
throw new import_utils31.InternalServerError("Failed to update subscription.");
|
|
5830
|
+
}
|
|
5831
|
+
}
|
|
5832
|
+
return {
|
|
5833
|
+
add,
|
|
5834
|
+
getAll,
|
|
5835
|
+
getByOrg,
|
|
5836
|
+
getById,
|
|
5837
|
+
deleteById,
|
|
5838
|
+
updateById
|
|
5839
|
+
};
|
|
5840
|
+
}
|
|
5841
|
+
|
|
5842
|
+
// src/resources/subscription/subscription.controller.ts
|
|
5843
|
+
var import_joi24 = __toESM(require("joi"));
|
|
5844
|
+
var import_utils35 = require("@goweekdays/utils");
|
|
5845
|
+
|
|
5846
|
+
// src/resources/subscription/subscription.service.ts
|
|
5847
|
+
var import_utils34 = require("@goweekdays/utils");
|
|
5848
|
+
|
|
5849
|
+
// src/resources/subscription/subscription.transaction.repository.ts
|
|
5850
|
+
var import_utils33 = require("@goweekdays/utils");
|
|
5851
|
+
|
|
5852
|
+
// src/resources/subscription/subscription.transaction.model.ts
|
|
5853
|
+
var import_utils32 = require("@goweekdays/utils");
|
|
5854
|
+
var import_joi23 = __toESM(require("joi"));
|
|
5855
|
+
var import_mongodb19 = require("mongodb");
|
|
5856
|
+
var schemaSubscriptionTransaction = import_joi23.default.object({
|
|
5857
|
+
subscription: import_joi23.default.string().hex().length(24).required(),
|
|
5858
|
+
amount: import_joi23.default.number().positive().required(),
|
|
5859
|
+
currency: import_joi23.default.string().length(3).required(),
|
|
5860
|
+
type: import_joi23.default.string().valid("initiate", "add-seat", "remove-seat", "renewal").required(),
|
|
5861
|
+
description: import_joi23.default.string().max(255).optional().allow("", null),
|
|
5862
|
+
createdBy: import_joi23.default.string().hex().length(24).required(),
|
|
5863
|
+
createdByName: import_joi23.default.string().optional().allow("", null)
|
|
5864
|
+
});
|
|
5865
|
+
function modelSubscriptionTransaction(data) {
|
|
5866
|
+
const { error } = schemaSubscriptionTransaction.validate(data);
|
|
5867
|
+
if (error) {
|
|
5868
|
+
throw new import_utils32.BadRequestError(
|
|
5869
|
+
`Invalid subscription transaction data: ${error.message}`
|
|
5870
|
+
);
|
|
5871
|
+
}
|
|
5872
|
+
if (data._id && typeof data._id === "string") {
|
|
5873
|
+
try {
|
|
5874
|
+
data._id = new import_mongodb19.ObjectId(data._id);
|
|
5875
|
+
} catch (error2) {
|
|
5876
|
+
throw new import_utils32.BadRequestError("Invalid subscription transaction ID.");
|
|
5877
|
+
}
|
|
5878
|
+
}
|
|
5879
|
+
if (data.subscription && typeof data.subscription === "string") {
|
|
5880
|
+
try {
|
|
5881
|
+
data.subscription = new import_mongodb19.ObjectId(data.subscription);
|
|
5882
|
+
} catch (error2) {
|
|
5883
|
+
throw new import_utils32.BadRequestError("Invalid subscription ID.");
|
|
5884
|
+
}
|
|
5885
|
+
}
|
|
5886
|
+
if (data.createdBy && typeof data.createdBy === "string") {
|
|
5887
|
+
try {
|
|
5888
|
+
data.createdBy = new import_mongodb19.ObjectId(data.createdBy);
|
|
5889
|
+
} catch (error2) {
|
|
5890
|
+
throw new import_utils32.BadRequestError("Invalid createdBy ID.");
|
|
5891
|
+
}
|
|
5892
|
+
}
|
|
5893
|
+
return {
|
|
5894
|
+
_id: data._id,
|
|
5895
|
+
subscription: data.subscription,
|
|
5896
|
+
amount: data.amount,
|
|
5897
|
+
currency: data.currency,
|
|
5898
|
+
type: data.type,
|
|
5899
|
+
description: data.description ?? "",
|
|
5900
|
+
createdBy: data.createdBy,
|
|
5901
|
+
createdByName: data.createdByName,
|
|
5902
|
+
createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
|
|
5903
|
+
updatedAt: data.updatedAt ?? ""
|
|
5904
|
+
};
|
|
5905
|
+
}
|
|
5906
|
+
|
|
5907
|
+
// src/resources/subscription/subscription.transaction.repository.ts
|
|
5908
|
+
var import_mongodb20 = require("mongodb");
|
|
5909
|
+
function useSubscriptionTransactionRepo() {
|
|
5910
|
+
const db = import_utils33.useAtlas.getDb();
|
|
5911
|
+
if (!db) {
|
|
5912
|
+
throw new import_utils33.InternalServerError("Unable to connect to server.");
|
|
5913
|
+
}
|
|
5914
|
+
const namespace_collection = "subscription.transactions";
|
|
5915
|
+
const collection = db.collection(namespace_collection);
|
|
5916
|
+
const { getCache, setCache, delNamespace } = (0, import_utils33.useCache)(namespace_collection);
|
|
5917
|
+
function delCachedData() {
|
|
5918
|
+
delNamespace().then(() => {
|
|
5919
|
+
import_utils33.logger.log({
|
|
5920
|
+
level: "info",
|
|
5921
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
5922
|
+
});
|
|
5923
|
+
}).catch((err) => {
|
|
5924
|
+
import_utils33.logger.log({
|
|
5925
|
+
level: "error",
|
|
5926
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
5927
|
+
});
|
|
5928
|
+
});
|
|
5929
|
+
}
|
|
5930
|
+
async function createIndexes() {
|
|
5931
|
+
try {
|
|
5932
|
+
await collection.createIndexes([
|
|
5933
|
+
{
|
|
5934
|
+
key: {
|
|
5935
|
+
subscription: 1
|
|
5936
|
+
},
|
|
5937
|
+
name: "subscription_index"
|
|
5938
|
+
},
|
|
5939
|
+
{
|
|
5940
|
+
key: { subscription: 1, type: 1 },
|
|
5941
|
+
name: "subscription_type_index"
|
|
5942
|
+
},
|
|
5943
|
+
{
|
|
5944
|
+
key: { createdAt: -1 },
|
|
5945
|
+
name: "createdAt_index"
|
|
5946
|
+
}
|
|
5947
|
+
]);
|
|
5948
|
+
} catch (error) {
|
|
5949
|
+
}
|
|
5950
|
+
}
|
|
5951
|
+
createIndexes().catch((error) => {
|
|
5952
|
+
import_utils33.logger.log({
|
|
5953
|
+
level: "error",
|
|
5954
|
+
message: `Failed to create indexes for subscription_transactions collection: ${error.message}`
|
|
5955
|
+
});
|
|
5956
|
+
});
|
|
5957
|
+
async function add(value, session) {
|
|
5958
|
+
try {
|
|
5959
|
+
value = modelSubscriptionTransaction(value);
|
|
5960
|
+
await collection.insertOne(value, { session });
|
|
5961
|
+
delCachedData();
|
|
5962
|
+
return "Successfully added subscription transaction.";
|
|
5963
|
+
} catch (error) {
|
|
5964
|
+
import_utils33.logger.log({
|
|
5965
|
+
level: "error",
|
|
5966
|
+
message: `${error}`
|
|
5967
|
+
});
|
|
5968
|
+
if (error instanceof import_utils33.AppError) {
|
|
5969
|
+
throw error;
|
|
5970
|
+
}
|
|
5971
|
+
throw new import_utils33.InternalServerError("Failed to add subscription transaction.");
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
async function getAll({ page = 1, limit = 10, search = "", id = "" } = {}) {
|
|
5975
|
+
page = page > 0 ? page - 1 : page;
|
|
5976
|
+
const query = {};
|
|
5977
|
+
const cacheKeyOptions = {
|
|
5978
|
+
page,
|
|
5979
|
+
limit,
|
|
5980
|
+
search,
|
|
5981
|
+
tag: "getAll"
|
|
5982
|
+
};
|
|
5983
|
+
try {
|
|
5984
|
+
query.subscription = new import_mongodb20.ObjectId(id);
|
|
5985
|
+
cacheKeyOptions.subscription = id;
|
|
5986
|
+
} catch (error) {
|
|
5987
|
+
throw new import_utils33.InternalServerError("Invalid organization ID.");
|
|
5988
|
+
}
|
|
5989
|
+
if (search) {
|
|
5990
|
+
query.$text = { $search: search };
|
|
5991
|
+
}
|
|
5992
|
+
const cacheKey = (0, import_utils33.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
5993
|
+
try {
|
|
5994
|
+
const cachedData = await getCache(
|
|
5995
|
+
cacheKey
|
|
5996
|
+
);
|
|
5997
|
+
if (cachedData) {
|
|
5998
|
+
import_utils33.logger.log({
|
|
5999
|
+
level: "info",
|
|
6000
|
+
message: `Cache hit for getAll subscription transaction: ${cacheKey}`
|
|
6001
|
+
});
|
|
6002
|
+
return cachedData;
|
|
6003
|
+
}
|
|
6004
|
+
const items = await collection.aggregate([
|
|
6005
|
+
{ $match: query },
|
|
6006
|
+
{ $skip: page * limit },
|
|
6007
|
+
{ $limit: limit }
|
|
6008
|
+
]).toArray();
|
|
6009
|
+
const length = await collection.countDocuments(query);
|
|
6010
|
+
const data = (0, import_utils33.paginate)(
|
|
6011
|
+
items,
|
|
6012
|
+
page,
|
|
6013
|
+
limit,
|
|
6014
|
+
length
|
|
6015
|
+
);
|
|
6016
|
+
setCache(cacheKey, data).then(() => {
|
|
6017
|
+
import_utils33.logger.log({
|
|
6018
|
+
level: "info",
|
|
6019
|
+
message: `Cache set for getAll subscription transaction: ${cacheKey}`
|
|
6020
|
+
});
|
|
6021
|
+
}).catch((err) => {
|
|
6022
|
+
import_utils33.logger.log({
|
|
6023
|
+
level: "error",
|
|
6024
|
+
message: `Failed to set cache for getAll subscription transaction: ${err.message}`
|
|
6025
|
+
});
|
|
6026
|
+
});
|
|
6027
|
+
return data;
|
|
6028
|
+
} catch (error) {
|
|
6029
|
+
throw new import_utils33.InternalServerError("Failed to get subscription transactions.");
|
|
6030
|
+
}
|
|
6031
|
+
}
|
|
6032
|
+
return {
|
|
6033
|
+
add,
|
|
6034
|
+
getAll
|
|
6035
|
+
};
|
|
6036
|
+
}
|
|
6037
|
+
|
|
6038
|
+
// src/resources/subscription/subscription.service.ts
|
|
6039
|
+
function useSubscriptionService() {
|
|
6040
|
+
const { getById, updateById } = useSubscriptionRepo();
|
|
6041
|
+
const { add: addTransaction } = useSubscriptionTransactionRepo();
|
|
6042
|
+
const { getUserById } = useUserRepo();
|
|
6043
|
+
async function updateSeats({
|
|
6044
|
+
id = "",
|
|
6045
|
+
user = "",
|
|
6046
|
+
amount = 0,
|
|
6047
|
+
seats = 0
|
|
6048
|
+
} = {}) {
|
|
6049
|
+
const { error } = schemaSubscriptionSeats.validate({
|
|
6050
|
+
id,
|
|
6051
|
+
seats,
|
|
6052
|
+
amount,
|
|
6053
|
+
user
|
|
6054
|
+
});
|
|
6055
|
+
if (error) {
|
|
6056
|
+
throw new import_utils34.BadRequestError(error.message);
|
|
6057
|
+
}
|
|
6058
|
+
const subscription = await getById(id);
|
|
6059
|
+
if (!subscription) {
|
|
6060
|
+
throw new Error("Subscription not found");
|
|
6061
|
+
}
|
|
6062
|
+
if (subscription.seats === seats) {
|
|
6063
|
+
throw new Error("Failed to update subscription, no changes detected.");
|
|
6064
|
+
}
|
|
6065
|
+
const userData = await getUserById(user);
|
|
6066
|
+
if (!userData) {
|
|
6067
|
+
throw new Error("User not found.");
|
|
6068
|
+
}
|
|
6069
|
+
const session = import_utils34.useAtlas.getClient()?.startSession();
|
|
6070
|
+
if (!session) {
|
|
6071
|
+
throw new Error("Unable to start database session.");
|
|
6072
|
+
}
|
|
6073
|
+
let subscriptionAmount = subscription.amount;
|
|
6074
|
+
const seatIncreased = seats > subscription.paidSeats;
|
|
6075
|
+
let paidSeats = subscription.paidSeats;
|
|
6076
|
+
if (seatIncreased) {
|
|
6077
|
+
subscriptionAmount += amount ?? 0;
|
|
6078
|
+
paidSeats = seats;
|
|
6079
|
+
}
|
|
6080
|
+
try {
|
|
6081
|
+
session.startTransaction();
|
|
6082
|
+
await updateById(
|
|
6083
|
+
id,
|
|
6084
|
+
{ seats, amount: subscriptionAmount, paidSeats },
|
|
6085
|
+
session
|
|
6086
|
+
);
|
|
6087
|
+
if (seatIncreased) {
|
|
6088
|
+
await addTransaction(
|
|
6089
|
+
{
|
|
6090
|
+
type: "add-seat",
|
|
6091
|
+
description: `Added ${seats - subscription.paidSeats} seats.`,
|
|
6092
|
+
amount: amount ?? 0,
|
|
6093
|
+
currency: subscription.currency,
|
|
6094
|
+
subscription: id,
|
|
6095
|
+
createdBy: user,
|
|
6096
|
+
createdByName: `${userData.firstName} ${userData.lastName}`
|
|
6097
|
+
},
|
|
6098
|
+
session
|
|
6099
|
+
);
|
|
6100
|
+
}
|
|
6101
|
+
await session.commitTransaction();
|
|
6102
|
+
return "Successfully updated subscription seats.";
|
|
6103
|
+
} catch (error2) {
|
|
6104
|
+
await session.abortTransaction();
|
|
6105
|
+
throw error2;
|
|
6106
|
+
} finally {
|
|
6107
|
+
session.endSession();
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
6110
|
+
return {
|
|
6111
|
+
updateSeats
|
|
6112
|
+
};
|
|
6113
|
+
}
|
|
6114
|
+
|
|
6115
|
+
// src/resources/subscription/subscription.controller.ts
|
|
6116
|
+
function useSubscriptionController() {
|
|
6117
|
+
const {
|
|
6118
|
+
getAll: _getAll,
|
|
6119
|
+
getById: _getById,
|
|
6120
|
+
getByOrg: _getByOrg
|
|
6121
|
+
} = useSubscriptionRepo();
|
|
6122
|
+
const { updateSeats: _updateSeats } = useSubscriptionService();
|
|
6123
|
+
async function getAll(req, res, next) {
|
|
6124
|
+
const validation = import_joi24.default.object({
|
|
6125
|
+
page: import_joi24.default.number().min(1).max(100).optional().allow(null, "").default(1),
|
|
6126
|
+
limit: import_joi24.default.number().min(1).max(100).optional().allow(null, "").default(10),
|
|
6127
|
+
status: import_joi24.default.string().valid("active", "suspended").optional().default("active")
|
|
6128
|
+
});
|
|
6129
|
+
const query = req.query;
|
|
6130
|
+
const { error, value } = validation.validate(query);
|
|
6131
|
+
if (error) {
|
|
6132
|
+
next(new import_utils35.BadRequestError(error.message));
|
|
6133
|
+
return;
|
|
6134
|
+
}
|
|
6135
|
+
try {
|
|
6136
|
+
const data = await _getAll(value);
|
|
6137
|
+
res.json(data);
|
|
6138
|
+
return;
|
|
6139
|
+
} catch (error2) {
|
|
6140
|
+
next(error2);
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
6143
|
+
async function getById(req, res, next) {
|
|
6144
|
+
const id = req.params.id ?? "";
|
|
6145
|
+
const validation = import_joi24.default.object({
|
|
6146
|
+
id: import_joi24.default.string().hex().length(24).required()
|
|
6147
|
+
});
|
|
6148
|
+
const { error, value } = validation.validate({ id });
|
|
6149
|
+
if (error) {
|
|
6150
|
+
next(new import_utils35.BadRequestError(error.message));
|
|
6151
|
+
return;
|
|
6152
|
+
}
|
|
6153
|
+
try {
|
|
6154
|
+
const data = await _getById(value.id);
|
|
6155
|
+
res.json(data);
|
|
6156
|
+
return;
|
|
6157
|
+
} catch (error2) {
|
|
6158
|
+
next(error2);
|
|
6159
|
+
}
|
|
6160
|
+
}
|
|
6161
|
+
async function getByOrg(req, res, next) {
|
|
6162
|
+
const org = req.params.org ?? "";
|
|
6163
|
+
const validation = import_joi24.default.object({
|
|
6164
|
+
org: import_joi24.default.string().hex().length(24).required()
|
|
6165
|
+
});
|
|
6166
|
+
const { error, value } = validation.validate({ org });
|
|
6167
|
+
if (error) {
|
|
6168
|
+
next(new import_utils35.BadRequestError(error.message));
|
|
6169
|
+
return;
|
|
6170
|
+
}
|
|
6171
|
+
try {
|
|
6172
|
+
const data = await _getByOrg(value.org);
|
|
6173
|
+
res.json(data);
|
|
6174
|
+
return;
|
|
6175
|
+
} catch (error2) {
|
|
6176
|
+
next(error2);
|
|
6177
|
+
}
|
|
6178
|
+
}
|
|
6179
|
+
async function updateSeats(req, res, next) {
|
|
6180
|
+
const id = req.params.id ?? "";
|
|
6181
|
+
const payload = req.body;
|
|
6182
|
+
const { error } = schemaSubscriptionSeats.validate({ ...payload, id });
|
|
6183
|
+
if (error) {
|
|
6184
|
+
next(new import_utils35.BadRequestError(error.message));
|
|
6185
|
+
return;
|
|
6186
|
+
}
|
|
6187
|
+
const user = payload.user ?? "";
|
|
6188
|
+
const seats = payload.seats ?? 0;
|
|
6189
|
+
const amount = payload.amount ?? 0;
|
|
6190
|
+
try {
|
|
6191
|
+
const message = await _updateSeats({ id, seats, amount, user });
|
|
6192
|
+
res.json({ message });
|
|
6193
|
+
return;
|
|
6194
|
+
} catch (error2) {
|
|
6195
|
+
next(error2);
|
|
6196
|
+
}
|
|
6197
|
+
}
|
|
6198
|
+
return {
|
|
6199
|
+
getAll,
|
|
6200
|
+
getById,
|
|
6201
|
+
getByOrg,
|
|
6202
|
+
updateSeats
|
|
6203
|
+
};
|
|
6204
|
+
}
|
|
6205
|
+
|
|
6206
|
+
// src/resources/subscription/subscription.transaction.controller.ts
|
|
6207
|
+
var import_joi25 = __toESM(require("joi"));
|
|
6208
|
+
var import_utils36 = require("@goweekdays/utils");
|
|
6209
|
+
function useSubscriptionTransactionController() {
|
|
6210
|
+
const { getAll: _getAll } = useSubscriptionTransactionRepo();
|
|
6211
|
+
async function getAll(req, res, next) {
|
|
6212
|
+
const validation = import_joi25.default.object({
|
|
6213
|
+
id: import_joi25.default.string().hex().length(24).required(),
|
|
6214
|
+
page: import_joi25.default.number().min(1).max(100).optional().allow(null, "").default(1),
|
|
6215
|
+
limit: import_joi25.default.number().min(1).max(100).optional().allow(null, "").default(10)
|
|
6216
|
+
});
|
|
6217
|
+
const query = req.query;
|
|
6218
|
+
const id = req.params.id ?? "";
|
|
6219
|
+
const { error, value } = validation.validate({ ...query, id });
|
|
6220
|
+
if (error) {
|
|
6221
|
+
next(new import_utils36.BadRequestError(error.message));
|
|
6222
|
+
return;
|
|
6223
|
+
}
|
|
6224
|
+
try {
|
|
6225
|
+
const data = await _getAll(value);
|
|
6226
|
+
res.json(data);
|
|
6227
|
+
return;
|
|
6228
|
+
} catch (error2) {
|
|
6229
|
+
next(error2);
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
return {
|
|
6233
|
+
getAll
|
|
6234
|
+
};
|
|
6235
|
+
}
|
|
6236
|
+
|
|
6237
|
+
// src/resources/plan/plan.model.ts
|
|
6238
|
+
var import_joi26 = __toESM(require("joi"));
|
|
6239
|
+
var currencies = ["USD", "PHP"];
|
|
6240
|
+
var schemaPlan = import_joi26.default.object({
|
|
6241
|
+
name: import_joi26.default.string().min(3).max(100).required(),
|
|
6242
|
+
description: import_joi26.default.string().max(255).optional().allow("", null),
|
|
6243
|
+
features: import_joi26.default.array().items(import_joi26.default.string().max(100)).optional(),
|
|
6244
|
+
price: import_joi26.default.number().positive().required(),
|
|
6245
|
+
currency: import_joi26.default.string().length(3).allow(...currencies).required(),
|
|
6246
|
+
default: import_joi26.default.boolean().optional().allow(null, ""),
|
|
6247
|
+
billingCycle: import_joi26.default.string().valid("monthly", "yearly").required()
|
|
6248
|
+
});
|
|
6249
|
+
function modelPlan(data) {
|
|
6250
|
+
const { error } = schemaPlan.validate(data);
|
|
6251
|
+
if (error) {
|
|
6252
|
+
throw new Error(`Invalid plan data: ${error.message}`);
|
|
6253
|
+
}
|
|
6254
|
+
return {
|
|
6255
|
+
_id: data._id,
|
|
6256
|
+
name: data.name,
|
|
6257
|
+
description: data.description,
|
|
6258
|
+
features: data.features,
|
|
6259
|
+
price: data.price,
|
|
6260
|
+
currency: data.currency,
|
|
6261
|
+
billingCycle: data.billingCycle,
|
|
6262
|
+
status: data.status ?? "active",
|
|
6263
|
+
default: data.default ?? false,
|
|
6264
|
+
createdAt: data.createdAt ?? /* @__PURE__ */ new Date(),
|
|
6265
|
+
updatedAt: data.updatedAt ?? ""
|
|
6266
|
+
};
|
|
6267
|
+
}
|
|
6268
|
+
|
|
6269
|
+
// src/resources/plan/plan.repository.ts
|
|
6270
|
+
var import_utils37 = require("@goweekdays/utils");
|
|
6271
|
+
var import_joi27 = __toESM(require("joi"));
|
|
6272
|
+
var import_mongodb21 = require("mongodb");
|
|
6273
|
+
function usePlanRepo() {
|
|
6274
|
+
const db = import_utils37.useAtlas.getDb();
|
|
6275
|
+
if (!db) {
|
|
6276
|
+
throw new import_utils37.InternalServerError("Unable to connect to server.");
|
|
6277
|
+
}
|
|
6278
|
+
const namespace_collection = "plans";
|
|
6279
|
+
const collection = db.collection(namespace_collection);
|
|
6280
|
+
const { getCache, setCache, delNamespace } = (0, import_utils37.useCache)(namespace_collection);
|
|
6281
|
+
function delCachedData() {
|
|
6282
|
+
delNamespace().then(() => {
|
|
6283
|
+
import_utils37.logger.log({
|
|
6284
|
+
level: "info",
|
|
6285
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
6286
|
+
});
|
|
6287
|
+
}).catch((err) => {
|
|
6288
|
+
import_utils37.logger.log({
|
|
6289
|
+
level: "error",
|
|
6290
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
6291
|
+
});
|
|
6292
|
+
});
|
|
6293
|
+
}
|
|
6294
|
+
async function createIndexes() {
|
|
6295
|
+
try {
|
|
6296
|
+
await collection.createIndexes([
|
|
6297
|
+
{
|
|
6298
|
+
key: {
|
|
6299
|
+
status: 1
|
|
6300
|
+
}
|
|
6301
|
+
},
|
|
6302
|
+
{
|
|
6303
|
+
key: {
|
|
6304
|
+
name: 1
|
|
6305
|
+
}
|
|
6306
|
+
},
|
|
6307
|
+
{
|
|
6308
|
+
key: { billingCycle: 1 }
|
|
6309
|
+
},
|
|
6310
|
+
{
|
|
6311
|
+
key: { name: "text", description: "text" },
|
|
6312
|
+
name: "name_description_text_index"
|
|
6313
|
+
},
|
|
6314
|
+
{
|
|
6315
|
+
key: { name: 1, status: 1 },
|
|
6316
|
+
partialFilterExpression: { status: "active" },
|
|
6317
|
+
unique: true,
|
|
6318
|
+
name: "unique_name_index"
|
|
6319
|
+
},
|
|
6320
|
+
{
|
|
6321
|
+
key: { default: 1 },
|
|
6322
|
+
unique: true,
|
|
6323
|
+
partialFilterExpression: { status: "active" }
|
|
6324
|
+
}
|
|
6325
|
+
]);
|
|
6326
|
+
} catch (error) {
|
|
6327
|
+
}
|
|
6328
|
+
}
|
|
6329
|
+
createIndexes().catch((error) => {
|
|
6330
|
+
import_utils37.logger.log({
|
|
6331
|
+
level: "error",
|
|
6332
|
+
message: `Failed to create indexes for plans collection: ${error.message}`
|
|
6333
|
+
});
|
|
6334
|
+
});
|
|
6335
|
+
async function add(value) {
|
|
6336
|
+
try {
|
|
6337
|
+
value = modelPlan(value);
|
|
6338
|
+
await collection.insertOne(value);
|
|
6339
|
+
delCachedData();
|
|
6340
|
+
return "Successfully added plan.";
|
|
6341
|
+
} catch (error) {
|
|
6342
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
6343
|
+
if (isDuplicated) {
|
|
6344
|
+
throw new import_utils37.BadRequestError("Plan name already exist.");
|
|
6345
|
+
}
|
|
6346
|
+
throw new import_utils37.InternalServerError("Failed to add plan.");
|
|
6347
|
+
}
|
|
6348
|
+
}
|
|
6349
|
+
async function getAll({
|
|
6350
|
+
page = 1,
|
|
6351
|
+
limit = 10,
|
|
6352
|
+
search = "",
|
|
6353
|
+
status = "active"
|
|
6354
|
+
} = {}) {
|
|
6355
|
+
page = page < 1 ? page - 1 : page;
|
|
6356
|
+
const query = { status };
|
|
6357
|
+
const cacheKeyOptions = {
|
|
6358
|
+
page,
|
|
6359
|
+
limit,
|
|
6360
|
+
search,
|
|
6361
|
+
status,
|
|
6362
|
+
tag: "getAll"
|
|
6363
|
+
};
|
|
6364
|
+
if (search) {
|
|
6365
|
+
query.$text = { $search: search };
|
|
6366
|
+
}
|
|
6367
|
+
const cacheKey = (0, import_utils37.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
6368
|
+
try {
|
|
6369
|
+
const cachedData = await getCache(cacheKey);
|
|
6370
|
+
if (cachedData) {
|
|
6371
|
+
return cachedData;
|
|
6372
|
+
}
|
|
6373
|
+
const items = await collection.aggregate([
|
|
6374
|
+
{ $match: query },
|
|
6375
|
+
{ $skip: page * limit },
|
|
6376
|
+
{ $limit: limit }
|
|
6377
|
+
]).toArray();
|
|
6378
|
+
const length = await collection.countDocuments(query);
|
|
6379
|
+
const data = (0, import_utils37.paginate)(items, page, limit, length);
|
|
6380
|
+
setCache(cacheKey, data).then(() => {
|
|
6381
|
+
import_utils37.logger.log({
|
|
6382
|
+
level: "info",
|
|
6383
|
+
message: `Cache set for getAll plan: ${cacheKey}`
|
|
6384
|
+
});
|
|
6385
|
+
}).catch((err) => {
|
|
6386
|
+
import_utils37.logger.log({
|
|
6387
|
+
level: "error",
|
|
6388
|
+
message: `Failed to set cache for getAll plan: ${err.message}`
|
|
6389
|
+
});
|
|
6390
|
+
});
|
|
6391
|
+
return data;
|
|
6392
|
+
} catch (error) {
|
|
6393
|
+
throw new import_utils37.InternalServerError("Failed to get plans.");
|
|
6394
|
+
}
|
|
6395
|
+
}
|
|
6396
|
+
async function getById(_id) {
|
|
6397
|
+
const { error } = import_joi27.default.string().hex().length(24).required().validate(_id);
|
|
6398
|
+
if (error) {
|
|
6399
|
+
throw new Error(`Invalid plan ID: ${error.message}`);
|
|
6400
|
+
}
|
|
6401
|
+
try {
|
|
6402
|
+
_id = new import_mongodb21.ObjectId(_id);
|
|
6403
|
+
} catch (error2) {
|
|
6404
|
+
throw new import_utils37.BadRequestError("Invalid plan ID.");
|
|
6405
|
+
}
|
|
6406
|
+
try {
|
|
6407
|
+
const cacheKey = (0, import_utils37.makeCacheKey)(namespace_collection, {
|
|
6408
|
+
_id: String(_id),
|
|
6409
|
+
tag: "getById"
|
|
6410
|
+
});
|
|
6411
|
+
const cachedData = await getCache(cacheKey);
|
|
6412
|
+
if (cachedData) {
|
|
6413
|
+
return cachedData;
|
|
6414
|
+
}
|
|
6415
|
+
const data = await collection.findOne({
|
|
6416
|
+
_id,
|
|
6417
|
+
status: { $ne: "deleted" }
|
|
6418
|
+
});
|
|
6419
|
+
setCache(cacheKey, data).then(() => {
|
|
6420
|
+
import_utils37.logger.log({
|
|
6421
|
+
level: "info",
|
|
6422
|
+
message: `Cache set for getById plan: ${cacheKey}`
|
|
6423
|
+
});
|
|
6424
|
+
}).catch((err) => {
|
|
6425
|
+
import_utils37.logger.log({
|
|
6426
|
+
level: "error",
|
|
6427
|
+
message: `Failed to set cache for getById plan: ${err.message}`
|
|
6428
|
+
});
|
|
6429
|
+
});
|
|
6430
|
+
return data;
|
|
6431
|
+
} catch (error2) {
|
|
6432
|
+
throw new import_utils37.InternalServerError("Failed to get plan.");
|
|
6433
|
+
}
|
|
6434
|
+
}
|
|
6435
|
+
async function getDefault() {
|
|
6436
|
+
try {
|
|
6437
|
+
const cacheKey = (0, import_utils37.makeCacheKey)(namespace_collection, {
|
|
6438
|
+
default: true,
|
|
6439
|
+
tag: "getDefault"
|
|
6440
|
+
});
|
|
6441
|
+
const cachedData = await getCache(cacheKey);
|
|
6442
|
+
if (cachedData) {
|
|
6443
|
+
return cachedData;
|
|
6444
|
+
}
|
|
6445
|
+
const data = await collection.findOne({
|
|
6446
|
+
default: true,
|
|
6447
|
+
status: "active"
|
|
6448
|
+
});
|
|
6449
|
+
setCache(cacheKey, data).then(() => {
|
|
6450
|
+
import_utils37.logger.log({
|
|
6451
|
+
level: "info",
|
|
6452
|
+
message: `Cache set for default plan: ${cacheKey}`
|
|
6453
|
+
});
|
|
6454
|
+
}).catch((err) => {
|
|
6455
|
+
import_utils37.logger.log({
|
|
6456
|
+
level: "error",
|
|
6457
|
+
message: `Failed to set cache for default plan: ${err.message}`
|
|
6458
|
+
});
|
|
6459
|
+
});
|
|
6460
|
+
return data;
|
|
6461
|
+
} catch (error) {
|
|
6462
|
+
throw new import_utils37.InternalServerError("Failed to get default plan.");
|
|
6463
|
+
}
|
|
6464
|
+
}
|
|
6465
|
+
async function deleteById(_id) {
|
|
6466
|
+
const { error } = import_joi27.default.string().hex().length(24).required().validate(_id);
|
|
6467
|
+
if (error) {
|
|
6468
|
+
throw new Error(`Invalid plan ID: ${error.message}`);
|
|
6469
|
+
}
|
|
6470
|
+
try {
|
|
6471
|
+
_id = new import_mongodb21.ObjectId(_id);
|
|
6472
|
+
} catch (error2) {
|
|
6473
|
+
throw new import_utils37.BadRequestError("Invalid plan ID.");
|
|
6474
|
+
}
|
|
6475
|
+
try {
|
|
6476
|
+
const result = await collection.updateOne(
|
|
6477
|
+
{ _id },
|
|
6478
|
+
{ $set: { status: "deleted" } }
|
|
6479
|
+
);
|
|
6480
|
+
if (result.modifiedCount === 0) {
|
|
6481
|
+
throw new import_utils37.InternalServerError("Failed to delete plan.");
|
|
6482
|
+
}
|
|
6483
|
+
delCachedData();
|
|
6484
|
+
return "Successfully deleted plan.";
|
|
6485
|
+
} catch (error2) {
|
|
6486
|
+
if (error2 instanceof import_utils37.AppError) {
|
|
6487
|
+
throw error2;
|
|
6488
|
+
}
|
|
6489
|
+
throw new import_utils37.InternalServerError("Failed to delete plan.");
|
|
6490
|
+
}
|
|
6491
|
+
}
|
|
6492
|
+
return {
|
|
6493
|
+
add,
|
|
6494
|
+
getAll,
|
|
6495
|
+
getById,
|
|
6496
|
+
getDefault,
|
|
6497
|
+
deleteById
|
|
6498
|
+
};
|
|
6499
|
+
}
|
|
6500
|
+
|
|
6501
|
+
// src/resources/plan/plan.service.ts
|
|
6502
|
+
function usePlanService() {
|
|
6503
|
+
const { add } = usePlanRepo();
|
|
6504
|
+
async function addDefaultPlan() {
|
|
6505
|
+
try {
|
|
6506
|
+
await add({
|
|
6507
|
+
name: "Standard",
|
|
6508
|
+
description: "Default standard plan",
|
|
6509
|
+
price: 1e3,
|
|
6510
|
+
currency: "PHP",
|
|
6511
|
+
billingCycle: "monthly",
|
|
6512
|
+
default: true
|
|
6513
|
+
});
|
|
6514
|
+
} catch (error) {
|
|
6515
|
+
throw error;
|
|
6516
|
+
}
|
|
6517
|
+
}
|
|
6518
|
+
return {
|
|
6519
|
+
addDefaultPlan
|
|
6520
|
+
};
|
|
6521
|
+
}
|
|
6522
|
+
|
|
6523
|
+
// src/resources/plan/plan.controller.ts
|
|
6524
|
+
var import_joi28 = __toESM(require("joi"));
|
|
6525
|
+
var import_utils38 = require("@goweekdays/utils");
|
|
6526
|
+
function usePlanController() {
|
|
6527
|
+
const {
|
|
6528
|
+
add: _add,
|
|
6529
|
+
getAll: _getAll,
|
|
6530
|
+
getById: _getById,
|
|
6531
|
+
deleteById: _deleteById,
|
|
6532
|
+
getDefault: _getDefault
|
|
6533
|
+
} = usePlanRepo();
|
|
6534
|
+
async function add(req, res, next) {
|
|
6535
|
+
const value = req.body;
|
|
6536
|
+
const validation = import_joi28.default.object({
|
|
6537
|
+
name: import_joi28.default.string().min(3).max(100).required(),
|
|
6538
|
+
description: import_joi28.default.string().max(255).optional().allow("", null),
|
|
6539
|
+
features: import_joi28.default.array().items(import_joi28.default.string().max(100)).optional(),
|
|
6540
|
+
price: import_joi28.default.number().positive().required(),
|
|
6541
|
+
currency: import_joi28.default.string().length(3).required(),
|
|
6542
|
+
billingCycle: import_joi28.default.string().valid("monthly", "yearly").required()
|
|
6543
|
+
});
|
|
6544
|
+
const { error } = validation.validate(value);
|
|
6545
|
+
if (error) {
|
|
6546
|
+
next(new import_utils38.BadRequestError(error.message));
|
|
6547
|
+
return;
|
|
6548
|
+
}
|
|
6549
|
+
try {
|
|
6550
|
+
const message = await _add(value);
|
|
6551
|
+
res.json({ message });
|
|
6552
|
+
return;
|
|
6553
|
+
} catch (error2) {
|
|
6554
|
+
next(error2);
|
|
6555
|
+
}
|
|
6556
|
+
}
|
|
6557
|
+
async function getAll(req, res, next) {
|
|
6558
|
+
const status = req.query.status ?? "active";
|
|
6559
|
+
const search = req.query.search ?? "";
|
|
6560
|
+
const page = Number(req.query.page) ?? 1;
|
|
6561
|
+
const limit = Number(req.query.limit) ?? 10;
|
|
6562
|
+
const validation = import_joi28.default.object({
|
|
6563
|
+
status: import_joi28.default.string().required(),
|
|
6564
|
+
search: import_joi28.default.string().optional().allow("", null),
|
|
6565
|
+
page: import_joi28.default.number().required(),
|
|
6566
|
+
limit: import_joi28.default.number().required()
|
|
6567
|
+
});
|
|
6568
|
+
const { error } = validation.validate({ status, search, page, limit });
|
|
6569
|
+
if (error) {
|
|
6570
|
+
next(new import_utils38.BadRequestError(error.message));
|
|
6571
|
+
return;
|
|
6572
|
+
}
|
|
6573
|
+
try {
|
|
6574
|
+
const plans = await _getAll({ status, search, page, limit });
|
|
6575
|
+
res.json(plans);
|
|
6576
|
+
return;
|
|
6577
|
+
} catch (error2) {
|
|
6578
|
+
next(error2);
|
|
6579
|
+
}
|
|
6580
|
+
}
|
|
6581
|
+
async function getById(req, res, next) {
|
|
6582
|
+
const id = req.params.id;
|
|
6583
|
+
const validation = import_joi28.default.string().hex().length(24).required();
|
|
6584
|
+
const { error } = validation.validate(id);
|
|
6585
|
+
if (error) {
|
|
6586
|
+
next(new import_utils38.BadRequestError(error.message));
|
|
6587
|
+
return;
|
|
6588
|
+
}
|
|
6589
|
+
try {
|
|
6590
|
+
const plan = await _getById(id);
|
|
6591
|
+
res.json(plan);
|
|
6592
|
+
return;
|
|
6593
|
+
} catch (error2) {
|
|
6594
|
+
next(error2);
|
|
6595
|
+
}
|
|
6596
|
+
}
|
|
6597
|
+
async function deleteById(req, res, next) {
|
|
6598
|
+
const id = req.params.id;
|
|
6599
|
+
const validation = import_joi28.default.string().hex().length(24).required();
|
|
6600
|
+
const { error } = validation.validate(id);
|
|
6601
|
+
if (error) {
|
|
6602
|
+
next(new import_utils38.BadRequestError(error.message));
|
|
6603
|
+
return;
|
|
6604
|
+
}
|
|
6605
|
+
try {
|
|
6606
|
+
const message = await _deleteById(id);
|
|
6607
|
+
res.json({ message });
|
|
6608
|
+
return;
|
|
6609
|
+
} catch (error2) {
|
|
6610
|
+
next(error2);
|
|
6611
|
+
}
|
|
6612
|
+
}
|
|
6613
|
+
async function getDefault(req, res, next) {
|
|
6614
|
+
try {
|
|
6615
|
+
const plan = await _getDefault();
|
|
6616
|
+
res.json(plan);
|
|
6617
|
+
return;
|
|
6618
|
+
} catch (error) {
|
|
6619
|
+
next(error);
|
|
6620
|
+
}
|
|
6621
|
+
}
|
|
6622
|
+
return {
|
|
6623
|
+
add,
|
|
6624
|
+
getAll,
|
|
6625
|
+
getById,
|
|
6626
|
+
deleteById,
|
|
6627
|
+
getDefault
|
|
6628
|
+
};
|
|
6629
|
+
}
|
|
6630
|
+
|
|
6631
|
+
// src/resources/organization/organization.service.ts
|
|
6632
|
+
function useOrgService() {
|
|
6633
|
+
const { add: addOrg } = useOrgRepo();
|
|
6634
|
+
const { addRole } = useRoleRepo();
|
|
6635
|
+
const { getAll: getAllPermission } = usePermissionRepo();
|
|
6636
|
+
const { add: addMember, updateRoleById: _updateRoleById } = useMemberRepo();
|
|
6637
|
+
const { getUserById } = useUserRepo();
|
|
6638
|
+
const { getDefault } = usePlanRepo();
|
|
6639
|
+
const { add: addSubscription } = useSubscriptionRepo();
|
|
6640
|
+
const { add: addSubscriptionTransaction } = useSubscriptionTransactionRepo();
|
|
6641
|
+
async function add(value) {
|
|
6642
|
+
const { error } = schemaOrgAdd.validate(value);
|
|
6643
|
+
if (error) {
|
|
6644
|
+
throw new import_utils39.BadRequestError(error.message);
|
|
6645
|
+
}
|
|
6646
|
+
const session = import_utils39.useAtlas.getClient()?.startSession();
|
|
6647
|
+
if (!session) {
|
|
6648
|
+
throw new import_utils39.BadRequestError("Unable to start database session.");
|
|
6649
|
+
}
|
|
6650
|
+
try {
|
|
6651
|
+
session?.startTransaction();
|
|
6652
|
+
const org = await addOrg(
|
|
6653
|
+
{
|
|
6654
|
+
email: value.email,
|
|
6655
|
+
name: value.name,
|
|
6656
|
+
contact: value.contact,
|
|
6657
|
+
createdBy: value.createdBy
|
|
6658
|
+
},
|
|
6659
|
+
session
|
|
6660
|
+
);
|
|
6661
|
+
const plan = await getDefault();
|
|
6662
|
+
if (!plan) {
|
|
6663
|
+
throw new import_utils39.BadRequestError(
|
|
6664
|
+
"Failed to create organization, plan not found."
|
|
6665
|
+
);
|
|
6666
|
+
}
|
|
6667
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
6668
|
+
const nextBillingDate = new Date(currentDate);
|
|
6669
|
+
nextBillingDate.setMonth(currentDate.getMonth() + 1);
|
|
6670
|
+
const amount = plan.price * value.seats;
|
|
6671
|
+
const subscriptionId = await addSubscription(
|
|
6672
|
+
{
|
|
6673
|
+
amount,
|
|
6674
|
+
org: String(org),
|
|
6675
|
+
seats: value.seats,
|
|
6676
|
+
paidSeats: value.seats,
|
|
6677
|
+
currency: plan.currency,
|
|
6678
|
+
billingCycle: plan.billingCycle,
|
|
6679
|
+
nextBillingDate
|
|
6680
|
+
},
|
|
6681
|
+
session
|
|
6682
|
+
);
|
|
6683
|
+
const createdBy = String(value.createdBy);
|
|
6684
|
+
const user = await getUserById(createdBy);
|
|
6685
|
+
if (!user) {
|
|
6686
|
+
throw new import_utils39.BadRequestError("User is required to create org member.");
|
|
6687
|
+
}
|
|
6688
|
+
await addSubscriptionTransaction(
|
|
6689
|
+
{
|
|
6690
|
+
subscription: subscriptionId,
|
|
6691
|
+
type: "initiate",
|
|
6692
|
+
amount,
|
|
6693
|
+
currency: plan.currency,
|
|
6694
|
+
description: "Initial subscription transaction",
|
|
6695
|
+
createdBy: value.createdBy,
|
|
6696
|
+
createdByName: `${user.firstName} ${user.lastName}`
|
|
6697
|
+
},
|
|
6698
|
+
session
|
|
6699
|
+
);
|
|
6700
|
+
const allPermissions = await getAllPermission({
|
|
6701
|
+
app: "org",
|
|
6702
|
+
limit: 100
|
|
6703
|
+
});
|
|
6704
|
+
let permissions = [];
|
|
6705
|
+
if (allPermissions && allPermissions.items && allPermissions.items.length) {
|
|
6706
|
+
permissions = allPermissions.items.map((perm) => perm.key);
|
|
6707
|
+
}
|
|
6708
|
+
if (permissions.length === 0) {
|
|
6709
|
+
throw new Error("No permissions found for the organization type.");
|
|
6710
|
+
}
|
|
6711
|
+
const roleData = {
|
|
6712
|
+
org: String(org),
|
|
6713
|
+
name: "Owner",
|
|
6714
|
+
description: "Owner of the organization",
|
|
6715
|
+
permissions,
|
|
6716
|
+
createdBy,
|
|
6717
|
+
app: "org"
|
|
6718
|
+
};
|
|
6719
|
+
const role = await addRole(roleData, session);
|
|
6720
|
+
if (!role) {
|
|
6721
|
+
throw new import_utils39.BadRequestError("Role is required to create org member.");
|
|
6722
|
+
}
|
|
6723
|
+
await addMember(
|
|
6724
|
+
{
|
|
6725
|
+
role: String(role),
|
|
6726
|
+
roleName: roleData.name,
|
|
6727
|
+
org: String(org),
|
|
6728
|
+
name: `${user.firstName} ${user.lastName}`,
|
|
6729
|
+
user: createdBy,
|
|
6730
|
+
app: "org"
|
|
6731
|
+
},
|
|
6732
|
+
session
|
|
6733
|
+
);
|
|
6734
|
+
await session?.commitTransaction();
|
|
6735
|
+
return String(org);
|
|
6736
|
+
} catch (error2) {
|
|
6737
|
+
await session?.abortTransaction();
|
|
6738
|
+
throw error2;
|
|
6739
|
+
} finally {
|
|
6740
|
+
await session?.endSession();
|
|
6741
|
+
}
|
|
6742
|
+
}
|
|
6743
|
+
return {
|
|
6744
|
+
add
|
|
6745
|
+
};
|
|
6746
|
+
}
|
|
6747
|
+
|
|
6748
|
+
// src/resources/organization/organization.controller.ts
|
|
6749
|
+
var import_utils40 = require("@goweekdays/utils");
|
|
6750
|
+
var import_joi29 = __toESM(require("joi"));
|
|
6751
|
+
function useOrgController() {
|
|
6752
|
+
const { add: _add } = useOrgService();
|
|
6753
|
+
const { getOrgsByMembership } = useMemberRepo();
|
|
6754
|
+
const {
|
|
6755
|
+
getByName: _getByName,
|
|
6756
|
+
getAll: getAllOrg,
|
|
6757
|
+
getById: _getById,
|
|
6758
|
+
updateById: _updateById
|
|
6759
|
+
} = useOrgRepo();
|
|
6760
|
+
async function add(req, res, next) {
|
|
6761
|
+
const value = req.body;
|
|
6762
|
+
const { error } = schemaOrgAdd.validate(value);
|
|
6763
|
+
if (error) {
|
|
6764
|
+
next(new import_utils40.BadRequestError(error.message));
|
|
6765
|
+
return;
|
|
6766
|
+
}
|
|
6767
|
+
try {
|
|
6768
|
+
const org = await _add(value);
|
|
6769
|
+
res.json({
|
|
6770
|
+
message: "Organization created successfully.",
|
|
6771
|
+
data: { org }
|
|
6772
|
+
});
|
|
6773
|
+
return;
|
|
6774
|
+
} catch (error2) {
|
|
6775
|
+
next(error2);
|
|
6776
|
+
}
|
|
6777
|
+
}
|
|
6778
|
+
async function getOrgsByUserId(req, res, next) {
|
|
6779
|
+
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
6780
|
+
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
6781
|
+
const search = req.query.search ?? "";
|
|
6782
|
+
const user = req.params.user ?? "";
|
|
6783
|
+
const isPageNumber = isFinite(page);
|
|
6784
|
+
if (!isPageNumber) {
|
|
6785
|
+
next(new import_utils40.BadRequestError("Invalid page number."));
|
|
6786
|
+
return;
|
|
6787
|
+
}
|
|
6788
|
+
const isLimitNumber = isFinite(limit);
|
|
6789
|
+
if (!isLimitNumber) {
|
|
6790
|
+
next(new import_utils40.BadRequestError("Invalid limit number."));
|
|
6791
|
+
return;
|
|
6792
|
+
}
|
|
6793
|
+
const validation = import_joi29.default.object({
|
|
6794
|
+
user: import_joi29.default.string().hex().required(),
|
|
6795
|
+
page: import_joi29.default.number().min(1).optional().allow("", null),
|
|
6796
|
+
limit: import_joi29.default.number().min(1).optional().allow("", null),
|
|
6797
|
+
search: import_joi29.default.string().optional().allow("", null)
|
|
6798
|
+
});
|
|
6799
|
+
const { error } = validation.validate({ user, page, limit, search });
|
|
6800
|
+
if (error) {
|
|
6801
|
+
next(new import_utils40.BadRequestError(error.message));
|
|
6802
|
+
return;
|
|
6803
|
+
}
|
|
6804
|
+
try {
|
|
6805
|
+
const orgs = await getOrgsByMembership({ user, page, limit, search });
|
|
6806
|
+
res.json(orgs);
|
|
6807
|
+
return;
|
|
6808
|
+
} catch (error2) {
|
|
6809
|
+
next(error2);
|
|
6810
|
+
}
|
|
6811
|
+
}
|
|
6812
|
+
async function getAll(req, res, next) {
|
|
6813
|
+
const query = req.query;
|
|
6814
|
+
const validation = import_joi29.default.object({
|
|
6815
|
+
page: import_joi29.default.number().min(1).optional().allow("", null),
|
|
6816
|
+
limit: import_joi29.default.number().min(1).optional().allow("", null),
|
|
6817
|
+
search: import_joi29.default.string().optional().allow("", null),
|
|
6818
|
+
status: import_joi29.default.string().valid("active", "suspended", "inactive", "deleted").optional()
|
|
6819
|
+
});
|
|
6820
|
+
const { error } = validation.validate(query);
|
|
6821
|
+
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
6822
|
+
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
6823
|
+
const search = req.query.search ?? "";
|
|
6824
|
+
const status = req.query.status ?? "active";
|
|
6825
|
+
const isPageNumber = isFinite(page);
|
|
6826
|
+
if (!isPageNumber) {
|
|
6827
|
+
next(new import_utils40.BadRequestError("Invalid page number."));
|
|
6828
|
+
return;
|
|
6829
|
+
}
|
|
6830
|
+
const isLimitNumber = isFinite(limit);
|
|
6831
|
+
if (!isLimitNumber) {
|
|
6832
|
+
next(new import_utils40.BadRequestError("Invalid limit number."));
|
|
6833
|
+
return;
|
|
6834
|
+
}
|
|
6835
|
+
if (error) {
|
|
6836
|
+
next(new import_utils40.BadRequestError(error.message));
|
|
6837
|
+
return;
|
|
6838
|
+
}
|
|
6839
|
+
try {
|
|
6840
|
+
const orgs = await getAllOrg({ page, limit, search, status });
|
|
6841
|
+
res.json(orgs);
|
|
6842
|
+
return;
|
|
6843
|
+
} catch (error2) {
|
|
6844
|
+
next(error2);
|
|
6845
|
+
}
|
|
6846
|
+
}
|
|
5600
6847
|
async function getByName(req, res, next) {
|
|
5601
6848
|
const name = req.params.name;
|
|
5602
|
-
const validation =
|
|
5603
|
-
name:
|
|
6849
|
+
const validation = import_joi29.default.object({
|
|
6850
|
+
name: import_joi29.default.string().required()
|
|
5604
6851
|
});
|
|
5605
6852
|
const { error } = validation.validate({ name });
|
|
5606
6853
|
if (error) {
|
|
5607
|
-
next(new
|
|
6854
|
+
next(new import_utils40.BadRequestError(error.message));
|
|
5608
6855
|
return;
|
|
5609
6856
|
}
|
|
5610
6857
|
try {
|
|
@@ -5617,12 +6864,12 @@ function useOrgController() {
|
|
|
5617
6864
|
}
|
|
5618
6865
|
async function getById(req, res, next) {
|
|
5619
6866
|
const id = req.params.id;
|
|
5620
|
-
const validation =
|
|
5621
|
-
id:
|
|
6867
|
+
const validation = import_joi29.default.object({
|
|
6868
|
+
id: import_joi29.default.string().hex().required()
|
|
5622
6869
|
});
|
|
5623
6870
|
const { error } = validation.validate({ id });
|
|
5624
6871
|
if (error) {
|
|
5625
|
-
next(new
|
|
6872
|
+
next(new import_utils40.BadRequestError(error.message));
|
|
5626
6873
|
return;
|
|
5627
6874
|
}
|
|
5628
6875
|
try {
|
|
@@ -5633,12 +6880,29 @@ function useOrgController() {
|
|
|
5633
6880
|
next(error2);
|
|
5634
6881
|
}
|
|
5635
6882
|
}
|
|
6883
|
+
async function updateById(req, res, next) {
|
|
6884
|
+
const _id = req.params.id ?? "";
|
|
6885
|
+
const payload = req.body;
|
|
6886
|
+
const { error } = schemaOrgUpdate.validate({ _id, ...payload });
|
|
6887
|
+
if (error) {
|
|
6888
|
+
next(new import_utils40.BadRequestError(error.message));
|
|
6889
|
+
return;
|
|
6890
|
+
}
|
|
6891
|
+
try {
|
|
6892
|
+
const message = await _updateById(_id, payload);
|
|
6893
|
+
res.json({ message });
|
|
6894
|
+
return;
|
|
6895
|
+
} catch (error2) {
|
|
6896
|
+
next(error2);
|
|
6897
|
+
}
|
|
6898
|
+
}
|
|
5636
6899
|
return {
|
|
5637
6900
|
add,
|
|
5638
6901
|
getOrgsByUserId,
|
|
5639
6902
|
getByName,
|
|
5640
6903
|
getAll,
|
|
5641
|
-
getById
|
|
6904
|
+
getById,
|
|
6905
|
+
updateById
|
|
5642
6906
|
};
|
|
5643
6907
|
}
|
|
5644
6908
|
|
|
@@ -5657,16 +6921,16 @@ function useUserService() {
|
|
|
5657
6921
|
const { getAll: getAllPermission } = usePermissionRepo();
|
|
5658
6922
|
const { getById: getOrgById } = useOrgRepo();
|
|
5659
6923
|
async function createDefaultUser() {
|
|
5660
|
-
const session =
|
|
6924
|
+
const session = import_utils41.useAtlas.getClient()?.startSession();
|
|
5661
6925
|
try {
|
|
5662
6926
|
session?.startTransaction();
|
|
5663
6927
|
const _user = await getUserByEmail(DEFAULT_USER_EMAIL);
|
|
5664
6928
|
if (_user) {
|
|
5665
|
-
throw new
|
|
6929
|
+
throw new import_utils41.BadRequestError(
|
|
5666
6930
|
`User already exists: ${DEFAULT_USER_EMAIL}.`
|
|
5667
6931
|
);
|
|
5668
6932
|
}
|
|
5669
|
-
const hashedPassword = await (0,
|
|
6933
|
+
const hashedPassword = await (0, import_utils41.hashPassword)(DEFAULT_USER_PASSWORD);
|
|
5670
6934
|
const userId = await addUser(
|
|
5671
6935
|
{
|
|
5672
6936
|
email: DEFAULT_USER_EMAIL,
|
|
@@ -5712,9 +6976,9 @@ function useUserService() {
|
|
|
5712
6976
|
try {
|
|
5713
6977
|
const _user = await getUserByEmail(value.email);
|
|
5714
6978
|
if (_user) {
|
|
5715
|
-
throw new
|
|
6979
|
+
throw new import_utils41.BadRequestError(`User already exists: ${value.email}.`);
|
|
5716
6980
|
}
|
|
5717
|
-
const hashedPassword = await (0,
|
|
6981
|
+
const hashedPassword = await (0, import_utils41.hashPassword)(value.password);
|
|
5718
6982
|
const insertedId = await addUser({
|
|
5719
6983
|
email: value.email,
|
|
5720
6984
|
password: hashedPassword,
|
|
@@ -5724,10 +6988,10 @@ function useUserService() {
|
|
|
5724
6988
|
});
|
|
5725
6989
|
return insertedId;
|
|
5726
6990
|
} catch (error) {
|
|
5727
|
-
if (error instanceof
|
|
6991
|
+
if (error instanceof import_utils41.AppError) {
|
|
5728
6992
|
throw error;
|
|
5729
6993
|
} else {
|
|
5730
|
-
throw new
|
|
6994
|
+
throw new import_utils41.InternalServerError(`Error creating user: ${error}`);
|
|
5731
6995
|
}
|
|
5732
6996
|
}
|
|
5733
6997
|
}
|
|
@@ -5738,28 +7002,28 @@ function useUserService() {
|
|
|
5738
7002
|
lastName = "",
|
|
5739
7003
|
password = ""
|
|
5740
7004
|
} = {}) {
|
|
5741
|
-
const session =
|
|
7005
|
+
const session = import_utils41.useAtlas.getClient()?.startSession();
|
|
5742
7006
|
session?.startTransaction();
|
|
5743
7007
|
try {
|
|
5744
7008
|
const invitation = await _getVerificationById(id);
|
|
5745
7009
|
if (!invitation || !invitation.metadata?.app || !invitation.metadata?.role) {
|
|
5746
|
-
throw new
|
|
7010
|
+
throw new import_utils41.BadRequestError("Invalid invitation.");
|
|
5747
7011
|
}
|
|
5748
7012
|
if (invitation.status === "complete") {
|
|
5749
|
-
throw new
|
|
7013
|
+
throw new import_utils41.BadRequestError("Invitation already used.");
|
|
5750
7014
|
}
|
|
5751
7015
|
if (!invitation.expireAt) {
|
|
5752
|
-
throw new
|
|
7016
|
+
throw new import_utils41.BadRequestError("Expiration date is required.");
|
|
5753
7017
|
}
|
|
5754
7018
|
const expired = new Date(invitation.expireAt) < /* @__PURE__ */ new Date();
|
|
5755
7019
|
if (invitation.status === "expired" || expired) {
|
|
5756
|
-
throw new
|
|
7020
|
+
throw new import_utils41.BadRequestError("Invitation expired.");
|
|
5757
7021
|
}
|
|
5758
7022
|
const email = invitation.email;
|
|
5759
7023
|
const user = await getUserByEmail(invitation.email);
|
|
5760
7024
|
let userId = user?._id ?? "";
|
|
5761
7025
|
if (!user) {
|
|
5762
|
-
const hashedPassword = await (0,
|
|
7026
|
+
const hashedPassword = await (0, import_utils41.hashPassword)(password);
|
|
5763
7027
|
userId = await addUser(
|
|
5764
7028
|
{
|
|
5765
7029
|
email,
|
|
@@ -5776,7 +7040,7 @@ function useUserService() {
|
|
|
5776
7040
|
if (invitation.metadata?.org) {
|
|
5777
7041
|
const org = await getOrgById(String(invitation.metadata.org));
|
|
5778
7042
|
if (!org) {
|
|
5779
|
-
throw new
|
|
7043
|
+
throw new import_utils41.NotFoundError("Organization not found.");
|
|
5780
7044
|
}
|
|
5781
7045
|
orgName = org.name;
|
|
5782
7046
|
}
|
|
@@ -5784,7 +7048,7 @@ function useUserService() {
|
|
|
5784
7048
|
if (invitation.metadata.role) {
|
|
5785
7049
|
const role = await getRoleById(String(invitation.metadata.role));
|
|
5786
7050
|
if (!role) {
|
|
5787
|
-
throw new
|
|
7051
|
+
throw new import_utils41.NotFoundError("Role not found.");
|
|
5788
7052
|
}
|
|
5789
7053
|
roleName = role.name;
|
|
5790
7054
|
}
|
|
@@ -5804,10 +7068,10 @@ function useUserService() {
|
|
|
5804
7068
|
return userId;
|
|
5805
7069
|
} catch (error) {
|
|
5806
7070
|
await session?.abortTransaction();
|
|
5807
|
-
if (error instanceof
|
|
7071
|
+
if (error instanceof import_utils41.AppError) {
|
|
5808
7072
|
throw error;
|
|
5809
7073
|
} else {
|
|
5810
|
-
throw new
|
|
7074
|
+
throw new import_utils41.InternalServerError("Failed to create user by invite.");
|
|
5811
7075
|
}
|
|
5812
7076
|
} finally {
|
|
5813
7077
|
session?.endSession();
|
|
@@ -5819,31 +7083,31 @@ function useUserService() {
|
|
|
5819
7083
|
lastName = "",
|
|
5820
7084
|
password = ""
|
|
5821
7085
|
} = {}) {
|
|
5822
|
-
const session =
|
|
7086
|
+
const session = import_utils41.useAtlas.getClient()?.startSession();
|
|
5823
7087
|
session?.startTransaction();
|
|
5824
7088
|
try {
|
|
5825
7089
|
const signUp = await _getVerificationById(id);
|
|
5826
7090
|
if (!signUp) {
|
|
5827
|
-
throw new
|
|
7091
|
+
throw new import_utils41.BadRequestError("Invalid sign up link.");
|
|
5828
7092
|
}
|
|
5829
7093
|
if (signUp.status === "complete") {
|
|
5830
|
-
throw new
|
|
7094
|
+
throw new import_utils41.BadRequestError(
|
|
5831
7095
|
"You have already an account created using this link."
|
|
5832
7096
|
);
|
|
5833
7097
|
}
|
|
5834
7098
|
if (!signUp.expireAt) {
|
|
5835
|
-
throw new
|
|
7099
|
+
throw new import_utils41.BadRequestError("Expiration date is required.");
|
|
5836
7100
|
}
|
|
5837
7101
|
const expired = new Date(signUp.expireAt) < /* @__PURE__ */ new Date();
|
|
5838
7102
|
if (signUp.status === "expired" || expired) {
|
|
5839
|
-
throw new
|
|
7103
|
+
throw new import_utils41.BadRequestError("Sign up link expired.");
|
|
5840
7104
|
}
|
|
5841
7105
|
const email = signUp.email;
|
|
5842
7106
|
const _user = await getUserByEmail(signUp.email);
|
|
5843
7107
|
if (_user) {
|
|
5844
|
-
throw new
|
|
7108
|
+
throw new import_utils41.BadRequestError(`User already exists: ${email}.`);
|
|
5845
7109
|
}
|
|
5846
|
-
const hashedPassword = await (0,
|
|
7110
|
+
const hashedPassword = await (0, import_utils41.hashPassword)(password);
|
|
5847
7111
|
const userId = await addUser(
|
|
5848
7112
|
{
|
|
5849
7113
|
email,
|
|
@@ -5867,33 +7131,33 @@ function useUserService() {
|
|
|
5867
7131
|
const { updateStatusById: updateVerificationStatusById } = useVerificationRepo();
|
|
5868
7132
|
async function resetPassword(value) {
|
|
5869
7133
|
if (value.newPassword !== value.confirmPassword) {
|
|
5870
|
-
throw new
|
|
7134
|
+
throw new import_utils41.BadRequestError("Passwords do not match.");
|
|
5871
7135
|
}
|
|
5872
7136
|
let hashedPassword = "";
|
|
5873
7137
|
try {
|
|
5874
|
-
hashedPassword = await (0,
|
|
7138
|
+
hashedPassword = await (0, import_utils41.hashPassword)(value.newPassword);
|
|
5875
7139
|
} catch (error) {
|
|
5876
|
-
throw new
|
|
7140
|
+
throw new import_utils41.InternalServerError(`Error hashing password: ${error}`);
|
|
5877
7141
|
}
|
|
5878
|
-
const session =
|
|
7142
|
+
const session = import_utils41.useAtlas.getClient()?.startSession();
|
|
5879
7143
|
if (!session) {
|
|
5880
|
-
throw new
|
|
7144
|
+
throw new import_utils41.InternalServerError("Failed to start database session.");
|
|
5881
7145
|
}
|
|
5882
7146
|
try {
|
|
5883
7147
|
session.startTransaction();
|
|
5884
7148
|
const otpDoc = await getById(value.id);
|
|
5885
7149
|
if (!otpDoc) {
|
|
5886
|
-
throw new
|
|
7150
|
+
throw new import_utils41.NotFoundError("You are using an invalid reset link.");
|
|
5887
7151
|
}
|
|
5888
7152
|
const user = await getUserByEmail(otpDoc.email);
|
|
5889
7153
|
if (!user) {
|
|
5890
|
-
throw new
|
|
7154
|
+
throw new import_utils41.NotFoundError("User not found.");
|
|
5891
7155
|
}
|
|
5892
7156
|
if (!user._id) {
|
|
5893
|
-
throw new
|
|
7157
|
+
throw new import_utils41.NotFoundError("User ID is invalid.");
|
|
5894
7158
|
}
|
|
5895
7159
|
if (otpDoc.status === "used") {
|
|
5896
|
-
throw new
|
|
7160
|
+
throw new import_utils41.BadRequestError("This link has already been invalidated.");
|
|
5897
7161
|
}
|
|
5898
7162
|
await updateVerificationStatusById(value.id, "used", session);
|
|
5899
7163
|
await _updateUserFieldById(
|
|
@@ -5904,31 +7168,31 @@ function useUserService() {
|
|
|
5904
7168
|
return "Successfully reset password.";
|
|
5905
7169
|
} catch (error) {
|
|
5906
7170
|
await session.abortTransaction();
|
|
5907
|
-
if (error instanceof
|
|
7171
|
+
if (error instanceof import_utils41.AppError) {
|
|
5908
7172
|
throw error;
|
|
5909
7173
|
}
|
|
5910
|
-
throw new
|
|
7174
|
+
throw new import_utils41.InternalServerError("Failed to reset password.");
|
|
5911
7175
|
}
|
|
5912
7176
|
}
|
|
5913
7177
|
const { updateName: updateMemberName } = useMemberRepo();
|
|
5914
7178
|
async function updateName(_id, firstName, lastName) {
|
|
5915
7179
|
if (!_id) {
|
|
5916
|
-
throw new
|
|
7180
|
+
throw new import_utils41.BadRequestError("Invalid user ID");
|
|
5917
7181
|
}
|
|
5918
7182
|
if (!firstName) {
|
|
5919
|
-
throw new
|
|
7183
|
+
throw new import_utils41.BadRequestError("Invalid firstName");
|
|
5920
7184
|
}
|
|
5921
7185
|
if (!lastName) {
|
|
5922
|
-
throw new
|
|
7186
|
+
throw new import_utils41.BadRequestError("Invalid lastName");
|
|
5923
7187
|
}
|
|
5924
|
-
const session =
|
|
7188
|
+
const session = import_utils41.useAtlas.getClient()?.startSession();
|
|
5925
7189
|
session?.startTransaction();
|
|
5926
|
-
const cacheKey = (0,
|
|
7190
|
+
const cacheKey = (0, import_utils41.makeCacheKey)("users", { user: _id });
|
|
5927
7191
|
try {
|
|
5928
|
-
(0,
|
|
5929
|
-
|
|
7192
|
+
(0, import_utils41.useCache)().delCache(cacheKey).then(() => {
|
|
7193
|
+
import_utils41.logger.info(`Cache cleared for user: ${_id}`);
|
|
5930
7194
|
}).catch((error) => {
|
|
5931
|
-
|
|
7195
|
+
import_utils41.logger.error(`Failed to clear cache for user: ${_id}`, error);
|
|
5932
7196
|
});
|
|
5933
7197
|
await _updateName({ _id, firstName, lastName }, session);
|
|
5934
7198
|
await updateMemberName(
|
|
@@ -5946,16 +7210,16 @@ function useUserService() {
|
|
|
5946
7210
|
}
|
|
5947
7211
|
async function updateBirthday(_id, month, day, year) {
|
|
5948
7212
|
if (!_id) {
|
|
5949
|
-
throw new
|
|
7213
|
+
throw new import_utils41.BadRequestError("Invalid user ID");
|
|
5950
7214
|
}
|
|
5951
7215
|
if (!month) {
|
|
5952
|
-
throw new
|
|
7216
|
+
throw new import_utils41.BadRequestError("Invalid birth month.");
|
|
5953
7217
|
}
|
|
5954
7218
|
if (!day) {
|
|
5955
|
-
throw new
|
|
7219
|
+
throw new import_utils41.BadRequestError("Invalid birthday.");
|
|
5956
7220
|
}
|
|
5957
7221
|
if (!year) {
|
|
5958
|
-
throw new
|
|
7222
|
+
throw new import_utils41.BadRequestError("Invalid birth year.");
|
|
5959
7223
|
}
|
|
5960
7224
|
try {
|
|
5961
7225
|
await _updateBirthday({ _id, month, day, year });
|
|
@@ -5972,7 +7236,7 @@ function useUserService() {
|
|
|
5972
7236
|
}
|
|
5973
7237
|
}
|
|
5974
7238
|
const { createFile: _createFile, deleteFileById } = useFileRepo();
|
|
5975
|
-
const s3 = new
|
|
7239
|
+
const s3 = new import_utils41.useS3({
|
|
5976
7240
|
accessKeyId: SPACES_ACCESS_KEY,
|
|
5977
7241
|
secretAccessKey: SPACES_SECRET_KEY,
|
|
5978
7242
|
endpoint: SPACES_ENDPOINT,
|
|
@@ -5980,7 +7244,7 @@ function useUserService() {
|
|
|
5980
7244
|
bucket: SPACES_BUCKET
|
|
5981
7245
|
});
|
|
5982
7246
|
async function updateUserProfile({ file, user, previousProfile } = {}) {
|
|
5983
|
-
const session =
|
|
7247
|
+
const session = import_utils41.useAtlas.getClient()?.startSession();
|
|
5984
7248
|
session?.startTransaction();
|
|
5985
7249
|
const _file = {
|
|
5986
7250
|
name: file.originalname,
|
|
@@ -6024,8 +7288,8 @@ function useUserService() {
|
|
|
6024
7288
|
}
|
|
6025
7289
|
|
|
6026
7290
|
// src/resources/user/user.controller.ts
|
|
6027
|
-
var
|
|
6028
|
-
var
|
|
7291
|
+
var import_utils42 = require("@goweekdays/utils");
|
|
7292
|
+
var import_joi30 = __toESM(require("joi"));
|
|
6029
7293
|
function useUserController() {
|
|
6030
7294
|
const {
|
|
6031
7295
|
updateName: _updateName,
|
|
@@ -6041,14 +7305,14 @@ function useUserController() {
|
|
|
6041
7305
|
const status = req.query.status ?? "";
|
|
6042
7306
|
const search = req.query.search ?? "";
|
|
6043
7307
|
const page = Number(req.query.page) ?? 1;
|
|
6044
|
-
const validation =
|
|
6045
|
-
status:
|
|
6046
|
-
search:
|
|
6047
|
-
page:
|
|
7308
|
+
const validation = import_joi30.default.object({
|
|
7309
|
+
status: import_joi30.default.string().required(),
|
|
7310
|
+
search: import_joi30.default.string().optional().allow("", null),
|
|
7311
|
+
page: import_joi30.default.number().required()
|
|
6048
7312
|
});
|
|
6049
7313
|
const { error } = validation.validate({ status, search, page });
|
|
6050
7314
|
if (error) {
|
|
6051
|
-
next(new
|
|
7315
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
6052
7316
|
return;
|
|
6053
7317
|
}
|
|
6054
7318
|
try {
|
|
@@ -6061,14 +7325,14 @@ function useUserController() {
|
|
|
6061
7325
|
}
|
|
6062
7326
|
async function getUserById(req, res, next) {
|
|
6063
7327
|
const id = req.params.id || "";
|
|
6064
|
-
const validation =
|
|
7328
|
+
const validation = import_joi30.default.string().hex().validate(id);
|
|
6065
7329
|
if (validation.error) {
|
|
6066
|
-
throw new
|
|
7330
|
+
throw new import_utils42.BadRequestError("Invalid id.");
|
|
6067
7331
|
}
|
|
6068
7332
|
try {
|
|
6069
7333
|
const user = await _getUserById(id);
|
|
6070
7334
|
if (!user) {
|
|
6071
|
-
throw new
|
|
7335
|
+
throw new import_utils42.BadRequestError("User not found.");
|
|
6072
7336
|
}
|
|
6073
7337
|
res.json(user);
|
|
6074
7338
|
} catch (error) {
|
|
@@ -6079,13 +7343,13 @@ function useUserController() {
|
|
|
6079
7343
|
const id = req.headers.user ?? "";
|
|
6080
7344
|
const firstName = req.body.firstName ?? "";
|
|
6081
7345
|
const lastName = req.body.lastName ?? "";
|
|
6082
|
-
const validation =
|
|
6083
|
-
firstName:
|
|
6084
|
-
lastName:
|
|
7346
|
+
const validation = import_joi30.default.object({
|
|
7347
|
+
firstName: import_joi30.default.string().required(),
|
|
7348
|
+
lastName: import_joi30.default.string().required()
|
|
6085
7349
|
});
|
|
6086
7350
|
const { error } = validation.validate({ firstName, lastName });
|
|
6087
7351
|
if (error) {
|
|
6088
|
-
next(new
|
|
7352
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
6089
7353
|
return;
|
|
6090
7354
|
}
|
|
6091
7355
|
try {
|
|
@@ -6101,14 +7365,14 @@ function useUserController() {
|
|
|
6101
7365
|
const month = req.body.month ?? "";
|
|
6102
7366
|
const day = req.body.day ?? 0;
|
|
6103
7367
|
const year = req.body.year ?? 0;
|
|
6104
|
-
const validation =
|
|
6105
|
-
month:
|
|
6106
|
-
day:
|
|
6107
|
-
year:
|
|
7368
|
+
const validation = import_joi30.default.object({
|
|
7369
|
+
month: import_joi30.default.string().required(),
|
|
7370
|
+
day: import_joi30.default.number().integer().min(1).max(31).required(),
|
|
7371
|
+
year: import_joi30.default.number().integer().min(1900).max((/* @__PURE__ */ new Date()).getFullYear()).required()
|
|
6108
7372
|
});
|
|
6109
7373
|
const { error } = validation.validate({ month, day, year });
|
|
6110
7374
|
if (error) {
|
|
6111
|
-
next(new
|
|
7375
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
6112
7376
|
return;
|
|
6113
7377
|
}
|
|
6114
7378
|
try {
|
|
@@ -6122,18 +7386,18 @@ function useUserController() {
|
|
|
6122
7386
|
async function updateUserFieldById(req, res, next) {
|
|
6123
7387
|
const _id = req.params.id;
|
|
6124
7388
|
const { field, value } = req.body;
|
|
6125
|
-
const validation =
|
|
6126
|
-
_id:
|
|
6127
|
-
field:
|
|
6128
|
-
value:
|
|
7389
|
+
const validation = import_joi30.default.object({
|
|
7390
|
+
_id: import_joi30.default.string().hex().required(),
|
|
7391
|
+
field: import_joi30.default.string().valid("gender", "email", "contact", "profile").required(),
|
|
7392
|
+
value: import_joi30.default.alternatives().conditional("field", {
|
|
6129
7393
|
is: "email",
|
|
6130
|
-
then:
|
|
6131
|
-
otherwise:
|
|
7394
|
+
then: import_joi30.default.string().email().required(),
|
|
7395
|
+
otherwise: import_joi30.default.string().required()
|
|
6132
7396
|
})
|
|
6133
7397
|
});
|
|
6134
7398
|
const { error } = validation.validate({ _id, field, value });
|
|
6135
7399
|
if (error) {
|
|
6136
|
-
next(new
|
|
7400
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
6137
7401
|
return;
|
|
6138
7402
|
}
|
|
6139
7403
|
try {
|
|
@@ -6149,12 +7413,12 @@ function useUserController() {
|
|
|
6149
7413
|
return;
|
|
6150
7414
|
}
|
|
6151
7415
|
const previousProfile = req.body.previousProfile ?? "";
|
|
6152
|
-
const validation =
|
|
6153
|
-
previousProfile:
|
|
7416
|
+
const validation = import_joi30.default.object({
|
|
7417
|
+
previousProfile: import_joi30.default.string().hex().optional().allow("", null)
|
|
6154
7418
|
});
|
|
6155
7419
|
const { error } = validation.validate({ previousProfile });
|
|
6156
7420
|
if (error) {
|
|
6157
|
-
next(new
|
|
7421
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
6158
7422
|
return;
|
|
6159
7423
|
}
|
|
6160
7424
|
const user = req.headers["user"] ?? "";
|
|
@@ -6167,10 +7431,10 @@ function useUserController() {
|
|
|
6167
7431
|
res.json({ message: "Successfully updated profile picture." });
|
|
6168
7432
|
return;
|
|
6169
7433
|
} catch (error2) {
|
|
6170
|
-
if (error2 instanceof
|
|
7434
|
+
if (error2 instanceof import_utils42.AppError) {
|
|
6171
7435
|
next(error2);
|
|
6172
7436
|
} else {
|
|
6173
|
-
next(new
|
|
7437
|
+
next(new import_utils42.InternalServerError(error2));
|
|
6174
7438
|
}
|
|
6175
7439
|
}
|
|
6176
7440
|
}
|
|
@@ -6180,12 +7444,12 @@ function useUserController() {
|
|
|
6180
7444
|
const password = req.body.password ?? "";
|
|
6181
7445
|
const id = req.params.id ?? "";
|
|
6182
7446
|
const type = req.body.type ?? "";
|
|
6183
|
-
const validation =
|
|
6184
|
-
firstName:
|
|
6185
|
-
lastName:
|
|
6186
|
-
password:
|
|
6187
|
-
id:
|
|
6188
|
-
type:
|
|
7447
|
+
const validation = import_joi30.default.object({
|
|
7448
|
+
firstName: import_joi30.default.string().required(),
|
|
7449
|
+
lastName: import_joi30.default.string().required(),
|
|
7450
|
+
password: import_joi30.default.string().required(),
|
|
7451
|
+
id: import_joi30.default.string().hex().required(),
|
|
7452
|
+
type: import_joi30.default.string().required()
|
|
6189
7453
|
});
|
|
6190
7454
|
const { error } = validation.validate({
|
|
6191
7455
|
firstName,
|
|
@@ -6195,7 +7459,7 @@ function useUserController() {
|
|
|
6195
7459
|
type
|
|
6196
7460
|
});
|
|
6197
7461
|
if (error) {
|
|
6198
|
-
next(new
|
|
7462
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
6199
7463
|
return;
|
|
6200
7464
|
}
|
|
6201
7465
|
try {
|
|
@@ -6218,14 +7482,14 @@ function useUserController() {
|
|
|
6218
7482
|
}
|
|
6219
7483
|
async function resetPassword(req, res, next) {
|
|
6220
7484
|
const payload = req.body;
|
|
6221
|
-
const validation =
|
|
6222
|
-
id:
|
|
6223
|
-
newPassword:
|
|
6224
|
-
confirmPassword:
|
|
7485
|
+
const validation = import_joi30.default.object({
|
|
7486
|
+
id: import_joi30.default.string().hex().required(),
|
|
7487
|
+
newPassword: import_joi30.default.string().min(8).required(),
|
|
7488
|
+
confirmPassword: import_joi30.default.string().min(8).required()
|
|
6225
7489
|
});
|
|
6226
7490
|
const { error } = validation.validate(payload);
|
|
6227
7491
|
if (error) {
|
|
6228
|
-
next(new
|
|
7492
|
+
next(new import_utils42.BadRequestError(error.message));
|
|
6229
7493
|
return;
|
|
6230
7494
|
}
|
|
6231
7495
|
try {
|
|
@@ -6250,7 +7514,7 @@ function useUserController() {
|
|
|
6250
7514
|
}
|
|
6251
7515
|
|
|
6252
7516
|
// src/resources/verification/verification.service.ts
|
|
6253
|
-
var
|
|
7517
|
+
var import_joi31 = __toESM(require("joi"));
|
|
6254
7518
|
function useVerificationService() {
|
|
6255
7519
|
const MailerConfig = {
|
|
6256
7520
|
host: MAILER_TRANSPORT_HOST,
|
|
@@ -6259,7 +7523,7 @@ function useVerificationService() {
|
|
|
6259
7523
|
email: MAILER_EMAIL,
|
|
6260
7524
|
password: MAILER_PASSWORD
|
|
6261
7525
|
};
|
|
6262
|
-
const mailer = new
|
|
7526
|
+
const mailer = new import_utils43.useMailer(MailerConfig);
|
|
6263
7527
|
const {
|
|
6264
7528
|
add,
|
|
6265
7529
|
getById: _getById,
|
|
@@ -6285,7 +7549,7 @@ function useVerificationService() {
|
|
|
6285
7549
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
6286
7550
|
};
|
|
6287
7551
|
if (!metadata.app) {
|
|
6288
|
-
throw new
|
|
7552
|
+
throw new import_utils43.BadRequestError("App metadata is required.");
|
|
6289
7553
|
}
|
|
6290
7554
|
try {
|
|
6291
7555
|
const user = await getUserByEmail(email);
|
|
@@ -6293,8 +7557,8 @@ function useVerificationService() {
|
|
|
6293
7557
|
if (user) {
|
|
6294
7558
|
value.type = "member-invite";
|
|
6295
7559
|
const res2 = await add(value);
|
|
6296
|
-
const filePath2 = (0,
|
|
6297
|
-
const emailContent2 = (0,
|
|
7560
|
+
const filePath2 = (0, import_utils43.getDirectory)(dir, "./public/handlebars/member-invite");
|
|
7561
|
+
const emailContent2 = (0, import_utils43.compileHandlebar)({
|
|
6298
7562
|
context: {
|
|
6299
7563
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
6300
7564
|
link: `${APP_MAIN}/verify/member-invite/${res2}`,
|
|
@@ -6308,7 +7572,7 @@ function useVerificationService() {
|
|
|
6308
7572
|
html: emailContent2,
|
|
6309
7573
|
from: "GoWeekdays"
|
|
6310
7574
|
}).catch((error) => {
|
|
6311
|
-
|
|
7575
|
+
import_utils43.logger.log({
|
|
6312
7576
|
level: "error",
|
|
6313
7577
|
message: `Error sending user invite email: ${error}`
|
|
6314
7578
|
});
|
|
@@ -6316,8 +7580,8 @@ function useVerificationService() {
|
|
|
6316
7580
|
return res2;
|
|
6317
7581
|
}
|
|
6318
7582
|
const res = await add(value);
|
|
6319
|
-
const filePath = (0,
|
|
6320
|
-
const emailContent = (0,
|
|
7583
|
+
const filePath = (0, import_utils43.getDirectory)(dir, "./public/handlebars/user-invite");
|
|
7584
|
+
const emailContent = (0, import_utils43.compileHandlebar)({
|
|
6321
7585
|
context: {
|
|
6322
7586
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
6323
7587
|
link: `${APP_MAIN}/verify/invitation/${res}`
|
|
@@ -6330,7 +7594,7 @@ function useVerificationService() {
|
|
|
6330
7594
|
html: emailContent,
|
|
6331
7595
|
from: "GoWeekdays"
|
|
6332
7596
|
}).catch((error) => {
|
|
6333
|
-
|
|
7597
|
+
import_utils43.logger.log({
|
|
6334
7598
|
level: "error",
|
|
6335
7599
|
message: `Error sending user invite email: ${error}`
|
|
6336
7600
|
});
|
|
@@ -6351,8 +7615,8 @@ function useVerificationService() {
|
|
|
6351
7615
|
try {
|
|
6352
7616
|
const res = await add(value);
|
|
6353
7617
|
const dir = __dirname;
|
|
6354
|
-
const filePath = (0,
|
|
6355
|
-
const emailContent = (0,
|
|
7618
|
+
const filePath = (0, import_utils43.getDirectory)(dir, "./public/handlebars/forget-password");
|
|
7619
|
+
const emailContent = (0, import_utils43.compileHandlebar)({
|
|
6356
7620
|
context: {
|
|
6357
7621
|
validity: VERIFICATION_FORGET_PASSWORD_DURATION,
|
|
6358
7622
|
link: `${APP_MAIN}/reset-password/${res}`
|
|
@@ -6365,21 +7629,21 @@ function useVerificationService() {
|
|
|
6365
7629
|
from: "GoWeekdays",
|
|
6366
7630
|
html: emailContent
|
|
6367
7631
|
}).catch((error) => {
|
|
6368
|
-
|
|
7632
|
+
import_utils43.logger.log({
|
|
6369
7633
|
level: "error",
|
|
6370
7634
|
message: `Error sending forget password email: ${error}`
|
|
6371
7635
|
});
|
|
6372
7636
|
});
|
|
6373
7637
|
return "Successfully created a link to reset password. Please check your email.";
|
|
6374
7638
|
} catch (error) {
|
|
6375
|
-
throw new
|
|
7639
|
+
throw new import_utils43.InternalServerError("Failed to create forget password link.");
|
|
6376
7640
|
}
|
|
6377
7641
|
}
|
|
6378
7642
|
async function getById(id) {
|
|
6379
7643
|
try {
|
|
6380
7644
|
const _id = await _getById(id);
|
|
6381
7645
|
if (!_id) {
|
|
6382
|
-
throw new
|
|
7646
|
+
throw new import_utils43.NotFoundError("Verification not found.");
|
|
6383
7647
|
}
|
|
6384
7648
|
return _id;
|
|
6385
7649
|
} catch (error) {
|
|
@@ -6411,48 +7675,48 @@ function useVerificationService() {
|
|
|
6411
7675
|
}
|
|
6412
7676
|
function errorByType(type, status) {
|
|
6413
7677
|
if (type === "user-invite" && status === "expired") {
|
|
6414
|
-
throw new
|
|
7678
|
+
throw new import_utils43.BadRequestError(
|
|
6415
7679
|
"Invitation has already expired, please contact admin to resend the invitation."
|
|
6416
7680
|
);
|
|
6417
7681
|
}
|
|
6418
7682
|
if (type === "user-sign-up" && status === "expired") {
|
|
6419
|
-
throw new
|
|
7683
|
+
throw new import_utils43.BadRequestError(
|
|
6420
7684
|
"Sign up verification has expired, please sign up again to get a new verification link."
|
|
6421
7685
|
);
|
|
6422
7686
|
}
|
|
6423
7687
|
if (type === "user-invite" && status === "complete") {
|
|
6424
|
-
throw new
|
|
7688
|
+
throw new import_utils43.BadRequestError(
|
|
6425
7689
|
"User already registered, please login to continue."
|
|
6426
7690
|
);
|
|
6427
7691
|
}
|
|
6428
7692
|
if (type === "forget-password" && status === "complete") {
|
|
6429
|
-
throw new
|
|
7693
|
+
throw new import_utils43.BadRequestError(
|
|
6430
7694
|
"Forget password verification has already been used, please request a new one."
|
|
6431
7695
|
);
|
|
6432
7696
|
}
|
|
6433
7697
|
if (type === "forget-password" && status === "expired") {
|
|
6434
|
-
throw new
|
|
7698
|
+
throw new import_utils43.BadRequestError(
|
|
6435
7699
|
"Forget password verification has expired, please request a new one."
|
|
6436
7700
|
);
|
|
6437
7701
|
}
|
|
6438
|
-
throw new
|
|
7702
|
+
throw new import_utils43.BadRequestError("Invalid verification.");
|
|
6439
7703
|
}
|
|
6440
7704
|
async function verify(id) {
|
|
6441
|
-
const session =
|
|
7705
|
+
const session = import_utils43.useAtlas.getClient()?.startSession();
|
|
6442
7706
|
session?.startTransaction();
|
|
6443
7707
|
try {
|
|
6444
7708
|
const _id = await _getById(id);
|
|
6445
7709
|
if (!_id) {
|
|
6446
|
-
throw new
|
|
7710
|
+
throw new import_utils43.NotFoundError("Verification not found.");
|
|
6447
7711
|
}
|
|
6448
7712
|
if (_id.status === "expired") {
|
|
6449
7713
|
errorByType(_id.type, "expired");
|
|
6450
7714
|
}
|
|
6451
7715
|
if (_id.status === "complete") {
|
|
6452
|
-
throw new
|
|
7716
|
+
throw new import_utils43.BadRequestError("Verification already completed.");
|
|
6453
7717
|
}
|
|
6454
7718
|
if (!_id.expireAt) {
|
|
6455
|
-
throw new
|
|
7719
|
+
throw new import_utils43.BadRequestError("Expiration date is required.");
|
|
6456
7720
|
}
|
|
6457
7721
|
const expiration = new Date(_id.expireAt).getTime();
|
|
6458
7722
|
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
@@ -6465,15 +7729,15 @@ function useVerificationService() {
|
|
|
6465
7729
|
await _updateStatusById(id, "complete", session);
|
|
6466
7730
|
const user = await getUserByEmail(_id.email);
|
|
6467
7731
|
if (!user) {
|
|
6468
|
-
throw new
|
|
7732
|
+
throw new import_utils43.NotFoundError("User not found for member invite.");
|
|
6469
7733
|
}
|
|
6470
7734
|
if (!_id.metadata?.app) {
|
|
6471
|
-
throw new
|
|
7735
|
+
throw new import_utils43.BadRequestError(
|
|
6472
7736
|
"App metadata is required for member invite."
|
|
6473
7737
|
);
|
|
6474
7738
|
}
|
|
6475
7739
|
if (!_id.metadata?.role || !_id.metadata?.roleName) {
|
|
6476
|
-
throw new
|
|
7740
|
+
throw new import_utils43.BadRequestError(
|
|
6477
7741
|
"Role metadata is required for member invite."
|
|
6478
7742
|
);
|
|
6479
7743
|
}
|
|
@@ -6495,7 +7759,7 @@ function useVerificationService() {
|
|
|
6495
7759
|
return _id;
|
|
6496
7760
|
} catch (error) {
|
|
6497
7761
|
await session?.abortTransaction();
|
|
6498
|
-
|
|
7762
|
+
import_utils43.logger.log({
|
|
6499
7763
|
level: "info",
|
|
6500
7764
|
message: `Error verifying user invitation: ${error}`
|
|
6501
7765
|
});
|
|
@@ -6508,7 +7772,7 @@ function useVerificationService() {
|
|
|
6508
7772
|
try {
|
|
6509
7773
|
await updateStatusById(id, "cancelled");
|
|
6510
7774
|
} catch (error) {
|
|
6511
|
-
throw new
|
|
7775
|
+
throw new import_utils43.InternalServerError(
|
|
6512
7776
|
`Error cancelling user invitation: ${error}`
|
|
6513
7777
|
);
|
|
6514
7778
|
}
|
|
@@ -6528,7 +7792,7 @@ function useVerificationService() {
|
|
|
6528
7792
|
try {
|
|
6529
7793
|
const user = await getUserByEmail(email);
|
|
6530
7794
|
if (user) {
|
|
6531
|
-
throw new
|
|
7795
|
+
throw new import_utils43.BadRequestError(
|
|
6532
7796
|
`Email ${email} is already registered, please login to continue.`
|
|
6533
7797
|
);
|
|
6534
7798
|
}
|
|
@@ -6541,8 +7805,8 @@ function useVerificationService() {
|
|
|
6541
7805
|
};
|
|
6542
7806
|
const res = await add(value);
|
|
6543
7807
|
const dir = __dirname;
|
|
6544
|
-
const filePath = (0,
|
|
6545
|
-
const emailContent = (0,
|
|
7808
|
+
const filePath = (0, import_utils43.getDirectory)(dir, "./public/handlebars/sign-up");
|
|
7809
|
+
const emailContent = (0, import_utils43.compileHandlebar)({
|
|
6546
7810
|
context: {
|
|
6547
7811
|
validity: "5 minutes",
|
|
6548
7812
|
link: `${APP_MAIN}/sign-up/${res}`
|
|
@@ -6555,7 +7819,7 @@ function useVerificationService() {
|
|
|
6555
7819
|
html: emailContent,
|
|
6556
7820
|
from: "GoWeekdays"
|
|
6557
7821
|
}).catch((error) => {
|
|
6558
|
-
|
|
7822
|
+
import_utils43.logger.log({
|
|
6559
7823
|
level: "error",
|
|
6560
7824
|
message: `Error sending user invite email: ${error}`
|
|
6561
7825
|
});
|
|
@@ -6568,11 +7832,11 @@ function useVerificationService() {
|
|
|
6568
7832
|
async function inviteMember(value) {
|
|
6569
7833
|
const { error } = schemaInviteMember.validate(value);
|
|
6570
7834
|
if (error) {
|
|
6571
|
-
throw new
|
|
7835
|
+
throw new import_utils43.BadRequestError(error.message);
|
|
6572
7836
|
}
|
|
6573
7837
|
const role = await getRoleById(value.role);
|
|
6574
7838
|
if (!role) {
|
|
6575
|
-
throw new
|
|
7839
|
+
throw new import_utils43.NotFoundError("Role not found.");
|
|
6576
7840
|
}
|
|
6577
7841
|
let verificationData = {
|
|
6578
7842
|
type: "user-invite",
|
|
@@ -6590,15 +7854,15 @@ function useVerificationService() {
|
|
|
6590
7854
|
if (user) {
|
|
6591
7855
|
verificationData.type = "member-invite";
|
|
6592
7856
|
const verificationId2 = await add(verificationData);
|
|
6593
|
-
const filePath2 = (0,
|
|
7857
|
+
const filePath2 = (0, import_utils43.getDirectory)(dir, "./public/handlebars/member-invite");
|
|
6594
7858
|
let org = null;
|
|
6595
7859
|
if (verificationData.metadata.org) {
|
|
6596
7860
|
org = await getOrgById(verificationData.metadata.org);
|
|
6597
7861
|
if (!org) {
|
|
6598
|
-
throw new
|
|
7862
|
+
throw new import_utils43.NotFoundError("Organization not found.");
|
|
6599
7863
|
}
|
|
6600
7864
|
}
|
|
6601
|
-
const emailContent2 = (0,
|
|
7865
|
+
const emailContent2 = (0, import_utils43.compileHandlebar)({
|
|
6602
7866
|
context: {
|
|
6603
7867
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
6604
7868
|
link: `${APP_MAIN}/verify/member-invite/${verificationId2}`,
|
|
@@ -6612,7 +7876,7 @@ function useVerificationService() {
|
|
|
6612
7876
|
html: emailContent2,
|
|
6613
7877
|
from: "GoWeekdays"
|
|
6614
7878
|
}).catch((error2) => {
|
|
6615
|
-
|
|
7879
|
+
import_utils43.logger.log({
|
|
6616
7880
|
level: "error",
|
|
6617
7881
|
message: `Error sending user invite email: ${error2}`
|
|
6618
7882
|
});
|
|
@@ -6620,8 +7884,8 @@ function useVerificationService() {
|
|
|
6620
7884
|
return verificationId2;
|
|
6621
7885
|
}
|
|
6622
7886
|
const verificationId = await add(verificationData);
|
|
6623
|
-
const filePath = (0,
|
|
6624
|
-
const emailContent = (0,
|
|
7887
|
+
const filePath = (0, import_utils43.getDirectory)(dir, "./public/handlebars/user-invite");
|
|
7888
|
+
const emailContent = (0, import_utils43.compileHandlebar)({
|
|
6625
7889
|
context: {
|
|
6626
7890
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
6627
7891
|
link: `${APP_MAIN}/verify/invitation/${verificationId}`
|
|
@@ -6634,55 +7898,55 @@ function useVerificationService() {
|
|
|
6634
7898
|
html: emailContent,
|
|
6635
7899
|
from: "GoWeekdays"
|
|
6636
7900
|
}).catch((error2) => {
|
|
6637
|
-
|
|
7901
|
+
import_utils43.logger.log({
|
|
6638
7902
|
level: "error",
|
|
6639
7903
|
message: `Error sending user invite email: ${error2}`
|
|
6640
7904
|
});
|
|
6641
7905
|
});
|
|
6642
7906
|
return verificationId;
|
|
6643
7907
|
} catch (error2) {
|
|
6644
|
-
if (error2 instanceof
|
|
7908
|
+
if (error2 instanceof import_utils43.AppError) {
|
|
6645
7909
|
throw error2;
|
|
6646
7910
|
} else {
|
|
6647
|
-
throw new
|
|
7911
|
+
throw new import_utils43.InternalServerError("Failed to invite member.");
|
|
6648
7912
|
}
|
|
6649
7913
|
}
|
|
6650
7914
|
}
|
|
6651
7915
|
async function cancelInviteMember(id) {
|
|
6652
|
-
const { error } =
|
|
7916
|
+
const { error } = import_joi31.default.string().hex().required().validate(id);
|
|
6653
7917
|
if (error) {
|
|
6654
|
-
throw new
|
|
7918
|
+
throw new import_utils43.BadRequestError("Invalid verification ID.");
|
|
6655
7919
|
}
|
|
6656
7920
|
try {
|
|
6657
7921
|
const invite = await _getById(id);
|
|
6658
7922
|
if (!invite) {
|
|
6659
|
-
throw new
|
|
7923
|
+
throw new import_utils43.NotFoundError("Invitation not found.");
|
|
6660
7924
|
}
|
|
6661
7925
|
if (invite.status === "cancelled") {
|
|
6662
|
-
throw new
|
|
7926
|
+
throw new import_utils43.BadRequestError("Invitation already cancelled.");
|
|
6663
7927
|
}
|
|
6664
7928
|
if (invite.status === "complete") {
|
|
6665
|
-
throw new
|
|
7929
|
+
throw new import_utils43.BadRequestError("Cannot cancel a completed invitation.");
|
|
6666
7930
|
}
|
|
6667
7931
|
await _updateStatusById(id, "cancelled");
|
|
6668
7932
|
return "Successfully cancelled the invitation.";
|
|
6669
7933
|
} catch (error2) {
|
|
6670
|
-
if (error2 instanceof
|
|
7934
|
+
if (error2 instanceof import_utils43.AppError) {
|
|
6671
7935
|
throw error2;
|
|
6672
7936
|
} else {
|
|
6673
|
-
throw new
|
|
7937
|
+
throw new import_utils43.InternalServerError("Failed to cancel the invitation.");
|
|
6674
7938
|
}
|
|
6675
7939
|
}
|
|
6676
7940
|
}
|
|
6677
7941
|
async function forgetPassword(email) {
|
|
6678
|
-
const { error } =
|
|
7942
|
+
const { error } = import_joi31.default.string().email().required().validate(email);
|
|
6679
7943
|
if (error) {
|
|
6680
|
-
throw new
|
|
7944
|
+
throw new import_utils43.BadRequestError("Invalid email address.");
|
|
6681
7945
|
}
|
|
6682
7946
|
try {
|
|
6683
7947
|
const member = await getUserByEmail(email);
|
|
6684
7948
|
if (!member) {
|
|
6685
|
-
throw new
|
|
7949
|
+
throw new import_utils43.NotFoundError("User not found.");
|
|
6686
7950
|
}
|
|
6687
7951
|
const value = {
|
|
6688
7952
|
type: "forget-password",
|
|
@@ -6692,8 +7956,8 @@ function useVerificationService() {
|
|
|
6692
7956
|
};
|
|
6693
7957
|
const res = await add(value);
|
|
6694
7958
|
const dir = __dirname;
|
|
6695
|
-
const filePath = (0,
|
|
6696
|
-
const emailContent = (0,
|
|
7959
|
+
const filePath = (0, import_utils43.getDirectory)(dir, "./public/handlebars/forget-password");
|
|
7960
|
+
const emailContent = (0, import_utils43.compileHandlebar)({
|
|
6697
7961
|
context: {
|
|
6698
7962
|
validity: VERIFICATION_FORGET_PASSWORD_DURATION,
|
|
6699
7963
|
link: `${APP_MAIN}/reset-password/${res}`
|
|
@@ -6706,17 +7970,17 @@ function useVerificationService() {
|
|
|
6706
7970
|
from: "GoWeekdays",
|
|
6707
7971
|
html: emailContent
|
|
6708
7972
|
}).catch((error2) => {
|
|
6709
|
-
|
|
7973
|
+
import_utils43.logger.log({
|
|
6710
7974
|
level: "error",
|
|
6711
7975
|
message: `Error sending forget password email: ${error2}`
|
|
6712
7976
|
});
|
|
6713
7977
|
});
|
|
6714
7978
|
return "Successfully created a link to reset password. Please check your email.";
|
|
6715
7979
|
} catch (error2) {
|
|
6716
|
-
if (error2 instanceof
|
|
7980
|
+
if (error2 instanceof import_utils43.AppError) {
|
|
6717
7981
|
throw error2;
|
|
6718
7982
|
} else {
|
|
6719
|
-
throw new
|
|
7983
|
+
throw new import_utils43.InternalServerError(
|
|
6720
7984
|
"Failed to process forget password request."
|
|
6721
7985
|
);
|
|
6722
7986
|
}
|
|
@@ -6743,13 +8007,13 @@ function useAuthController() {
|
|
|
6743
8007
|
async function login(req, res, next) {
|
|
6744
8008
|
const email = req.body.email;
|
|
6745
8009
|
const password = req.body.password;
|
|
6746
|
-
const validation =
|
|
6747
|
-
email:
|
|
6748
|
-
password:
|
|
8010
|
+
const validation = import_joi32.default.object({
|
|
8011
|
+
email: import_joi32.default.string().email().required(),
|
|
8012
|
+
password: import_joi32.default.string().required()
|
|
6749
8013
|
});
|
|
6750
8014
|
const { error } = validation.validate({ email, password });
|
|
6751
8015
|
if (error) {
|
|
6752
|
-
next(new
|
|
8016
|
+
next(new import_utils44.BadRequestError(error.message));
|
|
6753
8017
|
return;
|
|
6754
8018
|
}
|
|
6755
8019
|
try {
|
|
@@ -6765,14 +8029,14 @@ function useAuthController() {
|
|
|
6765
8029
|
res.cookie("sid", session.sid, cookieOptions).cookie("user", session.user, cookieOptions).json({ message: "Login successful" });
|
|
6766
8030
|
return;
|
|
6767
8031
|
} catch (error2) {
|
|
6768
|
-
|
|
8032
|
+
import_utils44.logger.log({
|
|
6769
8033
|
level: "error",
|
|
6770
8034
|
message: `Error during login: ${error2.message}`
|
|
6771
8035
|
});
|
|
6772
|
-
if (error2 instanceof
|
|
8036
|
+
if (error2 instanceof import_utils44.AppError) {
|
|
6773
8037
|
next(error2);
|
|
6774
8038
|
} else {
|
|
6775
|
-
next(new
|
|
8039
|
+
next(new import_utils44.InternalServerError("An unexpected error occurred"));
|
|
6776
8040
|
}
|
|
6777
8041
|
return;
|
|
6778
8042
|
}
|
|
@@ -6780,17 +8044,17 @@ function useAuthController() {
|
|
|
6780
8044
|
async function logout(req, res, next) {
|
|
6781
8045
|
const sid = req.headers["authorization"] ?? "";
|
|
6782
8046
|
if (!sid) {
|
|
6783
|
-
next(new
|
|
8047
|
+
next(new import_utils44.BadRequestError("Session ID is required"));
|
|
6784
8048
|
return;
|
|
6785
8049
|
}
|
|
6786
8050
|
try {
|
|
6787
8051
|
await useAuthService().logout(sid);
|
|
6788
8052
|
res.json({ message: "Logged out successfully" });
|
|
6789
8053
|
} catch (error) {
|
|
6790
|
-
if (error instanceof
|
|
8054
|
+
if (error instanceof import_utils44.AppError) {
|
|
6791
8055
|
next(error);
|
|
6792
8056
|
} else {
|
|
6793
|
-
next(new
|
|
8057
|
+
next(new import_utils44.InternalServerError("An unexpected error occurred"));
|
|
6794
8058
|
}
|
|
6795
8059
|
}
|
|
6796
8060
|
}
|
|
@@ -6801,64 +8065,64 @@ function useAuthController() {
|
|
|
6801
8065
|
}
|
|
6802
8066
|
|
|
6803
8067
|
// src/resources/building/building.model.ts
|
|
6804
|
-
var
|
|
6805
|
-
var
|
|
6806
|
-
var
|
|
6807
|
-
var schemaBuilding =
|
|
6808
|
-
_id:
|
|
6809
|
-
school:
|
|
6810
|
-
serial:
|
|
6811
|
-
name:
|
|
6812
|
-
levels:
|
|
6813
|
-
createdAt:
|
|
6814
|
-
updatedAt:
|
|
6815
|
-
deletedAt:
|
|
6816
|
-
status:
|
|
8068
|
+
var import_utils45 = require("@goweekdays/utils");
|
|
8069
|
+
var import_joi33 = __toESM(require("joi"));
|
|
8070
|
+
var import_mongodb22 = require("mongodb");
|
|
8071
|
+
var schemaBuilding = import_joi33.default.object({
|
|
8072
|
+
_id: import_joi33.default.string().hex().optional(),
|
|
8073
|
+
school: import_joi33.default.string().hex().required(),
|
|
8074
|
+
serial: import_joi33.default.string().optional().allow("", null),
|
|
8075
|
+
name: import_joi33.default.string().required(),
|
|
8076
|
+
levels: import_joi33.default.number().integer().min(1).required(),
|
|
8077
|
+
createdAt: import_joi33.default.date().optional().allow("", null),
|
|
8078
|
+
updatedAt: import_joi33.default.date().optional().allow("", null),
|
|
8079
|
+
deletedAt: import_joi33.default.date().optional().allow("", null),
|
|
8080
|
+
status: import_joi33.default.string().optional().allow("", null)
|
|
6817
8081
|
});
|
|
6818
|
-
var schemaBuildingUnit =
|
|
6819
|
-
_id:
|
|
6820
|
-
school:
|
|
6821
|
-
name:
|
|
6822
|
-
building:
|
|
6823
|
-
buildingName:
|
|
6824
|
-
level:
|
|
6825
|
-
category:
|
|
6826
|
-
type:
|
|
6827
|
-
seating_capacity:
|
|
6828
|
-
standing_capacity:
|
|
6829
|
-
description:
|
|
6830
|
-
unit_of_measurement:
|
|
6831
|
-
area:
|
|
6832
|
-
status:
|
|
8082
|
+
var schemaBuildingUnit = import_joi33.default.object({
|
|
8083
|
+
_id: import_joi33.default.string().hex().optional(),
|
|
8084
|
+
school: import_joi33.default.string().hex().required(),
|
|
8085
|
+
name: import_joi33.default.string().optional().allow("", null),
|
|
8086
|
+
building: import_joi33.default.string().hex().required(),
|
|
8087
|
+
buildingName: import_joi33.default.string().optional().allow("", null),
|
|
8088
|
+
level: import_joi33.default.number().integer().min(1).required(),
|
|
8089
|
+
category: import_joi33.default.string().required(),
|
|
8090
|
+
type: import_joi33.default.string().required(),
|
|
8091
|
+
seating_capacity: import_joi33.default.number().integer().min(0).required(),
|
|
8092
|
+
standing_capacity: import_joi33.default.number().integer().min(0).required(),
|
|
8093
|
+
description: import_joi33.default.string().optional().allow("", null),
|
|
8094
|
+
unit_of_measurement: import_joi33.default.string().valid("sqm").required(),
|
|
8095
|
+
area: import_joi33.default.number().positive().required(),
|
|
8096
|
+
status: import_joi33.default.string().optional().allow("", null)
|
|
6833
8097
|
});
|
|
6834
|
-
var schemaUpdateOptions =
|
|
6835
|
-
name:
|
|
6836
|
-
building:
|
|
6837
|
-
buildingName:
|
|
6838
|
-
level:
|
|
6839
|
-
category:
|
|
6840
|
-
type:
|
|
6841
|
-
seating_capacity:
|
|
6842
|
-
standing_capacity:
|
|
6843
|
-
area:
|
|
8098
|
+
var schemaUpdateOptions = import_joi33.default.object({
|
|
8099
|
+
name: import_joi33.default.string().optional().allow("", null),
|
|
8100
|
+
building: import_joi33.default.string().hex().optional().allow("", null),
|
|
8101
|
+
buildingName: import_joi33.default.string().optional().allow("", null),
|
|
8102
|
+
level: import_joi33.default.number().integer().min(1).optional().allow("", null),
|
|
8103
|
+
category: import_joi33.default.string().optional().allow("", null),
|
|
8104
|
+
type: import_joi33.default.string().optional().allow("", null),
|
|
8105
|
+
seating_capacity: import_joi33.default.number().integer().min(0).optional().allow("", null),
|
|
8106
|
+
standing_capacity: import_joi33.default.number().integer().min(0).optional().allow("", null),
|
|
8107
|
+
area: import_joi33.default.number().positive().optional().allow("", null)
|
|
6844
8108
|
});
|
|
6845
8109
|
function MBuilding(value) {
|
|
6846
8110
|
const { error } = schemaBuilding.validate(value);
|
|
6847
8111
|
if (error) {
|
|
6848
|
-
|
|
6849
|
-
throw new
|
|
8112
|
+
import_utils45.logger.info(`Building Model: ${error.message}`);
|
|
8113
|
+
throw new import_utils45.BadRequestError(error.message);
|
|
6850
8114
|
}
|
|
6851
8115
|
if (value._id && typeof value._id === "string") {
|
|
6852
8116
|
try {
|
|
6853
|
-
value._id = new
|
|
8117
|
+
value._id = new import_mongodb22.ObjectId(value._id);
|
|
6854
8118
|
} catch (error2) {
|
|
6855
|
-
throw new
|
|
8119
|
+
throw new import_utils45.BadRequestError("Invalid _id format");
|
|
6856
8120
|
}
|
|
6857
8121
|
}
|
|
6858
8122
|
try {
|
|
6859
|
-
value.school = new
|
|
8123
|
+
value.school = new import_mongodb22.ObjectId(value.school);
|
|
6860
8124
|
} catch (error2) {
|
|
6861
|
-
throw new
|
|
8125
|
+
throw new import_utils45.BadRequestError("Invalid school format");
|
|
6862
8126
|
}
|
|
6863
8127
|
return {
|
|
6864
8128
|
_id: value._id ?? void 0,
|
|
@@ -6875,25 +8139,25 @@ function MBuilding(value) {
|
|
|
6875
8139
|
function MBuildingUnit(value) {
|
|
6876
8140
|
const { error } = schemaBuildingUnit.validate(value);
|
|
6877
8141
|
if (error) {
|
|
6878
|
-
|
|
6879
|
-
throw new
|
|
8142
|
+
import_utils45.logger.info(`Building Unit Model: ${error.message}`);
|
|
8143
|
+
throw new import_utils45.BadRequestError(error.message);
|
|
6880
8144
|
}
|
|
6881
8145
|
if (value._id && typeof value._id === "string") {
|
|
6882
8146
|
try {
|
|
6883
|
-
value._id = new
|
|
8147
|
+
value._id = new import_mongodb22.ObjectId(value._id);
|
|
6884
8148
|
} catch (error2) {
|
|
6885
|
-
throw new
|
|
8149
|
+
throw new import_utils45.BadRequestError("Invalid ID");
|
|
6886
8150
|
}
|
|
6887
8151
|
}
|
|
6888
8152
|
try {
|
|
6889
|
-
value.school = new
|
|
8153
|
+
value.school = new import_mongodb22.ObjectId(value.school);
|
|
6890
8154
|
} catch (error2) {
|
|
6891
|
-
throw new
|
|
8155
|
+
throw new import_utils45.BadRequestError("Invalid school ID");
|
|
6892
8156
|
}
|
|
6893
8157
|
try {
|
|
6894
|
-
value.building = new
|
|
8158
|
+
value.building = new import_mongodb22.ObjectId(value.building);
|
|
6895
8159
|
} catch (error2) {
|
|
6896
|
-
throw new
|
|
8160
|
+
throw new import_utils45.BadRequestError("Invalid building ID");
|
|
6897
8161
|
}
|
|
6898
8162
|
return {
|
|
6899
8163
|
_id: value._id ?? void 0,
|
|
@@ -6917,16 +8181,16 @@ function MBuildingUnit(value) {
|
|
|
6917
8181
|
}
|
|
6918
8182
|
|
|
6919
8183
|
// src/resources/building/building.repository.ts
|
|
6920
|
-
var
|
|
6921
|
-
var
|
|
8184
|
+
var import_utils46 = require("@goweekdays/utils");
|
|
8185
|
+
var import_mongodb23 = require("mongodb");
|
|
6922
8186
|
function useBuildingRepo() {
|
|
6923
|
-
const db =
|
|
8187
|
+
const db = import_utils46.useAtlas.getDb();
|
|
6924
8188
|
if (!db) {
|
|
6925
8189
|
throw new Error("Unable to connect to server.");
|
|
6926
8190
|
}
|
|
6927
8191
|
const namespace_collection = "school.buildings";
|
|
6928
8192
|
const collection = db.collection(namespace_collection);
|
|
6929
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
8193
|
+
const { getCache, setCache, delNamespace } = (0, import_utils46.useCache)(namespace_collection);
|
|
6930
8194
|
async function createIndexes() {
|
|
6931
8195
|
try {
|
|
6932
8196
|
await collection.createIndexes([
|
|
@@ -6939,7 +8203,7 @@ function useBuildingRepo() {
|
|
|
6939
8203
|
}
|
|
6940
8204
|
}
|
|
6941
8205
|
createIndexes().catch((error) => {
|
|
6942
|
-
|
|
8206
|
+
import_utils46.logger.log({ level: "error", message: `Index creation error: ${error}` });
|
|
6943
8207
|
});
|
|
6944
8208
|
async function add(value, session) {
|
|
6945
8209
|
try {
|
|
@@ -6948,16 +8212,16 @@ function useBuildingRepo() {
|
|
|
6948
8212
|
delCachedData();
|
|
6949
8213
|
return res.insertedId;
|
|
6950
8214
|
} catch (error) {
|
|
6951
|
-
|
|
8215
|
+
import_utils46.logger.log({
|
|
6952
8216
|
level: "error",
|
|
6953
8217
|
message: error.message
|
|
6954
8218
|
});
|
|
6955
|
-
if (error instanceof
|
|
8219
|
+
if (error instanceof import_utils46.AppError) {
|
|
6956
8220
|
throw error;
|
|
6957
8221
|
} else {
|
|
6958
8222
|
const isDuplicated = error.message.includes("duplicate");
|
|
6959
8223
|
if (isDuplicated) {
|
|
6960
|
-
throw new
|
|
8224
|
+
throw new import_utils46.BadRequestError("Building already exists.");
|
|
6961
8225
|
}
|
|
6962
8226
|
throw new Error("Failed to create building.");
|
|
6963
8227
|
}
|
|
@@ -6965,9 +8229,9 @@ function useBuildingRepo() {
|
|
|
6965
8229
|
}
|
|
6966
8230
|
async function updateById(_id, value, session) {
|
|
6967
8231
|
try {
|
|
6968
|
-
_id = new
|
|
8232
|
+
_id = new import_mongodb23.ObjectId(_id);
|
|
6969
8233
|
} catch (error) {
|
|
6970
|
-
throw new
|
|
8234
|
+
throw new import_utils46.BadRequestError("Invalid ID.");
|
|
6971
8235
|
}
|
|
6972
8236
|
try {
|
|
6973
8237
|
const res = await collection.updateOne(
|
|
@@ -6978,11 +8242,11 @@ function useBuildingRepo() {
|
|
|
6978
8242
|
delCachedData();
|
|
6979
8243
|
return res;
|
|
6980
8244
|
} catch (error) {
|
|
6981
|
-
|
|
8245
|
+
import_utils46.logger.log({
|
|
6982
8246
|
level: "error",
|
|
6983
8247
|
message: error.message
|
|
6984
8248
|
});
|
|
6985
|
-
if (error instanceof
|
|
8249
|
+
if (error instanceof import_utils46.AppError) {
|
|
6986
8250
|
throw error;
|
|
6987
8251
|
} else {
|
|
6988
8252
|
throw new Error("Failed to update building.");
|
|
@@ -7007,9 +8271,9 @@ function useBuildingRepo() {
|
|
|
7007
8271
|
}
|
|
7008
8272
|
if (school) {
|
|
7009
8273
|
try {
|
|
7010
|
-
query.school = new
|
|
8274
|
+
query.school = new import_mongodb23.ObjectId(school);
|
|
7011
8275
|
} catch (error) {
|
|
7012
|
-
throw new
|
|
8276
|
+
throw new import_utils46.BadRequestError("Invalid school ID.");
|
|
7013
8277
|
}
|
|
7014
8278
|
}
|
|
7015
8279
|
const cacheParams = {
|
|
@@ -7023,15 +8287,15 @@ function useBuildingRepo() {
|
|
|
7023
8287
|
cacheParams.school = school;
|
|
7024
8288
|
if (status !== "active")
|
|
7025
8289
|
cacheParams.status = status;
|
|
7026
|
-
const cacheKey = (0,
|
|
7027
|
-
|
|
8290
|
+
const cacheKey = (0, import_utils46.makeCacheKey)(namespace_collection, cacheParams);
|
|
8291
|
+
import_utils46.logger.log({
|
|
7028
8292
|
level: "info",
|
|
7029
8293
|
message: `Cache key for getAll buildings: ${cacheKey}`
|
|
7030
8294
|
});
|
|
7031
8295
|
try {
|
|
7032
8296
|
const cached = await getCache(cacheKey);
|
|
7033
8297
|
if (cached) {
|
|
7034
|
-
|
|
8298
|
+
import_utils46.logger.log({
|
|
7035
8299
|
level: "info",
|
|
7036
8300
|
message: `Cache hit for getAll buildings: ${cacheKey}`
|
|
7037
8301
|
});
|
|
@@ -7044,35 +8308,35 @@ function useBuildingRepo() {
|
|
|
7044
8308
|
{ $limit: limit }
|
|
7045
8309
|
]).toArray();
|
|
7046
8310
|
const length = await collection.countDocuments(query);
|
|
7047
|
-
const data = (0,
|
|
8311
|
+
const data = (0, import_utils46.paginate)(items, page, limit, length);
|
|
7048
8312
|
setCache(cacheKey, data, 600).then(() => {
|
|
7049
|
-
|
|
8313
|
+
import_utils46.logger.log({
|
|
7050
8314
|
level: "info",
|
|
7051
8315
|
message: `Cache set for getAll buildings: ${cacheKey}`
|
|
7052
8316
|
});
|
|
7053
8317
|
}).catch((err) => {
|
|
7054
|
-
|
|
8318
|
+
import_utils46.logger.log({
|
|
7055
8319
|
level: "error",
|
|
7056
8320
|
message: `Failed to set cache for getAll buildings: ${err.message}`
|
|
7057
8321
|
});
|
|
7058
8322
|
});
|
|
7059
8323
|
return data;
|
|
7060
8324
|
} catch (error) {
|
|
7061
|
-
|
|
8325
|
+
import_utils46.logger.log({ level: "error", message: `${error}` });
|
|
7062
8326
|
throw error;
|
|
7063
8327
|
}
|
|
7064
8328
|
}
|
|
7065
8329
|
async function getById(_id) {
|
|
7066
8330
|
try {
|
|
7067
|
-
_id = new
|
|
8331
|
+
_id = new import_mongodb23.ObjectId(_id);
|
|
7068
8332
|
} catch (error) {
|
|
7069
|
-
throw new
|
|
8333
|
+
throw new import_utils46.BadRequestError("Invalid ID.");
|
|
7070
8334
|
}
|
|
7071
|
-
const cacheKey = (0,
|
|
8335
|
+
const cacheKey = (0, import_utils46.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
7072
8336
|
try {
|
|
7073
8337
|
const cached = await getCache(cacheKey);
|
|
7074
8338
|
if (cached) {
|
|
7075
|
-
|
|
8339
|
+
import_utils46.logger.log({
|
|
7076
8340
|
level: "info",
|
|
7077
8341
|
message: `Cache hit for getById building: ${cacheKey}`
|
|
7078
8342
|
});
|
|
@@ -7082,30 +8346,30 @@ function useBuildingRepo() {
|
|
|
7082
8346
|
_id
|
|
7083
8347
|
});
|
|
7084
8348
|
setCache(cacheKey, result, 300).then(() => {
|
|
7085
|
-
|
|
8349
|
+
import_utils46.logger.log({
|
|
7086
8350
|
level: "info",
|
|
7087
8351
|
message: `Cache set for building by id: ${cacheKey}`
|
|
7088
8352
|
});
|
|
7089
8353
|
}).catch((err) => {
|
|
7090
|
-
|
|
8354
|
+
import_utils46.logger.log({
|
|
7091
8355
|
level: "error",
|
|
7092
8356
|
message: `Failed to set cache for building by id: ${err.message}`
|
|
7093
8357
|
});
|
|
7094
8358
|
});
|
|
7095
8359
|
return result;
|
|
7096
8360
|
} catch (error) {
|
|
7097
|
-
if (error instanceof
|
|
8361
|
+
if (error instanceof import_utils46.AppError) {
|
|
7098
8362
|
throw error;
|
|
7099
8363
|
} else {
|
|
7100
|
-
throw new
|
|
8364
|
+
throw new import_utils46.InternalServerError("Failed to get building.");
|
|
7101
8365
|
}
|
|
7102
8366
|
}
|
|
7103
8367
|
}
|
|
7104
8368
|
async function deleteById(_id, session) {
|
|
7105
8369
|
try {
|
|
7106
|
-
_id = new
|
|
8370
|
+
_id = new import_mongodb23.ObjectId(_id);
|
|
7107
8371
|
} catch (error) {
|
|
7108
|
-
throw new
|
|
8372
|
+
throw new import_utils46.BadRequestError("Invalid ID.");
|
|
7109
8373
|
}
|
|
7110
8374
|
try {
|
|
7111
8375
|
const res = await collection.updateOne(
|
|
@@ -7115,25 +8379,25 @@ function useBuildingRepo() {
|
|
|
7115
8379
|
delCachedData();
|
|
7116
8380
|
return res;
|
|
7117
8381
|
} catch (error) {
|
|
7118
|
-
|
|
8382
|
+
import_utils46.logger.log({
|
|
7119
8383
|
level: "error",
|
|
7120
8384
|
message: error.message
|
|
7121
8385
|
});
|
|
7122
|
-
if (error instanceof
|
|
8386
|
+
if (error instanceof import_utils46.AppError) {
|
|
7123
8387
|
throw error;
|
|
7124
8388
|
} else {
|
|
7125
|
-
throw new
|
|
8389
|
+
throw new import_utils46.InternalServerError("Failed to delete building.");
|
|
7126
8390
|
}
|
|
7127
8391
|
}
|
|
7128
8392
|
}
|
|
7129
8393
|
function delCachedData() {
|
|
7130
8394
|
delNamespace().then(() => {
|
|
7131
|
-
|
|
8395
|
+
import_utils46.logger.log({
|
|
7132
8396
|
level: "info",
|
|
7133
8397
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
7134
8398
|
});
|
|
7135
8399
|
}).catch((err) => {
|
|
7136
|
-
|
|
8400
|
+
import_utils46.logger.log({
|
|
7137
8401
|
level: "error",
|
|
7138
8402
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
7139
8403
|
});
|
|
@@ -7150,19 +8414,19 @@ function useBuildingRepo() {
|
|
|
7150
8414
|
}
|
|
7151
8415
|
|
|
7152
8416
|
// src/resources/building/building.service.ts
|
|
7153
|
-
var
|
|
8417
|
+
var import_utils48 = require("@goweekdays/utils");
|
|
7154
8418
|
|
|
7155
8419
|
// src/resources/building/building-unit.repository.ts
|
|
7156
|
-
var
|
|
7157
|
-
var
|
|
8420
|
+
var import_utils47 = require("@goweekdays/utils");
|
|
8421
|
+
var import_mongodb24 = require("mongodb");
|
|
7158
8422
|
function useBuildingUnitRepo() {
|
|
7159
|
-
const db =
|
|
8423
|
+
const db = import_utils47.useAtlas.getDb();
|
|
7160
8424
|
if (!db) {
|
|
7161
8425
|
throw new Error("Unable to connect to server.");
|
|
7162
8426
|
}
|
|
7163
8427
|
const namespace_collection = "school.building-units";
|
|
7164
8428
|
const collection = db.collection(namespace_collection);
|
|
7165
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
8429
|
+
const { getCache, setCache, delNamespace } = (0, import_utils47.useCache)(namespace_collection);
|
|
7166
8430
|
async function createIndexes() {
|
|
7167
8431
|
try {
|
|
7168
8432
|
await collection.createIndexes([
|
|
@@ -7190,12 +8454,12 @@ function useBuildingUnitRepo() {
|
|
|
7190
8454
|
}
|
|
7191
8455
|
function delCachedData() {
|
|
7192
8456
|
delNamespace().then(() => {
|
|
7193
|
-
|
|
8457
|
+
import_utils47.logger.log({
|
|
7194
8458
|
level: "info",
|
|
7195
8459
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
7196
8460
|
});
|
|
7197
8461
|
}).catch((err) => {
|
|
7198
|
-
|
|
8462
|
+
import_utils47.logger.log({
|
|
7199
8463
|
level: "error",
|
|
7200
8464
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
7201
8465
|
});
|
|
@@ -7208,11 +8472,11 @@ function useBuildingUnitRepo() {
|
|
|
7208
8472
|
delCachedData();
|
|
7209
8473
|
return res.insertedId;
|
|
7210
8474
|
} catch (error) {
|
|
7211
|
-
|
|
8475
|
+
import_utils47.logger.log({
|
|
7212
8476
|
level: "error",
|
|
7213
8477
|
message: error.message
|
|
7214
8478
|
});
|
|
7215
|
-
if (error instanceof
|
|
8479
|
+
if (error instanceof import_utils47.AppError) {
|
|
7216
8480
|
throw error;
|
|
7217
8481
|
} else {
|
|
7218
8482
|
throw new Error("Failed to create building unit.");
|
|
@@ -7222,12 +8486,12 @@ function useBuildingUnitRepo() {
|
|
|
7222
8486
|
async function updateById(_id, value, session) {
|
|
7223
8487
|
const { error } = schemaUpdateOptions.validate(value);
|
|
7224
8488
|
if (error) {
|
|
7225
|
-
throw new
|
|
8489
|
+
throw new import_utils47.BadRequestError(error.message);
|
|
7226
8490
|
}
|
|
7227
8491
|
try {
|
|
7228
|
-
_id = new
|
|
8492
|
+
_id = new import_mongodb24.ObjectId(_id);
|
|
7229
8493
|
} catch (error2) {
|
|
7230
|
-
throw new
|
|
8494
|
+
throw new import_utils47.BadRequestError("Invalid ID.");
|
|
7231
8495
|
}
|
|
7232
8496
|
try {
|
|
7233
8497
|
const res = await collection.updateOne(
|
|
@@ -7238,11 +8502,11 @@ function useBuildingUnitRepo() {
|
|
|
7238
8502
|
delCachedData();
|
|
7239
8503
|
return res;
|
|
7240
8504
|
} catch (error2) {
|
|
7241
|
-
|
|
8505
|
+
import_utils47.logger.log({
|
|
7242
8506
|
level: "error",
|
|
7243
8507
|
message: error2.message
|
|
7244
8508
|
});
|
|
7245
|
-
if (error2 instanceof
|
|
8509
|
+
if (error2 instanceof import_utils47.AppError) {
|
|
7246
8510
|
throw error2;
|
|
7247
8511
|
} else {
|
|
7248
8512
|
throw new Error("Failed to create building unit.");
|
|
@@ -7252,12 +8516,12 @@ function useBuildingUnitRepo() {
|
|
|
7252
8516
|
async function updateByBuildingId(building, value, session) {
|
|
7253
8517
|
const { error } = schemaUpdateOptions.validate(value);
|
|
7254
8518
|
if (error) {
|
|
7255
|
-
throw new
|
|
8519
|
+
throw new import_utils47.BadRequestError(error.message);
|
|
7256
8520
|
}
|
|
7257
8521
|
try {
|
|
7258
|
-
building = new
|
|
8522
|
+
building = new import_mongodb24.ObjectId(building);
|
|
7259
8523
|
} catch (error2) {
|
|
7260
|
-
throw new
|
|
8524
|
+
throw new import_utils47.BadRequestError("Invalid building ID.");
|
|
7261
8525
|
}
|
|
7262
8526
|
try {
|
|
7263
8527
|
const res = await collection.updateMany(
|
|
@@ -7268,11 +8532,11 @@ function useBuildingUnitRepo() {
|
|
|
7268
8532
|
delCachedData();
|
|
7269
8533
|
return res;
|
|
7270
8534
|
} catch (error2) {
|
|
7271
|
-
|
|
8535
|
+
import_utils47.logger.log({
|
|
7272
8536
|
level: "error",
|
|
7273
8537
|
message: error2.message
|
|
7274
8538
|
});
|
|
7275
|
-
if (error2 instanceof
|
|
8539
|
+
if (error2 instanceof import_utils47.AppError) {
|
|
7276
8540
|
throw error2;
|
|
7277
8541
|
} else {
|
|
7278
8542
|
throw new Error("Failed to update building unit.");
|
|
@@ -7299,16 +8563,16 @@ function useBuildingUnitRepo() {
|
|
|
7299
8563
|
}
|
|
7300
8564
|
if (school) {
|
|
7301
8565
|
try {
|
|
7302
|
-
query.school = new
|
|
8566
|
+
query.school = new import_mongodb24.ObjectId(school);
|
|
7303
8567
|
} catch (error) {
|
|
7304
|
-
throw new
|
|
8568
|
+
throw new import_utils47.BadRequestError("Invalid school ID.");
|
|
7305
8569
|
}
|
|
7306
8570
|
}
|
|
7307
8571
|
if (building) {
|
|
7308
8572
|
try {
|
|
7309
|
-
query.building = new
|
|
8573
|
+
query.building = new import_mongodb24.ObjectId(building);
|
|
7310
8574
|
} catch (error) {
|
|
7311
|
-
throw new
|
|
8575
|
+
throw new import_utils47.BadRequestError("Invalid building ID.");
|
|
7312
8576
|
}
|
|
7313
8577
|
}
|
|
7314
8578
|
const cacheParams = {
|
|
@@ -7324,15 +8588,15 @@ function useBuildingUnitRepo() {
|
|
|
7324
8588
|
cacheParams.building = building;
|
|
7325
8589
|
if (status !== "active")
|
|
7326
8590
|
cacheParams.status = status;
|
|
7327
|
-
const cacheKey = (0,
|
|
7328
|
-
|
|
8591
|
+
const cacheKey = (0, import_utils47.makeCacheKey)(namespace_collection, cacheParams);
|
|
8592
|
+
import_utils47.logger.log({
|
|
7329
8593
|
level: "info",
|
|
7330
8594
|
message: `Cache key for getAll building units: ${cacheKey}`
|
|
7331
8595
|
});
|
|
7332
8596
|
try {
|
|
7333
8597
|
const cached = await getCache(cacheKey);
|
|
7334
8598
|
if (cached) {
|
|
7335
|
-
|
|
8599
|
+
import_utils47.logger.log({
|
|
7336
8600
|
level: "info",
|
|
7337
8601
|
message: `Cache hit for getAll building units: ${cacheKey}`
|
|
7338
8602
|
});
|
|
@@ -7345,35 +8609,35 @@ function useBuildingUnitRepo() {
|
|
|
7345
8609
|
{ $limit: limit }
|
|
7346
8610
|
]).toArray();
|
|
7347
8611
|
const length = await collection.countDocuments(query);
|
|
7348
|
-
const data = (0,
|
|
8612
|
+
const data = (0, import_utils47.paginate)(items, page, limit, length);
|
|
7349
8613
|
setCache(cacheKey, data, 600).then(() => {
|
|
7350
|
-
|
|
8614
|
+
import_utils47.logger.log({
|
|
7351
8615
|
level: "info",
|
|
7352
8616
|
message: `Cache set for getAll building units: ${cacheKey}`
|
|
7353
8617
|
});
|
|
7354
8618
|
}).catch((err) => {
|
|
7355
|
-
|
|
8619
|
+
import_utils47.logger.log({
|
|
7356
8620
|
level: "error",
|
|
7357
8621
|
message: `Failed to set cache for getAll building units: ${err.message}`
|
|
7358
8622
|
});
|
|
7359
8623
|
});
|
|
7360
8624
|
return data;
|
|
7361
8625
|
} catch (error) {
|
|
7362
|
-
|
|
8626
|
+
import_utils47.logger.log({ level: "error", message: `${error}` });
|
|
7363
8627
|
throw error;
|
|
7364
8628
|
}
|
|
7365
8629
|
}
|
|
7366
8630
|
async function getById(_id) {
|
|
7367
8631
|
try {
|
|
7368
|
-
_id = new
|
|
8632
|
+
_id = new import_mongodb24.ObjectId(_id);
|
|
7369
8633
|
} catch (error) {
|
|
7370
|
-
throw new
|
|
8634
|
+
throw new import_utils47.BadRequestError("Invalid ID.");
|
|
7371
8635
|
}
|
|
7372
|
-
const cacheKey = (0,
|
|
8636
|
+
const cacheKey = (0, import_utils47.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
7373
8637
|
try {
|
|
7374
8638
|
const cached = await getCache(cacheKey);
|
|
7375
8639
|
if (cached) {
|
|
7376
|
-
|
|
8640
|
+
import_utils47.logger.log({
|
|
7377
8641
|
level: "info",
|
|
7378
8642
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
7379
8643
|
});
|
|
@@ -7384,42 +8648,42 @@ function useBuildingUnitRepo() {
|
|
|
7384
8648
|
deletedAt: { $in: ["", null] }
|
|
7385
8649
|
});
|
|
7386
8650
|
if (!result) {
|
|
7387
|
-
throw new
|
|
8651
|
+
throw new import_utils47.BadRequestError("Building unit not found.");
|
|
7388
8652
|
}
|
|
7389
8653
|
setCache(cacheKey, result, 300).then(() => {
|
|
7390
|
-
|
|
8654
|
+
import_utils47.logger.log({
|
|
7391
8655
|
level: "info",
|
|
7392
8656
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
7393
8657
|
});
|
|
7394
8658
|
}).catch((err) => {
|
|
7395
|
-
|
|
8659
|
+
import_utils47.logger.log({
|
|
7396
8660
|
level: "error",
|
|
7397
8661
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
7398
8662
|
});
|
|
7399
8663
|
});
|
|
7400
8664
|
return result;
|
|
7401
8665
|
} catch (error) {
|
|
7402
|
-
if (error instanceof
|
|
8666
|
+
if (error instanceof import_utils47.AppError) {
|
|
7403
8667
|
throw error;
|
|
7404
8668
|
} else {
|
|
7405
|
-
throw new
|
|
8669
|
+
throw new import_utils47.InternalServerError("Failed to get building unit.");
|
|
7406
8670
|
}
|
|
7407
8671
|
}
|
|
7408
8672
|
}
|
|
7409
8673
|
async function getByBuildingLevel(building, level) {
|
|
7410
8674
|
try {
|
|
7411
|
-
building = new
|
|
8675
|
+
building = new import_mongodb24.ObjectId(building);
|
|
7412
8676
|
} catch (error) {
|
|
7413
|
-
throw new
|
|
8677
|
+
throw new import_utils47.BadRequestError("Invalid building ID.");
|
|
7414
8678
|
}
|
|
7415
|
-
const cacheKey = (0,
|
|
8679
|
+
const cacheKey = (0, import_utils47.makeCacheKey)(namespace_collection, {
|
|
7416
8680
|
building: String(building),
|
|
7417
8681
|
level
|
|
7418
8682
|
});
|
|
7419
8683
|
try {
|
|
7420
8684
|
const cached = await getCache(cacheKey);
|
|
7421
8685
|
if (cached) {
|
|
7422
|
-
|
|
8686
|
+
import_utils47.logger.log({
|
|
7423
8687
|
level: "info",
|
|
7424
8688
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
7425
8689
|
});
|
|
@@ -7431,38 +8695,38 @@ function useBuildingUnitRepo() {
|
|
|
7431
8695
|
status: "active"
|
|
7432
8696
|
});
|
|
7433
8697
|
setCache(cacheKey, result, 300).then(() => {
|
|
7434
|
-
|
|
8698
|
+
import_utils47.logger.log({
|
|
7435
8699
|
level: "info",
|
|
7436
8700
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
7437
8701
|
});
|
|
7438
8702
|
}).catch((err) => {
|
|
7439
|
-
|
|
8703
|
+
import_utils47.logger.log({
|
|
7440
8704
|
level: "error",
|
|
7441
8705
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
7442
8706
|
});
|
|
7443
8707
|
});
|
|
7444
8708
|
return result;
|
|
7445
8709
|
} catch (error) {
|
|
7446
|
-
if (error instanceof
|
|
8710
|
+
if (error instanceof import_utils47.AppError) {
|
|
7447
8711
|
throw error;
|
|
7448
8712
|
} else {
|
|
7449
|
-
throw new
|
|
8713
|
+
throw new import_utils47.InternalServerError("Failed to get building unit.");
|
|
7450
8714
|
}
|
|
7451
8715
|
}
|
|
7452
8716
|
}
|
|
7453
8717
|
async function getByBuilding(building) {
|
|
7454
8718
|
try {
|
|
7455
|
-
building = new
|
|
8719
|
+
building = new import_mongodb24.ObjectId(building);
|
|
7456
8720
|
} catch (error) {
|
|
7457
|
-
throw new
|
|
8721
|
+
throw new import_utils47.BadRequestError("Invalid building ID.");
|
|
7458
8722
|
}
|
|
7459
|
-
const cacheKey = (0,
|
|
8723
|
+
const cacheKey = (0, import_utils47.makeCacheKey)(namespace_collection, {
|
|
7460
8724
|
building: String(building)
|
|
7461
8725
|
});
|
|
7462
8726
|
try {
|
|
7463
8727
|
const cached = await getCache(cacheKey);
|
|
7464
8728
|
if (cached) {
|
|
7465
|
-
|
|
8729
|
+
import_utils47.logger.log({
|
|
7466
8730
|
level: "info",
|
|
7467
8731
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
7468
8732
|
});
|
|
@@ -7473,30 +8737,30 @@ function useBuildingUnitRepo() {
|
|
|
7473
8737
|
status: "active"
|
|
7474
8738
|
});
|
|
7475
8739
|
setCache(cacheKey, result, 300).then(() => {
|
|
7476
|
-
|
|
8740
|
+
import_utils47.logger.log({
|
|
7477
8741
|
level: "info",
|
|
7478
8742
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
7479
8743
|
});
|
|
7480
8744
|
}).catch((err) => {
|
|
7481
|
-
|
|
8745
|
+
import_utils47.logger.log({
|
|
7482
8746
|
level: "error",
|
|
7483
8747
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
7484
8748
|
});
|
|
7485
8749
|
});
|
|
7486
8750
|
return result;
|
|
7487
8751
|
} catch (error) {
|
|
7488
|
-
if (error instanceof
|
|
8752
|
+
if (error instanceof import_utils47.AppError) {
|
|
7489
8753
|
throw error;
|
|
7490
8754
|
} else {
|
|
7491
|
-
throw new
|
|
8755
|
+
throw new import_utils47.InternalServerError("Failed to get building unit.");
|
|
7492
8756
|
}
|
|
7493
8757
|
}
|
|
7494
8758
|
}
|
|
7495
8759
|
async function deleteById(_id, session) {
|
|
7496
8760
|
try {
|
|
7497
|
-
_id = new
|
|
8761
|
+
_id = new import_mongodb24.ObjectId(_id);
|
|
7498
8762
|
} catch (error) {
|
|
7499
|
-
throw new
|
|
8763
|
+
throw new import_utils47.BadRequestError("Invalid ID.");
|
|
7500
8764
|
}
|
|
7501
8765
|
try {
|
|
7502
8766
|
const res = await collection.updateOne(
|
|
@@ -7507,11 +8771,11 @@ function useBuildingUnitRepo() {
|
|
|
7507
8771
|
delCachedData();
|
|
7508
8772
|
return "Room/Facility deleted successfully.";
|
|
7509
8773
|
} catch (error) {
|
|
7510
|
-
|
|
8774
|
+
import_utils47.logger.log({
|
|
7511
8775
|
level: "error",
|
|
7512
8776
|
message: error.message
|
|
7513
8777
|
});
|
|
7514
|
-
if (error instanceof
|
|
8778
|
+
if (error instanceof import_utils47.AppError) {
|
|
7515
8779
|
throw error;
|
|
7516
8780
|
} else {
|
|
7517
8781
|
throw new Error("Failed to deleted room/facility.");
|
|
@@ -7541,16 +8805,16 @@ function useBuildingService() {
|
|
|
7541
8805
|
const { getByBuildingLevel, getByBuilding, updateByBuildingId } = useBuildingUnitRepo();
|
|
7542
8806
|
async function updateById(id, data) {
|
|
7543
8807
|
data.levels = Number(data.levels);
|
|
7544
|
-
const session =
|
|
8808
|
+
const session = import_utils48.useAtlas.getClient()?.startSession();
|
|
7545
8809
|
try {
|
|
7546
8810
|
const building = await _getById(id);
|
|
7547
8811
|
if (!building) {
|
|
7548
|
-
throw new
|
|
8812
|
+
throw new import_utils48.NotFoundError("Building not found.");
|
|
7549
8813
|
}
|
|
7550
8814
|
if (data.levels < building.levels) {
|
|
7551
8815
|
const unit = await getByBuildingLevel(id, building.levels);
|
|
7552
8816
|
if (unit) {
|
|
7553
|
-
throw new
|
|
8817
|
+
throw new import_utils48.BadRequestError(
|
|
7554
8818
|
"Cannot reduce floors, there are existing building units at higher floors."
|
|
7555
8819
|
);
|
|
7556
8820
|
}
|
|
@@ -7572,7 +8836,7 @@ function useBuildingService() {
|
|
|
7572
8836
|
async function deleteById(id) {
|
|
7573
8837
|
const building = await getByBuilding(id);
|
|
7574
8838
|
if (building) {
|
|
7575
|
-
throw new
|
|
8839
|
+
throw new import_utils48.BadRequestError(
|
|
7576
8840
|
"Cannot delete building with existing room/facility. Please delete room/facility first."
|
|
7577
8841
|
);
|
|
7578
8842
|
}
|
|
@@ -7590,24 +8854,24 @@ function useBuildingService() {
|
|
|
7590
8854
|
}
|
|
7591
8855
|
|
|
7592
8856
|
// src/resources/building/building.controller.ts
|
|
7593
|
-
var
|
|
7594
|
-
var
|
|
8857
|
+
var import_utils49 = require("@goweekdays/utils");
|
|
8858
|
+
var import_joi34 = __toESM(require("joi"));
|
|
7595
8859
|
function useBuildingController() {
|
|
7596
8860
|
const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
|
|
7597
8861
|
const { updateById: _updateById, deleteById: _deleteById } = useBuildingService();
|
|
7598
8862
|
async function createBuilding(req, res, next) {
|
|
7599
8863
|
const value = req.body;
|
|
7600
|
-
const validation =
|
|
7601
|
-
name:
|
|
7602
|
-
school:
|
|
7603
|
-
levels:
|
|
7604
|
-
serial:
|
|
7605
|
-
status:
|
|
8864
|
+
const validation = import_joi34.default.object({
|
|
8865
|
+
name: import_joi34.default.string().required(),
|
|
8866
|
+
school: import_joi34.default.string().hex().required(),
|
|
8867
|
+
levels: import_joi34.default.number().integer().min(1).required(),
|
|
8868
|
+
serial: import_joi34.default.string().optional().allow("", null),
|
|
8869
|
+
status: import_joi34.default.string().optional().allow("", null)
|
|
7606
8870
|
});
|
|
7607
8871
|
const { error } = validation.validate(value);
|
|
7608
8872
|
if (error) {
|
|
7609
|
-
next(new
|
|
7610
|
-
|
|
8873
|
+
next(new import_utils49.BadRequestError(error.message));
|
|
8874
|
+
import_utils49.logger.info(`Controller: ${error.message}`);
|
|
7611
8875
|
return;
|
|
7612
8876
|
}
|
|
7613
8877
|
try {
|
|
@@ -7621,18 +8885,18 @@ function useBuildingController() {
|
|
|
7621
8885
|
async function updateById(req, res, next) {
|
|
7622
8886
|
const value = req.body;
|
|
7623
8887
|
const id = req.params.id ?? "";
|
|
7624
|
-
const validation =
|
|
7625
|
-
id:
|
|
7626
|
-
value:
|
|
7627
|
-
name:
|
|
7628
|
-
serial:
|
|
7629
|
-
levels:
|
|
8888
|
+
const validation = import_joi34.default.object({
|
|
8889
|
+
id: import_joi34.default.string().hex().required(),
|
|
8890
|
+
value: import_joi34.default.object({
|
|
8891
|
+
name: import_joi34.default.string().required(),
|
|
8892
|
+
serial: import_joi34.default.string().optional().allow("", null),
|
|
8893
|
+
levels: import_joi34.default.number().integer().min(1).required()
|
|
7630
8894
|
})
|
|
7631
8895
|
});
|
|
7632
8896
|
const { error } = validation.validate({ id, value });
|
|
7633
8897
|
if (error) {
|
|
7634
|
-
next(new
|
|
7635
|
-
|
|
8898
|
+
next(new import_utils49.BadRequestError(error.message));
|
|
8899
|
+
import_utils49.logger.info(`Controller: ${error.message}`);
|
|
7636
8900
|
return;
|
|
7637
8901
|
}
|
|
7638
8902
|
try {
|
|
@@ -7645,16 +8909,16 @@ function useBuildingController() {
|
|
|
7645
8909
|
}
|
|
7646
8910
|
async function getAll(req, res, next) {
|
|
7647
8911
|
const query = req.query;
|
|
7648
|
-
const validation =
|
|
7649
|
-
page:
|
|
7650
|
-
limit:
|
|
7651
|
-
search:
|
|
7652
|
-
school:
|
|
7653
|
-
status:
|
|
8912
|
+
const validation = import_joi34.default.object({
|
|
8913
|
+
page: import_joi34.default.number().min(1).optional().allow("", null),
|
|
8914
|
+
limit: import_joi34.default.number().min(1).optional().allow("", null),
|
|
8915
|
+
search: import_joi34.default.string().optional().allow("", null),
|
|
8916
|
+
school: import_joi34.default.string().hex().optional().allow("", null),
|
|
8917
|
+
status: import_joi34.default.string().optional().allow("", null)
|
|
7654
8918
|
});
|
|
7655
8919
|
const { error } = validation.validate(query);
|
|
7656
8920
|
if (error) {
|
|
7657
|
-
next(new
|
|
8921
|
+
next(new import_utils49.BadRequestError(error.message));
|
|
7658
8922
|
return;
|
|
7659
8923
|
}
|
|
7660
8924
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -7688,12 +8952,12 @@ function useBuildingController() {
|
|
|
7688
8952
|
}
|
|
7689
8953
|
async function getById(req, res, next) {
|
|
7690
8954
|
const id = req.params.id;
|
|
7691
|
-
const validation =
|
|
7692
|
-
id:
|
|
8955
|
+
const validation = import_joi34.default.object({
|
|
8956
|
+
id: import_joi34.default.string().hex().required()
|
|
7693
8957
|
});
|
|
7694
8958
|
const { error } = validation.validate({ id });
|
|
7695
8959
|
if (error) {
|
|
7696
|
-
next(new
|
|
8960
|
+
next(new import_utils49.BadRequestError(error.message));
|
|
7697
8961
|
return;
|
|
7698
8962
|
}
|
|
7699
8963
|
try {
|
|
@@ -7709,12 +8973,12 @@ function useBuildingController() {
|
|
|
7709
8973
|
}
|
|
7710
8974
|
async function deleteById(req, res, next) {
|
|
7711
8975
|
const id = req.params.id;
|
|
7712
|
-
const validation =
|
|
7713
|
-
id:
|
|
8976
|
+
const validation = import_joi34.default.object({
|
|
8977
|
+
id: import_joi34.default.string().hex().required()
|
|
7714
8978
|
});
|
|
7715
8979
|
const { error } = validation.validate({ id });
|
|
7716
8980
|
if (error) {
|
|
7717
|
-
next(new
|
|
8981
|
+
next(new import_utils49.BadRequestError(error.message));
|
|
7718
8982
|
return;
|
|
7719
8983
|
}
|
|
7720
8984
|
try {
|
|
@@ -7735,11 +8999,11 @@ function useBuildingController() {
|
|
|
7735
8999
|
}
|
|
7736
9000
|
|
|
7737
9001
|
// src/resources/building/building-unit.service.ts
|
|
7738
|
-
var
|
|
9002
|
+
var import_utils50 = require("@goweekdays/utils");
|
|
7739
9003
|
function useBuildingUnitService() {
|
|
7740
9004
|
const { add: _add } = useBuildingUnitRepo();
|
|
7741
9005
|
async function add(value) {
|
|
7742
|
-
const session =
|
|
9006
|
+
const session = import_utils50.useAtlas.getClient()?.startSession();
|
|
7743
9007
|
if (!session) {
|
|
7744
9008
|
throw new Error("Unable to start session for building unit service.");
|
|
7745
9009
|
}
|
|
@@ -7766,8 +9030,8 @@ function useBuildingUnitService() {
|
|
|
7766
9030
|
}
|
|
7767
9031
|
|
|
7768
9032
|
// src/resources/building/building-unit.controller.ts
|
|
7769
|
-
var
|
|
7770
|
-
var
|
|
9033
|
+
var import_utils51 = require("@goweekdays/utils");
|
|
9034
|
+
var import_joi35 = __toESM(require("joi"));
|
|
7771
9035
|
function useBuildingUnitController() {
|
|
7772
9036
|
const {
|
|
7773
9037
|
getAll: _getAll,
|
|
@@ -7778,27 +9042,27 @@ function useBuildingUnitController() {
|
|
|
7778
9042
|
const { add: _add } = useBuildingUnitService();
|
|
7779
9043
|
async function add(req, res, next) {
|
|
7780
9044
|
const data = req.body;
|
|
7781
|
-
const validation =
|
|
7782
|
-
building:
|
|
7783
|
-
school:
|
|
7784
|
-
name:
|
|
7785
|
-
building:
|
|
7786
|
-
buildingName:
|
|
7787
|
-
level:
|
|
7788
|
-
category:
|
|
7789
|
-
type:
|
|
7790
|
-
seating_capacity:
|
|
7791
|
-
standing_capacity:
|
|
7792
|
-
description:
|
|
7793
|
-
unit_of_measurement:
|
|
7794
|
-
area:
|
|
7795
|
-
status:
|
|
9045
|
+
const validation = import_joi35.default.object({
|
|
9046
|
+
building: import_joi35.default.object({
|
|
9047
|
+
school: import_joi35.default.string().hex().required(),
|
|
9048
|
+
name: import_joi35.default.string().optional().allow("", null),
|
|
9049
|
+
building: import_joi35.default.string().hex().required(),
|
|
9050
|
+
buildingName: import_joi35.default.string().optional().allow("", null),
|
|
9051
|
+
level: import_joi35.default.number().integer().min(1).required(),
|
|
9052
|
+
category: import_joi35.default.string().required(),
|
|
9053
|
+
type: import_joi35.default.string().required(),
|
|
9054
|
+
seating_capacity: import_joi35.default.number().integer().min(0).required(),
|
|
9055
|
+
standing_capacity: import_joi35.default.number().integer().min(0).required(),
|
|
9056
|
+
description: import_joi35.default.string().optional().allow("", null),
|
|
9057
|
+
unit_of_measurement: import_joi35.default.string().valid("sqm").required(),
|
|
9058
|
+
area: import_joi35.default.number().positive().required(),
|
|
9059
|
+
status: import_joi35.default.string().optional().allow("", null)
|
|
7796
9060
|
}),
|
|
7797
|
-
qty:
|
|
9061
|
+
qty: import_joi35.default.number().integer().min(1).max(20).optional().default(1)
|
|
7798
9062
|
});
|
|
7799
9063
|
const { error } = validation.validate(data);
|
|
7800
9064
|
if (error) {
|
|
7801
|
-
next(new
|
|
9065
|
+
next(new import_utils51.BadRequestError(error.message));
|
|
7802
9066
|
return;
|
|
7803
9067
|
}
|
|
7804
9068
|
try {
|
|
@@ -7814,13 +9078,13 @@ function useBuildingUnitController() {
|
|
|
7814
9078
|
async function updateById(req, res, next) {
|
|
7815
9079
|
const data = req.body;
|
|
7816
9080
|
const id = req.params.id ?? "";
|
|
7817
|
-
const validation =
|
|
7818
|
-
id:
|
|
9081
|
+
const validation = import_joi35.default.object({
|
|
9082
|
+
id: import_joi35.default.string().hex().required(),
|
|
7819
9083
|
value: schemaUpdateOptions
|
|
7820
9084
|
});
|
|
7821
9085
|
const { error } = validation.validate({ id, value: data });
|
|
7822
9086
|
if (error) {
|
|
7823
|
-
next(new
|
|
9087
|
+
next(new import_utils51.BadRequestError(error.message));
|
|
7824
9088
|
return;
|
|
7825
9089
|
}
|
|
7826
9090
|
try {
|
|
@@ -7835,17 +9099,17 @@ function useBuildingUnitController() {
|
|
|
7835
9099
|
}
|
|
7836
9100
|
async function getAll(req, res, next) {
|
|
7837
9101
|
const query = req.query;
|
|
7838
|
-
const validation =
|
|
7839
|
-
page:
|
|
7840
|
-
limit:
|
|
7841
|
-
search:
|
|
7842
|
-
school:
|
|
7843
|
-
building:
|
|
7844
|
-
status:
|
|
9102
|
+
const validation = import_joi35.default.object({
|
|
9103
|
+
page: import_joi35.default.number().min(1).optional().allow("", null),
|
|
9104
|
+
limit: import_joi35.default.number().min(1).optional().allow("", null),
|
|
9105
|
+
search: import_joi35.default.string().optional().allow("", null),
|
|
9106
|
+
school: import_joi35.default.string().hex().optional().allow("", null),
|
|
9107
|
+
building: import_joi35.default.string().hex().optional().allow("", null),
|
|
9108
|
+
status: import_joi35.default.string().optional().allow("", null)
|
|
7845
9109
|
});
|
|
7846
9110
|
const { error } = validation.validate(query);
|
|
7847
9111
|
if (error) {
|
|
7848
|
-
next(new
|
|
9112
|
+
next(new import_utils51.BadRequestError(error.message));
|
|
7849
9113
|
return;
|
|
7850
9114
|
}
|
|
7851
9115
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -7881,12 +9145,12 @@ function useBuildingUnitController() {
|
|
|
7881
9145
|
}
|
|
7882
9146
|
async function getById(req, res, next) {
|
|
7883
9147
|
const id = req.params.id;
|
|
7884
|
-
const validation =
|
|
7885
|
-
id:
|
|
9148
|
+
const validation = import_joi35.default.object({
|
|
9149
|
+
id: import_joi35.default.string().hex().required()
|
|
7886
9150
|
});
|
|
7887
9151
|
const { error } = validation.validate({ id });
|
|
7888
9152
|
if (error) {
|
|
7889
|
-
next(new
|
|
9153
|
+
next(new import_utils51.BadRequestError(error.message));
|
|
7890
9154
|
return;
|
|
7891
9155
|
}
|
|
7892
9156
|
try {
|
|
@@ -7902,12 +9166,12 @@ function useBuildingUnitController() {
|
|
|
7902
9166
|
}
|
|
7903
9167
|
async function deleteById(req, res, next) {
|
|
7904
9168
|
const id = req.params.id;
|
|
7905
|
-
const validation =
|
|
7906
|
-
id:
|
|
9169
|
+
const validation = import_joi35.default.object({
|
|
9170
|
+
id: import_joi35.default.string().hex().required()
|
|
7907
9171
|
});
|
|
7908
9172
|
const { error } = validation.validate({ id });
|
|
7909
9173
|
if (error) {
|
|
7910
|
-
next(new
|
|
9174
|
+
next(new import_utils51.BadRequestError(error.message));
|
|
7911
9175
|
return;
|
|
7912
9176
|
}
|
|
7913
9177
|
try {
|
|
@@ -7928,14 +9192,14 @@ function useBuildingUnitController() {
|
|
|
7928
9192
|
}
|
|
7929
9193
|
|
|
7930
9194
|
// src/resources/counter/counter.model.ts
|
|
7931
|
-
var
|
|
7932
|
-
var
|
|
9195
|
+
var import_utils52 = require("@goweekdays/utils");
|
|
9196
|
+
var import_mongodb25 = require("mongodb");
|
|
7933
9197
|
var import_zod = require("zod");
|
|
7934
9198
|
var TCounter = import_zod.z.object({
|
|
7935
9199
|
_id: import_zod.z.union([
|
|
7936
9200
|
import_zod.z.string().length(24, "Invalid ObjectId hex string"),
|
|
7937
|
-
import_zod.z.instanceof(
|
|
7938
|
-
]).transform((val) => typeof val === "string" ? new
|
|
9201
|
+
import_zod.z.instanceof(import_mongodb25.ObjectId)
|
|
9202
|
+
]).transform((val) => typeof val === "string" ? new import_mongodb25.ObjectId(val) : val).optional(),
|
|
7939
9203
|
count: import_zod.z.number().int().min(0).default(0),
|
|
7940
9204
|
type: import_zod.z.string(),
|
|
7941
9205
|
createdAt: import_zod.z.date().optional().default(() => /* @__PURE__ */ new Date()),
|
|
@@ -7948,7 +9212,7 @@ function useCounterModel(db) {
|
|
|
7948
9212
|
try {
|
|
7949
9213
|
return TCounter.parse(value);
|
|
7950
9214
|
} catch (error) {
|
|
7951
|
-
throw new
|
|
9215
|
+
throw new import_utils52.BadRequestError(error.issues[0].message);
|
|
7952
9216
|
}
|
|
7953
9217
|
}
|
|
7954
9218
|
function validateCounter(data) {
|
|
@@ -7962,23 +9226,23 @@ function useCounterModel(db) {
|
|
|
7962
9226
|
}
|
|
7963
9227
|
|
|
7964
9228
|
// src/resources/counter/counter.repository.ts
|
|
7965
|
-
var
|
|
9229
|
+
var import_utils53 = require("@goweekdays/utils");
|
|
7966
9230
|
function useCounterRepo() {
|
|
7967
|
-
const db =
|
|
9231
|
+
const db = import_utils53.useAtlas.getDb();
|
|
7968
9232
|
if (!db) {
|
|
7969
9233
|
throw new Error("Unable to connect to server.");
|
|
7970
9234
|
}
|
|
7971
9235
|
const namespace_collection = "counters";
|
|
7972
9236
|
const { collection, createCounter } = useCounterModel(db);
|
|
7973
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
9237
|
+
const { getCache, setCache, delNamespace } = (0, import_utils53.useCache)(namespace_collection);
|
|
7974
9238
|
function delCachedData() {
|
|
7975
9239
|
delNamespace().then(() => {
|
|
7976
|
-
|
|
9240
|
+
import_utils53.logger.log({
|
|
7977
9241
|
level: "info",
|
|
7978
9242
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
7979
9243
|
});
|
|
7980
9244
|
}).catch((err) => {
|
|
7981
|
-
|
|
9245
|
+
import_utils53.logger.log({
|
|
7982
9246
|
level: "error",
|
|
7983
9247
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
7984
9248
|
});
|
|
@@ -8030,11 +9294,11 @@ function useCounterRepo() {
|
|
|
8030
9294
|
}
|
|
8031
9295
|
}
|
|
8032
9296
|
async function getByType(type) {
|
|
8033
|
-
const cacheKey = (0,
|
|
9297
|
+
const cacheKey = (0, import_utils53.makeCacheKey)(namespace_collection, { type });
|
|
8034
9298
|
try {
|
|
8035
9299
|
const cached = await getCache(cacheKey);
|
|
8036
9300
|
if (cached) {
|
|
8037
|
-
|
|
9301
|
+
import_utils53.logger.log({
|
|
8038
9302
|
level: "info",
|
|
8039
9303
|
message: `Cache hit for getByType counter: ${cacheKey}`
|
|
8040
9304
|
});
|
|
@@ -8043,12 +9307,12 @@ function useCounterRepo() {
|
|
|
8043
9307
|
const data = await collection.findOne({ type });
|
|
8044
9308
|
if (data) {
|
|
8045
9309
|
setCache(cacheKey, data, 300).then(() => {
|
|
8046
|
-
|
|
9310
|
+
import_utils53.logger.log({
|
|
8047
9311
|
level: "info",
|
|
8048
9312
|
message: `Cache set for counter by type: ${cacheKey}`
|
|
8049
9313
|
});
|
|
8050
9314
|
}).catch((err) => {
|
|
8051
|
-
|
|
9315
|
+
import_utils53.logger.log({
|
|
8052
9316
|
level: "error",
|
|
8053
9317
|
message: `Failed to set cache for counter by type: ${err.message}`
|
|
8054
9318
|
});
|
|
@@ -8069,7 +9333,7 @@ function useCounterRepo() {
|
|
|
8069
9333
|
}
|
|
8070
9334
|
|
|
8071
9335
|
// src/resources/file/file.service.ts
|
|
8072
|
-
var
|
|
9336
|
+
var import_utils54 = require("@goweekdays/utils");
|
|
8073
9337
|
var import_node_cron = __toESM(require("node-cron"));
|
|
8074
9338
|
var fs = __toESM(require("fs"));
|
|
8075
9339
|
function useFileService() {
|
|
@@ -8078,7 +9342,7 @@ function useFileService() {
|
|
|
8078
9342
|
deleteFileById,
|
|
8079
9343
|
getAllDraftedFiles
|
|
8080
9344
|
} = useFileRepo();
|
|
8081
|
-
const s3 = new
|
|
9345
|
+
const s3 = new import_utils54.useS3({
|
|
8082
9346
|
accessKeyId: SPACES_ACCESS_KEY,
|
|
8083
9347
|
secretAccessKey: SPACES_SECRET_KEY,
|
|
8084
9348
|
endpoint: SPACES_ENDPOINT,
|
|
@@ -8087,7 +9351,7 @@ function useFileService() {
|
|
|
8087
9351
|
forcePathStyle: true
|
|
8088
9352
|
});
|
|
8089
9353
|
async function createFile(value) {
|
|
8090
|
-
const session =
|
|
9354
|
+
const session = import_utils54.useAtlas.getClient()?.startSession();
|
|
8091
9355
|
session?.startTransaction();
|
|
8092
9356
|
const file = {
|
|
8093
9357
|
name: value.originalname,
|
|
@@ -8121,7 +9385,7 @@ function useFileService() {
|
|
|
8121
9385
|
}
|
|
8122
9386
|
}
|
|
8123
9387
|
async function deleteFile(id) {
|
|
8124
|
-
const session =
|
|
9388
|
+
const session = import_utils54.useAtlas.getClient()?.startSession();
|
|
8125
9389
|
session?.startTransaction();
|
|
8126
9390
|
try {
|
|
8127
9391
|
await deleteFileById(id, session);
|
|
@@ -8142,12 +9406,12 @@ function useFileService() {
|
|
|
8142
9406
|
const file = files[index];
|
|
8143
9407
|
try {
|
|
8144
9408
|
await deleteFile(file._id.toString());
|
|
8145
|
-
await
|
|
9409
|
+
await import_utils54.logger.log({
|
|
8146
9410
|
level: "info",
|
|
8147
9411
|
message: "Successfully deleted draft files."
|
|
8148
9412
|
});
|
|
8149
9413
|
} catch (error) {
|
|
8150
|
-
|
|
9414
|
+
import_utils54.logger.log({
|
|
8151
9415
|
level: "info",
|
|
8152
9416
|
message: "Successfully deleted draft files."
|
|
8153
9417
|
});
|
|
@@ -8164,8 +9428,8 @@ function useFileService() {
|
|
|
8164
9428
|
}
|
|
8165
9429
|
|
|
8166
9430
|
// src/resources/file/file.controller.ts
|
|
8167
|
-
var
|
|
8168
|
-
var
|
|
9431
|
+
var import_utils55 = require("@goweekdays/utils");
|
|
9432
|
+
var import_joi36 = __toESM(require("joi"));
|
|
8169
9433
|
function useFileController() {
|
|
8170
9434
|
const { createFile, deleteFile: _deleteFile } = useFileService();
|
|
8171
9435
|
async function upload(req, res, next) {
|
|
@@ -8178,29 +9442,29 @@ function useFileController() {
|
|
|
8178
9442
|
res.json({ message: "Successfully uploaded file", id });
|
|
8179
9443
|
return;
|
|
8180
9444
|
} catch (error) {
|
|
8181
|
-
if (error instanceof
|
|
9445
|
+
if (error instanceof import_utils55.AppError) {
|
|
8182
9446
|
next(error);
|
|
8183
9447
|
} else {
|
|
8184
|
-
next(new
|
|
9448
|
+
next(new import_utils55.InternalServerError(error));
|
|
8185
9449
|
}
|
|
8186
9450
|
}
|
|
8187
9451
|
}
|
|
8188
9452
|
async function deleteFile(req, res, next) {
|
|
8189
9453
|
const id = req.params.id;
|
|
8190
|
-
const validation =
|
|
9454
|
+
const validation = import_joi36.default.string().required();
|
|
8191
9455
|
const { error } = validation.validate(id);
|
|
8192
9456
|
if (error) {
|
|
8193
|
-
next(new
|
|
9457
|
+
next(new import_utils55.BadRequestError(error.message));
|
|
8194
9458
|
}
|
|
8195
9459
|
try {
|
|
8196
9460
|
const message = await _deleteFile(id);
|
|
8197
9461
|
res.json({ message });
|
|
8198
9462
|
return;
|
|
8199
9463
|
} catch (error2) {
|
|
8200
|
-
if (error2 instanceof
|
|
9464
|
+
if (error2 instanceof import_utils55.AppError) {
|
|
8201
9465
|
next(error2);
|
|
8202
9466
|
} else {
|
|
8203
|
-
next(new
|
|
9467
|
+
next(new import_utils55.InternalServerError(error2));
|
|
8204
9468
|
}
|
|
8205
9469
|
}
|
|
8206
9470
|
}
|
|
@@ -8211,11 +9475,11 @@ function useFileController() {
|
|
|
8211
9475
|
}
|
|
8212
9476
|
|
|
8213
9477
|
// src/resources/psgc/psgc.model.ts
|
|
8214
|
-
var
|
|
8215
|
-
var schemaPSGC =
|
|
8216
|
-
code:
|
|
8217
|
-
name:
|
|
8218
|
-
type:
|
|
9478
|
+
var import_joi37 = __toESM(require("joi"));
|
|
9479
|
+
var schemaPSGC = import_joi37.default.object({
|
|
9480
|
+
code: import_joi37.default.string().length(10).required(),
|
|
9481
|
+
name: import_joi37.default.string().required(),
|
|
9482
|
+
type: import_joi37.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required()
|
|
8219
9483
|
});
|
|
8220
9484
|
function modelPSGC(data) {
|
|
8221
9485
|
const { error } = schemaPSGC.validate(data);
|
|
@@ -8230,16 +9494,16 @@ function modelPSGC(data) {
|
|
|
8230
9494
|
}
|
|
8231
9495
|
|
|
8232
9496
|
// src/resources/psgc/psgc.repository.ts
|
|
8233
|
-
var
|
|
8234
|
-
var
|
|
9497
|
+
var import_utils56 = require("@goweekdays/utils");
|
|
9498
|
+
var import_mongodb26 = require("mongodb");
|
|
8235
9499
|
function usePSGCRepo() {
|
|
8236
|
-
const db =
|
|
9500
|
+
const db = import_utils56.useAtlas.getDb();
|
|
8237
9501
|
if (!db) {
|
|
8238
9502
|
throw new Error("Unable to connect to server.");
|
|
8239
9503
|
}
|
|
8240
9504
|
const namespace_collection = "psgc";
|
|
8241
9505
|
const collection = db.collection(namespace_collection);
|
|
8242
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
9506
|
+
const { getCache, setCache, delNamespace } = (0, import_utils56.useCache)(namespace_collection);
|
|
8243
9507
|
async function createIndexes() {
|
|
8244
9508
|
try {
|
|
8245
9509
|
await collection.createIndexes([
|
|
@@ -8253,12 +9517,12 @@ function usePSGCRepo() {
|
|
|
8253
9517
|
}
|
|
8254
9518
|
function delCachedData() {
|
|
8255
9519
|
delNamespace().then(() => {
|
|
8256
|
-
|
|
9520
|
+
import_utils56.logger.log({
|
|
8257
9521
|
level: "info",
|
|
8258
9522
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
8259
9523
|
});
|
|
8260
9524
|
}).catch((err) => {
|
|
8261
|
-
|
|
9525
|
+
import_utils56.logger.log({
|
|
8262
9526
|
level: "error",
|
|
8263
9527
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
8264
9528
|
});
|
|
@@ -8271,16 +9535,16 @@ function usePSGCRepo() {
|
|
|
8271
9535
|
delCachedData();
|
|
8272
9536
|
return res.insertedId;
|
|
8273
9537
|
} catch (error) {
|
|
8274
|
-
|
|
9538
|
+
import_utils56.logger.log({
|
|
8275
9539
|
level: "error",
|
|
8276
9540
|
message: error.message
|
|
8277
9541
|
});
|
|
8278
|
-
if (error instanceof
|
|
9542
|
+
if (error instanceof import_utils56.AppError) {
|
|
8279
9543
|
throw error;
|
|
8280
9544
|
} else {
|
|
8281
9545
|
const isDuplicated = error.message.includes("duplicate");
|
|
8282
9546
|
if (isDuplicated) {
|
|
8283
|
-
throw new
|
|
9547
|
+
throw new import_utils56.BadRequestError("Region already exists.");
|
|
8284
9548
|
}
|
|
8285
9549
|
throw new Error("Failed to create PSGC.");
|
|
8286
9550
|
}
|
|
@@ -8316,15 +9580,15 @@ function usePSGCRepo() {
|
|
|
8316
9580
|
query.$text = { $search: search };
|
|
8317
9581
|
cacheKeyOptions.search = search;
|
|
8318
9582
|
}
|
|
8319
|
-
const cacheKey = (0,
|
|
8320
|
-
|
|
9583
|
+
const cacheKey = (0, import_utils56.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
9584
|
+
import_utils56.logger.log({
|
|
8321
9585
|
level: "info",
|
|
8322
9586
|
message: `Cache key for getAll PSGC: ${cacheKey}`
|
|
8323
9587
|
});
|
|
8324
9588
|
try {
|
|
8325
9589
|
const cached = await getCache(cacheKey);
|
|
8326
9590
|
if (cached) {
|
|
8327
|
-
|
|
9591
|
+
import_utils56.logger.log({
|
|
8328
9592
|
level: "info",
|
|
8329
9593
|
message: `Cache hit for getAll PSGC: ${cacheKey}`
|
|
8330
9594
|
});
|
|
@@ -8337,35 +9601,35 @@ function usePSGCRepo() {
|
|
|
8337
9601
|
{ $limit: limit }
|
|
8338
9602
|
]).toArray();
|
|
8339
9603
|
const length = await collection.countDocuments(query);
|
|
8340
|
-
const data = (0,
|
|
9604
|
+
const data = (0, import_utils56.paginate)(items, page, limit, length);
|
|
8341
9605
|
setCache(cacheKey, data, 600).then(() => {
|
|
8342
|
-
|
|
9606
|
+
import_utils56.logger.log({
|
|
8343
9607
|
level: "info",
|
|
8344
9608
|
message: `Cache set for getAll PSGC: ${cacheKey}`
|
|
8345
9609
|
});
|
|
8346
9610
|
}).catch((err) => {
|
|
8347
|
-
|
|
9611
|
+
import_utils56.logger.log({
|
|
8348
9612
|
level: "error",
|
|
8349
9613
|
message: `Failed to set cache for getAll PSGC: ${err.message}`
|
|
8350
9614
|
});
|
|
8351
9615
|
});
|
|
8352
9616
|
return data;
|
|
8353
9617
|
} catch (error) {
|
|
8354
|
-
|
|
9618
|
+
import_utils56.logger.log({ level: "error", message: `${error}` });
|
|
8355
9619
|
throw error;
|
|
8356
9620
|
}
|
|
8357
9621
|
}
|
|
8358
9622
|
async function getById(_id) {
|
|
8359
9623
|
try {
|
|
8360
|
-
_id = new
|
|
9624
|
+
_id = new import_mongodb26.ObjectId(_id);
|
|
8361
9625
|
} catch (error) {
|
|
8362
|
-
throw new
|
|
9626
|
+
throw new import_utils56.BadRequestError("Invalid ID.");
|
|
8363
9627
|
}
|
|
8364
|
-
const cacheKey = (0,
|
|
9628
|
+
const cacheKey = (0, import_utils56.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
8365
9629
|
try {
|
|
8366
9630
|
const cached = await getCache(cacheKey);
|
|
8367
9631
|
if (cached) {
|
|
8368
|
-
|
|
9632
|
+
import_utils56.logger.log({
|
|
8369
9633
|
level: "info",
|
|
8370
9634
|
message: `Cache hit for getById PSGC: ${cacheKey}`
|
|
8371
9635
|
});
|
|
@@ -8376,25 +9640,25 @@ function usePSGCRepo() {
|
|
|
8376
9640
|
deletedAt: { $in: ["", null] }
|
|
8377
9641
|
});
|
|
8378
9642
|
if (!result) {
|
|
8379
|
-
throw new
|
|
9643
|
+
throw new import_utils56.BadRequestError("Region not found.");
|
|
8380
9644
|
}
|
|
8381
9645
|
setCache(cacheKey, result, 300).then(() => {
|
|
8382
|
-
|
|
9646
|
+
import_utils56.logger.log({
|
|
8383
9647
|
level: "info",
|
|
8384
9648
|
message: `Cache set for PSGC by id: ${cacheKey}`
|
|
8385
9649
|
});
|
|
8386
9650
|
}).catch((err) => {
|
|
8387
|
-
|
|
9651
|
+
import_utils56.logger.log({
|
|
8388
9652
|
level: "error",
|
|
8389
9653
|
message: `Failed to set cache for PSGC by id: ${err.message}`
|
|
8390
9654
|
});
|
|
8391
9655
|
});
|
|
8392
9656
|
return result;
|
|
8393
9657
|
} catch (error) {
|
|
8394
|
-
if (error instanceof
|
|
9658
|
+
if (error instanceof import_utils56.AppError) {
|
|
8395
9659
|
throw error;
|
|
8396
9660
|
} else {
|
|
8397
|
-
throw new
|
|
9661
|
+
throw new import_utils56.InternalServerError("Failed to get PSGC.");
|
|
8398
9662
|
}
|
|
8399
9663
|
}
|
|
8400
9664
|
}
|
|
@@ -8418,15 +9682,15 @@ function usePSGCRepo() {
|
|
|
8418
9682
|
query.code = { $regex: `^${prefix}` };
|
|
8419
9683
|
cacheKeyOptions.prefix = prefix;
|
|
8420
9684
|
}
|
|
8421
|
-
const cacheKey = (0,
|
|
8422
|
-
|
|
9685
|
+
const cacheKey = (0, import_utils56.makeCacheKey)(namespace_collection, { name });
|
|
9686
|
+
import_utils56.logger.log({
|
|
8423
9687
|
level: "info",
|
|
8424
9688
|
message: `Query for getByName PSGC: ${JSON.stringify(query)}`
|
|
8425
9689
|
});
|
|
8426
9690
|
try {
|
|
8427
9691
|
const cached = await getCache(cacheKey);
|
|
8428
9692
|
if (cached) {
|
|
8429
|
-
|
|
9693
|
+
import_utils56.logger.log({
|
|
8430
9694
|
level: "info",
|
|
8431
9695
|
message: `Cache hit for getByName PSGC: ${cacheKey}`
|
|
8432
9696
|
});
|
|
@@ -8434,36 +9698,36 @@ function usePSGCRepo() {
|
|
|
8434
9698
|
}
|
|
8435
9699
|
const result = await collection.findOne(query);
|
|
8436
9700
|
setCache(cacheKey, result, 300).then(() => {
|
|
8437
|
-
|
|
9701
|
+
import_utils56.logger.log({
|
|
8438
9702
|
level: "info",
|
|
8439
9703
|
message: `Cache set for PSGC by name: ${cacheKey}`
|
|
8440
9704
|
});
|
|
8441
9705
|
}).catch((err) => {
|
|
8442
|
-
|
|
9706
|
+
import_utils56.logger.log({
|
|
8443
9707
|
level: "error",
|
|
8444
9708
|
message: `Failed to set cache for PSGC by name: ${err.message}`
|
|
8445
9709
|
});
|
|
8446
9710
|
});
|
|
8447
9711
|
return result;
|
|
8448
9712
|
} catch (error) {
|
|
8449
|
-
if (error instanceof
|
|
9713
|
+
if (error instanceof import_utils56.AppError) {
|
|
8450
9714
|
throw error;
|
|
8451
9715
|
} else {
|
|
8452
|
-
throw new
|
|
9716
|
+
throw new import_utils56.InternalServerError("Failed to get PSGC.");
|
|
8453
9717
|
}
|
|
8454
9718
|
}
|
|
8455
9719
|
}
|
|
8456
9720
|
async function updateFieldById({ _id, field, value } = {}, session) {
|
|
8457
9721
|
const allowedFields = ["name"];
|
|
8458
9722
|
if (!allowedFields.includes(field)) {
|
|
8459
|
-
throw new
|
|
9723
|
+
throw new import_utils56.BadRequestError(
|
|
8460
9724
|
`Field "${field}" is not allowed to be updated.`
|
|
8461
9725
|
);
|
|
8462
9726
|
}
|
|
8463
9727
|
try {
|
|
8464
|
-
_id = new
|
|
9728
|
+
_id = new import_mongodb26.ObjectId(_id);
|
|
8465
9729
|
} catch (error) {
|
|
8466
|
-
throw new
|
|
9730
|
+
throw new import_utils56.BadRequestError("Invalid ID.");
|
|
8467
9731
|
}
|
|
8468
9732
|
try {
|
|
8469
9733
|
await collection.updateOne(
|
|
@@ -8474,14 +9738,14 @@ function usePSGCRepo() {
|
|
|
8474
9738
|
delCachedData();
|
|
8475
9739
|
return `Successfully updated PSGC ${field}.`;
|
|
8476
9740
|
} catch (error) {
|
|
8477
|
-
throw new
|
|
9741
|
+
throw new import_utils56.InternalServerError(`Failed to update PSGC ${field}.`);
|
|
8478
9742
|
}
|
|
8479
9743
|
}
|
|
8480
9744
|
async function deleteById(_id) {
|
|
8481
9745
|
try {
|
|
8482
|
-
_id = new
|
|
9746
|
+
_id = new import_mongodb26.ObjectId(_id);
|
|
8483
9747
|
} catch (error) {
|
|
8484
|
-
throw new
|
|
9748
|
+
throw new import_utils56.BadRequestError("Invalid ID.");
|
|
8485
9749
|
}
|
|
8486
9750
|
try {
|
|
8487
9751
|
await collection.updateOne(
|
|
@@ -8491,7 +9755,7 @@ function usePSGCRepo() {
|
|
|
8491
9755
|
delCachedData();
|
|
8492
9756
|
return "Successfully deleted PSGC.";
|
|
8493
9757
|
} catch (error) {
|
|
8494
|
-
throw new
|
|
9758
|
+
throw new import_utils56.InternalServerError("Failed to delete PSGC.");
|
|
8495
9759
|
}
|
|
8496
9760
|
}
|
|
8497
9761
|
return {
|
|
@@ -8506,8 +9770,8 @@ function usePSGCRepo() {
|
|
|
8506
9770
|
}
|
|
8507
9771
|
|
|
8508
9772
|
// src/resources/psgc/psgc.controller.ts
|
|
8509
|
-
var
|
|
8510
|
-
var
|
|
9773
|
+
var import_utils57 = require("@goweekdays/utils");
|
|
9774
|
+
var import_joi38 = __toESM(require("joi"));
|
|
8511
9775
|
function usePSGCController() {
|
|
8512
9776
|
const {
|
|
8513
9777
|
add: _add,
|
|
@@ -8521,7 +9785,7 @@ function usePSGCController() {
|
|
|
8521
9785
|
const value = req.body;
|
|
8522
9786
|
const { error } = schemaPSGC.validate(value);
|
|
8523
9787
|
if (error) {
|
|
8524
|
-
next(new
|
|
9788
|
+
next(new import_utils57.BadRequestError(error.message));
|
|
8525
9789
|
return;
|
|
8526
9790
|
}
|
|
8527
9791
|
try {
|
|
@@ -8537,12 +9801,12 @@ function usePSGCController() {
|
|
|
8537
9801
|
}
|
|
8538
9802
|
async function getAll(req, res, next) {
|
|
8539
9803
|
const query = req.query;
|
|
8540
|
-
const validation =
|
|
8541
|
-
page:
|
|
8542
|
-
limit:
|
|
8543
|
-
search:
|
|
8544
|
-
type:
|
|
8545
|
-
prefix:
|
|
9804
|
+
const validation = import_joi38.default.object({
|
|
9805
|
+
page: import_joi38.default.number().min(1).optional().allow("", null),
|
|
9806
|
+
limit: import_joi38.default.number().min(1).optional().allow("", null),
|
|
9807
|
+
search: import_joi38.default.string().optional().allow("", null),
|
|
9808
|
+
type: import_joi38.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required(),
|
|
9809
|
+
prefix: import_joi38.default.string().optional().allow("", null)
|
|
8546
9810
|
});
|
|
8547
9811
|
const { error } = validation.validate(query);
|
|
8548
9812
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
@@ -8552,16 +9816,16 @@ function usePSGCController() {
|
|
|
8552
9816
|
const prefix = req.query.prefix ? String(req.query.prefix) : "";
|
|
8553
9817
|
const isPageNumber = isFinite(page);
|
|
8554
9818
|
if (!isPageNumber) {
|
|
8555
|
-
next(new
|
|
9819
|
+
next(new import_utils57.BadRequestError("Invalid page number."));
|
|
8556
9820
|
return;
|
|
8557
9821
|
}
|
|
8558
9822
|
const isLimitNumber = isFinite(limit);
|
|
8559
9823
|
if (!isLimitNumber) {
|
|
8560
|
-
next(new
|
|
9824
|
+
next(new import_utils57.BadRequestError("Invalid limit number."));
|
|
8561
9825
|
return;
|
|
8562
9826
|
}
|
|
8563
9827
|
if (error) {
|
|
8564
|
-
next(new
|
|
9828
|
+
next(new import_utils57.BadRequestError(error.message));
|
|
8565
9829
|
return;
|
|
8566
9830
|
}
|
|
8567
9831
|
try {
|
|
@@ -8580,12 +9844,12 @@ function usePSGCController() {
|
|
|
8580
9844
|
}
|
|
8581
9845
|
async function getById(req, res, next) {
|
|
8582
9846
|
const id = req.params.id;
|
|
8583
|
-
const validation =
|
|
8584
|
-
id:
|
|
9847
|
+
const validation = import_joi38.default.object({
|
|
9848
|
+
id: import_joi38.default.string().hex().required()
|
|
8585
9849
|
});
|
|
8586
9850
|
const { error } = validation.validate({ id });
|
|
8587
9851
|
if (error) {
|
|
8588
|
-
next(new
|
|
9852
|
+
next(new import_utils57.BadRequestError(error.message));
|
|
8589
9853
|
return;
|
|
8590
9854
|
}
|
|
8591
9855
|
try {
|
|
@@ -8601,12 +9865,12 @@ function usePSGCController() {
|
|
|
8601
9865
|
}
|
|
8602
9866
|
async function getByName(req, res, next) {
|
|
8603
9867
|
const name = req.params.name;
|
|
8604
|
-
const validation =
|
|
8605
|
-
name:
|
|
9868
|
+
const validation = import_joi38.default.object({
|
|
9869
|
+
name: import_joi38.default.string().required()
|
|
8606
9870
|
});
|
|
8607
9871
|
const { error } = validation.validate({ name });
|
|
8608
9872
|
if (error) {
|
|
8609
|
-
next(new
|
|
9873
|
+
next(new import_utils57.BadRequestError(error.message));
|
|
8610
9874
|
return;
|
|
8611
9875
|
}
|
|
8612
9876
|
try {
|
|
@@ -8623,14 +9887,14 @@ function usePSGCController() {
|
|
|
8623
9887
|
async function updateField(req, res, next) {
|
|
8624
9888
|
const _id = req.params.id;
|
|
8625
9889
|
const { field, value } = req.body;
|
|
8626
|
-
const validation =
|
|
8627
|
-
_id:
|
|
8628
|
-
field:
|
|
8629
|
-
value:
|
|
9890
|
+
const validation = import_joi38.default.object({
|
|
9891
|
+
_id: import_joi38.default.string().hex().required(),
|
|
9892
|
+
field: import_joi38.default.string().valid("name", "director", "directorName").required(),
|
|
9893
|
+
value: import_joi38.default.string().required()
|
|
8630
9894
|
});
|
|
8631
9895
|
const { error } = validation.validate({ _id, field, value });
|
|
8632
9896
|
if (error) {
|
|
8633
|
-
next(new
|
|
9897
|
+
next(new import_utils57.BadRequestError(error.message));
|
|
8634
9898
|
return;
|
|
8635
9899
|
}
|
|
8636
9900
|
try {
|
|
@@ -8643,12 +9907,12 @@ function usePSGCController() {
|
|
|
8643
9907
|
}
|
|
8644
9908
|
async function deleteById(req, res, next) {
|
|
8645
9909
|
const _id = req.params.id;
|
|
8646
|
-
const validation =
|
|
8647
|
-
_id:
|
|
9910
|
+
const validation = import_joi38.default.object({
|
|
9911
|
+
_id: import_joi38.default.string().hex().required()
|
|
8648
9912
|
});
|
|
8649
9913
|
const { error } = validation.validate({ _id });
|
|
8650
9914
|
if (error) {
|
|
8651
|
-
next(new
|
|
9915
|
+
next(new import_utils57.BadRequestError(error.message));
|
|
8652
9916
|
return;
|
|
8653
9917
|
}
|
|
8654
9918
|
try {
|
|
@@ -8670,7 +9934,7 @@ function usePSGCController() {
|
|
|
8670
9934
|
}
|
|
8671
9935
|
|
|
8672
9936
|
// src/resources/utils/github.service.ts
|
|
8673
|
-
var
|
|
9937
|
+
var import_utils58 = require("@goweekdays/utils");
|
|
8674
9938
|
var import_rest = require("@octokit/rest");
|
|
8675
9939
|
var import_libsodium_wrappers = __toESM(require("libsodium-wrappers"));
|
|
8676
9940
|
function useGitHubService() {
|
|
@@ -8684,23 +9948,23 @@ function useGitHubService() {
|
|
|
8684
9948
|
try {
|
|
8685
9949
|
const { data: repoData } = await octokit.repos.get({ owner, repo });
|
|
8686
9950
|
if (!repoData.permissions?.admin) {
|
|
8687
|
-
throw new
|
|
9951
|
+
throw new import_utils58.BadRequestError(
|
|
8688
9952
|
"You do not have admin access to this repository."
|
|
8689
9953
|
);
|
|
8690
9954
|
}
|
|
8691
9955
|
} catch (error) {
|
|
8692
9956
|
if (error.status === 404) {
|
|
8693
|
-
throw new
|
|
9957
|
+
throw new import_utils58.BadRequestError(
|
|
8694
9958
|
"Repository not found or you don't have access to it."
|
|
8695
9959
|
);
|
|
8696
9960
|
} else if (error.status === 401) {
|
|
8697
|
-
throw new
|
|
9961
|
+
throw new import_utils58.BadRequestError(
|
|
8698
9962
|
"Invalid GitHub token or insufficient permissions."
|
|
8699
9963
|
);
|
|
8700
9964
|
} else if (error.message.includes("admin access")) {
|
|
8701
9965
|
throw error;
|
|
8702
9966
|
} else {
|
|
8703
|
-
throw new
|
|
9967
|
+
throw new import_utils58.BadRequestError(
|
|
8704
9968
|
`Failed to check repository permissions: ${error.message}`
|
|
8705
9969
|
);
|
|
8706
9970
|
}
|
|
@@ -8749,7 +10013,7 @@ function useGitHubService() {
|
|
|
8749
10013
|
key_id: publicKeyRes.key_id
|
|
8750
10014
|
});
|
|
8751
10015
|
} catch (encryptionError) {
|
|
8752
|
-
throw new
|
|
10016
|
+
throw new import_utils58.BadRequestError(
|
|
8753
10017
|
`Failed to encrypt secret '${key}': ${encryptionError.message}`
|
|
8754
10018
|
);
|
|
8755
10019
|
}
|
|
@@ -8779,22 +10043,22 @@ function useGitHubService() {
|
|
|
8779
10043
|
}
|
|
8780
10044
|
return `Successfully set ${lines.length} ${type} variables/secrets in environment '${environment}'`;
|
|
8781
10045
|
} catch (error) {
|
|
8782
|
-
if (error instanceof
|
|
10046
|
+
if (error instanceof import_utils58.AppError)
|
|
8783
10047
|
throw error;
|
|
8784
10048
|
if (error.status === 422) {
|
|
8785
|
-
throw new
|
|
10049
|
+
throw new import_utils58.BadRequestError(
|
|
8786
10050
|
`GitHub API validation error: ${error.message}`
|
|
8787
10051
|
);
|
|
8788
10052
|
} else if (error.status === 404) {
|
|
8789
|
-
throw new
|
|
10053
|
+
throw new import_utils58.BadRequestError("Environment or repository not found.");
|
|
8790
10054
|
} else if (error.status === 403) {
|
|
8791
|
-
throw new
|
|
10055
|
+
throw new import_utils58.BadRequestError(
|
|
8792
10056
|
"Forbidden: Insufficient permissions or rate limit exceeded."
|
|
8793
10057
|
);
|
|
8794
10058
|
} else if (error.message.includes("admin access") || error.message.includes("permissions")) {
|
|
8795
10059
|
throw error;
|
|
8796
10060
|
} else {
|
|
8797
|
-
throw new
|
|
10061
|
+
throw new import_utils58.BadRequestError(
|
|
8798
10062
|
`Failed to set GitHub variables: ${error.message}`
|
|
8799
10063
|
);
|
|
8800
10064
|
}
|
|
@@ -8806,8 +10070,8 @@ function useGitHubService() {
|
|
|
8806
10070
|
}
|
|
8807
10071
|
|
|
8808
10072
|
// src/resources/utils/util.controller.ts
|
|
8809
|
-
var
|
|
8810
|
-
var
|
|
10073
|
+
var import_joi39 = __toESM(require("joi"));
|
|
10074
|
+
var import_utils59 = require("@goweekdays/utils");
|
|
8811
10075
|
function useUtilController() {
|
|
8812
10076
|
async function healthCheck(req, res, next) {
|
|
8813
10077
|
try {
|
|
@@ -8823,32 +10087,32 @@ function useUtilController() {
|
|
|
8823
10087
|
}
|
|
8824
10088
|
});
|
|
8825
10089
|
} catch (error) {
|
|
8826
|
-
|
|
8827
|
-
next(new
|
|
10090
|
+
import_utils59.logger.error("Health check failed", { error: error.message });
|
|
10091
|
+
next(new import_utils59.InternalServerError("Health check failed"));
|
|
8828
10092
|
}
|
|
8829
10093
|
}
|
|
8830
10094
|
async function setGitHubVariables(req, res, next) {
|
|
8831
10095
|
try {
|
|
8832
10096
|
const { githubToken, repoUrl, environment, type, keyValues } = req.body;
|
|
8833
|
-
const validation =
|
|
8834
|
-
githubToken:
|
|
10097
|
+
const validation = import_joi39.default.object({
|
|
10098
|
+
githubToken: import_joi39.default.string().required().messages({
|
|
8835
10099
|
"string.empty": "GitHub token is required",
|
|
8836
10100
|
"any.required": "GitHub token is required"
|
|
8837
10101
|
}),
|
|
8838
|
-
repoUrl:
|
|
10102
|
+
repoUrl: import_joi39.default.string().uri().required().messages({
|
|
8839
10103
|
"string.empty": "Repository URL is required",
|
|
8840
10104
|
"string.uri": "Repository URL must be a valid URL",
|
|
8841
10105
|
"any.required": "Repository URL is required"
|
|
8842
10106
|
}),
|
|
8843
|
-
environment:
|
|
10107
|
+
environment: import_joi39.default.string().required().messages({
|
|
8844
10108
|
"string.empty": "Environment name is required",
|
|
8845
10109
|
"any.required": "Environment name is required"
|
|
8846
10110
|
}),
|
|
8847
|
-
type:
|
|
10111
|
+
type: import_joi39.default.string().valid("env", "secret").required().messages({
|
|
8848
10112
|
"any.only": 'Type must be either "env" or "secret"',
|
|
8849
10113
|
"any.required": "Type is required"
|
|
8850
10114
|
}),
|
|
8851
|
-
keyValues:
|
|
10115
|
+
keyValues: import_joi39.default.string().required().messages({
|
|
8852
10116
|
"string.empty": "Key-value pairs are required",
|
|
8853
10117
|
"any.required": "Key-value pairs are required"
|
|
8854
10118
|
})
|
|
@@ -8861,13 +10125,13 @@ function useUtilController() {
|
|
|
8861
10125
|
keyValues
|
|
8862
10126
|
});
|
|
8863
10127
|
if (error) {
|
|
8864
|
-
next(new
|
|
10128
|
+
next(new import_utils59.BadRequestError(error.message));
|
|
8865
10129
|
return;
|
|
8866
10130
|
}
|
|
8867
10131
|
const repoUrlPattern = /github\.com[:\/]([^\/]+)\/(.+)\.git$/;
|
|
8868
10132
|
if (!repoUrlPattern.test(repoUrl)) {
|
|
8869
10133
|
next(
|
|
8870
|
-
new
|
|
10134
|
+
new import_utils59.BadRequestError(
|
|
8871
10135
|
"Invalid GitHub repository URL format. Expected format: https://github.com/owner/repo.git"
|
|
8872
10136
|
)
|
|
8873
10137
|
);
|
|
@@ -8879,7 +10143,7 @@ function useUtilController() {
|
|
|
8879
10143
|
);
|
|
8880
10144
|
if (invalidLines.length > 0) {
|
|
8881
10145
|
next(
|
|
8882
|
-
new
|
|
10146
|
+
new import_utils59.BadRequestError(
|
|
8883
10147
|
"Invalid key-value format. Each pair should be in format: KEY=value. Pairs should be separated by semicolons."
|
|
8884
10148
|
)
|
|
8885
10149
|
);
|
|
@@ -8893,7 +10157,7 @@ function useUtilController() {
|
|
|
8893
10157
|
type,
|
|
8894
10158
|
keyValues
|
|
8895
10159
|
});
|
|
8896
|
-
|
|
10160
|
+
import_utils59.logger.info(`GitHub variables set successfully`, {
|
|
8897
10161
|
repoUrl,
|
|
8898
10162
|
environment,
|
|
8899
10163
|
type,
|
|
@@ -8910,15 +10174,15 @@ function useUtilController() {
|
|
|
8910
10174
|
}
|
|
8911
10175
|
});
|
|
8912
10176
|
} catch (error) {
|
|
8913
|
-
|
|
10177
|
+
import_utils59.logger.error("Failed to set GitHub variables", {
|
|
8914
10178
|
error: error.message,
|
|
8915
10179
|
stack: error.stack
|
|
8916
10180
|
});
|
|
8917
|
-
if (error instanceof
|
|
10181
|
+
if (error instanceof import_utils59.AppError) {
|
|
8918
10182
|
next(error);
|
|
8919
10183
|
} else {
|
|
8920
10184
|
next(
|
|
8921
|
-
new
|
|
10185
|
+
new import_utils59.InternalServerError(
|
|
8922
10186
|
`Failed to set GitHub variables: ${error.message}`
|
|
8923
10187
|
)
|
|
8924
10188
|
);
|
|
@@ -8932,31 +10196,31 @@ function useUtilController() {
|
|
|
8932
10196
|
}
|
|
8933
10197
|
|
|
8934
10198
|
// src/resources/utils/transaction.schema.ts
|
|
8935
|
-
var
|
|
8936
|
-
var transactionSchema =
|
|
8937
|
-
_id:
|
|
8938
|
-
payment:
|
|
8939
|
-
user:
|
|
8940
|
-
org:
|
|
8941
|
-
type:
|
|
8942
|
-
amount:
|
|
8943
|
-
currency:
|
|
8944
|
-
description:
|
|
8945
|
-
metadata:
|
|
8946
|
-
subscriptionId:
|
|
8947
|
-
cycle:
|
|
8948
|
-
seats:
|
|
8949
|
-
promoCode:
|
|
10199
|
+
var import_joi40 = __toESM(require("joi"));
|
|
10200
|
+
var transactionSchema = import_joi40.default.object({
|
|
10201
|
+
_id: import_joi40.default.string().hex().optional().allow("", null),
|
|
10202
|
+
payment: import_joi40.default.string().required(),
|
|
10203
|
+
user: import_joi40.default.string().hex().optional().allow("", null),
|
|
10204
|
+
org: import_joi40.default.string().hex().optional().allow("", null),
|
|
10205
|
+
type: import_joi40.default.string().required(),
|
|
10206
|
+
amount: import_joi40.default.number().positive().min(0).required(),
|
|
10207
|
+
currency: import_joi40.default.string().required(),
|
|
10208
|
+
description: import_joi40.default.string().optional().allow("", null),
|
|
10209
|
+
metadata: import_joi40.default.object({
|
|
10210
|
+
subscriptionId: import_joi40.default.string().hex().optional().allow("", null),
|
|
10211
|
+
cycle: import_joi40.default.number().optional().allow("", null),
|
|
10212
|
+
seats: import_joi40.default.number().optional().allow("", null),
|
|
10213
|
+
promoCode: import_joi40.default.string().optional().allow("", null)
|
|
8950
10214
|
}).optional().allow("", null),
|
|
8951
|
-
status:
|
|
8952
|
-
createdAt:
|
|
8953
|
-
updatedAt:
|
|
8954
|
-
deletedAt:
|
|
10215
|
+
status: import_joi40.default.string().optional().allow("", null),
|
|
10216
|
+
createdAt: import_joi40.default.string().optional().allow("", null),
|
|
10217
|
+
updatedAt: import_joi40.default.string().optional().allow("", null),
|
|
10218
|
+
deletedAt: import_joi40.default.string().optional().allow("", null)
|
|
8955
10219
|
});
|
|
8956
10220
|
|
|
8957
10221
|
// src/resources/verification/verification.controller.ts
|
|
8958
|
-
var
|
|
8959
|
-
var
|
|
10222
|
+
var import_utils60 = require("@goweekdays/utils");
|
|
10223
|
+
var import_joi41 = __toESM(require("joi"));
|
|
8960
10224
|
function useVerificationController() {
|
|
8961
10225
|
const {
|
|
8962
10226
|
createUserInvite: _createUserInvite,
|
|
@@ -8970,17 +10234,17 @@ function useVerificationController() {
|
|
|
8970
10234
|
} = useVerificationService();
|
|
8971
10235
|
const { getVerifications: _getVerifications } = useVerificationRepo();
|
|
8972
10236
|
async function createUserInvite(req, res, next) {
|
|
8973
|
-
const validation =
|
|
8974
|
-
email:
|
|
8975
|
-
app:
|
|
8976
|
-
role:
|
|
8977
|
-
roleName:
|
|
8978
|
-
org:
|
|
8979
|
-
orgName:
|
|
10237
|
+
const validation = import_joi41.default.object({
|
|
10238
|
+
email: import_joi41.default.string().email().required(),
|
|
10239
|
+
app: import_joi41.default.string().required(),
|
|
10240
|
+
role: import_joi41.default.string().hex().required(),
|
|
10241
|
+
roleName: import_joi41.default.string().required(),
|
|
10242
|
+
org: import_joi41.default.string().hex().optional().optional().allow("", null),
|
|
10243
|
+
orgName: import_joi41.default.string().optional().optional().allow("", null)
|
|
8980
10244
|
});
|
|
8981
10245
|
const { error } = validation.validate(req.body);
|
|
8982
10246
|
if (error) {
|
|
8983
|
-
next(new
|
|
10247
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
8984
10248
|
return;
|
|
8985
10249
|
}
|
|
8986
10250
|
const email = req.body.email ?? "";
|
|
@@ -9008,10 +10272,10 @@ function useVerificationController() {
|
|
|
9008
10272
|
}
|
|
9009
10273
|
async function createForgetPassword(req, res, next) {
|
|
9010
10274
|
const email = req.body.email || "";
|
|
9011
|
-
const validation =
|
|
10275
|
+
const validation = import_joi41.default.string().email().required();
|
|
9012
10276
|
const { error } = validation.validate(email);
|
|
9013
10277
|
if (error) {
|
|
9014
|
-
next(new
|
|
10278
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
9015
10279
|
return;
|
|
9016
10280
|
}
|
|
9017
10281
|
try {
|
|
@@ -9021,26 +10285,26 @@ function useVerificationController() {
|
|
|
9021
10285
|
});
|
|
9022
10286
|
return;
|
|
9023
10287
|
} catch (error2) {
|
|
9024
|
-
if (error2 instanceof
|
|
10288
|
+
if (error2 instanceof import_utils60.AppError) {
|
|
9025
10289
|
next(error2);
|
|
9026
10290
|
} else {
|
|
9027
|
-
next(new
|
|
10291
|
+
next(new import_utils60.InternalServerError("An unexpected error occurred"));
|
|
9028
10292
|
}
|
|
9029
10293
|
}
|
|
9030
10294
|
}
|
|
9031
10295
|
async function getVerifications(req, res, next) {
|
|
9032
|
-
const validation =
|
|
9033
|
-
status:
|
|
9034
|
-
search:
|
|
9035
|
-
page:
|
|
9036
|
-
type:
|
|
9037
|
-
email:
|
|
9038
|
-
app:
|
|
9039
|
-
org:
|
|
10296
|
+
const validation = import_joi41.default.object({
|
|
10297
|
+
status: import_joi41.default.string().required(),
|
|
10298
|
+
search: import_joi41.default.string().optional().allow("", null),
|
|
10299
|
+
page: import_joi41.default.number().required(),
|
|
10300
|
+
type: import_joi41.default.string().optional().allow("", null),
|
|
10301
|
+
email: import_joi41.default.string().optional().allow("", null),
|
|
10302
|
+
app: import_joi41.default.string().optional().allow("", null),
|
|
10303
|
+
org: import_joi41.default.string().optional().allow("", null)
|
|
9040
10304
|
});
|
|
9041
10305
|
const { error } = validation.validate(req.query);
|
|
9042
10306
|
if (error) {
|
|
9043
|
-
next(new
|
|
10307
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
9044
10308
|
return;
|
|
9045
10309
|
}
|
|
9046
10310
|
const status = req.query.status ?? "";
|
|
@@ -9073,10 +10337,10 @@ function useVerificationController() {
|
|
|
9073
10337
|
}
|
|
9074
10338
|
async function verify(req, res, next) {
|
|
9075
10339
|
const id = req.params.id || "";
|
|
9076
|
-
const validation =
|
|
10340
|
+
const validation = import_joi41.default.string().hex().required();
|
|
9077
10341
|
const { error } = validation.validate(id);
|
|
9078
10342
|
if (error) {
|
|
9079
|
-
next(new
|
|
10343
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
9080
10344
|
return;
|
|
9081
10345
|
}
|
|
9082
10346
|
try {
|
|
@@ -9089,10 +10353,10 @@ function useVerificationController() {
|
|
|
9089
10353
|
}
|
|
9090
10354
|
async function cancelUserInvitation(req, res, next) {
|
|
9091
10355
|
const otpId = req.params.id || "";
|
|
9092
|
-
const validation =
|
|
10356
|
+
const validation = import_joi41.default.string().hex().required();
|
|
9093
10357
|
const { error } = validation.validate(otpId);
|
|
9094
10358
|
if (error) {
|
|
9095
|
-
next(new
|
|
10359
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
9096
10360
|
return;
|
|
9097
10361
|
}
|
|
9098
10362
|
try {
|
|
@@ -9105,10 +10369,10 @@ function useVerificationController() {
|
|
|
9105
10369
|
}
|
|
9106
10370
|
}
|
|
9107
10371
|
async function signUp(req, res, next) {
|
|
9108
|
-
const validation =
|
|
10372
|
+
const validation = import_joi41.default.string().email().required();
|
|
9109
10373
|
const { error } = validation.validate(req.body.email);
|
|
9110
10374
|
if (error) {
|
|
9111
|
-
next(new
|
|
10375
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
9112
10376
|
return;
|
|
9113
10377
|
}
|
|
9114
10378
|
const email = req.body.email ?? "";
|
|
@@ -9123,7 +10387,7 @@ function useVerificationController() {
|
|
|
9123
10387
|
async function inviteMember(req, res, next) {
|
|
9124
10388
|
const { error } = schemaInviteMember.validate(req.body);
|
|
9125
10389
|
if (error) {
|
|
9126
|
-
next(new
|
|
10390
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
9127
10391
|
return;
|
|
9128
10392
|
}
|
|
9129
10393
|
try {
|
|
@@ -9136,10 +10400,10 @@ function useVerificationController() {
|
|
|
9136
10400
|
}
|
|
9137
10401
|
async function cancelInviteMember(req, res, next) {
|
|
9138
10402
|
const id = req.params.id || "";
|
|
9139
|
-
const validation =
|
|
10403
|
+
const validation = import_joi41.default.string().hex().required();
|
|
9140
10404
|
const { error } = validation.validate(id);
|
|
9141
10405
|
if (error) {
|
|
9142
|
-
next(new
|
|
10406
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
9143
10407
|
return;
|
|
9144
10408
|
}
|
|
9145
10409
|
try {
|
|
@@ -9152,10 +10416,10 @@ function useVerificationController() {
|
|
|
9152
10416
|
}
|
|
9153
10417
|
async function forgetPassword(req, res, next) {
|
|
9154
10418
|
const email = req.body.email ?? "";
|
|
9155
|
-
const validation =
|
|
10419
|
+
const validation = import_joi41.default.string().email().required();
|
|
9156
10420
|
const { error } = validation.validate(email);
|
|
9157
10421
|
if (error) {
|
|
9158
|
-
next(new
|
|
10422
|
+
next(new import_utils60.BadRequestError(error.message));
|
|
9159
10423
|
return;
|
|
9160
10424
|
}
|
|
9161
10425
|
try {
|
|
@@ -9165,10 +10429,10 @@ function useVerificationController() {
|
|
|
9165
10429
|
});
|
|
9166
10430
|
return;
|
|
9167
10431
|
} catch (error2) {
|
|
9168
|
-
if (error2 instanceof
|
|
10432
|
+
if (error2 instanceof import_utils60.AppError) {
|
|
9169
10433
|
next(error2);
|
|
9170
10434
|
} else {
|
|
9171
|
-
next(new
|
|
10435
|
+
next(new import_utils60.InternalServerError("An unexpected error occurred"));
|
|
9172
10436
|
}
|
|
9173
10437
|
}
|
|
9174
10438
|
}
|
|
@@ -9226,6 +10490,7 @@ function useVerificationController() {
|
|
|
9226
10490
|
XENDIT_BASE_URL,
|
|
9227
10491
|
XENDIT_SECRET_KEY,
|
|
9228
10492
|
addressSchema,
|
|
10493
|
+
currencies,
|
|
9229
10494
|
isDev,
|
|
9230
10495
|
modelApp,
|
|
9231
10496
|
modelMember,
|
|
@@ -9233,7 +10498,10 @@ function useVerificationController() {
|
|
|
9233
10498
|
modelPSGC,
|
|
9234
10499
|
modelPermission,
|
|
9235
10500
|
modelPermissionGroup,
|
|
10501
|
+
modelPlan,
|
|
9236
10502
|
modelRole,
|
|
10503
|
+
modelSubscription,
|
|
10504
|
+
modelSubscriptionTransaction,
|
|
9237
10505
|
modelUser,
|
|
9238
10506
|
modelVerification,
|
|
9239
10507
|
schemaApp,
|
|
@@ -9245,13 +10513,20 @@ function useVerificationController() {
|
|
|
9245
10513
|
schemaMemberRole,
|
|
9246
10514
|
schemaMemberStatus,
|
|
9247
10515
|
schemaOrg,
|
|
10516
|
+
schemaOrgAdd,
|
|
10517
|
+
schemaOrgUpdate,
|
|
9248
10518
|
schemaPSGC,
|
|
9249
10519
|
schemaPermission,
|
|
9250
10520
|
schemaPermissionGroup,
|
|
9251
10521
|
schemaPermissionGroupUpdate,
|
|
9252
10522
|
schemaPermissionUpdate,
|
|
10523
|
+
schemaPlan,
|
|
9253
10524
|
schemaRole,
|
|
9254
10525
|
schemaRoleUpdate,
|
|
10526
|
+
schemaSubscription,
|
|
10527
|
+
schemaSubscriptionSeats,
|
|
10528
|
+
schemaSubscriptionTransaction,
|
|
10529
|
+
schemaSubscriptionUpdate,
|
|
9255
10530
|
schemaUpdateOptions,
|
|
9256
10531
|
schemaUser,
|
|
9257
10532
|
schemaVerification,
|
|
@@ -9288,9 +10563,16 @@ function useVerificationController() {
|
|
|
9288
10563
|
usePermissionGroupService,
|
|
9289
10564
|
usePermissionRepo,
|
|
9290
10565
|
usePermissionService,
|
|
10566
|
+
usePlanController,
|
|
10567
|
+
usePlanRepo,
|
|
10568
|
+
usePlanService,
|
|
9291
10569
|
useRoleController,
|
|
9292
10570
|
useRoleRepo,
|
|
9293
10571
|
useRoleService,
|
|
10572
|
+
useSubscriptionController,
|
|
10573
|
+
useSubscriptionRepo,
|
|
10574
|
+
useSubscriptionTransactionController,
|
|
10575
|
+
useSubscriptionTransactionRepo,
|
|
9294
10576
|
useUserController,
|
|
9295
10577
|
useUserRepo,
|
|
9296
10578
|
useUserService,
|