@goweekdays/core 0.0.20 → 0.0.22
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 +12 -0
- package/dist/index.d.ts +31 -11
- package/dist/index.js +637 -218
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +636 -218
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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");
|
|
@@ -21344,6 +21492,7 @@ function useSubscriptionService() {
|
|
|
21344
21492
|
const { add: addPayment } = usePaymentRepo();
|
|
21345
21493
|
const { getByType, incrementByType } = useCounterRepo();
|
|
21346
21494
|
const { getByNameType } = usePriceRepo();
|
|
21495
|
+
const { getByNumber } = useInvoiceRepo();
|
|
21347
21496
|
function calculateTieredPricing(seats, tiers, prorationFactor = 1) {
|
|
21348
21497
|
let totalCost = 0;
|
|
21349
21498
|
let nonProratedCost = 0;
|
|
@@ -21938,8 +22087,8 @@ function useSubscriptionService() {
|
|
|
21938
22087
|
return remainingDays > 1 ? Number((seats * price * prorationFactor).toFixed(2)) : Number((seats * price).toFixed(2));
|
|
21939
22088
|
}
|
|
21940
22089
|
function formatAmount(amount) {
|
|
21941
|
-
const validation =
|
|
21942
|
-
amount:
|
|
22090
|
+
const validation = import_joi18.default.object({
|
|
22091
|
+
amount: import_joi18.default.number().required()
|
|
21943
22092
|
});
|
|
21944
22093
|
const { error } = validation.validate({ amount });
|
|
21945
22094
|
if (error) {
|
|
@@ -22019,10 +22168,10 @@ function useSubscriptionService() {
|
|
|
22019
22168
|
}
|
|
22020
22169
|
}
|
|
22021
22170
|
async function updateSeatsById(value) {
|
|
22022
|
-
const schema3 =
|
|
22023
|
-
subscriptionId:
|
|
22024
|
-
seats:
|
|
22025
|
-
amount:
|
|
22171
|
+
const schema3 = import_joi18.default.object({
|
|
22172
|
+
subscriptionId: import_joi18.default.string().hex().required(),
|
|
22173
|
+
seats: import_joi18.default.number().min(1).required(),
|
|
22174
|
+
amount: import_joi18.default.number().required()
|
|
22026
22175
|
});
|
|
22027
22176
|
const { error } = schema3.validate(value);
|
|
22028
22177
|
if (error) {
|
|
@@ -22223,54 +22372,156 @@ function useSubscriptionService() {
|
|
|
22223
22372
|
session?.endSession();
|
|
22224
22373
|
}
|
|
22225
22374
|
}
|
|
22375
|
+
async function processSubscriptionPayment(invoiceNumber, subscriptionId) {
|
|
22376
|
+
const invoice = await getByNumber(invoiceNumber);
|
|
22377
|
+
if (!invoice) {
|
|
22378
|
+
throw new import_utils69.BadRequestError("Invoice not found.");
|
|
22379
|
+
}
|
|
22380
|
+
if (invoice.status === "paid") {
|
|
22381
|
+
throw new import_utils69.BadRequestError("Invoice already paid.");
|
|
22382
|
+
}
|
|
22383
|
+
if (!invoice._id) {
|
|
22384
|
+
throw new import_utils69.BadRequestError("Invoice ID is missing.");
|
|
22385
|
+
}
|
|
22386
|
+
if (!invoice.metadata?.subscriptionId) {
|
|
22387
|
+
throw new import_utils69.BadRequestError("Subscription ID is missing.");
|
|
22388
|
+
}
|
|
22389
|
+
if (invoice.metadata.subscriptionId.toString() !== subscriptionId) {
|
|
22390
|
+
throw new import_utils69.BadRequestError("Subscription ID does not match invoice.");
|
|
22391
|
+
}
|
|
22392
|
+
const subscription = await _getById(invoice.metadata.subscriptionId);
|
|
22393
|
+
if (!subscription) {
|
|
22394
|
+
throw new import_utils69.BadRequestError("Subscription not found.");
|
|
22395
|
+
}
|
|
22396
|
+
if (!subscription._id) {
|
|
22397
|
+
throw new import_utils69.BadRequestError("Subscription ID is missing.");
|
|
22398
|
+
}
|
|
22399
|
+
if (!subscription.customerId) {
|
|
22400
|
+
throw new import_utils69.BadRequestError("Customer ID is missing.");
|
|
22401
|
+
}
|
|
22402
|
+
if (!subscription.paymentMethodId) {
|
|
22403
|
+
throw new import_utils69.BadRequestError("Payment method ID is missing.");
|
|
22404
|
+
}
|
|
22405
|
+
if (!subscription.amount) {
|
|
22406
|
+
throw new import_utils69.BadRequestError("Subscription amount is missing.");
|
|
22407
|
+
}
|
|
22408
|
+
if (!subscription.currency) {
|
|
22409
|
+
throw new import_utils69.BadRequestError("Subscription currency is missing.");
|
|
22410
|
+
}
|
|
22411
|
+
const session = import_utils69.useAtlas.getClient()?.startSession();
|
|
22412
|
+
try {
|
|
22413
|
+
session?.startTransaction();
|
|
22414
|
+
const payment = await pay({
|
|
22415
|
+
customer_id: subscription.customerId,
|
|
22416
|
+
payment_method_id: subscription.paymentMethodId,
|
|
22417
|
+
amount: subscription.amount,
|
|
22418
|
+
currency: subscription.currency,
|
|
22419
|
+
description: "GoWeekdays Subscription Payment"
|
|
22420
|
+
});
|
|
22421
|
+
if (!payment.id) {
|
|
22422
|
+
throw new import_utils69.BadRequestError("Failed to process payment.");
|
|
22423
|
+
}
|
|
22424
|
+
const paymentMethod = await getPaymentMethodById(
|
|
22425
|
+
subscription.paymentMethodId
|
|
22426
|
+
);
|
|
22427
|
+
if (!paymentMethod) {
|
|
22428
|
+
throw new import_utils69.BadRequestError("Payment method not found.");
|
|
22429
|
+
}
|
|
22430
|
+
const paymentData = {
|
|
22431
|
+
invoiceId: invoiceNumber,
|
|
22432
|
+
amount: subscription.amount,
|
|
22433
|
+
paymentMethod: paymentMethod.type,
|
|
22434
|
+
status: "completed",
|
|
22435
|
+
metadata: {
|
|
22436
|
+
userId: String(subscription.user),
|
|
22437
|
+
orgId: String(subscription.org),
|
|
22438
|
+
currency: subscription.currency,
|
|
22439
|
+
paymentMethod: paymentMethod.type === "EWALLET" ? paymentMethod.ewallet.channel_code : paymentMethod.type === "DIRECT_DEBIT" ? paymentMethod.direct_debit.channel_code : "",
|
|
22440
|
+
paymentMethodType: paymentMethod.type,
|
|
22441
|
+
paymentMethodId: subscription.paymentMethodId,
|
|
22442
|
+
payment: payment.id,
|
|
22443
|
+
subscriptionId: subscription._id.toString()
|
|
22444
|
+
}
|
|
22445
|
+
};
|
|
22446
|
+
if (!paymentData.metadata.userId) {
|
|
22447
|
+
delete paymentData.metadata.userId;
|
|
22448
|
+
}
|
|
22449
|
+
if (!paymentData.metadata.orgId) {
|
|
22450
|
+
delete paymentData.metadata.orgId;
|
|
22451
|
+
}
|
|
22452
|
+
await addPayment(paymentData, session);
|
|
22453
|
+
await updateStatusByInvoiceNumber(invoiceNumber, "paid", session);
|
|
22454
|
+
await processSuccessfulPayment(
|
|
22455
|
+
{
|
|
22456
|
+
_id: subscription._id.toString(),
|
|
22457
|
+
nextBillingDate: subscription.nextBillingDate
|
|
22458
|
+
},
|
|
22459
|
+
session
|
|
22460
|
+
);
|
|
22461
|
+
await session?.commitTransaction();
|
|
22462
|
+
} catch (error) {
|
|
22463
|
+
await session?.abortTransaction();
|
|
22464
|
+
import_utils69.logger.log({
|
|
22465
|
+
level: "error",
|
|
22466
|
+
message: `Failed to process subscription payment: ${error}`
|
|
22467
|
+
});
|
|
22468
|
+
if (error instanceof import_utils69.AppError) {
|
|
22469
|
+
throw error;
|
|
22470
|
+
}
|
|
22471
|
+
throw new import_utils69.BadRequestError("Failed to process subscription payment.");
|
|
22472
|
+
} finally {
|
|
22473
|
+
session?.endSession();
|
|
22474
|
+
}
|
|
22475
|
+
}
|
|
22226
22476
|
return {
|
|
22227
22477
|
getByUserId,
|
|
22228
22478
|
getStatusByUser,
|
|
22229
22479
|
createAffiliateSubscription,
|
|
22230
22480
|
createOrgSubscription,
|
|
22231
22481
|
processSubscriptions,
|
|
22232
|
-
updateSeatsById
|
|
22482
|
+
updateSeatsById,
|
|
22483
|
+
processSubscriptionPayment
|
|
22233
22484
|
};
|
|
22234
22485
|
}
|
|
22235
22486
|
|
|
22236
22487
|
// src/controllers/subscription.controller.ts
|
|
22237
|
-
var
|
|
22488
|
+
var import_joi20 = __toESM(require("joi"));
|
|
22238
22489
|
var import_utils70 = require("@goweekdays/utils");
|
|
22239
22490
|
|
|
22240
22491
|
// src/validations/subscription.schema.ts
|
|
22241
|
-
var
|
|
22492
|
+
var import_joi19 = __toESM(require("joi"));
|
|
22242
22493
|
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:
|
|
22494
|
+
const schema3 = import_joi19.default.object({
|
|
22495
|
+
user: import_joi19.default.string().required().min(0),
|
|
22496
|
+
amount: import_joi19.default.number().min(0).required(),
|
|
22497
|
+
customer_id: import_joi19.default.string().required(),
|
|
22498
|
+
payment_method_id: import_joi19.default.string().required(),
|
|
22499
|
+
payment_method_type: import_joi19.default.string().required(),
|
|
22500
|
+
payment_method_channel: import_joi19.default.string().required(),
|
|
22501
|
+
payment_method_month_expiry: import_joi19.default.string().optional().allow(null, ""),
|
|
22502
|
+
payment_method_year_expiry: import_joi19.default.string().optional().allow(null, ""),
|
|
22503
|
+
payment_method_cvv: import_joi19.default.string().optional().allow(null, ""),
|
|
22504
|
+
currency: import_joi19.default.string().optional().allow("", null),
|
|
22505
|
+
seats: import_joi19.default.number().optional().min(0).allow(null),
|
|
22506
|
+
organization: import_joi19.default.object({
|
|
22507
|
+
name: import_joi19.default.string().required(),
|
|
22508
|
+
description: import_joi19.default.string().optional().allow("", null),
|
|
22509
|
+
type: import_joi19.default.string().allow("personal", "business").required(),
|
|
22510
|
+
email: import_joi19.default.string().email().required(),
|
|
22511
|
+
contact: import_joi19.default.string().required(),
|
|
22512
|
+
busInst: import_joi19.default.string().optional().allow(null, "")
|
|
22262
22513
|
}).optional().allow({}),
|
|
22263
|
-
billingAddress:
|
|
22264
|
-
type:
|
|
22265
|
-
country:
|
|
22266
|
-
address:
|
|
22267
|
-
continuedAddress:
|
|
22268
|
-
city:
|
|
22269
|
-
province:
|
|
22270
|
-
postalCode:
|
|
22271
|
-
taxId:
|
|
22514
|
+
billingAddress: import_joi19.default.object({
|
|
22515
|
+
type: import_joi19.default.string().required(),
|
|
22516
|
+
country: import_joi19.default.string().required(),
|
|
22517
|
+
address: import_joi19.default.string().required(),
|
|
22518
|
+
continuedAddress: import_joi19.default.string().optional().allow(null, ""),
|
|
22519
|
+
city: import_joi19.default.string().required(),
|
|
22520
|
+
province: import_joi19.default.string().required(),
|
|
22521
|
+
postalCode: import_joi19.default.string().required(),
|
|
22522
|
+
taxId: import_joi19.default.string().optional().allow(null, "")
|
|
22272
22523
|
}).required(),
|
|
22273
|
-
promoCode:
|
|
22524
|
+
promoCode: import_joi19.default.string().optional().allow("", null)
|
|
22274
22525
|
});
|
|
22275
22526
|
return {
|
|
22276
22527
|
schema: schema3
|
|
@@ -22286,20 +22537,25 @@ function useSubscriptionController() {
|
|
|
22286
22537
|
getByOrgId: _getByOrgId,
|
|
22287
22538
|
getById: _getById,
|
|
22288
22539
|
updatePromoCodeById: _updatePromoCodeById,
|
|
22289
|
-
updateStatusById: _updateStatusById
|
|
22540
|
+
updateStatusById: _updateStatusById,
|
|
22541
|
+
updatePaymentMethodById: _updatePaymentMethodById,
|
|
22542
|
+
addBillingContactById: _addBillingContactById,
|
|
22543
|
+
updateBillingContactByAddedAt: _updateBillingContactByAddedAt,
|
|
22544
|
+
deleteBillingContactByAddedAt: _deleteBillingContactByAddedAt
|
|
22290
22545
|
} = useSubscriptionRepo();
|
|
22291
22546
|
const {
|
|
22292
22547
|
getByUserId: _getByUserId,
|
|
22293
22548
|
getStatusByUser: _getStatusByUser,
|
|
22294
22549
|
createAffiliateSubscription: _createAffiliateSubscription,
|
|
22295
22550
|
createOrgSubscription: _createOrgSubscription,
|
|
22296
|
-
updateSeatsById: _updateSubscriptionSeats
|
|
22551
|
+
updateSeatsById: _updateSubscriptionSeats,
|
|
22552
|
+
processSubscriptionPayment: _processSubscriptionPayment
|
|
22297
22553
|
} = useSubscriptionService();
|
|
22298
22554
|
async function add(req, res, next) {
|
|
22299
22555
|
const value = req.body;
|
|
22300
|
-
const validation =
|
|
22301
|
-
user:
|
|
22302
|
-
subscriptionId:
|
|
22556
|
+
const validation = import_joi20.default.object({
|
|
22557
|
+
user: import_joi20.default.string().required(),
|
|
22558
|
+
subscriptionId: import_joi20.default.string().required()
|
|
22303
22559
|
});
|
|
22304
22560
|
const { error } = validation.validate(value);
|
|
22305
22561
|
if (error) {
|
|
@@ -22316,7 +22572,7 @@ function useSubscriptionController() {
|
|
|
22316
22572
|
}
|
|
22317
22573
|
async function getByUserId(req, res, next) {
|
|
22318
22574
|
const id = req.params.id;
|
|
22319
|
-
const validation =
|
|
22575
|
+
const validation = import_joi20.default.string().required();
|
|
22320
22576
|
const { error } = validation.validate(id);
|
|
22321
22577
|
if (error) {
|
|
22322
22578
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22331,7 +22587,7 @@ function useSubscriptionController() {
|
|
|
22331
22587
|
}
|
|
22332
22588
|
async function getByAffiliateUserId(req, res, next) {
|
|
22333
22589
|
const id = req.params.id;
|
|
22334
|
-
const validation =
|
|
22590
|
+
const validation = import_joi20.default.string().required();
|
|
22335
22591
|
const { error } = validation.validate(id);
|
|
22336
22592
|
if (error) {
|
|
22337
22593
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22346,7 +22602,7 @@ function useSubscriptionController() {
|
|
|
22346
22602
|
}
|
|
22347
22603
|
async function getByOrgId(req, res, next) {
|
|
22348
22604
|
const id = req.params.id;
|
|
22349
|
-
const validation =
|
|
22605
|
+
const validation = import_joi20.default.string().required();
|
|
22350
22606
|
const { error } = validation.validate(id);
|
|
22351
22607
|
if (error) {
|
|
22352
22608
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22361,7 +22617,7 @@ function useSubscriptionController() {
|
|
|
22361
22617
|
}
|
|
22362
22618
|
async function getById(req, res, next) {
|
|
22363
22619
|
const id = req.params.id;
|
|
22364
|
-
const validation =
|
|
22620
|
+
const validation = import_joi20.default.string().required();
|
|
22365
22621
|
const { error } = validation.validate(id);
|
|
22366
22622
|
if (error) {
|
|
22367
22623
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22378,10 +22634,10 @@ function useSubscriptionController() {
|
|
|
22378
22634
|
const status = req.query.status ?? "";
|
|
22379
22635
|
const search = req.query.search ?? "";
|
|
22380
22636
|
const page = Number(req.query.page) ?? 1;
|
|
22381
|
-
const validation =
|
|
22382
|
-
status:
|
|
22383
|
-
search:
|
|
22384
|
-
page:
|
|
22637
|
+
const validation = import_joi20.default.object({
|
|
22638
|
+
status: import_joi20.default.string().required(),
|
|
22639
|
+
search: import_joi20.default.string().optional().allow("", null),
|
|
22640
|
+
page: import_joi20.default.number().required()
|
|
22385
22641
|
});
|
|
22386
22642
|
const { error } = validation.validate({ status, search, page });
|
|
22387
22643
|
if (error) {
|
|
@@ -22397,7 +22653,7 @@ function useSubscriptionController() {
|
|
|
22397
22653
|
}
|
|
22398
22654
|
async function getSubscriptionStatus(req, res, next) {
|
|
22399
22655
|
const id = req.params.id;
|
|
22400
|
-
const validation =
|
|
22656
|
+
const validation = import_joi20.default.string().required();
|
|
22401
22657
|
const { error } = validation.validate(id);
|
|
22402
22658
|
if (error) {
|
|
22403
22659
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22449,11 +22705,11 @@ function useSubscriptionController() {
|
|
|
22449
22705
|
async function updateSubscriptionSeats(req, res, next) {
|
|
22450
22706
|
const subscriptionId = req.params.id ?? "";
|
|
22451
22707
|
const value = req.body;
|
|
22452
|
-
const { error } =
|
|
22453
|
-
subscriptionId:
|
|
22454
|
-
seats:
|
|
22455
|
-
promoCode:
|
|
22456
|
-
amount:
|
|
22708
|
+
const { error } = import_joi20.default.object({
|
|
22709
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22710
|
+
seats: import_joi20.default.number().required(),
|
|
22711
|
+
promoCode: import_joi20.default.string().optional().allow("", null),
|
|
22712
|
+
amount: import_joi20.default.number().min(0).optional()
|
|
22457
22713
|
}).validate({ subscriptionId, ...value });
|
|
22458
22714
|
if (error) {
|
|
22459
22715
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22471,9 +22727,9 @@ function useSubscriptionController() {
|
|
|
22471
22727
|
async function updatePromoCodeById(req, res, next) {
|
|
22472
22728
|
const subscriptionId = req.params.id ?? "";
|
|
22473
22729
|
const promoCode = req.body.promoCode;
|
|
22474
|
-
const { error } =
|
|
22475
|
-
subscriptionId:
|
|
22476
|
-
promoCode:
|
|
22730
|
+
const { error } = import_joi20.default.object({
|
|
22731
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22732
|
+
promoCode: import_joi20.default.string().optional().allow("", null)
|
|
22477
22733
|
}).validate({ subscriptionId, promoCode });
|
|
22478
22734
|
if (error) {
|
|
22479
22735
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22491,9 +22747,9 @@ function useSubscriptionController() {
|
|
|
22491
22747
|
async function updateStatusById(req, res, next) {
|
|
22492
22748
|
const subscriptionId = req.params.id ?? "";
|
|
22493
22749
|
const status = req.body.status;
|
|
22494
|
-
const { error } =
|
|
22495
|
-
subscriptionId:
|
|
22496
|
-
status:
|
|
22750
|
+
const { error } = import_joi20.default.object({
|
|
22751
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22752
|
+
status: import_joi20.default.string().optional().allow("", null)
|
|
22497
22753
|
}).validate({ subscriptionId, status });
|
|
22498
22754
|
if (error) {
|
|
22499
22755
|
next(new import_utils70.BadRequestError(error.message));
|
|
@@ -22508,6 +22764,110 @@ function useSubscriptionController() {
|
|
|
22508
22764
|
return;
|
|
22509
22765
|
}
|
|
22510
22766
|
}
|
|
22767
|
+
async function addBillingContactById(req, res, next) {
|
|
22768
|
+
const subscriptionId = req.params.id ?? "";
|
|
22769
|
+
const email = req.body.email;
|
|
22770
|
+
const { error } = import_joi20.default.object({
|
|
22771
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22772
|
+
email: import_joi20.default.string().email().required()
|
|
22773
|
+
}).validate({ subscriptionId, email });
|
|
22774
|
+
if (error) {
|
|
22775
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22776
|
+
return;
|
|
22777
|
+
}
|
|
22778
|
+
try {
|
|
22779
|
+
await _addBillingContactById(subscriptionId, email);
|
|
22780
|
+
res.json({ message: "Successfully added billing contact." });
|
|
22781
|
+
return;
|
|
22782
|
+
} catch (error2) {
|
|
22783
|
+
next(error2);
|
|
22784
|
+
return;
|
|
22785
|
+
}
|
|
22786
|
+
}
|
|
22787
|
+
async function updateBillingContactByAddedAt(req, res, next) {
|
|
22788
|
+
const id = req.params.id ?? "";
|
|
22789
|
+
const addedAt = req.params.addedAt ?? "";
|
|
22790
|
+
const email = req.body.email;
|
|
22791
|
+
const { error } = import_joi20.default.object({
|
|
22792
|
+
id: import_joi20.default.string().hex().required(),
|
|
22793
|
+
addedAt: import_joi20.default.string().isoDate().required(),
|
|
22794
|
+
email: import_joi20.default.string().email().required()
|
|
22795
|
+
}).validate({ id, addedAt, email });
|
|
22796
|
+
if (error) {
|
|
22797
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22798
|
+
return;
|
|
22799
|
+
}
|
|
22800
|
+
try {
|
|
22801
|
+
await _updateBillingContactByAddedAt(id, addedAt, email);
|
|
22802
|
+
res.json({ message: "Successfully updated billing contact." });
|
|
22803
|
+
return;
|
|
22804
|
+
} catch (error2) {
|
|
22805
|
+
next(error2);
|
|
22806
|
+
return;
|
|
22807
|
+
}
|
|
22808
|
+
}
|
|
22809
|
+
async function deleteBillingContactByAddedAt(req, res, next) {
|
|
22810
|
+
const id = req.params.id ?? "";
|
|
22811
|
+
const addedAt = req.params.addedAt ?? "";
|
|
22812
|
+
const { error } = import_joi20.default.object({
|
|
22813
|
+
id: import_joi20.default.string().hex().required(),
|
|
22814
|
+
addedAt: import_joi20.default.string().isoDate().required()
|
|
22815
|
+
}).validate({ id, addedAt });
|
|
22816
|
+
if (error) {
|
|
22817
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22818
|
+
return;
|
|
22819
|
+
}
|
|
22820
|
+
try {
|
|
22821
|
+
await _deleteBillingContactByAddedAt(id, addedAt);
|
|
22822
|
+
res.json({ message: "Successfully deleted billing contact." });
|
|
22823
|
+
return;
|
|
22824
|
+
} catch (error2) {
|
|
22825
|
+
next(error2);
|
|
22826
|
+
return;
|
|
22827
|
+
}
|
|
22828
|
+
}
|
|
22829
|
+
async function updatePaymentMethodById(req, res, next) {
|
|
22830
|
+
const subscriptionId = req.params.id ?? "";
|
|
22831
|
+
const paymentMethodId = req.body.paymentMethodId;
|
|
22832
|
+
const { error } = import_joi20.default.object({
|
|
22833
|
+
subscriptionId: import_joi20.default.string().required(),
|
|
22834
|
+
paymentMethodId: import_joi20.default.string().optional().allow("", null)
|
|
22835
|
+
}).validate({ subscriptionId, paymentMethodId });
|
|
22836
|
+
if (error) {
|
|
22837
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22838
|
+
return;
|
|
22839
|
+
}
|
|
22840
|
+
try {
|
|
22841
|
+
await _updatePaymentMethodById(subscriptionId, paymentMethodId);
|
|
22842
|
+
res.json({
|
|
22843
|
+
message: "Successfully updated subscription payment method."
|
|
22844
|
+
});
|
|
22845
|
+
return;
|
|
22846
|
+
} catch (error2) {
|
|
22847
|
+
next(error2);
|
|
22848
|
+
return;
|
|
22849
|
+
}
|
|
22850
|
+
}
|
|
22851
|
+
async function processSubscriptionPayment(req, res, next) {
|
|
22852
|
+
const id = req.params.id ?? "";
|
|
22853
|
+
const invoiceNumber = req.body.invoice ?? "";
|
|
22854
|
+
const { error } = import_joi20.default.object({
|
|
22855
|
+
id: import_joi20.default.string().hex().required(),
|
|
22856
|
+
invoiceNumber: import_joi20.default.string().required()
|
|
22857
|
+
}).validate({ id, invoiceNumber });
|
|
22858
|
+
if (error) {
|
|
22859
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22860
|
+
return;
|
|
22861
|
+
}
|
|
22862
|
+
try {
|
|
22863
|
+
const payment = await _processSubscriptionPayment(invoiceNumber, id);
|
|
22864
|
+
res.json(payment);
|
|
22865
|
+
return;
|
|
22866
|
+
} catch (error2) {
|
|
22867
|
+
next(error2);
|
|
22868
|
+
return;
|
|
22869
|
+
}
|
|
22870
|
+
}
|
|
22511
22871
|
return {
|
|
22512
22872
|
add,
|
|
22513
22873
|
getByUserId,
|
|
@@ -22520,7 +22880,12 @@ function useSubscriptionController() {
|
|
|
22520
22880
|
createOrgSubscription,
|
|
22521
22881
|
updateSubscriptionSeats,
|
|
22522
22882
|
updatePromoCodeById,
|
|
22523
|
-
updateStatusById
|
|
22883
|
+
updateStatusById,
|
|
22884
|
+
updatePaymentMethodById,
|
|
22885
|
+
addBillingContactById,
|
|
22886
|
+
updateBillingContactByAddedAt,
|
|
22887
|
+
deleteBillingContactByAddedAt,
|
|
22888
|
+
processSubscriptionPayment
|
|
22524
22889
|
};
|
|
22525
22890
|
}
|
|
22526
22891
|
|
|
@@ -22834,7 +23199,7 @@ function usePaymentMethodService() {
|
|
|
22834
23199
|
}
|
|
22835
23200
|
|
|
22836
23201
|
// src/controllers/payment-method.controller.ts
|
|
22837
|
-
var
|
|
23202
|
+
var import_joi21 = __toESM(require("joi"));
|
|
22838
23203
|
var import_utils74 = require("@goweekdays/utils");
|
|
22839
23204
|
function usePaymentMethodController() {
|
|
22840
23205
|
const { linkEWallet: _linkEWallet, linkCard: _linkCard } = usePaymentMethodService();
|
|
@@ -22850,12 +23215,12 @@ function usePaymentMethodController() {
|
|
|
22850
23215
|
const success_return_url = req.body.success_return_url ?? "";
|
|
22851
23216
|
const failure_return_url = req.body.failure_return_url ?? "";
|
|
22852
23217
|
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:
|
|
23218
|
+
const validation = import_joi21.default.object({
|
|
23219
|
+
customer_id: import_joi21.default.string().required(),
|
|
23220
|
+
type: import_joi21.default.string().valid("GCASH", "PAYMAYA", "SHOPEEPAY", "GRABPAY").required(),
|
|
23221
|
+
success_return_url: import_joi21.default.string().uri().required(),
|
|
23222
|
+
failure_return_url: import_joi21.default.string().uri().required(),
|
|
23223
|
+
cancel_return_url: import_joi21.default.string().uri().required()
|
|
22859
23224
|
});
|
|
22860
23225
|
const { error } = validation.validate({
|
|
22861
23226
|
customer_id,
|
|
@@ -22893,17 +23258,17 @@ function usePaymentMethodController() {
|
|
|
22893
23258
|
const failure_return_url = req.body.failure_return_url ?? "";
|
|
22894
23259
|
const cardType = req.body.cardType ?? "";
|
|
22895
23260
|
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:
|
|
23261
|
+
const validation = import_joi21.default.object({
|
|
23262
|
+
cardNumber: import_joi21.default.string().required(),
|
|
23263
|
+
expiryMonth: import_joi21.default.string().required(),
|
|
23264
|
+
expiryYear: import_joi21.default.string().required(),
|
|
23265
|
+
cvv: import_joi21.default.string().required(),
|
|
23266
|
+
cardholderName: import_joi21.default.string().required(),
|
|
23267
|
+
currency: import_joi21.default.string().optional().allow("", null),
|
|
23268
|
+
success_return_url: import_joi21.default.string().uri().required(),
|
|
23269
|
+
failure_return_url: import_joi21.default.string().uri().required(),
|
|
23270
|
+
cardType: import_joi21.default.string().required(),
|
|
23271
|
+
user: import_joi21.default.string().hex().required()
|
|
22907
23272
|
});
|
|
22908
23273
|
const { error } = validation.validate({
|
|
22909
23274
|
user,
|
|
@@ -22942,8 +23307,8 @@ function usePaymentMethodController() {
|
|
|
22942
23307
|
const { getByUser: _getByUser, getByOrg: _getByOrg } = usePaymentMethodRepo();
|
|
22943
23308
|
async function getByUser(req, res, next) {
|
|
22944
23309
|
const user = req.params.user ?? "";
|
|
22945
|
-
const validation =
|
|
22946
|
-
user:
|
|
23310
|
+
const validation = import_joi21.default.object({
|
|
23311
|
+
user: import_joi21.default.string().hex().required()
|
|
22947
23312
|
});
|
|
22948
23313
|
const { error } = validation.validate({ user });
|
|
22949
23314
|
if (error) {
|
|
@@ -22958,8 +23323,8 @@ function usePaymentMethodController() {
|
|
|
22958
23323
|
}
|
|
22959
23324
|
async function getByOrg(req, res, next) {
|
|
22960
23325
|
const org = req.params.org ?? "";
|
|
22961
|
-
const validation =
|
|
22962
|
-
org:
|
|
23326
|
+
const validation = import_joi21.default.object({
|
|
23327
|
+
org: import_joi21.default.string().hex().required()
|
|
22963
23328
|
});
|
|
22964
23329
|
const { error } = validation.validate({ org });
|
|
22965
23330
|
if (error) {
|
|
@@ -22974,8 +23339,8 @@ function usePaymentMethodController() {
|
|
|
22974
23339
|
}
|
|
22975
23340
|
async function getPaymentMethodById(req, res, next) {
|
|
22976
23341
|
const id = req.params.id ?? "";
|
|
22977
|
-
const validation =
|
|
22978
|
-
id:
|
|
23342
|
+
const validation = import_joi21.default.object({
|
|
23343
|
+
id: import_joi21.default.string().required()
|
|
22979
23344
|
});
|
|
22980
23345
|
const { error } = validation.validate({ id });
|
|
22981
23346
|
if (error) {
|
|
@@ -23053,22 +23418,27 @@ function usePaymentMethodController() {
|
|
|
23053
23418
|
|
|
23054
23419
|
// src/controllers/address.controller.ts
|
|
23055
23420
|
var import_utils75 = require("@goweekdays/utils");
|
|
23056
|
-
var
|
|
23421
|
+
var import_joi22 = __toESM(require("joi"));
|
|
23057
23422
|
function useAddressController() {
|
|
23058
|
-
const {
|
|
23423
|
+
const {
|
|
23424
|
+
add: _add,
|
|
23425
|
+
getByUserId: _getByUserId,
|
|
23426
|
+
getByOrgId: _getByOrgId,
|
|
23427
|
+
updateById: _updateById
|
|
23428
|
+
} = useAddressRepo();
|
|
23059
23429
|
async function add(req, res, next) {
|
|
23060
23430
|
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:
|
|
23431
|
+
const validation = import_joi22.default.object({
|
|
23432
|
+
type: import_joi22.default.string().required(),
|
|
23433
|
+
user: import_joi22.default.string().hex().optional().allow("", null),
|
|
23434
|
+
org: import_joi22.default.string().hex().optional().allow("", null),
|
|
23435
|
+
country: import_joi22.default.string().required(),
|
|
23436
|
+
address: import_joi22.default.string().required(),
|
|
23437
|
+
continuedAddress: import_joi22.default.string().optional().allow("", null),
|
|
23438
|
+
city: import_joi22.default.string().required(),
|
|
23439
|
+
province: import_joi22.default.string().required(),
|
|
23440
|
+
postalCode: import_joi22.default.string().required(),
|
|
23441
|
+
taxId: import_joi22.default.string().optional().allow("", null)
|
|
23072
23442
|
});
|
|
23073
23443
|
const { error } = validation.validate(value);
|
|
23074
23444
|
if (error) {
|
|
@@ -23083,9 +23453,35 @@ function useAddressController() {
|
|
|
23083
23453
|
next(error2);
|
|
23084
23454
|
}
|
|
23085
23455
|
}
|
|
23456
|
+
async function updateById(req, res, next) {
|
|
23457
|
+
const id = req.params.id ?? "";
|
|
23458
|
+
const value = req.body;
|
|
23459
|
+
const validation = import_joi22.default.object({
|
|
23460
|
+
id: import_joi22.default.string().hex().required(),
|
|
23461
|
+
country: import_joi22.default.string().required(),
|
|
23462
|
+
address: import_joi22.default.string().required(),
|
|
23463
|
+
continuedAddress: import_joi22.default.string().optional().allow("", null),
|
|
23464
|
+
city: import_joi22.default.string().required(),
|
|
23465
|
+
province: import_joi22.default.string().required(),
|
|
23466
|
+
postalCode: import_joi22.default.string().required(),
|
|
23467
|
+
taxId: import_joi22.default.string().optional().allow("", null)
|
|
23468
|
+
});
|
|
23469
|
+
const { error } = validation.validate({ id, ...value });
|
|
23470
|
+
if (error) {
|
|
23471
|
+
next(new import_utils75.BadRequestError(error.message));
|
|
23472
|
+
return;
|
|
23473
|
+
}
|
|
23474
|
+
try {
|
|
23475
|
+
const message = await _updateById(id, value);
|
|
23476
|
+
res.json({ message });
|
|
23477
|
+
return;
|
|
23478
|
+
} catch (error2) {
|
|
23479
|
+
next(error2);
|
|
23480
|
+
}
|
|
23481
|
+
}
|
|
23086
23482
|
async function getByUserId(req, res, next) {
|
|
23087
23483
|
const user = req.params.user;
|
|
23088
|
-
const validation =
|
|
23484
|
+
const validation = import_joi22.default.string().hex().required();
|
|
23089
23485
|
const { error } = validation.validate(user);
|
|
23090
23486
|
if (error) {
|
|
23091
23487
|
next(new import_utils75.BadRequestError(error.message));
|
|
@@ -23102,9 +23498,30 @@ function useAddressController() {
|
|
|
23102
23498
|
next(error2);
|
|
23103
23499
|
}
|
|
23104
23500
|
}
|
|
23501
|
+
async function getByOrgId(req, res, next) {
|
|
23502
|
+
const id = req.params.id;
|
|
23503
|
+
const validation = import_joi22.default.string().hex().required();
|
|
23504
|
+
const { error } = validation.validate(id);
|
|
23505
|
+
if (error) {
|
|
23506
|
+
next(new import_utils75.BadRequestError(error.message));
|
|
23507
|
+
}
|
|
23508
|
+
try {
|
|
23509
|
+
const address = await _getByOrgId(id);
|
|
23510
|
+
if (!address) {
|
|
23511
|
+
next(new import_utils75.NotFoundError("Address not found."));
|
|
23512
|
+
return;
|
|
23513
|
+
}
|
|
23514
|
+
res.json(address);
|
|
23515
|
+
return;
|
|
23516
|
+
} catch (error2) {
|
|
23517
|
+
next(error2);
|
|
23518
|
+
}
|
|
23519
|
+
}
|
|
23105
23520
|
return {
|
|
23106
23521
|
add,
|
|
23107
|
-
getByUserId
|
|
23522
|
+
getByUserId,
|
|
23523
|
+
getByOrgId,
|
|
23524
|
+
updateById
|
|
23108
23525
|
};
|
|
23109
23526
|
}
|
|
23110
23527
|
|
|
@@ -23166,20 +23583,20 @@ function useOrgService() {
|
|
|
23166
23583
|
|
|
23167
23584
|
// src/controllers/organization.controller.ts
|
|
23168
23585
|
var import_utils77 = require("@goweekdays/utils");
|
|
23169
|
-
var
|
|
23586
|
+
var import_joi23 = __toESM(require("joi"));
|
|
23170
23587
|
function useOrgController() {
|
|
23171
23588
|
const { createOrg: _createOrg } = useOrgService();
|
|
23172
23589
|
const { getOrgsByMembership } = useMemberRepo();
|
|
23173
23590
|
const { getByName: _getByName } = useOrgRepo();
|
|
23174
23591
|
async function createOrg(req, res, next) {
|
|
23175
23592
|
const value = req.body;
|
|
23176
|
-
const validation =
|
|
23177
|
-
name:
|
|
23178
|
-
type:
|
|
23179
|
-
email:
|
|
23180
|
-
contact:
|
|
23181
|
-
description:
|
|
23182
|
-
user:
|
|
23593
|
+
const validation = import_joi23.default.object({
|
|
23594
|
+
name: import_joi23.default.string().required(),
|
|
23595
|
+
type: import_joi23.default.string().required(),
|
|
23596
|
+
email: import_joi23.default.string().email().required(),
|
|
23597
|
+
contact: import_joi23.default.string().required(),
|
|
23598
|
+
description: import_joi23.default.string().required(),
|
|
23599
|
+
user: import_joi23.default.string().hex().required()
|
|
23183
23600
|
});
|
|
23184
23601
|
const { error } = validation.validate(value);
|
|
23185
23602
|
if (error) {
|
|
@@ -23209,11 +23626,11 @@ function useOrgController() {
|
|
|
23209
23626
|
next(new import_utils77.BadRequestError("Invalid limit number."));
|
|
23210
23627
|
return;
|
|
23211
23628
|
}
|
|
23212
|
-
const validation =
|
|
23213
|
-
user:
|
|
23214
|
-
page:
|
|
23215
|
-
limit:
|
|
23216
|
-
search:
|
|
23629
|
+
const validation = import_joi23.default.object({
|
|
23630
|
+
user: import_joi23.default.string().hex().required(),
|
|
23631
|
+
page: import_joi23.default.number().min(1).optional().allow("", null),
|
|
23632
|
+
limit: import_joi23.default.number().min(1).optional().allow("", null),
|
|
23633
|
+
search: import_joi23.default.string().optional().allow("", null)
|
|
23217
23634
|
});
|
|
23218
23635
|
const { error } = validation.validate({ user, page, limit, search });
|
|
23219
23636
|
if (error) {
|
|
@@ -23230,8 +23647,8 @@ function useOrgController() {
|
|
|
23230
23647
|
}
|
|
23231
23648
|
async function getByName(req, res, next) {
|
|
23232
23649
|
const name = req.params.name;
|
|
23233
|
-
const validation =
|
|
23234
|
-
name:
|
|
23650
|
+
const validation = import_joi23.default.object({
|
|
23651
|
+
name: import_joi23.default.string().required()
|
|
23235
23652
|
});
|
|
23236
23653
|
const { error } = validation.validate({ name });
|
|
23237
23654
|
if (error) {
|
|
@@ -23254,7 +23671,7 @@ function useOrgController() {
|
|
|
23254
23671
|
}
|
|
23255
23672
|
|
|
23256
23673
|
// src/controllers/member.controller.ts
|
|
23257
|
-
var
|
|
23674
|
+
var import_joi24 = __toESM(require("joi"));
|
|
23258
23675
|
var import_utils78 = require("@goweekdays/utils");
|
|
23259
23676
|
function useMemberController() {
|
|
23260
23677
|
const {
|
|
@@ -23264,8 +23681,8 @@ function useMemberController() {
|
|
|
23264
23681
|
} = useMemberRepo();
|
|
23265
23682
|
async function getByUserId(req, res, next) {
|
|
23266
23683
|
const userId = req.params.id;
|
|
23267
|
-
const validation =
|
|
23268
|
-
id:
|
|
23684
|
+
const validation = import_joi24.default.object({
|
|
23685
|
+
id: import_joi24.default.string().hex().required()
|
|
23269
23686
|
});
|
|
23270
23687
|
const { error } = validation.validate({ id: userId });
|
|
23271
23688
|
if (error) {
|
|
@@ -23291,14 +23708,14 @@ function useMemberController() {
|
|
|
23291
23708
|
const org = req.query.org ?? "";
|
|
23292
23709
|
const type = req.query.type ?? "main";
|
|
23293
23710
|
const status = req.query.status ?? "active";
|
|
23294
|
-
const validation =
|
|
23295
|
-
limit:
|
|
23296
|
-
search:
|
|
23297
|
-
page:
|
|
23298
|
-
user:
|
|
23299
|
-
org:
|
|
23300
|
-
type:
|
|
23301
|
-
status:
|
|
23711
|
+
const validation = import_joi24.default.object({
|
|
23712
|
+
limit: import_joi24.default.number().min(10).max(50).required(),
|
|
23713
|
+
search: import_joi24.default.string().optional().allow("", null),
|
|
23714
|
+
page: import_joi24.default.number().required(),
|
|
23715
|
+
user: import_joi24.default.string().hex().optional().allow("", null),
|
|
23716
|
+
org: import_joi24.default.string().hex().optional().allow("", null),
|
|
23717
|
+
type: import_joi24.default.string().required(),
|
|
23718
|
+
status: import_joi24.default.string().required()
|
|
23302
23719
|
});
|
|
23303
23720
|
const { error } = validation.validate({
|
|
23304
23721
|
search,
|
|
@@ -23311,6 +23728,7 @@ function useMemberController() {
|
|
|
23311
23728
|
});
|
|
23312
23729
|
if (error) {
|
|
23313
23730
|
next(new import_utils78.BadRequestError(error.message));
|
|
23731
|
+
return;
|
|
23314
23732
|
}
|
|
23315
23733
|
try {
|
|
23316
23734
|
const items = await _getAll({
|
|
@@ -23333,11 +23751,11 @@ function useMemberController() {
|
|
|
23333
23751
|
const search = req.query.search ?? "";
|
|
23334
23752
|
const page = Number(req.query.page) ?? 1;
|
|
23335
23753
|
const user = req.query.user ?? "";
|
|
23336
|
-
const validation =
|
|
23337
|
-
limit:
|
|
23338
|
-
search:
|
|
23339
|
-
page:
|
|
23340
|
-
user:
|
|
23754
|
+
const validation = import_joi24.default.object({
|
|
23755
|
+
limit: import_joi24.default.number().min(10).max(50).required(),
|
|
23756
|
+
search: import_joi24.default.string().optional().allow("", null),
|
|
23757
|
+
page: import_joi24.default.number().required(),
|
|
23758
|
+
user: import_joi24.default.string().hex().optional().allow("", null)
|
|
23341
23759
|
});
|
|
23342
23760
|
const { error } = validation.validate({
|
|
23343
23761
|
search,
|
|
@@ -23370,7 +23788,7 @@ function useMemberController() {
|
|
|
23370
23788
|
|
|
23371
23789
|
// src/controllers/promo-code.controller.ts
|
|
23372
23790
|
var import_utils79 = require("@goweekdays/utils");
|
|
23373
|
-
var
|
|
23791
|
+
var import_joi25 = __toESM(require("joi"));
|
|
23374
23792
|
function usePromoCodeController() {
|
|
23375
23793
|
const {
|
|
23376
23794
|
add: _add,
|
|
@@ -23401,11 +23819,11 @@ function usePromoCodeController() {
|
|
|
23401
23819
|
const code = req.query.code;
|
|
23402
23820
|
const type = req.query.type;
|
|
23403
23821
|
const assigned = req.query.assigned === "true" ? true : req.query.assigned === "false" ? false : null;
|
|
23404
|
-
const validation =
|
|
23405
|
-
code:
|
|
23406
|
-
type:
|
|
23822
|
+
const validation = import_joi25.default.object({
|
|
23823
|
+
code: import_joi25.default.string().trim().required(),
|
|
23824
|
+
type: import_joi25.default.string().optional(),
|
|
23407
23825
|
// true or false
|
|
23408
|
-
assigned:
|
|
23826
|
+
assigned: import_joi25.default.boolean().optional().allow(null, "")
|
|
23409
23827
|
});
|
|
23410
23828
|
const { error } = validation.validate({ code, type, assigned });
|
|
23411
23829
|
if (error) {
|
|
@@ -23430,8 +23848,8 @@ function usePromoCodeController() {
|
|
|
23430
23848
|
}
|
|
23431
23849
|
async function getById(req, res, next) {
|
|
23432
23850
|
const id = req.params.id;
|
|
23433
|
-
const validation =
|
|
23434
|
-
id:
|
|
23851
|
+
const validation = import_joi25.default.object({
|
|
23852
|
+
id: import_joi25.default.string().hex().required()
|
|
23435
23853
|
});
|
|
23436
23854
|
const { error } = validation.validate({ id });
|
|
23437
23855
|
if (error) {
|
|
@@ -23459,11 +23877,11 @@ function usePromoCodeController() {
|
|
|
23459
23877
|
const limit = req.query.limit ? Number(req.query.limit) : 10;
|
|
23460
23878
|
const search = req.query.search;
|
|
23461
23879
|
const status = req.query.status;
|
|
23462
|
-
const validation =
|
|
23463
|
-
page:
|
|
23464
|
-
limit:
|
|
23465
|
-
search:
|
|
23466
|
-
status:
|
|
23880
|
+
const validation = import_joi25.default.object({
|
|
23881
|
+
page: import_joi25.default.number().required(),
|
|
23882
|
+
limit: import_joi25.default.number().integer().optional().min(10).max(100),
|
|
23883
|
+
search: import_joi25.default.string().optional().allow(""),
|
|
23884
|
+
status: import_joi25.default.string().required()
|
|
23467
23885
|
});
|
|
23468
23886
|
const { error } = validation.validate({ page, limit, search, status });
|
|
23469
23887
|
if (error) {
|
|
@@ -23495,26 +23913,26 @@ function usePromoCodeController() {
|
|
|
23495
23913
|
var import_mongodb38 = require("mongodb");
|
|
23496
23914
|
|
|
23497
23915
|
// 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:
|
|
23916
|
+
var import_joi26 = __toESM(require("joi"));
|
|
23917
|
+
var schema2 = import_joi26.default.object({
|
|
23918
|
+
_id: import_joi26.default.string().hex().optional().allow("", null),
|
|
23919
|
+
payment: import_joi26.default.string().required(),
|
|
23920
|
+
user: import_joi26.default.string().hex().optional().allow("", null),
|
|
23921
|
+
org: import_joi26.default.string().hex().optional().allow("", null),
|
|
23922
|
+
type: import_joi26.default.string().required(),
|
|
23923
|
+
amount: import_joi26.default.number().positive().min(0).required(),
|
|
23924
|
+
currency: import_joi26.default.string().required(),
|
|
23925
|
+
description: import_joi26.default.string().optional().allow("", null),
|
|
23926
|
+
metadata: import_joi26.default.object({
|
|
23927
|
+
subscriptionId: import_joi26.default.string().hex().optional().allow("", null),
|
|
23928
|
+
cycle: import_joi26.default.number().optional().allow("", null),
|
|
23929
|
+
seats: import_joi26.default.number().optional().allow("", null),
|
|
23930
|
+
promoCode: import_joi26.default.string().optional().allow("", null)
|
|
23513
23931
|
}).optional().allow("", null),
|
|
23514
|
-
status:
|
|
23515
|
-
createdAt:
|
|
23516
|
-
updatedAt:
|
|
23517
|
-
deletedAt:
|
|
23932
|
+
status: import_joi26.default.string().optional().allow("", null),
|
|
23933
|
+
createdAt: import_joi26.default.string().optional().allow("", null),
|
|
23934
|
+
updatedAt: import_joi26.default.string().optional().allow("", null),
|
|
23935
|
+
deletedAt: import_joi26.default.string().optional().allow("", null)
|
|
23518
23936
|
});
|
|
23519
23937
|
|
|
23520
23938
|
// src/models/order.model.ts
|
|
@@ -23651,7 +24069,7 @@ function useOrderRepo() {
|
|
|
23651
24069
|
|
|
23652
24070
|
// src/controllers/order.controller.ts
|
|
23653
24071
|
var import_utils82 = require("@goweekdays/utils");
|
|
23654
|
-
var
|
|
24072
|
+
var import_joi27 = __toESM(require("joi"));
|
|
23655
24073
|
function useOrderController() {
|
|
23656
24074
|
const { getOrders: _getOrders } = useOrderRepo();
|
|
23657
24075
|
async function getOrders(req, res, next) {
|
|
@@ -23660,12 +24078,12 @@ function useOrderController() {
|
|
|
23660
24078
|
const search = req.query.search ?? "";
|
|
23661
24079
|
const status = req.query.status ?? "succeeded";
|
|
23662
24080
|
const id = req.query.id ?? "";
|
|
23663
|
-
const validation =
|
|
23664
|
-
page:
|
|
23665
|
-
limit:
|
|
23666
|
-
search:
|
|
23667
|
-
status:
|
|
23668
|
-
id:
|
|
24081
|
+
const validation = import_joi27.default.object({
|
|
24082
|
+
page: import_joi27.default.number().required(),
|
|
24083
|
+
limit: import_joi27.default.number().required().min(10),
|
|
24084
|
+
search: import_joi27.default.string().optional().allow("", null),
|
|
24085
|
+
status: import_joi27.default.string().optional().allow("", null),
|
|
24086
|
+
id: import_joi27.default.string().hex().optional().allow("", null)
|
|
23669
24087
|
});
|
|
23670
24088
|
const { error } = validation.validate({ page, limit, search, status, id });
|
|
23671
24089
|
if (error) {
|
|
@@ -23694,7 +24112,7 @@ function useOrderController() {
|
|
|
23694
24112
|
// src/services/invoice.service.ts
|
|
23695
24113
|
var import_utils83 = require("@goweekdays/utils");
|
|
23696
24114
|
function useInvoiceService() {
|
|
23697
|
-
const { getOverdueInvoices, updateStatusByInvoiceNumber } = useInvoiceRepo();
|
|
24115
|
+
const { getOverdueInvoices, updateStatusByInvoiceNumber, getByNumber } = useInvoiceRepo();
|
|
23698
24116
|
const {
|
|
23699
24117
|
getById,
|
|
23700
24118
|
processSuccessfulPayment,
|
|
@@ -23874,7 +24292,7 @@ function useInvoiceService() {
|
|
|
23874
24292
|
|
|
23875
24293
|
// src/controllers/invoice.controller.ts
|
|
23876
24294
|
var import_utils84 = require("@goweekdays/utils");
|
|
23877
|
-
var
|
|
24295
|
+
var import_joi28 = __toESM(require("joi"));
|
|
23878
24296
|
function useInvoiceController() {
|
|
23879
24297
|
const {
|
|
23880
24298
|
getBySubscriptionId: _getBySubscriptionId,
|
|
@@ -23886,11 +24304,11 @@ function useInvoiceController() {
|
|
|
23886
24304
|
const page = req.query.page ? Number(req.query.page) : 1;
|
|
23887
24305
|
const limit = req.query.limit ? Number(req.query.limit) : 10;
|
|
23888
24306
|
const search = req.query.search ?? "";
|
|
23889
|
-
const validation =
|
|
23890
|
-
id:
|
|
23891
|
-
page:
|
|
23892
|
-
limit:
|
|
23893
|
-
search:
|
|
24307
|
+
const validation = import_joi28.default.object({
|
|
24308
|
+
id: import_joi28.default.string().required(),
|
|
24309
|
+
page: import_joi28.default.number().integer().min(1).default(1),
|
|
24310
|
+
limit: import_joi28.default.number().integer().min(1).default(10),
|
|
24311
|
+
search: import_joi28.default.string().optional().allow("", null)
|
|
23894
24312
|
});
|
|
23895
24313
|
const { error } = validation.validate({
|
|
23896
24314
|
id,
|
|
@@ -23917,7 +24335,7 @@ function useInvoiceController() {
|
|
|
23917
24335
|
}
|
|
23918
24336
|
async function getByNumber(req, res, next) {
|
|
23919
24337
|
const number = req.params.number;
|
|
23920
|
-
const validation =
|
|
24338
|
+
const validation = import_joi28.default.string().required();
|
|
23921
24339
|
const { error } = validation.validate(number);
|
|
23922
24340
|
if (error) {
|
|
23923
24341
|
next(new import_utils84.BadRequestError(error.message));
|
|
@@ -23937,9 +24355,9 @@ function useInvoiceController() {
|
|
|
23937
24355
|
async function getByDueDateStatus(req, res, next) {
|
|
23938
24356
|
const date = req.params.date;
|
|
23939
24357
|
const status = req.params.status;
|
|
23940
|
-
const validation =
|
|
23941
|
-
date:
|
|
23942
|
-
status:
|
|
24358
|
+
const validation = import_joi28.default.object({
|
|
24359
|
+
date: import_joi28.default.string().required(),
|
|
24360
|
+
status: import_joi28.default.string().required()
|
|
23943
24361
|
});
|
|
23944
24362
|
const { error } = validation.validate({ date, status });
|
|
23945
24363
|
if (error) {
|
|
@@ -23966,7 +24384,7 @@ function useInvoiceController() {
|
|
|
23966
24384
|
|
|
23967
24385
|
// src/controllers/payment.controller.ts
|
|
23968
24386
|
var import_utils85 = require("@goweekdays/utils");
|
|
23969
|
-
var
|
|
24387
|
+
var import_joi29 = __toESM(require("joi"));
|
|
23970
24388
|
function usePaymentController() {
|
|
23971
24389
|
const { getPayments: _getPayments } = usePaymentRepo();
|
|
23972
24390
|
async function getPayments(req, res, next) {
|
|
@@ -23975,12 +24393,12 @@ function usePaymentController() {
|
|
|
23975
24393
|
const search = req.query.search ?? "";
|
|
23976
24394
|
const status = req.query.status ?? "succeeded";
|
|
23977
24395
|
const id = req.query.id ?? "";
|
|
23978
|
-
const validation =
|
|
23979
|
-
page:
|
|
23980
|
-
limit:
|
|
23981
|
-
search:
|
|
23982
|
-
status:
|
|
23983
|
-
id:
|
|
24396
|
+
const validation = import_joi29.default.object({
|
|
24397
|
+
page: import_joi29.default.number().required(),
|
|
24398
|
+
limit: import_joi29.default.number().required().min(10),
|
|
24399
|
+
search: import_joi29.default.string().optional().allow("", null),
|
|
24400
|
+
status: import_joi29.default.string().optional().allow("", null),
|
|
24401
|
+
id: import_joi29.default.string().hex().optional().allow("", null)
|
|
23984
24402
|
});
|
|
23985
24403
|
const { error } = validation.validate({ page, limit, search, status, id });
|
|
23986
24404
|
if (error) {
|
|
@@ -24087,6 +24505,7 @@ function usePriceController() {
|
|
|
24087
24505
|
VERIFICATION_USER_INVITE_DURATION,
|
|
24088
24506
|
XENDIT_BASE_URL,
|
|
24089
24507
|
XENDIT_SECRET_KEY,
|
|
24508
|
+
addressSchema,
|
|
24090
24509
|
isDev,
|
|
24091
24510
|
schema,
|
|
24092
24511
|
useAddressController,
|