@goweekdays/core 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -19294,6 +19294,21 @@ function useOrgRepo() {
19294
19294
  }
19295
19295
  }
19296
19296
  }
19297
+ async function getByName(name) {
19298
+ try {
19299
+ const result = await collection.findOne({ name });
19300
+ if (!result) {
19301
+ throw new BadRequestError27("Organization not found.");
19302
+ }
19303
+ return result;
19304
+ } catch (error) {
19305
+ if (error instanceof AppError6) {
19306
+ throw error;
19307
+ } else {
19308
+ throw new InternalServerError19("Failed to get organization.");
19309
+ }
19310
+ }
19311
+ }
19297
19312
  async function updateFieldById({ _id, field, value } = {}, session) {
19298
19313
  const allowedFields = ["name", "description"];
19299
19314
  if (!allowedFields.includes(field)) {
@@ -19342,7 +19357,8 @@ function useOrgRepo() {
19342
19357
  getOrgs,
19343
19358
  getById,
19344
19359
  updateFieldById,
19345
- deleteById
19360
+ deleteById,
19361
+ getByName
19346
19362
  };
19347
19363
  }
19348
19364
 
@@ -19540,8 +19556,43 @@ function useSubscriptionService() {
19540
19556
  }
19541
19557
 
19542
19558
  // src/controllers/subscription.controller.ts
19543
- import Joi11 from "joi";
19559
+ import Joi12 from "joi";
19544
19560
  import { BadRequestError as BadRequestError31 } from "@goweekdays/utils";
19561
+
19562
+ // src/validations/subscription.schema.ts
19563
+ import Joi11 from "joi";
19564
+ function useSubscriptionSchema() {
19565
+ const schema = Joi11.object({
19566
+ user: Joi11.string().required(),
19567
+ amount: Joi11.number().required(),
19568
+ customer_id: Joi11.string().required(),
19569
+ payment_method_id: Joi11.string().required(),
19570
+ currency: Joi11.string().optional().allow("", null),
19571
+ organization: Joi11.object({
19572
+ name: Joi11.string().required(),
19573
+ description: Joi11.string().optional().allow("", null),
19574
+ type: Joi11.string().allow("personal", "business").required(),
19575
+ email: Joi11.string().email().required(),
19576
+ contact: Joi11.string().required(),
19577
+ busInst: Joi11.string().optional().allow(null, "")
19578
+ }).required(),
19579
+ billingAddress: Joi11.object({
19580
+ type: Joi11.string().required(),
19581
+ country: Joi11.string().required(),
19582
+ address: Joi11.string().required(),
19583
+ continuedAddress: Joi11.string().optional().allow(null, ""),
19584
+ city: Joi11.string().required(),
19585
+ province: Joi11.string().required(),
19586
+ postalCode: Joi11.string().required(),
19587
+ taxId: Joi11.string().optional().allow(null, "")
19588
+ }).required()
19589
+ });
19590
+ return {
19591
+ schema
19592
+ };
19593
+ }
19594
+
19595
+ // src/controllers/subscription.controller.ts
19545
19596
  function useSubscriptionController() {
19546
19597
  const { add: _add, getSubscriptions: _getSubscriptions } = useSubscriptionRepo();
19547
19598
  const {
@@ -19552,9 +19603,9 @@ function useSubscriptionController() {
19552
19603
  } = useSubscriptionService();
19553
19604
  async function add(req, res, next) {
19554
19605
  const value = req.body;
19555
- const validation = Joi11.object({
19556
- user: Joi11.string().required(),
19557
- subscriptionId: Joi11.string().required()
19606
+ const validation = Joi12.object({
19607
+ user: Joi12.string().required(),
19608
+ subscriptionId: Joi12.string().required()
19558
19609
  });
19559
19610
  const { error } = validation.validate(value);
19560
19611
  if (error) {
@@ -19571,7 +19622,7 @@ function useSubscriptionController() {
19571
19622
  }
19572
19623
  async function getByUserId(req, res, next) {
19573
19624
  const id = req.params.id;
19574
- const validation = Joi11.string().required();
19625
+ const validation = Joi12.string().required();
19575
19626
  const { error } = validation.validate(id);
19576
19627
  if (error) {
19577
19628
  next(new BadRequestError31(error.message));
@@ -19588,10 +19639,10 @@ function useSubscriptionController() {
19588
19639
  const status = req.query.status ?? "";
19589
19640
  const search = req.query.search ?? "";
19590
19641
  const page = Number(req.query.page) ?? 1;
19591
- const validation = Joi11.object({
19592
- status: Joi11.string().required(),
19593
- search: Joi11.string().optional().allow("", null),
19594
- page: Joi11.number().required()
19642
+ const validation = Joi12.object({
19643
+ status: Joi12.string().required(),
19644
+ search: Joi12.string().optional().allow("", null),
19645
+ page: Joi12.number().required()
19595
19646
  });
19596
19647
  const { error } = validation.validate({ status, search, page });
19597
19648
  if (error) {
@@ -19607,7 +19658,7 @@ function useSubscriptionController() {
19607
19658
  }
19608
19659
  async function getSubscriptionStatus(req, res, next) {
19609
19660
  const id = req.params.id;
19610
- const validation = Joi11.string().required();
19661
+ const validation = Joi12.string().required();
19611
19662
  const { error } = validation.validate(id);
19612
19663
  if (error) {
19613
19664
  next(new BadRequestError31(error.message));
@@ -19626,12 +19677,12 @@ function useSubscriptionController() {
19626
19677
  const customer_id = req.body.customer_id ?? "";
19627
19678
  const currency = req.body.currency ?? "PHP";
19628
19679
  const user = req.headers["user"];
19629
- const validation = Joi11.object({
19630
- user: Joi11.string().required(),
19631
- amount: Joi11.number().required(),
19632
- customer_id: Joi11.string().required(),
19633
- payment_method_id: Joi11.string().required(),
19634
- currency: Joi11.string().optional().allow("", null)
19680
+ const validation = Joi12.object({
19681
+ user: Joi12.string().required(),
19682
+ amount: Joi12.number().required(),
19683
+ customer_id: Joi12.string().required(),
19684
+ payment_method_id: Joi12.string().required(),
19685
+ currency: Joi12.string().optional().allow("", null)
19635
19686
  });
19636
19687
  const { error } = validation.validate({
19637
19688
  user,
@@ -19659,35 +19710,11 @@ function useSubscriptionController() {
19659
19710
  return;
19660
19711
  }
19661
19712
  }
19713
+ const { schema: subscriptionSchema } = useSubscriptionSchema();
19662
19714
  async function createOrgSubscription(req, res, next) {
19663
19715
  const value = req.body;
19664
19716
  value.user = req.headers["user"];
19665
- const validation = Joi11.object({
19666
- user: Joi11.string().required(),
19667
- amount: Joi11.number().required(),
19668
- customer_id: Joi11.string().required(),
19669
- payment_method_id: Joi11.string().required(),
19670
- currency: Joi11.string().optional().allow("", null),
19671
- organization: Joi11.object({
19672
- name: Joi11.string().required(),
19673
- description: Joi11.string().optional().allow("", null),
19674
- type: Joi11.string().allow("personal", "business").required(),
19675
- email: Joi11.string().email().required(),
19676
- contact: Joi11.string().required(),
19677
- busInst: Joi11.string().optional().allow(null, "")
19678
- }).required(),
19679
- billingAddress: Joi11.object({
19680
- type: Joi11.string().required(),
19681
- country: Joi11.string().required(),
19682
- address: Joi11.string().required(),
19683
- continuedAddress: Joi11.string().optional().allow(null, ""),
19684
- city: Joi11.string().required(),
19685
- province: Joi11.string().required(),
19686
- postalCode: Joi11.string().required(),
19687
- taxId: Joi11.string().optional().allow(null, "")
19688
- }).required()
19689
- });
19690
- const { error } = validation.validate(value);
19717
+ const { error } = subscriptionSchema.validate(value);
19691
19718
  if (error) {
19692
19719
  next(new BadRequestError31(error.message));
19693
19720
  return;
@@ -19761,7 +19788,8 @@ function usePaymentMethodService() {
19761
19788
  type = "GCASH",
19762
19789
  success_return_url = "",
19763
19790
  failure_return_url = "",
19764
- cancel_return_url = ""
19791
+ cancel_return_url = "",
19792
+ metadata = {}
19765
19793
  } = {}) {
19766
19794
  const session = useAtlas19.getClient()?.startSession();
19767
19795
  session?.startTransaction();
@@ -19779,7 +19807,7 @@ function usePaymentMethodService() {
19779
19807
  given_names: _user.firstName,
19780
19808
  surname: _user.lastName
19781
19809
  });
19782
- const result = await linkPaymentMethodEWallet({
19810
+ const paymentMethod = await linkPaymentMethodEWallet({
19783
19811
  customerId: customer.id,
19784
19812
  type,
19785
19813
  success_return_url,
@@ -19791,17 +19819,20 @@ function usePaymentMethodService() {
19791
19819
  user: _user._id,
19792
19820
  type,
19793
19821
  status: "active",
19794
- paymentId: result.id,
19822
+ paymentId: paymentMethod.id,
19795
19823
  customerId: customer.id,
19796
- name: result.type,
19824
+ name: paymentMethod.type,
19797
19825
  number: mobile_number
19798
19826
  },
19799
19827
  session
19800
19828
  );
19801
19829
  await session?.commitTransaction();
19802
- return result;
19830
+ return {
19831
+ paymentMethod: paymentMethod.id,
19832
+ customer: customer.id,
19833
+ actions: paymentMethod.actions
19834
+ };
19803
19835
  } catch (error) {
19804
- console.log(error);
19805
19836
  await session?.abortTransaction();
19806
19837
  throw error;
19807
19838
  } finally {
@@ -19868,7 +19899,7 @@ function usePaymentMethodService() {
19868
19899
  }
19869
19900
 
19870
19901
  // src/controllers/payment-method.controller.ts
19871
- import Joi12 from "joi";
19902
+ import Joi13 from "joi";
19872
19903
  import { BadRequestError as BadRequestError33 } from "@goweekdays/utils";
19873
19904
  function usePaymentMethodController() {
19874
19905
  const { linkEWallet: _linkEWallet, linkCard: _linkCard } = usePaymentMethodService();
@@ -19879,13 +19910,13 @@ function usePaymentMethodController() {
19879
19910
  const success_return_url = req.body.success_return_url ?? "";
19880
19911
  const failure_return_url = req.body.failure_return_url ?? "";
19881
19912
  const cancel_return_url = req.body.cancel_return_url ?? "";
19882
- const validation = Joi12.object({
19883
- user: Joi12.string().hex().required(),
19884
- mobile_number: Joi12.string().required(),
19885
- type: Joi12.string().valid("GCASH", "PAYMAYA").required(),
19886
- success_return_url: Joi12.string().uri().required(),
19887
- failure_return_url: Joi12.string().uri().required(),
19888
- cancel_return_url: Joi12.string().uri().required()
19913
+ const validation = Joi13.object({
19914
+ user: Joi13.string().hex().required(),
19915
+ mobile_number: Joi13.string().required(),
19916
+ type: Joi13.string().valid("GCASH", "PAYMAYA").required(),
19917
+ success_return_url: Joi13.string().uri().required(),
19918
+ failure_return_url: Joi13.string().uri().required(),
19919
+ cancel_return_url: Joi13.string().uri().required()
19889
19920
  });
19890
19921
  const { error } = validation.validate({
19891
19922
  user,
@@ -19924,17 +19955,17 @@ function usePaymentMethodController() {
19924
19955
  const failure_return_url = req.body.failure_return_url ?? "";
19925
19956
  const cardType = req.body.cardType ?? "";
19926
19957
  const user = req.headers["user"] ?? "";
19927
- const validation = Joi12.object({
19928
- cardNumber: Joi12.string().required(),
19929
- expiryMonth: Joi12.string().required(),
19930
- expiryYear: Joi12.string().required(),
19931
- cvv: Joi12.string().required(),
19932
- cardholderName: Joi12.string().required(),
19933
- currency: Joi12.string().optional().allow("", null),
19934
- success_return_url: Joi12.string().uri().required(),
19935
- failure_return_url: Joi12.string().uri().required(),
19936
- cardType: Joi12.string().required(),
19937
- user: Joi12.string().hex().required()
19958
+ const validation = Joi13.object({
19959
+ cardNumber: Joi13.string().required(),
19960
+ expiryMonth: Joi13.string().required(),
19961
+ expiryYear: Joi13.string().required(),
19962
+ cvv: Joi13.string().required(),
19963
+ cardholderName: Joi13.string().required(),
19964
+ currency: Joi13.string().optional().allow("", null),
19965
+ success_return_url: Joi13.string().uri().required(),
19966
+ failure_return_url: Joi13.string().uri().required(),
19967
+ cardType: Joi13.string().required(),
19968
+ user: Joi13.string().hex().required()
19938
19969
  });
19939
19970
  const { error } = validation.validate({
19940
19971
  user,
@@ -19989,22 +20020,22 @@ function usePaymentMethodController() {
19989
20020
 
19990
20021
  // src/controllers/address.controller.ts
19991
20022
  import { BadRequestError as BadRequestError34, NotFoundError as NotFoundError4 } from "@goweekdays/utils";
19992
- import Joi13 from "joi";
20023
+ import Joi14 from "joi";
19993
20024
  function useAddressController() {
19994
20025
  const { add: _add, getByUserId: _getByUserId } = useAddressRepo();
19995
20026
  async function add(req, res, next) {
19996
20027
  const value = req.body;
19997
- const validation = Joi13.object({
19998
- type: Joi13.string().required(),
19999
- user: Joi13.string().hex().optional().allow("", null),
20000
- org: Joi13.string().hex().optional().allow("", null),
20001
- country: Joi13.string().required(),
20002
- address: Joi13.string().required(),
20003
- continuedAddress: Joi13.string().optional().allow("", null),
20004
- city: Joi13.string().required(),
20005
- province: Joi13.string().required(),
20006
- postalCode: Joi13.string().required(),
20007
- taxId: Joi13.string().optional().allow("", null)
20028
+ const validation = Joi14.object({
20029
+ type: Joi14.string().required(),
20030
+ user: Joi14.string().hex().optional().allow("", null),
20031
+ org: Joi14.string().hex().optional().allow("", null),
20032
+ country: Joi14.string().required(),
20033
+ address: Joi14.string().required(),
20034
+ continuedAddress: Joi14.string().optional().allow("", null),
20035
+ city: Joi14.string().required(),
20036
+ province: Joi14.string().required(),
20037
+ postalCode: Joi14.string().required(),
20038
+ taxId: Joi14.string().optional().allow("", null)
20008
20039
  });
20009
20040
  const { error } = validation.validate(value);
20010
20041
  if (error) {
@@ -20021,7 +20052,7 @@ function useAddressController() {
20021
20052
  }
20022
20053
  async function getByUserId(req, res, next) {
20023
20054
  const user = req.params.user;
20024
- const validation = Joi13.string().hex().required();
20055
+ const validation = Joi14.string().hex().required();
20025
20056
  const { error } = validation.validate(user);
20026
20057
  if (error) {
20027
20058
  next(new BadRequestError34(error.message));
@@ -20057,19 +20088,19 @@ import {
20057
20088
 
20058
20089
  // src/models/member.model.ts
20059
20090
  import { BadRequestError as BadRequestError35 } from "@goweekdays/utils";
20060
- import Joi14 from "joi";
20091
+ import Joi15 from "joi";
20061
20092
  import { ObjectId as ObjectId27 } from "mongodb";
20062
20093
  function MMember(value) {
20063
- const schema = Joi14.object({
20064
- _id: Joi14.string().hex().optional().allow("", null),
20065
- org: Joi14.string().hex().required(),
20066
- name: Joi14.string().required(),
20067
- user: Joi14.string().hex().required(),
20068
- role: Joi14.string().hex().required(),
20069
- status: Joi14.string().optional().allow("", null),
20070
- createdAt: Joi14.string().optional().allow("", null),
20071
- updatedAt: Joi14.string().optional().allow("", null),
20072
- deletedAt: Joi14.string().optional().allow("", null)
20094
+ const schema = Joi15.object({
20095
+ _id: Joi15.string().hex().optional().allow("", null),
20096
+ org: Joi15.string().hex().required(),
20097
+ name: Joi15.string().required(),
20098
+ user: Joi15.string().hex().required(),
20099
+ role: Joi15.string().hex().required(),
20100
+ status: Joi15.string().optional().allow("", null),
20101
+ createdAt: Joi15.string().optional().allow("", null),
20102
+ updatedAt: Joi15.string().optional().allow("", null),
20103
+ deletedAt: Joi15.string().optional().allow("", null)
20073
20104
  });
20074
20105
  const { error } = schema.validate(value);
20075
20106
  if (error) {
@@ -20326,19 +20357,20 @@ function useOrgService() {
20326
20357
  import {
20327
20358
  BadRequestError as BadRequestError37
20328
20359
  } from "@goweekdays/utils";
20329
- import Joi15 from "joi";
20360
+ import Joi16 from "joi";
20330
20361
  function useOrgController() {
20331
20362
  const { createOrg: _createOrg } = useOrgService();
20332
20363
  const { getOrgsByUserId: _getOrgsByUserId } = useMemberRepo();
20364
+ const { getByName: _getByName } = useOrgRepo();
20333
20365
  async function createOrg(req, res, next) {
20334
20366
  const value = req.body;
20335
- const validation = Joi15.object({
20336
- name: Joi15.string().required(),
20337
- type: Joi15.string().required(),
20338
- email: Joi15.string().email().required(),
20339
- contact: Joi15.string().required(),
20340
- description: Joi15.string().required(),
20341
- user: Joi15.string().hex().required()
20367
+ const validation = Joi16.object({
20368
+ name: Joi16.string().required(),
20369
+ type: Joi16.string().required(),
20370
+ email: Joi16.string().email().required(),
20371
+ contact: Joi16.string().required(),
20372
+ description: Joi16.string().required(),
20373
+ user: Joi16.string().hex().required()
20342
20374
  });
20343
20375
  const { error } = validation.validate(value);
20344
20376
  if (error) {
@@ -20358,11 +20390,11 @@ function useOrgController() {
20358
20390
  const limit = Number(req.query.limit) ?? 10;
20359
20391
  const search = req.query.search ?? "";
20360
20392
  const user = req.headers["user"];
20361
- const validation = Joi15.object({
20362
- user: Joi15.string().hex().required(),
20363
- page: Joi15.number().min(1).optional().allow("", null),
20364
- limit: Joi15.number().min(1).optional().allow("", null),
20365
- search: Joi15.string().optional().allow("", null)
20393
+ const validation = Joi16.object({
20394
+ user: Joi16.string().hex().required(),
20395
+ page: Joi16.number().min(1).optional().allow("", null),
20396
+ limit: Joi16.number().min(1).optional().allow("", null),
20397
+ search: Joi16.string().optional().allow("", null)
20366
20398
  });
20367
20399
  const { error } = validation.validate({ user, page, limit, search });
20368
20400
  if (error) {
@@ -20377,9 +20409,28 @@ function useOrgController() {
20377
20409
  next(error2);
20378
20410
  }
20379
20411
  }
20412
+ async function getByName(req, res, next) {
20413
+ const name = req.params.name;
20414
+ const validation = Joi16.object({
20415
+ name: Joi16.string().required()
20416
+ });
20417
+ const { error } = validation.validate({ name });
20418
+ if (error) {
20419
+ next(new BadRequestError37(error.message));
20420
+ return;
20421
+ }
20422
+ try {
20423
+ const org = await _getByName(name);
20424
+ res.json(org);
20425
+ return;
20426
+ } catch (error2) {
20427
+ next(error2);
20428
+ }
20429
+ }
20380
20430
  return {
20381
20431
  createOrg,
20382
- getOrgsByUserId
20432
+ getOrgsByUserId,
20433
+ getByName
20383
20434
  };
20384
20435
  }
20385
20436
  export {