@goweekdays/core 0.0.18 → 0.0.21
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 +18 -0
- package/dist/index.d.ts +29 -11
- package/dist/index.js +509 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +508 -215
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -11375,6 +11375,7 @@ __export(src_exports, {
|
|
|
11375
11375
|
VERIFICATION_USER_INVITE_DURATION: () => VERIFICATION_USER_INVITE_DURATION,
|
|
11376
11376
|
XENDIT_BASE_URL: () => XENDIT_BASE_URL,
|
|
11377
11377
|
XENDIT_SECRET_KEY: () => XENDIT_SECRET_KEY,
|
|
11378
|
+
addressSchema: () => addressSchema,
|
|
11378
11379
|
isDev: () => isDev,
|
|
11379
11380
|
schema: () => schema,
|
|
11380
11381
|
useAddressController: () => useAddressController,
|
|
@@ -19722,6 +19723,12 @@ function MSubscription(value) {
|
|
|
19722
19723
|
status: import_joi12.default.string().optional().allow("", null),
|
|
19723
19724
|
billingCycle: import_joi12.default.string().valid("monthly", "yearly").required(),
|
|
19724
19725
|
// Ensure valid values
|
|
19726
|
+
billingContacts: import_joi12.default.array().items(
|
|
19727
|
+
import_joi12.default.object({
|
|
19728
|
+
addedAt: import_joi12.default.date().optional(),
|
|
19729
|
+
email: import_joi12.default.string().email().required()
|
|
19730
|
+
})
|
|
19731
|
+
).optional().allow([]),
|
|
19725
19732
|
nextBillingDate: import_joi12.default.date().optional(),
|
|
19726
19733
|
lastPaymentStatus: import_joi12.default.string().optional().allow("", null),
|
|
19727
19734
|
failedAttempts: import_joi12.default.number().optional().allow("", null),
|
|
@@ -19770,6 +19777,7 @@ function MSubscription(value) {
|
|
|
19770
19777
|
maxSeats: value.maxSeats ?? 0,
|
|
19771
19778
|
status: "active",
|
|
19772
19779
|
billingCycle: value.billingCycle,
|
|
19780
|
+
billingContacts: value.billingContacts ?? [],
|
|
19773
19781
|
nextBillingDate,
|
|
19774
19782
|
// Fixed nextBillingDate logic
|
|
19775
19783
|
lastPaymentStatus: value.lastPaymentStatus ?? "success",
|
|
@@ -19929,6 +19937,70 @@ function useSubscriptionRepo() {
|
|
|
19929
19937
|
throw new import_utils55.BadRequestError("Failed to update subscription status.");
|
|
19930
19938
|
}
|
|
19931
19939
|
}
|
|
19940
|
+
async function addBillingContactById(_id, email) {
|
|
19941
|
+
try {
|
|
19942
|
+
_id = new import_mongodb24.ObjectId(_id);
|
|
19943
|
+
} catch (error) {
|
|
19944
|
+
throw new import_utils55.BadRequestError("Invalid ID.");
|
|
19945
|
+
}
|
|
19946
|
+
try {
|
|
19947
|
+
await collection.updateOne(
|
|
19948
|
+
{ _id },
|
|
19949
|
+
{ $push: { billingContacts: { email, addedAt: /* @__PURE__ */ new Date() } } }
|
|
19950
|
+
);
|
|
19951
|
+
return "Successfully updated subscription billing contact.";
|
|
19952
|
+
} catch (error) {
|
|
19953
|
+
throw new import_utils55.BadRequestError(
|
|
19954
|
+
"Failed to update subscription billing contact."
|
|
19955
|
+
);
|
|
19956
|
+
}
|
|
19957
|
+
}
|
|
19958
|
+
async function updateBillingContactByAddedAt(_id, addedAt, email) {
|
|
19959
|
+
try {
|
|
19960
|
+
_id = new import_mongodb24.ObjectId(_id);
|
|
19961
|
+
} catch (error) {
|
|
19962
|
+
throw new import_utils55.BadRequestError("Invalid ID.");
|
|
19963
|
+
}
|
|
19964
|
+
try {
|
|
19965
|
+
addedAt = new Date(addedAt);
|
|
19966
|
+
} catch (error) {
|
|
19967
|
+
throw new import_utils55.BadRequestError("Invalid addedAt date.");
|
|
19968
|
+
}
|
|
19969
|
+
try {
|
|
19970
|
+
await collection.updateOne(
|
|
19971
|
+
{ _id, "billingContacts.addedAt": addedAt },
|
|
19972
|
+
{ $set: { "billingContacts.$.email": email } }
|
|
19973
|
+
);
|
|
19974
|
+
return "Successfully updated subscription billing contact.";
|
|
19975
|
+
} catch (error) {
|
|
19976
|
+
throw new import_utils55.BadRequestError(
|
|
19977
|
+
"Failed to update subscription billing contact."
|
|
19978
|
+
);
|
|
19979
|
+
}
|
|
19980
|
+
}
|
|
19981
|
+
async function deleteBillingContactByAddedAt(_id, addedAt) {
|
|
19982
|
+
try {
|
|
19983
|
+
_id = new import_mongodb24.ObjectId(_id);
|
|
19984
|
+
} catch (error) {
|
|
19985
|
+
throw new import_utils55.BadRequestError("Invalid ID.");
|
|
19986
|
+
}
|
|
19987
|
+
try {
|
|
19988
|
+
addedAt = new Date(addedAt);
|
|
19989
|
+
} catch (error) {
|
|
19990
|
+
throw new import_utils55.BadRequestError("Invalid addedAt date.");
|
|
19991
|
+
}
|
|
19992
|
+
try {
|
|
19993
|
+
await collection.updateOne(
|
|
19994
|
+
{ _id },
|
|
19995
|
+
{ $pull: { billingContacts: { addedAt } } }
|
|
19996
|
+
);
|
|
19997
|
+
return "Successfully delete subscription billing contact.";
|
|
19998
|
+
} catch (error) {
|
|
19999
|
+
throw new import_utils55.BadRequestError(
|
|
20000
|
+
"Failed to delete subscription billing contact."
|
|
20001
|
+
);
|
|
20002
|
+
}
|
|
20003
|
+
}
|
|
19932
20004
|
async function getDueSubscriptions(BATCH_SIZE = 100) {
|
|
19933
20005
|
const today = /* @__PURE__ */ new Date();
|
|
19934
20006
|
const startOfDay = new Date(today.setUTCHours(0, 0, 0, 0));
|
|
@@ -20077,6 +20149,34 @@ function useSubscriptionRepo() {
|
|
|
20077
20149
|
throw new import_utils55.BadRequestError("Failed to update subscription status.");
|
|
20078
20150
|
}
|
|
20079
20151
|
}
|
|
20152
|
+
async function updatePaymentMethodById(_id, paymentMethodId, session) {
|
|
20153
|
+
const schema3 = import_joi13.default.object({
|
|
20154
|
+
_id: import_joi13.default.string().hex().required(),
|
|
20155
|
+
paymentMethodId: import_joi13.default.string().required()
|
|
20156
|
+
});
|
|
20157
|
+
const { error } = schema3.validate({ _id, paymentMethodId });
|
|
20158
|
+
if (error) {
|
|
20159
|
+
throw new import_utils55.BadRequestError(error.message);
|
|
20160
|
+
}
|
|
20161
|
+
try {
|
|
20162
|
+
_id = new import_mongodb24.ObjectId(_id);
|
|
20163
|
+
} catch (error2) {
|
|
20164
|
+
throw new import_utils55.BadRequestError("Invalid ID.");
|
|
20165
|
+
}
|
|
20166
|
+
try {
|
|
20167
|
+
return await collection.updateOne(
|
|
20168
|
+
{ _id },
|
|
20169
|
+
{
|
|
20170
|
+
$set: { paymentMethodId }
|
|
20171
|
+
},
|
|
20172
|
+
{ session }
|
|
20173
|
+
);
|
|
20174
|
+
} catch (error2) {
|
|
20175
|
+
throw new import_utils55.BadRequestError(
|
|
20176
|
+
"Failed to update subscription payment method."
|
|
20177
|
+
);
|
|
20178
|
+
}
|
|
20179
|
+
}
|
|
20080
20180
|
async function updatePromoCodeById(_id, promoCode, session) {
|
|
20081
20181
|
const schema3 = import_joi13.default.object({
|
|
20082
20182
|
_id: import_joi13.default.string().hex().required(),
|
|
@@ -20210,7 +20310,11 @@ function useSubscriptionRepo() {
|
|
|
20210
20310
|
updateSeatsById,
|
|
20211
20311
|
updateMaxSeatsById,
|
|
20212
20312
|
updateStatusById,
|
|
20213
|
-
updatePromoCodeById
|
|
20313
|
+
updatePromoCodeById,
|
|
20314
|
+
updatePaymentMethodById,
|
|
20315
|
+
addBillingContactById,
|
|
20316
|
+
updateBillingContactByAddedAt,
|
|
20317
|
+
deleteBillingContactByAddedAt
|
|
20214
20318
|
};
|
|
20215
20319
|
}
|
|
20216
20320
|
|
|
@@ -20454,7 +20558,20 @@ var import_utils59 = require("@goweekdays/utils");
|
|
|
20454
20558
|
|
|
20455
20559
|
// src/models/address.model.ts
|
|
20456
20560
|
var import_utils58 = require("@goweekdays/utils");
|
|
20561
|
+
var import_joi15 = __toESM(require("joi"));
|
|
20457
20562
|
var import_mongodb27 = require("mongodb");
|
|
20563
|
+
var addressSchema = import_joi15.default.object({
|
|
20564
|
+
type: import_joi15.default.string().required(),
|
|
20565
|
+
user: import_joi15.default.string().hex().optional().allow("", null),
|
|
20566
|
+
org: import_joi15.default.string().hex().optional().allow("", null),
|
|
20567
|
+
country: import_joi15.default.string().required(),
|
|
20568
|
+
address: import_joi15.default.string().required(),
|
|
20569
|
+
continuedAddress: import_joi15.default.string().optional().allow("", null),
|
|
20570
|
+
city: import_joi15.default.string().required(),
|
|
20571
|
+
province: import_joi15.default.string().required(),
|
|
20572
|
+
postalCode: import_joi15.default.string().required(),
|
|
20573
|
+
taxId: import_joi15.default.string().optional().allow("", null)
|
|
20574
|
+
});
|
|
20458
20575
|
function MAddress(value) {
|
|
20459
20576
|
if (value.user) {
|
|
20460
20577
|
try {
|
|
@@ -20494,7 +20611,11 @@ function useAddressRepo() {
|
|
|
20494
20611
|
const collection = db.collection("addresses");
|
|
20495
20612
|
async function createIndex() {
|
|
20496
20613
|
try {
|
|
20497
|
-
await collection.
|
|
20614
|
+
await collection.createIndexes([
|
|
20615
|
+
{ key: { user: 1 } },
|
|
20616
|
+
{ key: { type: 1 } },
|
|
20617
|
+
{ key: { orgId: 1 } }
|
|
20618
|
+
]);
|
|
20498
20619
|
} catch (error) {
|
|
20499
20620
|
throw new import_utils59.BadRequestError("Failed to create index on address.");
|
|
20500
20621
|
}
|
|
@@ -20508,6 +20629,19 @@ function useAddressRepo() {
|
|
|
20508
20629
|
throw new import_utils59.BadRequestError("Failed to create address.");
|
|
20509
20630
|
}
|
|
20510
20631
|
}
|
|
20632
|
+
async function updateById(_id, value, session) {
|
|
20633
|
+
try {
|
|
20634
|
+
_id = new import_mongodb28.ObjectId(_id);
|
|
20635
|
+
} catch (error) {
|
|
20636
|
+
throw new import_utils59.BadRequestError("Invalid address ID.");
|
|
20637
|
+
}
|
|
20638
|
+
try {
|
|
20639
|
+
await collection.updateOne({ _id }, { $set: value }, { session });
|
|
20640
|
+
return "Successfully updated address.";
|
|
20641
|
+
} catch (error) {
|
|
20642
|
+
throw new import_utils59.BadRequestError("Failed to update address.");
|
|
20643
|
+
}
|
|
20644
|
+
}
|
|
20511
20645
|
async function getByUserId(user) {
|
|
20512
20646
|
try {
|
|
20513
20647
|
user = new import_mongodb28.ObjectId(user);
|
|
@@ -20520,10 +20654,24 @@ function useAddressRepo() {
|
|
|
20520
20654
|
throw new import_utils59.BadRequestError("Failed to get address by ID.");
|
|
20521
20655
|
}
|
|
20522
20656
|
}
|
|
20657
|
+
async function getByOrgId(org) {
|
|
20658
|
+
try {
|
|
20659
|
+
org = new import_mongodb28.ObjectId(org);
|
|
20660
|
+
} catch (error) {
|
|
20661
|
+
throw new import_utils59.BadRequestError("Invalid orgId.");
|
|
20662
|
+
}
|
|
20663
|
+
try {
|
|
20664
|
+
return await collection.findOne({ org });
|
|
20665
|
+
} catch (error) {
|
|
20666
|
+
throw new import_utils59.BadRequestError("Failed to get address by orgId.");
|
|
20667
|
+
}
|
|
20668
|
+
}
|
|
20523
20669
|
return {
|
|
20524
20670
|
createIndex,
|
|
20525
20671
|
add,
|
|
20526
|
-
getByUserId
|
|
20672
|
+
getByUserId,
|
|
20673
|
+
getByOrgId,
|
|
20674
|
+
updateById
|
|
20527
20675
|
};
|
|
20528
20676
|
}
|
|
20529
20677
|
|
|
@@ -20531,28 +20679,28 @@ function useAddressRepo() {
|
|
|
20531
20679
|
var import_utils61 = require("@goweekdays/utils");
|
|
20532
20680
|
|
|
20533
20681
|
// src/validations/promo-code.schema.ts
|
|
20534
|
-
var
|
|
20535
|
-
var promoTypeSchema =
|
|
20536
|
-
var promoTierSchema =
|
|
20537
|
-
min:
|
|
20538
|
-
max:
|
|
20539
|
-
price:
|
|
20682
|
+
var import_joi16 = __toESM(require("joi"));
|
|
20683
|
+
var promoTypeSchema = import_joi16.default.string().valid("tiered", "fixed").required();
|
|
20684
|
+
var promoTierSchema = import_joi16.default.object({
|
|
20685
|
+
min: import_joi16.default.number().integer().min(1).required(),
|
|
20686
|
+
max: import_joi16.default.number().integer().min(import_joi16.default.ref("min")).allow(0).required(),
|
|
20687
|
+
price: import_joi16.default.number().positive().required()
|
|
20540
20688
|
});
|
|
20541
|
-
var schema =
|
|
20542
|
-
code:
|
|
20543
|
-
description:
|
|
20689
|
+
var schema = import_joi16.default.object({
|
|
20690
|
+
code: import_joi16.default.string().trim().uppercase().required(),
|
|
20691
|
+
description: import_joi16.default.string().trim().optional(),
|
|
20544
20692
|
type: promoTypeSchema,
|
|
20545
|
-
tiers:
|
|
20693
|
+
tiers: import_joi16.default.alternatives().conditional("type", {
|
|
20546
20694
|
is: "tiered",
|
|
20547
|
-
then:
|
|
20548
|
-
otherwise:
|
|
20695
|
+
then: import_joi16.default.array().items(promoTierSchema).min(1).required(),
|
|
20696
|
+
otherwise: import_joi16.default.forbidden()
|
|
20549
20697
|
}),
|
|
20550
|
-
fixed_rate:
|
|
20698
|
+
fixed_rate: import_joi16.default.alternatives().conditional("type", {
|
|
20551
20699
|
is: "fixed",
|
|
20552
|
-
then:
|
|
20553
|
-
otherwise:
|
|
20700
|
+
then: import_joi16.default.number().required().min(0),
|
|
20701
|
+
otherwise: import_joi16.default.number().integer().allow(0)
|
|
20554
20702
|
}),
|
|
20555
|
-
expiresAt:
|
|
20703
|
+
expiresAt: import_joi16.default.string().optional().allow(null, "")
|
|
20556
20704
|
});
|
|
20557
20705
|
|
|
20558
20706
|
// src/models/promo-code.model.ts
|
|
@@ -20578,7 +20726,7 @@ function MPromoCode(data) {
|
|
|
20578
20726
|
}
|
|
20579
20727
|
|
|
20580
20728
|
// src/repositories/promo-code.repository.ts
|
|
20581
|
-
var
|
|
20729
|
+
var import_joi17 = __toESM(require("joi"));
|
|
20582
20730
|
var import_mongodb29 = require("mongodb");
|
|
20583
20731
|
function usePromoCodeRepo() {
|
|
20584
20732
|
const db = import_utils61.useAtlas.getDb();
|
|
@@ -20621,8 +20769,8 @@ function usePromoCodeRepo() {
|
|
|
20621
20769
|
}
|
|
20622
20770
|
}
|
|
20623
20771
|
async function getByCode(code, type, assigned) {
|
|
20624
|
-
const schema3 =
|
|
20625
|
-
code:
|
|
20772
|
+
const schema3 = import_joi17.default.object({
|
|
20773
|
+
code: import_joi17.default.string().trim().required()
|
|
20626
20774
|
});
|
|
20627
20775
|
const { error } = schema3.validate({ code });
|
|
20628
20776
|
if (error) {
|
|
@@ -20644,8 +20792,8 @@ function usePromoCodeRepo() {
|
|
|
20644
20792
|
}
|
|
20645
20793
|
}
|
|
20646
20794
|
async function getById(_id) {
|
|
20647
|
-
const schema3 =
|
|
20648
|
-
_id:
|
|
20795
|
+
const schema3 = import_joi17.default.object({
|
|
20796
|
+
_id: import_joi17.default.string().hex().required()
|
|
20649
20797
|
});
|
|
20650
20798
|
const { error } = schema3.validate({ _id });
|
|
20651
20799
|
if (error) {
|
|
@@ -20694,9 +20842,9 @@ function usePromoCodeRepo() {
|
|
|
20694
20842
|
}
|
|
20695
20843
|
}
|
|
20696
20844
|
async function assignByUserId({ user, code } = {}, session) {
|
|
20697
|
-
const schema3 =
|
|
20698
|
-
user:
|
|
20699
|
-
code:
|
|
20845
|
+
const schema3 = import_joi17.default.object({
|
|
20846
|
+
user: import_joi17.default.string().required(),
|
|
20847
|
+
code: import_joi17.default.string().required()
|
|
20700
20848
|
});
|
|
20701
20849
|
const { error } = schema3.validate({ user, code });
|
|
20702
20850
|
if (error) {
|
|
@@ -20729,7 +20877,7 @@ function usePromoCodeRepo() {
|
|
|
20729
20877
|
}
|
|
20730
20878
|
|
|
20731
20879
|
// src/services/subscription.service.ts
|
|
20732
|
-
var
|
|
20880
|
+
var import_joi18 = __toESM(require("joi"));
|
|
20733
20881
|
|
|
20734
20882
|
// src/repositories/invoice.repository.ts
|
|
20735
20883
|
var import_utils63 = require("@goweekdays/utils");
|
|
@@ -21938,8 +22086,8 @@ function useSubscriptionService() {
|
|
|
21938
22086
|
return remainingDays > 1 ? Number((seats * price * prorationFactor).toFixed(2)) : Number((seats * price).toFixed(2));
|
|
21939
22087
|
}
|
|
21940
22088
|
function formatAmount(amount) {
|
|
21941
|
-
const validation =
|
|
21942
|
-
amount:
|
|
22089
|
+
const validation = import_joi18.default.object({
|
|
22090
|
+
amount: import_joi18.default.number().required()
|
|
21943
22091
|
});
|
|
21944
22092
|
const { error } = validation.validate({ amount });
|
|
21945
22093
|
if (error) {
|
|
@@ -22019,10 +22167,10 @@ function useSubscriptionService() {
|
|
|
22019
22167
|
}
|
|
22020
22168
|
}
|
|
22021
22169
|
async function updateSeatsById(value) {
|
|
22022
|
-
const schema3 =
|
|
22023
|
-
subscriptionId:
|
|
22024
|
-
seats:
|
|
22025
|
-
amount:
|
|
22170
|
+
const schema3 = import_joi18.default.object({
|
|
22171
|
+
subscriptionId: import_joi18.default.string().hex().required(),
|
|
22172
|
+
seats: import_joi18.default.number().min(1).required(),
|
|
22173
|
+
amount: import_joi18.default.number().required()
|
|
22026
22174
|
});
|
|
22027
22175
|
const { error } = schema3.validate(value);
|
|
22028
22176
|
if (error) {
|
|
@@ -22234,43 +22382,43 @@ function useSubscriptionService() {
|
|
|
22234
22382
|
}
|
|
22235
22383
|
|
|
22236
22384
|
// src/controllers/subscription.controller.ts
|
|
22237
|
-
var
|
|
22385
|
+
var import_joi20 = __toESM(require("joi"));
|
|
22238
22386
|
var import_utils70 = require("@goweekdays/utils");
|
|
22239
22387
|
|
|
22240
22388
|
// src/validations/subscription.schema.ts
|
|
22241
|
-
var
|
|
22389
|
+
var import_joi19 = __toESM(require("joi"));
|
|
22242
22390
|
function useSubscriptionSchema() {
|
|
22243
|
-
const schema3 =
|
|
22244
|
-
user:
|
|
22245
|
-
amount:
|
|
22246
|
-
customer_id:
|
|
22247
|
-
payment_method_id:
|
|
22248
|
-
payment_method_type:
|
|
22249
|
-
payment_method_channel:
|
|
22250
|
-
payment_method_month_expiry:
|
|
22251
|
-
payment_method_year_expiry:
|
|
22252
|
-
payment_method_cvv:
|
|
22253
|
-
currency:
|
|
22254
|
-
seats:
|
|
22255
|
-
organization:
|
|
22256
|
-
name:
|
|
22257
|
-
description:
|
|
22258
|
-
type:
|
|
22259
|
-
email:
|
|
22260
|
-
contact:
|
|
22261
|
-
busInst:
|
|
22391
|
+
const schema3 = import_joi19.default.object({
|
|
22392
|
+
user: import_joi19.default.string().required().min(0),
|
|
22393
|
+
amount: import_joi19.default.number().min(0).required(),
|
|
22394
|
+
customer_id: import_joi19.default.string().required(),
|
|
22395
|
+
payment_method_id: import_joi19.default.string().required(),
|
|
22396
|
+
payment_method_type: import_joi19.default.string().required(),
|
|
22397
|
+
payment_method_channel: import_joi19.default.string().required(),
|
|
22398
|
+
payment_method_month_expiry: import_joi19.default.string().optional().allow(null, ""),
|
|
22399
|
+
payment_method_year_expiry: import_joi19.default.string().optional().allow(null, ""),
|
|
22400
|
+
payment_method_cvv: import_joi19.default.string().optional().allow(null, ""),
|
|
22401
|
+
currency: import_joi19.default.string().optional().allow("", null),
|
|
22402
|
+
seats: import_joi19.default.number().optional().min(0).allow(null),
|
|
22403
|
+
organization: import_joi19.default.object({
|
|
22404
|
+
name: import_joi19.default.string().required(),
|
|
22405
|
+
description: import_joi19.default.string().optional().allow("", null),
|
|
22406
|
+
type: import_joi19.default.string().allow("personal", "business").required(),
|
|
22407
|
+
email: import_joi19.default.string().email().required(),
|
|
22408
|
+
contact: import_joi19.default.string().required(),
|
|
22409
|
+
busInst: import_joi19.default.string().optional().allow(null, "")
|
|
22262
22410
|
}).optional().allow({}),
|
|
22263
|
-
billingAddress:
|
|
22264
|
-
type:
|
|
22265
|
-
country:
|
|
22266
|
-
address:
|
|
22267
|
-
continuedAddress:
|
|
22268
|
-
city:
|
|
22269
|
-
province:
|
|
22270
|
-
postalCode:
|
|
22271
|
-
taxId:
|
|
22411
|
+
billingAddress: import_joi19.default.object({
|
|
22412
|
+
type: import_joi19.default.string().required(),
|
|
22413
|
+
country: import_joi19.default.string().required(),
|
|
22414
|
+
address: import_joi19.default.string().required(),
|
|
22415
|
+
continuedAddress: import_joi19.default.string().optional().allow(null, ""),
|
|
22416
|
+
city: import_joi19.default.string().required(),
|
|
22417
|
+
province: import_joi19.default.string().required(),
|
|
22418
|
+
postalCode: import_joi19.default.string().required(),
|
|
22419
|
+
taxId: import_joi19.default.string().optional().allow(null, "")
|
|
22272
22420
|
}).required(),
|
|
22273
|
-
promoCode:
|
|
22421
|
+
promoCode: import_joi19.default.string().optional().allow("", null)
|
|
22274
22422
|
});
|
|
22275
22423
|
return {
|
|
22276
22424
|
schema: schema3
|
|
@@ -22286,7 +22434,11 @@ function useSubscriptionController() {
|
|
|
22286
22434
|
getByOrgId: _getByOrgId,
|
|
22287
22435
|
getById: _getById,
|
|
22288
22436
|
updatePromoCodeById: _updatePromoCodeById,
|
|
22289
|
-
updateStatusById: _updateStatusById
|
|
22437
|
+
updateStatusById: _updateStatusById,
|
|
22438
|
+
updatePaymentMethodById: _updatePaymentMethodById,
|
|
22439
|
+
addBillingContactById: _addBillingContactById,
|
|
22440
|
+
updateBillingContactByAddedAt: _updateBillingContactByAddedAt,
|
|
22441
|
+
deleteBillingContactByAddedAt: _deleteBillingContactByAddedAt
|
|
22290
22442
|
} = useSubscriptionRepo();
|
|
22291
22443
|
const {
|
|
22292
22444
|
getByUserId: _getByUserId,
|
|
@@ -22297,9 +22449,9 @@ function useSubscriptionController() {
|
|
|
22297
22449
|
} = useSubscriptionService();
|
|
22298
22450
|
async function add(req, res, next) {
|
|
22299
22451
|
const value = req.body;
|
|
22300
|
-
const validation =
|
|
22301
|
-
user:
|
|
22302
|
-
subscriptionId:
|
|
22452
|
+
const validation = import_joi20.default.object({
|
|
22453
|
+
user: import_joi20.default.string().required(),
|
|
22454
|
+
subscriptionId: import_joi20.default.string().required()
|
|
22303
22455
|
});
|
|
22304
22456
|
const { error } = validation.validate(value);
|
|
22305
22457
|
if (error) {
|
|
@@ -22316,7 +22468,7 @@ function useSubscriptionController() {
|
|
|
22316
22468
|
}
|
|
22317
22469
|
async function getByUserId(req, res, next) {
|
|
22318
22470
|
const id = req.params.id;
|
|
22319
|
-
const validation =
|
|
22471
|
+
const validation = import_joi20.default.string().required();
|
|
22320
22472
|
const { error } = validation.validate(id);
|
|
22321
22473
|
if (error) {
|
|
22322
22474
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22331,7 +22483,7 @@ function useSubscriptionController() {
|
|
|
22331
22483
|
}
|
|
22332
22484
|
async function getByAffiliateUserId(req, res, next) {
|
|
22333
22485
|
const id = req.params.id;
|
|
22334
|
-
const validation =
|
|
22486
|
+
const validation = import_joi20.default.string().required();
|
|
22335
22487
|
const { error } = validation.validate(id);
|
|
22336
22488
|
if (error) {
|
|
22337
22489
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22346,7 +22498,7 @@ function useSubscriptionController() {
|
|
|
22346
22498
|
}
|
|
22347
22499
|
async function getByOrgId(req, res, next) {
|
|
22348
22500
|
const id = req.params.id;
|
|
22349
|
-
const validation =
|
|
22501
|
+
const validation = import_joi20.default.string().required();
|
|
22350
22502
|
const { error } = validation.validate(id);
|
|
22351
22503
|
if (error) {
|
|
22352
22504
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22361,7 +22513,7 @@ function useSubscriptionController() {
|
|
|
22361
22513
|
}
|
|
22362
22514
|
async function getById(req, res, next) {
|
|
22363
22515
|
const id = req.params.id;
|
|
22364
|
-
const validation =
|
|
22516
|
+
const validation = import_joi20.default.string().required();
|
|
22365
22517
|
const { error } = validation.validate(id);
|
|
22366
22518
|
if (error) {
|
|
22367
22519
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22378,10 +22530,10 @@ function useSubscriptionController() {
|
|
|
22378
22530
|
const status = req.query.status ?? "";
|
|
22379
22531
|
const search = req.query.search ?? "";
|
|
22380
22532
|
const page = Number(req.query.page) ?? 1;
|
|
22381
|
-
const validation =
|
|
22382
|
-
status:
|
|
22383
|
-
search:
|
|
22384
|
-
page:
|
|
22533
|
+
const validation = import_joi20.default.object({
|
|
22534
|
+
status: import_joi20.default.string().required(),
|
|
22535
|
+
search: import_joi20.default.string().optional().allow("", null),
|
|
22536
|
+
page: import_joi20.default.number().required()
|
|
22385
22537
|
});
|
|
22386
22538
|
const { error } = validation.validate({ status, search, page });
|
|
22387
22539
|
if (error) {
|
|
@@ -22397,7 +22549,7 @@ function useSubscriptionController() {
|
|
|
22397
22549
|
}
|
|
22398
22550
|
async function getSubscriptionStatus(req, res, next) {
|
|
22399
22551
|
const id = req.params.id;
|
|
22400
|
-
const validation =
|
|
22552
|
+
const validation = import_joi20.default.string().required();
|
|
22401
22553
|
const { error } = validation.validate(id);
|
|
22402
22554
|
if (error) {
|
|
22403
22555
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22449,11 +22601,11 @@ function useSubscriptionController() {
|
|
|
22449
22601
|
async function updateSubscriptionSeats(req, res, next) {
|
|
22450
22602
|
const subscriptionId = req.params.id ?? "";
|
|
22451
22603
|
const value = req.body;
|
|
22452
|
-
const { error } =
|
|
22453
|
-
subscriptionId:
|
|
22454
|
-
seats:
|
|
22455
|
-
promoCode:
|
|
22456
|
-
amount:
|
|
22604
|
+
const { error } = import_joi20.default.object({
|
|
22605
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22606
|
+
seats: import_joi20.default.number().required(),
|
|
22607
|
+
promoCode: import_joi20.default.string().optional().allow("", null),
|
|
22608
|
+
amount: import_joi20.default.number().min(0).optional()
|
|
22457
22609
|
}).validate({ subscriptionId, ...value });
|
|
22458
22610
|
if (error) {
|
|
22459
22611
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22471,9 +22623,9 @@ function useSubscriptionController() {
|
|
|
22471
22623
|
async function updatePromoCodeById(req, res, next) {
|
|
22472
22624
|
const subscriptionId = req.params.id ?? "";
|
|
22473
22625
|
const promoCode = req.body.promoCode;
|
|
22474
|
-
const { error } =
|
|
22475
|
-
subscriptionId:
|
|
22476
|
-
promoCode:
|
|
22626
|
+
const { error } = import_joi20.default.object({
|
|
22627
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22628
|
+
promoCode: import_joi20.default.string().optional().allow("", null)
|
|
22477
22629
|
}).validate({ subscriptionId, promoCode });
|
|
22478
22630
|
if (error) {
|
|
22479
22631
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22491,9 +22643,9 @@ function useSubscriptionController() {
|
|
|
22491
22643
|
async function updateStatusById(req, res, next) {
|
|
22492
22644
|
const subscriptionId = req.params.id ?? "";
|
|
22493
22645
|
const status = req.body.status;
|
|
22494
|
-
const { error } =
|
|
22495
|
-
subscriptionId:
|
|
22496
|
-
status:
|
|
22646
|
+
const { error } = import_joi20.default.object({
|
|
22647
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22648
|
+
status: import_joi20.default.string().optional().allow("", null)
|
|
22497
22649
|
}).validate({ subscriptionId, status });
|
|
22498
22650
|
if (error) {
|
|
22499
22651
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22508,6 +22660,90 @@ function useSubscriptionController() {
|
|
|
22508
22660
|
return;
|
|
22509
22661
|
}
|
|
22510
22662
|
}
|
|
22663
|
+
async function addBillingContactById(req, res, next) {
|
|
22664
|
+
const subscriptionId = req.params.id ?? "";
|
|
22665
|
+
const email = req.body.email;
|
|
22666
|
+
const { error } = import_joi20.default.object({
|
|
22667
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22668
|
+
email: import_joi20.default.string().email().required()
|
|
22669
|
+
}).validate({ subscriptionId, email });
|
|
22670
|
+
if (error) {
|
|
22671
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22672
|
+
return;
|
|
22673
|
+
}
|
|
22674
|
+
try {
|
|
22675
|
+
await _addBillingContactById(subscriptionId, email);
|
|
22676
|
+
res.json({ message: "Successfully added billing contact." });
|
|
22677
|
+
return;
|
|
22678
|
+
} catch (error2) {
|
|
22679
|
+
next(error2);
|
|
22680
|
+
return;
|
|
22681
|
+
}
|
|
22682
|
+
}
|
|
22683
|
+
async function updateBillingContactByAddedAt(req, res, next) {
|
|
22684
|
+
const id = req.params.id ?? "";
|
|
22685
|
+
const addedAt = req.params.addedAt ?? "";
|
|
22686
|
+
const email = req.body.email;
|
|
22687
|
+
const { error } = import_joi20.default.object({
|
|
22688
|
+
id: import_joi20.default.string().hex().required(),
|
|
22689
|
+
addedAt: import_joi20.default.string().isoDate().required(),
|
|
22690
|
+
email: import_joi20.default.string().email().required()
|
|
22691
|
+
}).validate({ id, addedAt, email });
|
|
22692
|
+
if (error) {
|
|
22693
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22694
|
+
return;
|
|
22695
|
+
}
|
|
22696
|
+
try {
|
|
22697
|
+
await _updateBillingContactByAddedAt(id, addedAt, email);
|
|
22698
|
+
res.json({ message: "Successfully updated billing contact." });
|
|
22699
|
+
return;
|
|
22700
|
+
} catch (error2) {
|
|
22701
|
+
next(error2);
|
|
22702
|
+
return;
|
|
22703
|
+
}
|
|
22704
|
+
}
|
|
22705
|
+
async function deleteBillingContactByAddedAt(req, res, next) {
|
|
22706
|
+
const id = req.params.id ?? "";
|
|
22707
|
+
const addedAt = req.params.addedAt ?? "";
|
|
22708
|
+
const { error } = import_joi20.default.object({
|
|
22709
|
+
id: import_joi20.default.string().hex().required(),
|
|
22710
|
+
addedAt: import_joi20.default.string().isoDate().required()
|
|
22711
|
+
}).validate({ id, addedAt });
|
|
22712
|
+
if (error) {
|
|
22713
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22714
|
+
return;
|
|
22715
|
+
}
|
|
22716
|
+
try {
|
|
22717
|
+
await _deleteBillingContactByAddedAt(id, addedAt);
|
|
22718
|
+
res.json({ message: "Successfully deleted billing contact." });
|
|
22719
|
+
return;
|
|
22720
|
+
} catch (error2) {
|
|
22721
|
+
next(error2);
|
|
22722
|
+
return;
|
|
22723
|
+
}
|
|
22724
|
+
}
|
|
22725
|
+
async function updatePaymentMethodById(req, res, next) {
|
|
22726
|
+
const subscriptionId = req.params.id ?? "";
|
|
22727
|
+
const paymentMethodId = req.body.paymentMethodId;
|
|
22728
|
+
const { error } = import_joi20.default.object({
|
|
22729
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22730
|
+
paymentMethodId: import_joi20.default.string().optional().allow("", null)
|
|
22731
|
+
}).validate({ subscriptionId, paymentMethodId });
|
|
22732
|
+
if (error) {
|
|
22733
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22734
|
+
return;
|
|
22735
|
+
}
|
|
22736
|
+
try {
|
|
22737
|
+
await _updatePaymentMethodById(subscriptionId, paymentMethodId);
|
|
22738
|
+
res.json({
|
|
22739
|
+
message: "Successfully updated subscription payment method."
|
|
22740
|
+
});
|
|
22741
|
+
return;
|
|
22742
|
+
} catch (error2) {
|
|
22743
|
+
next(error2);
|
|
22744
|
+
return;
|
|
22745
|
+
}
|
|
22746
|
+
}
|
|
22511
22747
|
return {
|
|
22512
22748
|
add,
|
|
22513
22749
|
getByUserId,
|
|
@@ -22520,7 +22756,11 @@ function useSubscriptionController() {
|
|
|
22520
22756
|
createOrgSubscription,
|
|
22521
22757
|
updateSubscriptionSeats,
|
|
22522
22758
|
updatePromoCodeById,
|
|
22523
|
-
updateStatusById
|
|
22759
|
+
updateStatusById,
|
|
22760
|
+
updatePaymentMethodById,
|
|
22761
|
+
addBillingContactById,
|
|
22762
|
+
updateBillingContactByAddedAt,
|
|
22763
|
+
deleteBillingContactByAddedAt
|
|
22524
22764
|
};
|
|
22525
22765
|
}
|
|
22526
22766
|
|
|
@@ -22834,7 +23074,7 @@ function usePaymentMethodService() {
|
|
|
22834
23074
|
}
|
|
22835
23075
|
|
|
22836
23076
|
// src/controllers/payment-method.controller.ts
|
|
22837
|
-
var
|
|
23077
|
+
var import_joi21 = __toESM(require("joi"));
|
|
22838
23078
|
var import_utils74 = require("@goweekdays/utils");
|
|
22839
23079
|
function usePaymentMethodController() {
|
|
22840
23080
|
const { linkEWallet: _linkEWallet, linkCard: _linkCard } = usePaymentMethodService();
|
|
@@ -22850,12 +23090,12 @@ function usePaymentMethodController() {
|
|
|
22850
23090
|
const success_return_url = req.body.success_return_url ?? "";
|
|
22851
23091
|
const failure_return_url = req.body.failure_return_url ?? "";
|
|
22852
23092
|
const cancel_return_url = req.body.cancel_return_url ?? "";
|
|
22853
|
-
const validation =
|
|
22854
|
-
customer_id:
|
|
22855
|
-
type:
|
|
22856
|
-
success_return_url:
|
|
22857
|
-
failure_return_url:
|
|
22858
|
-
cancel_return_url:
|
|
23093
|
+
const validation = import_joi21.default.object({
|
|
23094
|
+
customer_id: import_joi21.default.string().required(),
|
|
23095
|
+
type: import_joi21.default.string().valid("GCASH", "PAYMAYA", "SHOPEEPAY", "GRABPAY").required(),
|
|
23096
|
+
success_return_url: import_joi21.default.string().uri().required(),
|
|
23097
|
+
failure_return_url: import_joi21.default.string().uri().required(),
|
|
23098
|
+
cancel_return_url: import_joi21.default.string().uri().required()
|
|
22859
23099
|
});
|
|
22860
23100
|
const { error } = validation.validate({
|
|
22861
23101
|
customer_id,
|
|
@@ -22893,17 +23133,17 @@ function usePaymentMethodController() {
|
|
|
22893
23133
|
const failure_return_url = req.body.failure_return_url ?? "";
|
|
22894
23134
|
const cardType = req.body.cardType ?? "";
|
|
22895
23135
|
const user = req.headers["user"] ?? "";
|
|
22896
|
-
const validation =
|
|
22897
|
-
cardNumber:
|
|
22898
|
-
expiryMonth:
|
|
22899
|
-
expiryYear:
|
|
22900
|
-
cvv:
|
|
22901
|
-
cardholderName:
|
|
22902
|
-
currency:
|
|
22903
|
-
success_return_url:
|
|
22904
|
-
failure_return_url:
|
|
22905
|
-
cardType:
|
|
22906
|
-
user:
|
|
23136
|
+
const validation = import_joi21.default.object({
|
|
23137
|
+
cardNumber: import_joi21.default.string().required(),
|
|
23138
|
+
expiryMonth: import_joi21.default.string().required(),
|
|
23139
|
+
expiryYear: import_joi21.default.string().required(),
|
|
23140
|
+
cvv: import_joi21.default.string().required(),
|
|
23141
|
+
cardholderName: import_joi21.default.string().required(),
|
|
23142
|
+
currency: import_joi21.default.string().optional().allow("", null),
|
|
23143
|
+
success_return_url: import_joi21.default.string().uri().required(),
|
|
23144
|
+
failure_return_url: import_joi21.default.string().uri().required(),
|
|
23145
|
+
cardType: import_joi21.default.string().required(),
|
|
23146
|
+
user: import_joi21.default.string().hex().required()
|
|
22907
23147
|
});
|
|
22908
23148
|
const { error } = validation.validate({
|
|
22909
23149
|
user,
|
|
@@ -22942,8 +23182,8 @@ function usePaymentMethodController() {
|
|
|
22942
23182
|
const { getByUser: _getByUser, getByOrg: _getByOrg } = usePaymentMethodRepo();
|
|
22943
23183
|
async function getByUser(req, res, next) {
|
|
22944
23184
|
const user = req.params.user ?? "";
|
|
22945
|
-
const validation =
|
|
22946
|
-
user:
|
|
23185
|
+
const validation = import_joi21.default.object({
|
|
23186
|
+
user: import_joi21.default.string().hex().required()
|
|
22947
23187
|
});
|
|
22948
23188
|
const { error } = validation.validate({ user });
|
|
22949
23189
|
if (error) {
|
|
@@ -22958,8 +23198,8 @@ function usePaymentMethodController() {
|
|
|
22958
23198
|
}
|
|
22959
23199
|
async function getByOrg(req, res, next) {
|
|
22960
23200
|
const org = req.params.org ?? "";
|
|
22961
|
-
const validation =
|
|
22962
|
-
org:
|
|
23201
|
+
const validation = import_joi21.default.object({
|
|
23202
|
+
org: import_joi21.default.string().hex().required()
|
|
22963
23203
|
});
|
|
22964
23204
|
const { error } = validation.validate({ org });
|
|
22965
23205
|
if (error) {
|
|
@@ -22974,8 +23214,8 @@ function usePaymentMethodController() {
|
|
|
22974
23214
|
}
|
|
22975
23215
|
async function getPaymentMethodById(req, res, next) {
|
|
22976
23216
|
const id = req.params.id ?? "";
|
|
22977
|
-
const validation =
|
|
22978
|
-
id:
|
|
23217
|
+
const validation = import_joi21.default.object({
|
|
23218
|
+
id: import_joi21.default.string().required()
|
|
22979
23219
|
});
|
|
22980
23220
|
const { error } = validation.validate({ id });
|
|
22981
23221
|
if (error) {
|
|
@@ -23053,22 +23293,27 @@ function usePaymentMethodController() {
|
|
|
23053
23293
|
|
|
23054
23294
|
// src/controllers/address.controller.ts
|
|
23055
23295
|
var import_utils75 = require("@goweekdays/utils");
|
|
23056
|
-
var
|
|
23296
|
+
var import_joi22 = __toESM(require("joi"));
|
|
23057
23297
|
function useAddressController() {
|
|
23058
|
-
const {
|
|
23298
|
+
const {
|
|
23299
|
+
add: _add,
|
|
23300
|
+
getByUserId: _getByUserId,
|
|
23301
|
+
getByOrgId: _getByOrgId,
|
|
23302
|
+
updateById: _updateById
|
|
23303
|
+
} = useAddressRepo();
|
|
23059
23304
|
async function add(req, res, next) {
|
|
23060
23305
|
const value = req.body;
|
|
23061
|
-
const validation =
|
|
23062
|
-
type:
|
|
23063
|
-
user:
|
|
23064
|
-
org:
|
|
23065
|
-
country:
|
|
23066
|
-
address:
|
|
23067
|
-
continuedAddress:
|
|
23068
|
-
city:
|
|
23069
|
-
province:
|
|
23070
|
-
postalCode:
|
|
23071
|
-
taxId:
|
|
23306
|
+
const validation = import_joi22.default.object({
|
|
23307
|
+
type: import_joi22.default.string().required(),
|
|
23308
|
+
user: import_joi22.default.string().hex().optional().allow("", null),
|
|
23309
|
+
org: import_joi22.default.string().hex().optional().allow("", null),
|
|
23310
|
+
country: import_joi22.default.string().required(),
|
|
23311
|
+
address: import_joi22.default.string().required(),
|
|
23312
|
+
continuedAddress: import_joi22.default.string().optional().allow("", null),
|
|
23313
|
+
city: import_joi22.default.string().required(),
|
|
23314
|
+
province: import_joi22.default.string().required(),
|
|
23315
|
+
postalCode: import_joi22.default.string().required(),
|
|
23316
|
+
taxId: import_joi22.default.string().optional().allow("", null)
|
|
23072
23317
|
});
|
|
23073
23318
|
const { error } = validation.validate(value);
|
|
23074
23319
|
if (error) {
|
|
@@ -23083,9 +23328,35 @@ function useAddressController() {
|
|
|
23083
23328
|
next(error2);
|
|
23084
23329
|
}
|
|
23085
23330
|
}
|
|
23331
|
+
async function updateById(req, res, next) {
|
|
23332
|
+
const id = req.params.id ?? "";
|
|
23333
|
+
const value = req.body;
|
|
23334
|
+
const validation = import_joi22.default.object({
|
|
23335
|
+
id: import_joi22.default.string().hex().required(),
|
|
23336
|
+
country: import_joi22.default.string().required(),
|
|
23337
|
+
address: import_joi22.default.string().required(),
|
|
23338
|
+
continuedAddress: import_joi22.default.string().optional().allow("", null),
|
|
23339
|
+
city: import_joi22.default.string().required(),
|
|
23340
|
+
province: import_joi22.default.string().required(),
|
|
23341
|
+
postalCode: import_joi22.default.string().required(),
|
|
23342
|
+
taxId: import_joi22.default.string().optional().allow("", null)
|
|
23343
|
+
});
|
|
23344
|
+
const { error } = validation.validate({ id, ...value });
|
|
23345
|
+
if (error) {
|
|
23346
|
+
next(new import_utils75.BadRequestError(error.message));
|
|
23347
|
+
return;
|
|
23348
|
+
}
|
|
23349
|
+
try {
|
|
23350
|
+
const message = await _updateById(id, value);
|
|
23351
|
+
res.json({ message });
|
|
23352
|
+
return;
|
|
23353
|
+
} catch (error2) {
|
|
23354
|
+
next(error2);
|
|
23355
|
+
}
|
|
23356
|
+
}
|
|
23086
23357
|
async function getByUserId(req, res, next) {
|
|
23087
23358
|
const user = req.params.user;
|
|
23088
|
-
const validation =
|
|
23359
|
+
const validation = import_joi22.default.string().hex().required();
|
|
23089
23360
|
const { error } = validation.validate(user);
|
|
23090
23361
|
if (error) {
|
|
23091
23362
|
next(new import_utils75.BadRequestError(error.message));
|
|
@@ -23102,9 +23373,30 @@ function useAddressController() {
|
|
|
23102
23373
|
next(error2);
|
|
23103
23374
|
}
|
|
23104
23375
|
}
|
|
23376
|
+
async function getByOrgId(req, res, next) {
|
|
23377
|
+
const id = req.params.id;
|
|
23378
|
+
const validation = import_joi22.default.string().hex().required();
|
|
23379
|
+
const { error } = validation.validate(id);
|
|
23380
|
+
if (error) {
|
|
23381
|
+
next(new import_utils75.BadRequestError(error.message));
|
|
23382
|
+
}
|
|
23383
|
+
try {
|
|
23384
|
+
const address = await _getByOrgId(id);
|
|
23385
|
+
if (!address) {
|
|
23386
|
+
next(new import_utils75.NotFoundError("Address not found."));
|
|
23387
|
+
return;
|
|
23388
|
+
}
|
|
23389
|
+
res.json(address);
|
|
23390
|
+
return;
|
|
23391
|
+
} catch (error2) {
|
|
23392
|
+
next(error2);
|
|
23393
|
+
}
|
|
23394
|
+
}
|
|
23105
23395
|
return {
|
|
23106
23396
|
add,
|
|
23107
|
-
getByUserId
|
|
23397
|
+
getByUserId,
|
|
23398
|
+
getByOrgId,
|
|
23399
|
+
updateById
|
|
23108
23400
|
};
|
|
23109
23401
|
}
|
|
23110
23402
|
|
|
@@ -23166,20 +23458,20 @@ function useOrgService() {
|
|
|
23166
23458
|
|
|
23167
23459
|
// src/controllers/organization.controller.ts
|
|
23168
23460
|
var import_utils77 = require("@goweekdays/utils");
|
|
23169
|
-
var
|
|
23461
|
+
var import_joi23 = __toESM(require("joi"));
|
|
23170
23462
|
function useOrgController() {
|
|
23171
23463
|
const { createOrg: _createOrg } = useOrgService();
|
|
23172
23464
|
const { getOrgsByMembership } = useMemberRepo();
|
|
23173
23465
|
const { getByName: _getByName } = useOrgRepo();
|
|
23174
23466
|
async function createOrg(req, res, next) {
|
|
23175
23467
|
const value = req.body;
|
|
23176
|
-
const validation =
|
|
23177
|
-
name:
|
|
23178
|
-
type:
|
|
23179
|
-
email:
|
|
23180
|
-
contact:
|
|
23181
|
-
description:
|
|
23182
|
-
user:
|
|
23468
|
+
const validation = import_joi23.default.object({
|
|
23469
|
+
name: import_joi23.default.string().required(),
|
|
23470
|
+
type: import_joi23.default.string().required(),
|
|
23471
|
+
email: import_joi23.default.string().email().required(),
|
|
23472
|
+
contact: import_joi23.default.string().required(),
|
|
23473
|
+
description: import_joi23.default.string().required(),
|
|
23474
|
+
user: import_joi23.default.string().hex().required()
|
|
23183
23475
|
});
|
|
23184
23476
|
const { error } = validation.validate(value);
|
|
23185
23477
|
if (error) {
|
|
@@ -23209,11 +23501,11 @@ function useOrgController() {
|
|
|
23209
23501
|
next(new import_utils77.BadRequestError("Invalid limit number."));
|
|
23210
23502
|
return;
|
|
23211
23503
|
}
|
|
23212
|
-
const validation =
|
|
23213
|
-
user:
|
|
23214
|
-
page:
|
|
23215
|
-
limit:
|
|
23216
|
-
search:
|
|
23504
|
+
const validation = import_joi23.default.object({
|
|
23505
|
+
user: import_joi23.default.string().hex().required(),
|
|
23506
|
+
page: import_joi23.default.number().min(1).optional().allow("", null),
|
|
23507
|
+
limit: import_joi23.default.number().min(1).optional().allow("", null),
|
|
23508
|
+
search: import_joi23.default.string().optional().allow("", null)
|
|
23217
23509
|
});
|
|
23218
23510
|
const { error } = validation.validate({ user, page, limit, search });
|
|
23219
23511
|
if (error) {
|
|
@@ -23230,8 +23522,8 @@ function useOrgController() {
|
|
|
23230
23522
|
}
|
|
23231
23523
|
async function getByName(req, res, next) {
|
|
23232
23524
|
const name = req.params.name;
|
|
23233
|
-
const validation =
|
|
23234
|
-
name:
|
|
23525
|
+
const validation = import_joi23.default.object({
|
|
23526
|
+
name: import_joi23.default.string().required()
|
|
23235
23527
|
});
|
|
23236
23528
|
const { error } = validation.validate({ name });
|
|
23237
23529
|
if (error) {
|
|
@@ -23254,7 +23546,7 @@ function useOrgController() {
|
|
|
23254
23546
|
}
|
|
23255
23547
|
|
|
23256
23548
|
// src/controllers/member.controller.ts
|
|
23257
|
-
var
|
|
23549
|
+
var import_joi24 = __toESM(require("joi"));
|
|
23258
23550
|
var import_utils78 = require("@goweekdays/utils");
|
|
23259
23551
|
function useMemberController() {
|
|
23260
23552
|
const {
|
|
@@ -23264,8 +23556,8 @@ function useMemberController() {
|
|
|
23264
23556
|
} = useMemberRepo();
|
|
23265
23557
|
async function getByUserId(req, res, next) {
|
|
23266
23558
|
const userId = req.params.id;
|
|
23267
|
-
const validation =
|
|
23268
|
-
id:
|
|
23559
|
+
const validation = import_joi24.default.object({
|
|
23560
|
+
id: import_joi24.default.string().hex().required()
|
|
23269
23561
|
});
|
|
23270
23562
|
const { error } = validation.validate({ id: userId });
|
|
23271
23563
|
if (error) {
|
|
@@ -23291,14 +23583,14 @@ function useMemberController() {
|
|
|
23291
23583
|
const org = req.query.org ?? "";
|
|
23292
23584
|
const type = req.query.type ?? "main";
|
|
23293
23585
|
const status = req.query.status ?? "active";
|
|
23294
|
-
const validation =
|
|
23295
|
-
limit:
|
|
23296
|
-
search:
|
|
23297
|
-
page:
|
|
23298
|
-
user:
|
|
23299
|
-
org:
|
|
23300
|
-
type:
|
|
23301
|
-
status:
|
|
23586
|
+
const validation = import_joi24.default.object({
|
|
23587
|
+
limit: import_joi24.default.number().min(10).max(50).required(),
|
|
23588
|
+
search: import_joi24.default.string().optional().allow("", null),
|
|
23589
|
+
page: import_joi24.default.number().required(),
|
|
23590
|
+
user: import_joi24.default.string().hex().optional().allow("", null),
|
|
23591
|
+
org: import_joi24.default.string().hex().optional().allow("", null),
|
|
23592
|
+
type: import_joi24.default.string().required(),
|
|
23593
|
+
status: import_joi24.default.string().required()
|
|
23302
23594
|
});
|
|
23303
23595
|
const { error } = validation.validate({
|
|
23304
23596
|
search,
|
|
@@ -23311,6 +23603,7 @@ function useMemberController() {
|
|
|
23311
23603
|
});
|
|
23312
23604
|
if (error) {
|
|
23313
23605
|
next(new import_utils78.BadRequestError(error.message));
|
|
23606
|
+
return;
|
|
23314
23607
|
}
|
|
23315
23608
|
try {
|
|
23316
23609
|
const items = await _getAll({
|
|
@@ -23333,11 +23626,11 @@ function useMemberController() {
|
|
|
23333
23626
|
const search = req.query.search ?? "";
|
|
23334
23627
|
const page = Number(req.query.page) ?? 1;
|
|
23335
23628
|
const user = req.query.user ?? "";
|
|
23336
|
-
const validation =
|
|
23337
|
-
limit:
|
|
23338
|
-
search:
|
|
23339
|
-
page:
|
|
23340
|
-
user:
|
|
23629
|
+
const validation = import_joi24.default.object({
|
|
23630
|
+
limit: import_joi24.default.number().min(10).max(50).required(),
|
|
23631
|
+
search: import_joi24.default.string().optional().allow("", null),
|
|
23632
|
+
page: import_joi24.default.number().required(),
|
|
23633
|
+
user: import_joi24.default.string().hex().optional().allow("", null)
|
|
23341
23634
|
});
|
|
23342
23635
|
const { error } = validation.validate({
|
|
23343
23636
|
search,
|
|
@@ -23370,7 +23663,7 @@ function useMemberController() {
|
|
|
23370
23663
|
|
|
23371
23664
|
// src/controllers/promo-code.controller.ts
|
|
23372
23665
|
var import_utils79 = require("@goweekdays/utils");
|
|
23373
|
-
var
|
|
23666
|
+
var import_joi25 = __toESM(require("joi"));
|
|
23374
23667
|
function usePromoCodeController() {
|
|
23375
23668
|
const {
|
|
23376
23669
|
add: _add,
|
|
@@ -23401,11 +23694,11 @@ function usePromoCodeController() {
|
|
|
23401
23694
|
const code = req.query.code;
|
|
23402
23695
|
const type = req.query.type;
|
|
23403
23696
|
const assigned = req.query.assigned === "true" ? true : req.query.assigned === "false" ? false : null;
|
|
23404
|
-
const validation =
|
|
23405
|
-
code:
|
|
23406
|
-
type:
|
|
23697
|
+
const validation = import_joi25.default.object({
|
|
23698
|
+
code: import_joi25.default.string().trim().required(),
|
|
23699
|
+
type: import_joi25.default.string().optional(),
|
|
23407
23700
|
// true or false
|
|
23408
|
-
assigned:
|
|
23701
|
+
assigned: import_joi25.default.boolean().optional().allow(null, "")
|
|
23409
23702
|
});
|
|
23410
23703
|
const { error } = validation.validate({ code, type, assigned });
|
|
23411
23704
|
if (error) {
|
|
@@ -23430,8 +23723,8 @@ function usePromoCodeController() {
|
|
|
23430
23723
|
}
|
|
23431
23724
|
async function getById(req, res, next) {
|
|
23432
23725
|
const id = req.params.id;
|
|
23433
|
-
const validation =
|
|
23434
|
-
id:
|
|
23726
|
+
const validation = import_joi25.default.object({
|
|
23727
|
+
id: import_joi25.default.string().hex().required()
|
|
23435
23728
|
});
|
|
23436
23729
|
const { error } = validation.validate({ id });
|
|
23437
23730
|
if (error) {
|
|
@@ -23459,11 +23752,11 @@ function usePromoCodeController() {
|
|
|
23459
23752
|
const limit = req.query.limit ? Number(req.query.limit) : 10;
|
|
23460
23753
|
const search = req.query.search;
|
|
23461
23754
|
const status = req.query.status;
|
|
23462
|
-
const validation =
|
|
23463
|
-
page:
|
|
23464
|
-
limit:
|
|
23465
|
-
search:
|
|
23466
|
-
status:
|
|
23755
|
+
const validation = import_joi25.default.object({
|
|
23756
|
+
page: import_joi25.default.number().required(),
|
|
23757
|
+
limit: import_joi25.default.number().integer().optional().min(10).max(100),
|
|
23758
|
+
search: import_joi25.default.string().optional().allow(""),
|
|
23759
|
+
status: import_joi25.default.string().required()
|
|
23467
23760
|
});
|
|
23468
23761
|
const { error } = validation.validate({ page, limit, search, status });
|
|
23469
23762
|
if (error) {
|
|
@@ -23495,26 +23788,26 @@ function usePromoCodeController() {
|
|
|
23495
23788
|
var import_mongodb38 = require("mongodb");
|
|
23496
23789
|
|
|
23497
23790
|
// src/validations/order.schema.ts
|
|
23498
|
-
var
|
|
23499
|
-
var schema2 =
|
|
23500
|
-
_id:
|
|
23501
|
-
payment:
|
|
23502
|
-
user:
|
|
23503
|
-
org:
|
|
23504
|
-
type:
|
|
23505
|
-
amount:
|
|
23506
|
-
currency:
|
|
23507
|
-
description:
|
|
23508
|
-
metadata:
|
|
23509
|
-
subscriptionId:
|
|
23510
|
-
cycle:
|
|
23511
|
-
seats:
|
|
23512
|
-
promoCode:
|
|
23791
|
+
var import_joi26 = __toESM(require("joi"));
|
|
23792
|
+
var schema2 = import_joi26.default.object({
|
|
23793
|
+
_id: import_joi26.default.string().hex().optional().allow("", null),
|
|
23794
|
+
payment: import_joi26.default.string().required(),
|
|
23795
|
+
user: import_joi26.default.string().hex().optional().allow("", null),
|
|
23796
|
+
org: import_joi26.default.string().hex().optional().allow("", null),
|
|
23797
|
+
type: import_joi26.default.string().required(),
|
|
23798
|
+
amount: import_joi26.default.number().positive().min(0).required(),
|
|
23799
|
+
currency: import_joi26.default.string().required(),
|
|
23800
|
+
description: import_joi26.default.string().optional().allow("", null),
|
|
23801
|
+
metadata: import_joi26.default.object({
|
|
23802
|
+
subscriptionId: import_joi26.default.string().hex().optional().allow("", null),
|
|
23803
|
+
cycle: import_joi26.default.number().optional().allow("", null),
|
|
23804
|
+
seats: import_joi26.default.number().optional().allow("", null),
|
|
23805
|
+
promoCode: import_joi26.default.string().optional().allow("", null)
|
|
23513
23806
|
}).optional().allow("", null),
|
|
23514
|
-
status:
|
|
23515
|
-
createdAt:
|
|
23516
|
-
updatedAt:
|
|
23517
|
-
deletedAt:
|
|
23807
|
+
status: import_joi26.default.string().optional().allow("", null),
|
|
23808
|
+
createdAt: import_joi26.default.string().optional().allow("", null),
|
|
23809
|
+
updatedAt: import_joi26.default.string().optional().allow("", null),
|
|
23810
|
+
deletedAt: import_joi26.default.string().optional().allow("", null)
|
|
23518
23811
|
});
|
|
23519
23812
|
|
|
23520
23813
|
// src/models/order.model.ts
|
|
@@ -23651,7 +23944,7 @@ function useOrderRepo() {
|
|
|
23651
23944
|
|
|
23652
23945
|
// src/controllers/order.controller.ts
|
|
23653
23946
|
var import_utils82 = require("@goweekdays/utils");
|
|
23654
|
-
var
|
|
23947
|
+
var import_joi27 = __toESM(require("joi"));
|
|
23655
23948
|
function useOrderController() {
|
|
23656
23949
|
const { getOrders: _getOrders } = useOrderRepo();
|
|
23657
23950
|
async function getOrders(req, res, next) {
|
|
@@ -23660,12 +23953,12 @@ function useOrderController() {
|
|
|
23660
23953
|
const search = req.query.search ?? "";
|
|
23661
23954
|
const status = req.query.status ?? "succeeded";
|
|
23662
23955
|
const id = req.query.id ?? "";
|
|
23663
|
-
const validation =
|
|
23664
|
-
page:
|
|
23665
|
-
limit:
|
|
23666
|
-
search:
|
|
23667
|
-
status:
|
|
23668
|
-
id:
|
|
23956
|
+
const validation = import_joi27.default.object({
|
|
23957
|
+
page: import_joi27.default.number().required(),
|
|
23958
|
+
limit: import_joi27.default.number().required().min(10),
|
|
23959
|
+
search: import_joi27.default.string().optional().allow("", null),
|
|
23960
|
+
status: import_joi27.default.string().optional().allow("", null),
|
|
23961
|
+
id: import_joi27.default.string().hex().optional().allow("", null)
|
|
23669
23962
|
});
|
|
23670
23963
|
const { error } = validation.validate({ page, limit, search, status, id });
|
|
23671
23964
|
if (error) {
|
|
@@ -23874,7 +24167,7 @@ function useInvoiceService() {
|
|
|
23874
24167
|
|
|
23875
24168
|
// src/controllers/invoice.controller.ts
|
|
23876
24169
|
var import_utils84 = require("@goweekdays/utils");
|
|
23877
|
-
var
|
|
24170
|
+
var import_joi28 = __toESM(require("joi"));
|
|
23878
24171
|
function useInvoiceController() {
|
|
23879
24172
|
const {
|
|
23880
24173
|
getBySubscriptionId: _getBySubscriptionId,
|
|
@@ -23886,11 +24179,11 @@ function useInvoiceController() {
|
|
|
23886
24179
|
const page = req.query.page ? Number(req.query.page) : 1;
|
|
23887
24180
|
const limit = req.query.limit ? Number(req.query.limit) : 10;
|
|
23888
24181
|
const search = req.query.search ?? "";
|
|
23889
|
-
const validation =
|
|
23890
|
-
id:
|
|
23891
|
-
page:
|
|
23892
|
-
limit:
|
|
23893
|
-
search:
|
|
24182
|
+
const validation = import_joi28.default.object({
|
|
24183
|
+
id: import_joi28.default.string().required(),
|
|
24184
|
+
page: import_joi28.default.number().integer().min(1).default(1),
|
|
24185
|
+
limit: import_joi28.default.number().integer().min(1).default(10),
|
|
24186
|
+
search: import_joi28.default.string().optional().allow("", null)
|
|
23894
24187
|
});
|
|
23895
24188
|
const { error } = validation.validate({
|
|
23896
24189
|
id,
|
|
@@ -23917,7 +24210,7 @@ function useInvoiceController() {
|
|
|
23917
24210
|
}
|
|
23918
24211
|
async function getByNumber(req, res, next) {
|
|
23919
24212
|
const number = req.params.number;
|
|
23920
|
-
const validation =
|
|
24213
|
+
const validation = import_joi28.default.string().required();
|
|
23921
24214
|
const { error } = validation.validate(number);
|
|
23922
24215
|
if (error) {
|
|
23923
24216
|
next(new import_utils84.BadRequestError(error.message));
|
|
@@ -23937,9 +24230,9 @@ function useInvoiceController() {
|
|
|
23937
24230
|
async function getByDueDateStatus(req, res, next) {
|
|
23938
24231
|
const date = req.params.date;
|
|
23939
24232
|
const status = req.params.status;
|
|
23940
|
-
const validation =
|
|
23941
|
-
date:
|
|
23942
|
-
status:
|
|
24233
|
+
const validation = import_joi28.default.object({
|
|
24234
|
+
date: import_joi28.default.string().required(),
|
|
24235
|
+
status: import_joi28.default.string().required()
|
|
23943
24236
|
});
|
|
23944
24237
|
const { error } = validation.validate({ date, status });
|
|
23945
24238
|
if (error) {
|
|
@@ -23966,7 +24259,7 @@ function useInvoiceController() {
|
|
|
23966
24259
|
|
|
23967
24260
|
// src/controllers/payment.controller.ts
|
|
23968
24261
|
var import_utils85 = require("@goweekdays/utils");
|
|
23969
|
-
var
|
|
24262
|
+
var import_joi29 = __toESM(require("joi"));
|
|
23970
24263
|
function usePaymentController() {
|
|
23971
24264
|
const { getPayments: _getPayments } = usePaymentRepo();
|
|
23972
24265
|
async function getPayments(req, res, next) {
|
|
@@ -23975,12 +24268,12 @@ function usePaymentController() {
|
|
|
23975
24268
|
const search = req.query.search ?? "";
|
|
23976
24269
|
const status = req.query.status ?? "succeeded";
|
|
23977
24270
|
const id = req.query.id ?? "";
|
|
23978
|
-
const validation =
|
|
23979
|
-
page:
|
|
23980
|
-
limit:
|
|
23981
|
-
search:
|
|
23982
|
-
status:
|
|
23983
|
-
id:
|
|
24271
|
+
const validation = import_joi29.default.object({
|
|
24272
|
+
page: import_joi29.default.number().required(),
|
|
24273
|
+
limit: import_joi29.default.number().required().min(10),
|
|
24274
|
+
search: import_joi29.default.string().optional().allow("", null),
|
|
24275
|
+
status: import_joi29.default.string().optional().allow("", null),
|
|
24276
|
+
id: import_joi29.default.string().hex().optional().allow("", null)
|
|
23984
24277
|
});
|
|
23985
24278
|
const { error } = validation.validate({ page, limit, search, status, id });
|
|
23986
24279
|
if (error) {
|
|
@@ -24087,6 +24380,7 @@ function usePriceController() {
|
|
|
24087
24380
|
VERIFICATION_USER_INVITE_DURATION,
|
|
24088
24381
|
XENDIT_BASE_URL,
|
|
24089
24382
|
XENDIT_SECRET_KEY,
|
|
24383
|
+
addressSchema,
|
|
24090
24384
|
isDev,
|
|
24091
24385
|
schema,
|
|
24092
24386
|
useAddressController,
|