@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/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.createIndex([{ user: 1 }, { type: 1 }]);
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 import_joi15 = __toESM(require("joi"));
20535
- var promoTypeSchema = import_joi15.default.string().valid("tiered", "fixed").required();
20536
- var promoTierSchema = import_joi15.default.object({
20537
- min: import_joi15.default.number().integer().min(1).required(),
20538
- max: import_joi15.default.number().integer().min(import_joi15.default.ref("min")).allow(0).required(),
20539
- price: import_joi15.default.number().positive().required()
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 = import_joi15.default.object({
20542
- code: import_joi15.default.string().trim().uppercase().required(),
20543
- description: import_joi15.default.string().trim().optional(),
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: import_joi15.default.alternatives().conditional("type", {
20693
+ tiers: import_joi16.default.alternatives().conditional("type", {
20546
20694
  is: "tiered",
20547
- then: import_joi15.default.array().items(promoTierSchema).min(1).required(),
20548
- otherwise: import_joi15.default.forbidden()
20695
+ then: import_joi16.default.array().items(promoTierSchema).min(1).required(),
20696
+ otherwise: import_joi16.default.forbidden()
20549
20697
  }),
20550
- fixed_rate: import_joi15.default.alternatives().conditional("type", {
20698
+ fixed_rate: import_joi16.default.alternatives().conditional("type", {
20551
20699
  is: "fixed",
20552
- then: import_joi15.default.number().required().min(0),
20553
- otherwise: import_joi15.default.number().integer().allow(0)
20700
+ then: import_joi16.default.number().required().min(0),
20701
+ otherwise: import_joi16.default.number().integer().allow(0)
20554
20702
  }),
20555
- expiresAt: import_joi15.default.string().optional().allow(null, "")
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 import_joi16 = __toESM(require("joi"));
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 = import_joi16.default.object({
20625
- code: import_joi16.default.string().trim().required()
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 = import_joi16.default.object({
20648
- _id: import_joi16.default.string().hex().required()
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 = import_joi16.default.object({
20698
- user: import_joi16.default.string().required(),
20699
- code: import_joi16.default.string().required()
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 import_joi17 = __toESM(require("joi"));
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 = import_joi17.default.object({
21942
- amount: import_joi17.default.number().required()
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 = import_joi17.default.object({
22023
- subscriptionId: import_joi17.default.string().hex().required(),
22024
- seats: import_joi17.default.number().min(1).required(),
22025
- amount: import_joi17.default.number().required()
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 import_joi19 = __toESM(require("joi"));
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 import_joi18 = __toESM(require("joi"));
22492
+ var import_joi19 = __toESM(require("joi"));
22242
22493
  function useSubscriptionSchema() {
22243
- const schema3 = import_joi18.default.object({
22244
- user: import_joi18.default.string().required().min(0),
22245
- amount: import_joi18.default.number().min(0).required(),
22246
- customer_id: import_joi18.default.string().required(),
22247
- payment_method_id: import_joi18.default.string().required(),
22248
- payment_method_type: import_joi18.default.string().required(),
22249
- payment_method_channel: import_joi18.default.string().required(),
22250
- payment_method_month_expiry: import_joi18.default.string().optional().allow(null, ""),
22251
- payment_method_year_expiry: import_joi18.default.string().optional().allow(null, ""),
22252
- payment_method_cvv: import_joi18.default.string().optional().allow(null, ""),
22253
- currency: import_joi18.default.string().optional().allow("", null),
22254
- seats: import_joi18.default.number().optional().min(0).allow(null),
22255
- organization: import_joi18.default.object({
22256
- name: import_joi18.default.string().required(),
22257
- description: import_joi18.default.string().optional().allow("", null),
22258
- type: import_joi18.default.string().allow("personal", "business").required(),
22259
- email: import_joi18.default.string().email().required(),
22260
- contact: import_joi18.default.string().required(),
22261
- busInst: import_joi18.default.string().optional().allow(null, "")
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: import_joi18.default.object({
22264
- type: import_joi18.default.string().required(),
22265
- country: import_joi18.default.string().required(),
22266
- address: import_joi18.default.string().required(),
22267
- continuedAddress: import_joi18.default.string().optional().allow(null, ""),
22268
- city: import_joi18.default.string().required(),
22269
- province: import_joi18.default.string().required(),
22270
- postalCode: import_joi18.default.string().required(),
22271
- taxId: import_joi18.default.string().optional().allow(null, "")
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: import_joi18.default.string().optional().allow("", null)
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 = import_joi19.default.object({
22301
- user: import_joi19.default.string().required(),
22302
- subscriptionId: import_joi19.default.string().required()
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 = import_joi19.default.string().required();
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 = import_joi19.default.string().required();
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 = import_joi19.default.string().required();
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 = import_joi19.default.string().required();
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 = import_joi19.default.object({
22382
- status: import_joi19.default.string().required(),
22383
- search: import_joi19.default.string().optional().allow("", null),
22384
- page: import_joi19.default.number().required()
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 = import_joi19.default.string().required();
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 } = import_joi19.default.object({
22453
- subscriptionId: import_joi19.default.string().required(),
22454
- seats: import_joi19.default.number().required(),
22455
- promoCode: import_joi19.default.string().optional().allow("", null),
22456
- amount: import_joi19.default.number().min(0).optional()
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 } = import_joi19.default.object({
22475
- subscriptionId: import_joi19.default.string().required(),
22476
- promoCode: import_joi19.default.string().optional().allow("", null)
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 } = import_joi19.default.object({
22495
- subscriptionId: import_joi19.default.string().required(),
22496
- status: import_joi19.default.string().optional().allow("", null)
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 import_joi20 = __toESM(require("joi"));
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 = import_joi20.default.object({
22854
- customer_id: import_joi20.default.string().required(),
22855
- type: import_joi20.default.string().valid("GCASH", "PAYMAYA", "SHOPEEPAY", "GRABPAY").required(),
22856
- success_return_url: import_joi20.default.string().uri().required(),
22857
- failure_return_url: import_joi20.default.string().uri().required(),
22858
- cancel_return_url: import_joi20.default.string().uri().required()
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 = import_joi20.default.object({
22897
- cardNumber: import_joi20.default.string().required(),
22898
- expiryMonth: import_joi20.default.string().required(),
22899
- expiryYear: import_joi20.default.string().required(),
22900
- cvv: import_joi20.default.string().required(),
22901
- cardholderName: import_joi20.default.string().required(),
22902
- currency: import_joi20.default.string().optional().allow("", null),
22903
- success_return_url: import_joi20.default.string().uri().required(),
22904
- failure_return_url: import_joi20.default.string().uri().required(),
22905
- cardType: import_joi20.default.string().required(),
22906
- user: import_joi20.default.string().hex().required()
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 = import_joi20.default.object({
22946
- user: import_joi20.default.string().hex().required()
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 = import_joi20.default.object({
22962
- org: import_joi20.default.string().hex().required()
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 = import_joi20.default.object({
22978
- id: import_joi20.default.string().required()
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 import_joi21 = __toESM(require("joi"));
23421
+ var import_joi22 = __toESM(require("joi"));
23057
23422
  function useAddressController() {
23058
- const { add: _add, getByUserId: _getByUserId } = useAddressRepo();
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 = import_joi21.default.object({
23062
- type: import_joi21.default.string().required(),
23063
- user: import_joi21.default.string().hex().optional().allow("", null),
23064
- org: import_joi21.default.string().hex().optional().allow("", null),
23065
- country: import_joi21.default.string().required(),
23066
- address: import_joi21.default.string().required(),
23067
- continuedAddress: import_joi21.default.string().optional().allow("", null),
23068
- city: import_joi21.default.string().required(),
23069
- province: import_joi21.default.string().required(),
23070
- postalCode: import_joi21.default.string().required(),
23071
- taxId: import_joi21.default.string().optional().allow("", null)
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 = import_joi21.default.string().hex().required();
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 import_joi22 = __toESM(require("joi"));
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 = import_joi22.default.object({
23177
- name: import_joi22.default.string().required(),
23178
- type: import_joi22.default.string().required(),
23179
- email: import_joi22.default.string().email().required(),
23180
- contact: import_joi22.default.string().required(),
23181
- description: import_joi22.default.string().required(),
23182
- user: import_joi22.default.string().hex().required()
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 = import_joi22.default.object({
23213
- user: import_joi22.default.string().hex().required(),
23214
- page: import_joi22.default.number().min(1).optional().allow("", null),
23215
- limit: import_joi22.default.number().min(1).optional().allow("", null),
23216
- search: import_joi22.default.string().optional().allow("", null)
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 = import_joi22.default.object({
23234
- name: import_joi22.default.string().required()
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 import_joi23 = __toESM(require("joi"));
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 = import_joi23.default.object({
23268
- id: import_joi23.default.string().hex().required()
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 = import_joi23.default.object({
23295
- limit: import_joi23.default.number().min(10).max(50).required(),
23296
- search: import_joi23.default.string().optional().allow("", null),
23297
- page: import_joi23.default.number().required(),
23298
- user: import_joi23.default.string().hex().optional().allow("", null),
23299
- org: import_joi23.default.string().hex().optional().allow("", null),
23300
- type: import_joi23.default.string().required(),
23301
- status: import_joi23.default.string().required()
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 = import_joi23.default.object({
23337
- limit: import_joi23.default.number().min(10).max(50).required(),
23338
- search: import_joi23.default.string().optional().allow("", null),
23339
- page: import_joi23.default.number().required(),
23340
- user: import_joi23.default.string().hex().optional().allow("", null)
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 import_joi24 = __toESM(require("joi"));
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 = import_joi24.default.object({
23405
- code: import_joi24.default.string().trim().required(),
23406
- type: import_joi24.default.string().optional(),
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: import_joi24.default.boolean().optional().allow(null, "")
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 = import_joi24.default.object({
23434
- id: import_joi24.default.string().hex().required()
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 = import_joi24.default.object({
23463
- page: import_joi24.default.number().required(),
23464
- limit: import_joi24.default.number().integer().optional().min(10).max(100),
23465
- search: import_joi24.default.string().optional().allow(""),
23466
- status: import_joi24.default.string().required()
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 import_joi25 = __toESM(require("joi"));
23499
- var schema2 = import_joi25.default.object({
23500
- _id: import_joi25.default.string().hex().optional().allow("", null),
23501
- payment: import_joi25.default.string().required(),
23502
- user: import_joi25.default.string().hex().optional().allow("", null),
23503
- org: import_joi25.default.string().hex().optional().allow("", null),
23504
- type: import_joi25.default.string().required(),
23505
- amount: import_joi25.default.number().positive().min(0).required(),
23506
- currency: import_joi25.default.string().required(),
23507
- description: import_joi25.default.string().optional().allow("", null),
23508
- metadata: import_joi25.default.object({
23509
- subscriptionId: import_joi25.default.string().hex().optional().allow("", null),
23510
- cycle: import_joi25.default.number().optional().allow("", null),
23511
- seats: import_joi25.default.number().optional().allow("", null),
23512
- promoCode: import_joi25.default.string().optional().allow("", null)
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: import_joi25.default.string().optional().allow("", null),
23515
- createdAt: import_joi25.default.string().optional().allow("", null),
23516
- updatedAt: import_joi25.default.string().optional().allow("", null),
23517
- deletedAt: import_joi25.default.string().optional().allow("", null)
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 import_joi26 = __toESM(require("joi"));
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 = import_joi26.default.object({
23664
- page: import_joi26.default.number().required(),
23665
- limit: import_joi26.default.number().required().min(10),
23666
- search: import_joi26.default.string().optional().allow("", null),
23667
- status: import_joi26.default.string().optional().allow("", null),
23668
- id: import_joi26.default.string().hex().optional().allow("", null)
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 import_joi27 = __toESM(require("joi"));
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 = import_joi27.default.object({
23890
- id: import_joi27.default.string().required(),
23891
- page: import_joi27.default.number().integer().min(1).default(1),
23892
- limit: import_joi27.default.number().integer().min(1).default(10),
23893
- search: import_joi27.default.string().optional().allow("", null)
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 = import_joi27.default.string().required();
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 = import_joi27.default.object({
23941
- date: import_joi27.default.string().required(),
23942
- status: import_joi27.default.string().required()
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 import_joi28 = __toESM(require("joi"));
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 = import_joi28.default.object({
23979
- page: import_joi28.default.number().required(),
23980
- limit: import_joi28.default.number().required().min(10),
23981
- search: import_joi28.default.string().optional().allow("", null),
23982
- status: import_joi28.default.string().optional().allow("", null),
23983
- id: import_joi28.default.string().hex().optional().allow("", null)
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,