@goweekdays/core 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +29 -11
- package/dist/index.js +509 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +508 -215
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -19695,6 +19695,12 @@ function MSubscription(value) {
|
|
|
19695
19695
|
status: Joi12.string().optional().allow("", null),
|
|
19696
19696
|
billingCycle: Joi12.string().valid("monthly", "yearly").required(),
|
|
19697
19697
|
// Ensure valid values
|
|
19698
|
+
billingContacts: Joi12.array().items(
|
|
19699
|
+
Joi12.object({
|
|
19700
|
+
addedAt: Joi12.date().optional(),
|
|
19701
|
+
email: Joi12.string().email().required()
|
|
19702
|
+
})
|
|
19703
|
+
).optional().allow([]),
|
|
19698
19704
|
nextBillingDate: Joi12.date().optional(),
|
|
19699
19705
|
lastPaymentStatus: Joi12.string().optional().allow("", null),
|
|
19700
19706
|
failedAttempts: Joi12.number().optional().allow("", null),
|
|
@@ -19743,6 +19749,7 @@ function MSubscription(value) {
|
|
|
19743
19749
|
maxSeats: value.maxSeats ?? 0,
|
|
19744
19750
|
status: "active",
|
|
19745
19751
|
billingCycle: value.billingCycle,
|
|
19752
|
+
billingContacts: value.billingContacts ?? [],
|
|
19746
19753
|
nextBillingDate,
|
|
19747
19754
|
// Fixed nextBillingDate logic
|
|
19748
19755
|
lastPaymentStatus: value.lastPaymentStatus ?? "success",
|
|
@@ -19902,6 +19909,70 @@ function useSubscriptionRepo() {
|
|
|
19902
19909
|
throw new BadRequestError24("Failed to update subscription status.");
|
|
19903
19910
|
}
|
|
19904
19911
|
}
|
|
19912
|
+
async function addBillingContactById(_id, email) {
|
|
19913
|
+
try {
|
|
19914
|
+
_id = new ObjectId24(_id);
|
|
19915
|
+
} catch (error) {
|
|
19916
|
+
throw new BadRequestError24("Invalid ID.");
|
|
19917
|
+
}
|
|
19918
|
+
try {
|
|
19919
|
+
await collection.updateOne(
|
|
19920
|
+
{ _id },
|
|
19921
|
+
{ $push: { billingContacts: { email, addedAt: /* @__PURE__ */ new Date() } } }
|
|
19922
|
+
);
|
|
19923
|
+
return "Successfully updated subscription billing contact.";
|
|
19924
|
+
} catch (error) {
|
|
19925
|
+
throw new BadRequestError24(
|
|
19926
|
+
"Failed to update subscription billing contact."
|
|
19927
|
+
);
|
|
19928
|
+
}
|
|
19929
|
+
}
|
|
19930
|
+
async function updateBillingContactByAddedAt(_id, addedAt, email) {
|
|
19931
|
+
try {
|
|
19932
|
+
_id = new ObjectId24(_id);
|
|
19933
|
+
} catch (error) {
|
|
19934
|
+
throw new BadRequestError24("Invalid ID.");
|
|
19935
|
+
}
|
|
19936
|
+
try {
|
|
19937
|
+
addedAt = new Date(addedAt);
|
|
19938
|
+
} catch (error) {
|
|
19939
|
+
throw new BadRequestError24("Invalid addedAt date.");
|
|
19940
|
+
}
|
|
19941
|
+
try {
|
|
19942
|
+
await collection.updateOne(
|
|
19943
|
+
{ _id, "billingContacts.addedAt": addedAt },
|
|
19944
|
+
{ $set: { "billingContacts.$.email": email } }
|
|
19945
|
+
);
|
|
19946
|
+
return "Successfully updated subscription billing contact.";
|
|
19947
|
+
} catch (error) {
|
|
19948
|
+
throw new BadRequestError24(
|
|
19949
|
+
"Failed to update subscription billing contact."
|
|
19950
|
+
);
|
|
19951
|
+
}
|
|
19952
|
+
}
|
|
19953
|
+
async function deleteBillingContactByAddedAt(_id, addedAt) {
|
|
19954
|
+
try {
|
|
19955
|
+
_id = new ObjectId24(_id);
|
|
19956
|
+
} catch (error) {
|
|
19957
|
+
throw new BadRequestError24("Invalid ID.");
|
|
19958
|
+
}
|
|
19959
|
+
try {
|
|
19960
|
+
addedAt = new Date(addedAt);
|
|
19961
|
+
} catch (error) {
|
|
19962
|
+
throw new BadRequestError24("Invalid addedAt date.");
|
|
19963
|
+
}
|
|
19964
|
+
try {
|
|
19965
|
+
await collection.updateOne(
|
|
19966
|
+
{ _id },
|
|
19967
|
+
{ $pull: { billingContacts: { addedAt } } }
|
|
19968
|
+
);
|
|
19969
|
+
return "Successfully delete subscription billing contact.";
|
|
19970
|
+
} catch (error) {
|
|
19971
|
+
throw new BadRequestError24(
|
|
19972
|
+
"Failed to delete subscription billing contact."
|
|
19973
|
+
);
|
|
19974
|
+
}
|
|
19975
|
+
}
|
|
19905
19976
|
async function getDueSubscriptions(BATCH_SIZE = 100) {
|
|
19906
19977
|
const today = /* @__PURE__ */ new Date();
|
|
19907
19978
|
const startOfDay = new Date(today.setUTCHours(0, 0, 0, 0));
|
|
@@ -20050,6 +20121,34 @@ function useSubscriptionRepo() {
|
|
|
20050
20121
|
throw new BadRequestError24("Failed to update subscription status.");
|
|
20051
20122
|
}
|
|
20052
20123
|
}
|
|
20124
|
+
async function updatePaymentMethodById(_id, paymentMethodId, session) {
|
|
20125
|
+
const schema3 = Joi13.object({
|
|
20126
|
+
_id: Joi13.string().hex().required(),
|
|
20127
|
+
paymentMethodId: Joi13.string().required()
|
|
20128
|
+
});
|
|
20129
|
+
const { error } = schema3.validate({ _id, paymentMethodId });
|
|
20130
|
+
if (error) {
|
|
20131
|
+
throw new BadRequestError24(error.message);
|
|
20132
|
+
}
|
|
20133
|
+
try {
|
|
20134
|
+
_id = new ObjectId24(_id);
|
|
20135
|
+
} catch (error2) {
|
|
20136
|
+
throw new BadRequestError24("Invalid ID.");
|
|
20137
|
+
}
|
|
20138
|
+
try {
|
|
20139
|
+
return await collection.updateOne(
|
|
20140
|
+
{ _id },
|
|
20141
|
+
{
|
|
20142
|
+
$set: { paymentMethodId }
|
|
20143
|
+
},
|
|
20144
|
+
{ session }
|
|
20145
|
+
);
|
|
20146
|
+
} catch (error2) {
|
|
20147
|
+
throw new BadRequestError24(
|
|
20148
|
+
"Failed to update subscription payment method."
|
|
20149
|
+
);
|
|
20150
|
+
}
|
|
20151
|
+
}
|
|
20053
20152
|
async function updatePromoCodeById(_id, promoCode, session) {
|
|
20054
20153
|
const schema3 = Joi13.object({
|
|
20055
20154
|
_id: Joi13.string().hex().required(),
|
|
@@ -20183,7 +20282,11 @@ function useSubscriptionRepo() {
|
|
|
20183
20282
|
updateSeatsById,
|
|
20184
20283
|
updateMaxSeatsById,
|
|
20185
20284
|
updateStatusById,
|
|
20186
|
-
updatePromoCodeById
|
|
20285
|
+
updatePromoCodeById,
|
|
20286
|
+
updatePaymentMethodById,
|
|
20287
|
+
addBillingContactById,
|
|
20288
|
+
updateBillingContactByAddedAt,
|
|
20289
|
+
deleteBillingContactByAddedAt
|
|
20187
20290
|
};
|
|
20188
20291
|
}
|
|
20189
20292
|
|
|
@@ -20434,7 +20537,20 @@ import { BadRequestError as BadRequestError28, useAtlas as useAtlas17 } from "@g
|
|
|
20434
20537
|
|
|
20435
20538
|
// src/models/address.model.ts
|
|
20436
20539
|
import { BadRequestError as BadRequestError27 } from "@goweekdays/utils";
|
|
20540
|
+
import Joi15 from "joi";
|
|
20437
20541
|
import { ObjectId as ObjectId27 } from "mongodb";
|
|
20542
|
+
var addressSchema = Joi15.object({
|
|
20543
|
+
type: Joi15.string().required(),
|
|
20544
|
+
user: Joi15.string().hex().optional().allow("", null),
|
|
20545
|
+
org: Joi15.string().hex().optional().allow("", null),
|
|
20546
|
+
country: Joi15.string().required(),
|
|
20547
|
+
address: Joi15.string().required(),
|
|
20548
|
+
continuedAddress: Joi15.string().optional().allow("", null),
|
|
20549
|
+
city: Joi15.string().required(),
|
|
20550
|
+
province: Joi15.string().required(),
|
|
20551
|
+
postalCode: Joi15.string().required(),
|
|
20552
|
+
taxId: Joi15.string().optional().allow("", null)
|
|
20553
|
+
});
|
|
20438
20554
|
function MAddress(value) {
|
|
20439
20555
|
if (value.user) {
|
|
20440
20556
|
try {
|
|
@@ -20474,7 +20590,11 @@ function useAddressRepo() {
|
|
|
20474
20590
|
const collection = db.collection("addresses");
|
|
20475
20591
|
async function createIndex() {
|
|
20476
20592
|
try {
|
|
20477
|
-
await collection.
|
|
20593
|
+
await collection.createIndexes([
|
|
20594
|
+
{ key: { user: 1 } },
|
|
20595
|
+
{ key: { type: 1 } },
|
|
20596
|
+
{ key: { orgId: 1 } }
|
|
20597
|
+
]);
|
|
20478
20598
|
} catch (error) {
|
|
20479
20599
|
throw new BadRequestError28("Failed to create index on address.");
|
|
20480
20600
|
}
|
|
@@ -20488,6 +20608,19 @@ function useAddressRepo() {
|
|
|
20488
20608
|
throw new BadRequestError28("Failed to create address.");
|
|
20489
20609
|
}
|
|
20490
20610
|
}
|
|
20611
|
+
async function updateById(_id, value, session) {
|
|
20612
|
+
try {
|
|
20613
|
+
_id = new ObjectId28(_id);
|
|
20614
|
+
} catch (error) {
|
|
20615
|
+
throw new BadRequestError28("Invalid address ID.");
|
|
20616
|
+
}
|
|
20617
|
+
try {
|
|
20618
|
+
await collection.updateOne({ _id }, { $set: value }, { session });
|
|
20619
|
+
return "Successfully updated address.";
|
|
20620
|
+
} catch (error) {
|
|
20621
|
+
throw new BadRequestError28("Failed to update address.");
|
|
20622
|
+
}
|
|
20623
|
+
}
|
|
20491
20624
|
async function getByUserId(user) {
|
|
20492
20625
|
try {
|
|
20493
20626
|
user = new ObjectId28(user);
|
|
@@ -20500,10 +20633,24 @@ function useAddressRepo() {
|
|
|
20500
20633
|
throw new BadRequestError28("Failed to get address by ID.");
|
|
20501
20634
|
}
|
|
20502
20635
|
}
|
|
20636
|
+
async function getByOrgId(org) {
|
|
20637
|
+
try {
|
|
20638
|
+
org = new ObjectId28(org);
|
|
20639
|
+
} catch (error) {
|
|
20640
|
+
throw new BadRequestError28("Invalid orgId.");
|
|
20641
|
+
}
|
|
20642
|
+
try {
|
|
20643
|
+
return await collection.findOne({ org });
|
|
20644
|
+
} catch (error) {
|
|
20645
|
+
throw new BadRequestError28("Failed to get address by orgId.");
|
|
20646
|
+
}
|
|
20647
|
+
}
|
|
20503
20648
|
return {
|
|
20504
20649
|
createIndex,
|
|
20505
20650
|
add,
|
|
20506
|
-
getByUserId
|
|
20651
|
+
getByUserId,
|
|
20652
|
+
getByOrgId,
|
|
20653
|
+
updateById
|
|
20507
20654
|
};
|
|
20508
20655
|
}
|
|
20509
20656
|
|
|
@@ -20517,28 +20664,28 @@ import {
|
|
|
20517
20664
|
} from "@goweekdays/utils";
|
|
20518
20665
|
|
|
20519
20666
|
// src/validations/promo-code.schema.ts
|
|
20520
|
-
import
|
|
20521
|
-
var promoTypeSchema =
|
|
20522
|
-
var promoTierSchema =
|
|
20523
|
-
min:
|
|
20524
|
-
max:
|
|
20525
|
-
price:
|
|
20667
|
+
import Joi16 from "joi";
|
|
20668
|
+
var promoTypeSchema = Joi16.string().valid("tiered", "fixed").required();
|
|
20669
|
+
var promoTierSchema = Joi16.object({
|
|
20670
|
+
min: Joi16.number().integer().min(1).required(),
|
|
20671
|
+
max: Joi16.number().integer().min(Joi16.ref("min")).allow(0).required(),
|
|
20672
|
+
price: Joi16.number().positive().required()
|
|
20526
20673
|
});
|
|
20527
|
-
var schema =
|
|
20528
|
-
code:
|
|
20529
|
-
description:
|
|
20674
|
+
var schema = Joi16.object({
|
|
20675
|
+
code: Joi16.string().trim().uppercase().required(),
|
|
20676
|
+
description: Joi16.string().trim().optional(),
|
|
20530
20677
|
type: promoTypeSchema,
|
|
20531
|
-
tiers:
|
|
20678
|
+
tiers: Joi16.alternatives().conditional("type", {
|
|
20532
20679
|
is: "tiered",
|
|
20533
|
-
then:
|
|
20534
|
-
otherwise:
|
|
20680
|
+
then: Joi16.array().items(promoTierSchema).min(1).required(),
|
|
20681
|
+
otherwise: Joi16.forbidden()
|
|
20535
20682
|
}),
|
|
20536
|
-
fixed_rate:
|
|
20683
|
+
fixed_rate: Joi16.alternatives().conditional("type", {
|
|
20537
20684
|
is: "fixed",
|
|
20538
|
-
then:
|
|
20539
|
-
otherwise:
|
|
20685
|
+
then: Joi16.number().required().min(0),
|
|
20686
|
+
otherwise: Joi16.number().integer().allow(0)
|
|
20540
20687
|
}),
|
|
20541
|
-
expiresAt:
|
|
20688
|
+
expiresAt: Joi16.string().optional().allow(null, "")
|
|
20542
20689
|
});
|
|
20543
20690
|
|
|
20544
20691
|
// src/models/promo-code.model.ts
|
|
@@ -20564,7 +20711,7 @@ function MPromoCode(data) {
|
|
|
20564
20711
|
}
|
|
20565
20712
|
|
|
20566
20713
|
// src/repositories/promo-code.repository.ts
|
|
20567
|
-
import
|
|
20714
|
+
import Joi17 from "joi";
|
|
20568
20715
|
import { ObjectId as ObjectId29 } from "mongodb";
|
|
20569
20716
|
function usePromoCodeRepo() {
|
|
20570
20717
|
const db = useAtlas18.getDb();
|
|
@@ -20607,8 +20754,8 @@ function usePromoCodeRepo() {
|
|
|
20607
20754
|
}
|
|
20608
20755
|
}
|
|
20609
20756
|
async function getByCode(code, type, assigned) {
|
|
20610
|
-
const schema3 =
|
|
20611
|
-
code:
|
|
20757
|
+
const schema3 = Joi17.object({
|
|
20758
|
+
code: Joi17.string().trim().required()
|
|
20612
20759
|
});
|
|
20613
20760
|
const { error } = schema3.validate({ code });
|
|
20614
20761
|
if (error) {
|
|
@@ -20630,8 +20777,8 @@ function usePromoCodeRepo() {
|
|
|
20630
20777
|
}
|
|
20631
20778
|
}
|
|
20632
20779
|
async function getById(_id) {
|
|
20633
|
-
const schema3 =
|
|
20634
|
-
_id:
|
|
20780
|
+
const schema3 = Joi17.object({
|
|
20781
|
+
_id: Joi17.string().hex().required()
|
|
20635
20782
|
});
|
|
20636
20783
|
const { error } = schema3.validate({ _id });
|
|
20637
20784
|
if (error) {
|
|
@@ -20680,9 +20827,9 @@ function usePromoCodeRepo() {
|
|
|
20680
20827
|
}
|
|
20681
20828
|
}
|
|
20682
20829
|
async function assignByUserId({ user, code } = {}, session) {
|
|
20683
|
-
const schema3 =
|
|
20684
|
-
user:
|
|
20685
|
-
code:
|
|
20830
|
+
const schema3 = Joi17.object({
|
|
20831
|
+
user: Joi17.string().required(),
|
|
20832
|
+
code: Joi17.string().required()
|
|
20686
20833
|
});
|
|
20687
20834
|
const { error } = schema3.validate({ user, code });
|
|
20688
20835
|
if (error) {
|
|
@@ -20715,7 +20862,7 @@ function usePromoCodeRepo() {
|
|
|
20715
20862
|
}
|
|
20716
20863
|
|
|
20717
20864
|
// src/services/subscription.service.ts
|
|
20718
|
-
import
|
|
20865
|
+
import Joi18 from "joi";
|
|
20719
20866
|
|
|
20720
20867
|
// src/repositories/invoice.repository.ts
|
|
20721
20868
|
import {
|
|
@@ -21936,8 +22083,8 @@ function useSubscriptionService() {
|
|
|
21936
22083
|
return remainingDays > 1 ? Number((seats * price * prorationFactor).toFixed(2)) : Number((seats * price).toFixed(2));
|
|
21937
22084
|
}
|
|
21938
22085
|
function formatAmount(amount) {
|
|
21939
|
-
const validation =
|
|
21940
|
-
amount:
|
|
22086
|
+
const validation = Joi18.object({
|
|
22087
|
+
amount: Joi18.number().required()
|
|
21941
22088
|
});
|
|
21942
22089
|
const { error } = validation.validate({ amount });
|
|
21943
22090
|
if (error) {
|
|
@@ -22017,10 +22164,10 @@ function useSubscriptionService() {
|
|
|
22017
22164
|
}
|
|
22018
22165
|
}
|
|
22019
22166
|
async function updateSeatsById(value) {
|
|
22020
|
-
const schema3 =
|
|
22021
|
-
subscriptionId:
|
|
22022
|
-
seats:
|
|
22023
|
-
amount:
|
|
22167
|
+
const schema3 = Joi18.object({
|
|
22168
|
+
subscriptionId: Joi18.string().hex().required(),
|
|
22169
|
+
seats: Joi18.number().min(1).required(),
|
|
22170
|
+
amount: Joi18.number().required()
|
|
22024
22171
|
});
|
|
22025
22172
|
const { error } = schema3.validate(value);
|
|
22026
22173
|
if (error) {
|
|
@@ -22232,43 +22379,43 @@ function useSubscriptionService() {
|
|
|
22232
22379
|
}
|
|
22233
22380
|
|
|
22234
22381
|
// src/controllers/subscription.controller.ts
|
|
22235
|
-
import
|
|
22382
|
+
import Joi20 from "joi";
|
|
22236
22383
|
import { BadRequestError as BadRequestError37 } from "@goweekdays/utils";
|
|
22237
22384
|
|
|
22238
22385
|
// src/validations/subscription.schema.ts
|
|
22239
|
-
import
|
|
22386
|
+
import Joi19 from "joi";
|
|
22240
22387
|
function useSubscriptionSchema() {
|
|
22241
|
-
const schema3 =
|
|
22242
|
-
user:
|
|
22243
|
-
amount:
|
|
22244
|
-
customer_id:
|
|
22245
|
-
payment_method_id:
|
|
22246
|
-
payment_method_type:
|
|
22247
|
-
payment_method_channel:
|
|
22248
|
-
payment_method_month_expiry:
|
|
22249
|
-
payment_method_year_expiry:
|
|
22250
|
-
payment_method_cvv:
|
|
22251
|
-
currency:
|
|
22252
|
-
seats:
|
|
22253
|
-
organization:
|
|
22254
|
-
name:
|
|
22255
|
-
description:
|
|
22256
|
-
type:
|
|
22257
|
-
email:
|
|
22258
|
-
contact:
|
|
22259
|
-
busInst:
|
|
22388
|
+
const schema3 = Joi19.object({
|
|
22389
|
+
user: Joi19.string().required().min(0),
|
|
22390
|
+
amount: Joi19.number().min(0).required(),
|
|
22391
|
+
customer_id: Joi19.string().required(),
|
|
22392
|
+
payment_method_id: Joi19.string().required(),
|
|
22393
|
+
payment_method_type: Joi19.string().required(),
|
|
22394
|
+
payment_method_channel: Joi19.string().required(),
|
|
22395
|
+
payment_method_month_expiry: Joi19.string().optional().allow(null, ""),
|
|
22396
|
+
payment_method_year_expiry: Joi19.string().optional().allow(null, ""),
|
|
22397
|
+
payment_method_cvv: Joi19.string().optional().allow(null, ""),
|
|
22398
|
+
currency: Joi19.string().optional().allow("", null),
|
|
22399
|
+
seats: Joi19.number().optional().min(0).allow(null),
|
|
22400
|
+
organization: Joi19.object({
|
|
22401
|
+
name: Joi19.string().required(),
|
|
22402
|
+
description: Joi19.string().optional().allow("", null),
|
|
22403
|
+
type: Joi19.string().allow("personal", "business").required(),
|
|
22404
|
+
email: Joi19.string().email().required(),
|
|
22405
|
+
contact: Joi19.string().required(),
|
|
22406
|
+
busInst: Joi19.string().optional().allow(null, "")
|
|
22260
22407
|
}).optional().allow({}),
|
|
22261
|
-
billingAddress:
|
|
22262
|
-
type:
|
|
22263
|
-
country:
|
|
22264
|
-
address:
|
|
22265
|
-
continuedAddress:
|
|
22266
|
-
city:
|
|
22267
|
-
province:
|
|
22268
|
-
postalCode:
|
|
22269
|
-
taxId:
|
|
22408
|
+
billingAddress: Joi19.object({
|
|
22409
|
+
type: Joi19.string().required(),
|
|
22410
|
+
country: Joi19.string().required(),
|
|
22411
|
+
address: Joi19.string().required(),
|
|
22412
|
+
continuedAddress: Joi19.string().optional().allow(null, ""),
|
|
22413
|
+
city: Joi19.string().required(),
|
|
22414
|
+
province: Joi19.string().required(),
|
|
22415
|
+
postalCode: Joi19.string().required(),
|
|
22416
|
+
taxId: Joi19.string().optional().allow(null, "")
|
|
22270
22417
|
}).required(),
|
|
22271
|
-
promoCode:
|
|
22418
|
+
promoCode: Joi19.string().optional().allow("", null)
|
|
22272
22419
|
});
|
|
22273
22420
|
return {
|
|
22274
22421
|
schema: schema3
|
|
@@ -22284,7 +22431,11 @@ function useSubscriptionController() {
|
|
|
22284
22431
|
getByOrgId: _getByOrgId,
|
|
22285
22432
|
getById: _getById,
|
|
22286
22433
|
updatePromoCodeById: _updatePromoCodeById,
|
|
22287
|
-
updateStatusById: _updateStatusById
|
|
22434
|
+
updateStatusById: _updateStatusById,
|
|
22435
|
+
updatePaymentMethodById: _updatePaymentMethodById,
|
|
22436
|
+
addBillingContactById: _addBillingContactById,
|
|
22437
|
+
updateBillingContactByAddedAt: _updateBillingContactByAddedAt,
|
|
22438
|
+
deleteBillingContactByAddedAt: _deleteBillingContactByAddedAt
|
|
22288
22439
|
} = useSubscriptionRepo();
|
|
22289
22440
|
const {
|
|
22290
22441
|
getByUserId: _getByUserId,
|
|
@@ -22295,9 +22446,9 @@ function useSubscriptionController() {
|
|
|
22295
22446
|
} = useSubscriptionService();
|
|
22296
22447
|
async function add(req, res, next) {
|
|
22297
22448
|
const value = req.body;
|
|
22298
|
-
const validation =
|
|
22299
|
-
user:
|
|
22300
|
-
subscriptionId:
|
|
22449
|
+
const validation = Joi20.object({
|
|
22450
|
+
user: Joi20.string().required(),
|
|
22451
|
+
subscriptionId: Joi20.string().required()
|
|
22301
22452
|
});
|
|
22302
22453
|
const { error } = validation.validate(value);
|
|
22303
22454
|
if (error) {
|
|
@@ -22314,7 +22465,7 @@ function useSubscriptionController() {
|
|
|
22314
22465
|
}
|
|
22315
22466
|
async function getByUserId(req, res, next) {
|
|
22316
22467
|
const id = req.params.id;
|
|
22317
|
-
const validation =
|
|
22468
|
+
const validation = Joi20.string().required();
|
|
22318
22469
|
const { error } = validation.validate(id);
|
|
22319
22470
|
if (error) {
|
|
22320
22471
|
next(new BadRequestError37(error.message));
|
|
@@ -22329,7 +22480,7 @@ function useSubscriptionController() {
|
|
|
22329
22480
|
}
|
|
22330
22481
|
async function getByAffiliateUserId(req, res, next) {
|
|
22331
22482
|
const id = req.params.id;
|
|
22332
|
-
const validation =
|
|
22483
|
+
const validation = Joi20.string().required();
|
|
22333
22484
|
const { error } = validation.validate(id);
|
|
22334
22485
|
if (error) {
|
|
22335
22486
|
next(new BadRequestError37(error.message));
|
|
@@ -22344,7 +22495,7 @@ function useSubscriptionController() {
|
|
|
22344
22495
|
}
|
|
22345
22496
|
async function getByOrgId(req, res, next) {
|
|
22346
22497
|
const id = req.params.id;
|
|
22347
|
-
const validation =
|
|
22498
|
+
const validation = Joi20.string().required();
|
|
22348
22499
|
const { error } = validation.validate(id);
|
|
22349
22500
|
if (error) {
|
|
22350
22501
|
next(new BadRequestError37(error.message));
|
|
@@ -22359,7 +22510,7 @@ function useSubscriptionController() {
|
|
|
22359
22510
|
}
|
|
22360
22511
|
async function getById(req, res, next) {
|
|
22361
22512
|
const id = req.params.id;
|
|
22362
|
-
const validation =
|
|
22513
|
+
const validation = Joi20.string().required();
|
|
22363
22514
|
const { error } = validation.validate(id);
|
|
22364
22515
|
if (error) {
|
|
22365
22516
|
next(new BadRequestError37(error.message));
|
|
@@ -22376,10 +22527,10 @@ function useSubscriptionController() {
|
|
|
22376
22527
|
const status = req.query.status ?? "";
|
|
22377
22528
|
const search = req.query.search ?? "";
|
|
22378
22529
|
const page = Number(req.query.page) ?? 1;
|
|
22379
|
-
const validation =
|
|
22380
|
-
status:
|
|
22381
|
-
search:
|
|
22382
|
-
page:
|
|
22530
|
+
const validation = Joi20.object({
|
|
22531
|
+
status: Joi20.string().required(),
|
|
22532
|
+
search: Joi20.string().optional().allow("", null),
|
|
22533
|
+
page: Joi20.number().required()
|
|
22383
22534
|
});
|
|
22384
22535
|
const { error } = validation.validate({ status, search, page });
|
|
22385
22536
|
if (error) {
|
|
@@ -22395,7 +22546,7 @@ function useSubscriptionController() {
|
|
|
22395
22546
|
}
|
|
22396
22547
|
async function getSubscriptionStatus(req, res, next) {
|
|
22397
22548
|
const id = req.params.id;
|
|
22398
|
-
const validation =
|
|
22549
|
+
const validation = Joi20.string().required();
|
|
22399
22550
|
const { error } = validation.validate(id);
|
|
22400
22551
|
if (error) {
|
|
22401
22552
|
next(new BadRequestError37(error.message));
|
|
@@ -22447,11 +22598,11 @@ function useSubscriptionController() {
|
|
|
22447
22598
|
async function updateSubscriptionSeats(req, res, next) {
|
|
22448
22599
|
const subscriptionId = req.params.id ?? "";
|
|
22449
22600
|
const value = req.body;
|
|
22450
|
-
const { error } =
|
|
22451
|
-
subscriptionId:
|
|
22452
|
-
seats:
|
|
22453
|
-
promoCode:
|
|
22454
|
-
amount:
|
|
22601
|
+
const { error } = Joi20.object({
|
|
22602
|
+
subscriptionId: Joi20.string().required(),
|
|
22603
|
+
seats: Joi20.number().required(),
|
|
22604
|
+
promoCode: Joi20.string().optional().allow("", null),
|
|
22605
|
+
amount: Joi20.number().min(0).optional()
|
|
22455
22606
|
}).validate({ subscriptionId, ...value });
|
|
22456
22607
|
if (error) {
|
|
22457
22608
|
next(new BadRequestError37(error.message));
|
|
@@ -22469,9 +22620,9 @@ function useSubscriptionController() {
|
|
|
22469
22620
|
async function updatePromoCodeById(req, res, next) {
|
|
22470
22621
|
const subscriptionId = req.params.id ?? "";
|
|
22471
22622
|
const promoCode = req.body.promoCode;
|
|
22472
|
-
const { error } =
|
|
22473
|
-
subscriptionId:
|
|
22474
|
-
promoCode:
|
|
22623
|
+
const { error } = Joi20.object({
|
|
22624
|
+
subscriptionId: Joi20.string().required(),
|
|
22625
|
+
promoCode: Joi20.string().optional().allow("", null)
|
|
22475
22626
|
}).validate({ subscriptionId, promoCode });
|
|
22476
22627
|
if (error) {
|
|
22477
22628
|
next(new BadRequestError37(error.message));
|
|
@@ -22489,9 +22640,9 @@ function useSubscriptionController() {
|
|
|
22489
22640
|
async function updateStatusById(req, res, next) {
|
|
22490
22641
|
const subscriptionId = req.params.id ?? "";
|
|
22491
22642
|
const status = req.body.status;
|
|
22492
|
-
const { error } =
|
|
22493
|
-
subscriptionId:
|
|
22494
|
-
status:
|
|
22643
|
+
const { error } = Joi20.object({
|
|
22644
|
+
subscriptionId: Joi20.string().required(),
|
|
22645
|
+
status: Joi20.string().optional().allow("", null)
|
|
22495
22646
|
}).validate({ subscriptionId, status });
|
|
22496
22647
|
if (error) {
|
|
22497
22648
|
next(new BadRequestError37(error.message));
|
|
@@ -22506,6 +22657,90 @@ function useSubscriptionController() {
|
|
|
22506
22657
|
return;
|
|
22507
22658
|
}
|
|
22508
22659
|
}
|
|
22660
|
+
async function addBillingContactById(req, res, next) {
|
|
22661
|
+
const subscriptionId = req.params.id ?? "";
|
|
22662
|
+
const email = req.body.email;
|
|
22663
|
+
const { error } = Joi20.object({
|
|
22664
|
+
subscriptionId: Joi20.string().required(),
|
|
22665
|
+
email: Joi20.string().email().required()
|
|
22666
|
+
}).validate({ subscriptionId, email });
|
|
22667
|
+
if (error) {
|
|
22668
|
+
next(new BadRequestError37(error.message));
|
|
22669
|
+
return;
|
|
22670
|
+
}
|
|
22671
|
+
try {
|
|
22672
|
+
await _addBillingContactById(subscriptionId, email);
|
|
22673
|
+
res.json({ message: "Successfully added billing contact." });
|
|
22674
|
+
return;
|
|
22675
|
+
} catch (error2) {
|
|
22676
|
+
next(error2);
|
|
22677
|
+
return;
|
|
22678
|
+
}
|
|
22679
|
+
}
|
|
22680
|
+
async function updateBillingContactByAddedAt(req, res, next) {
|
|
22681
|
+
const id = req.params.id ?? "";
|
|
22682
|
+
const addedAt = req.params.addedAt ?? "";
|
|
22683
|
+
const email = req.body.email;
|
|
22684
|
+
const { error } = Joi20.object({
|
|
22685
|
+
id: Joi20.string().hex().required(),
|
|
22686
|
+
addedAt: Joi20.string().isoDate().required(),
|
|
22687
|
+
email: Joi20.string().email().required()
|
|
22688
|
+
}).validate({ id, addedAt, email });
|
|
22689
|
+
if (error) {
|
|
22690
|
+
next(new BadRequestError37(error.message));
|
|
22691
|
+
return;
|
|
22692
|
+
}
|
|
22693
|
+
try {
|
|
22694
|
+
await _updateBillingContactByAddedAt(id, addedAt, email);
|
|
22695
|
+
res.json({ message: "Successfully updated billing contact." });
|
|
22696
|
+
return;
|
|
22697
|
+
} catch (error2) {
|
|
22698
|
+
next(error2);
|
|
22699
|
+
return;
|
|
22700
|
+
}
|
|
22701
|
+
}
|
|
22702
|
+
async function deleteBillingContactByAddedAt(req, res, next) {
|
|
22703
|
+
const id = req.params.id ?? "";
|
|
22704
|
+
const addedAt = req.params.addedAt ?? "";
|
|
22705
|
+
const { error } = Joi20.object({
|
|
22706
|
+
id: Joi20.string().hex().required(),
|
|
22707
|
+
addedAt: Joi20.string().isoDate().required()
|
|
22708
|
+
}).validate({ id, addedAt });
|
|
22709
|
+
if (error) {
|
|
22710
|
+
next(new BadRequestError37(error.message));
|
|
22711
|
+
return;
|
|
22712
|
+
}
|
|
22713
|
+
try {
|
|
22714
|
+
await _deleteBillingContactByAddedAt(id, addedAt);
|
|
22715
|
+
res.json({ message: "Successfully deleted billing contact." });
|
|
22716
|
+
return;
|
|
22717
|
+
} catch (error2) {
|
|
22718
|
+
next(error2);
|
|
22719
|
+
return;
|
|
22720
|
+
}
|
|
22721
|
+
}
|
|
22722
|
+
async function updatePaymentMethodById(req, res, next) {
|
|
22723
|
+
const subscriptionId = req.params.id ?? "";
|
|
22724
|
+
const paymentMethodId = req.body.paymentMethodId;
|
|
22725
|
+
const { error } = Joi20.object({
|
|
22726
|
+
subscriptionId: Joi20.string().required(),
|
|
22727
|
+
paymentMethodId: Joi20.string().optional().allow("", null)
|
|
22728
|
+
}).validate({ subscriptionId, paymentMethodId });
|
|
22729
|
+
if (error) {
|
|
22730
|
+
next(new BadRequestError37(error.message));
|
|
22731
|
+
return;
|
|
22732
|
+
}
|
|
22733
|
+
try {
|
|
22734
|
+
await _updatePaymentMethodById(subscriptionId, paymentMethodId);
|
|
22735
|
+
res.json({
|
|
22736
|
+
message: "Successfully updated subscription payment method."
|
|
22737
|
+
});
|
|
22738
|
+
return;
|
|
22739
|
+
} catch (error2) {
|
|
22740
|
+
next(error2);
|
|
22741
|
+
return;
|
|
22742
|
+
}
|
|
22743
|
+
}
|
|
22509
22744
|
return {
|
|
22510
22745
|
add,
|
|
22511
22746
|
getByUserId,
|
|
@@ -22518,7 +22753,11 @@ function useSubscriptionController() {
|
|
|
22518
22753
|
createOrgSubscription,
|
|
22519
22754
|
updateSubscriptionSeats,
|
|
22520
22755
|
updatePromoCodeById,
|
|
22521
|
-
updateStatusById
|
|
22756
|
+
updateStatusById,
|
|
22757
|
+
updatePaymentMethodById,
|
|
22758
|
+
addBillingContactById,
|
|
22759
|
+
updateBillingContactByAddedAt,
|
|
22760
|
+
deleteBillingContactByAddedAt
|
|
22522
22761
|
};
|
|
22523
22762
|
}
|
|
22524
22763
|
|
|
@@ -22837,7 +23076,7 @@ function usePaymentMethodService() {
|
|
|
22837
23076
|
}
|
|
22838
23077
|
|
|
22839
23078
|
// src/controllers/payment-method.controller.ts
|
|
22840
|
-
import
|
|
23079
|
+
import Joi21 from "joi";
|
|
22841
23080
|
import { BadRequestError as BadRequestError41 } from "@goweekdays/utils";
|
|
22842
23081
|
function usePaymentMethodController() {
|
|
22843
23082
|
const { linkEWallet: _linkEWallet, linkCard: _linkCard } = usePaymentMethodService();
|
|
@@ -22853,12 +23092,12 @@ function usePaymentMethodController() {
|
|
|
22853
23092
|
const success_return_url = req.body.success_return_url ?? "";
|
|
22854
23093
|
const failure_return_url = req.body.failure_return_url ?? "";
|
|
22855
23094
|
const cancel_return_url = req.body.cancel_return_url ?? "";
|
|
22856
|
-
const validation =
|
|
22857
|
-
customer_id:
|
|
22858
|
-
type:
|
|
22859
|
-
success_return_url:
|
|
22860
|
-
failure_return_url:
|
|
22861
|
-
cancel_return_url:
|
|
23095
|
+
const validation = Joi21.object({
|
|
23096
|
+
customer_id: Joi21.string().required(),
|
|
23097
|
+
type: Joi21.string().valid("GCASH", "PAYMAYA", "SHOPEEPAY", "GRABPAY").required(),
|
|
23098
|
+
success_return_url: Joi21.string().uri().required(),
|
|
23099
|
+
failure_return_url: Joi21.string().uri().required(),
|
|
23100
|
+
cancel_return_url: Joi21.string().uri().required()
|
|
22862
23101
|
});
|
|
22863
23102
|
const { error } = validation.validate({
|
|
22864
23103
|
customer_id,
|
|
@@ -22896,17 +23135,17 @@ function usePaymentMethodController() {
|
|
|
22896
23135
|
const failure_return_url = req.body.failure_return_url ?? "";
|
|
22897
23136
|
const cardType = req.body.cardType ?? "";
|
|
22898
23137
|
const user = req.headers["user"] ?? "";
|
|
22899
|
-
const validation =
|
|
22900
|
-
cardNumber:
|
|
22901
|
-
expiryMonth:
|
|
22902
|
-
expiryYear:
|
|
22903
|
-
cvv:
|
|
22904
|
-
cardholderName:
|
|
22905
|
-
currency:
|
|
22906
|
-
success_return_url:
|
|
22907
|
-
failure_return_url:
|
|
22908
|
-
cardType:
|
|
22909
|
-
user:
|
|
23138
|
+
const validation = Joi21.object({
|
|
23139
|
+
cardNumber: Joi21.string().required(),
|
|
23140
|
+
expiryMonth: Joi21.string().required(),
|
|
23141
|
+
expiryYear: Joi21.string().required(),
|
|
23142
|
+
cvv: Joi21.string().required(),
|
|
23143
|
+
cardholderName: Joi21.string().required(),
|
|
23144
|
+
currency: Joi21.string().optional().allow("", null),
|
|
23145
|
+
success_return_url: Joi21.string().uri().required(),
|
|
23146
|
+
failure_return_url: Joi21.string().uri().required(),
|
|
23147
|
+
cardType: Joi21.string().required(),
|
|
23148
|
+
user: Joi21.string().hex().required()
|
|
22910
23149
|
});
|
|
22911
23150
|
const { error } = validation.validate({
|
|
22912
23151
|
user,
|
|
@@ -22945,8 +23184,8 @@ function usePaymentMethodController() {
|
|
|
22945
23184
|
const { getByUser: _getByUser, getByOrg: _getByOrg } = usePaymentMethodRepo();
|
|
22946
23185
|
async function getByUser(req, res, next) {
|
|
22947
23186
|
const user = req.params.user ?? "";
|
|
22948
|
-
const validation =
|
|
22949
|
-
user:
|
|
23187
|
+
const validation = Joi21.object({
|
|
23188
|
+
user: Joi21.string().hex().required()
|
|
22950
23189
|
});
|
|
22951
23190
|
const { error } = validation.validate({ user });
|
|
22952
23191
|
if (error) {
|
|
@@ -22961,8 +23200,8 @@ function usePaymentMethodController() {
|
|
|
22961
23200
|
}
|
|
22962
23201
|
async function getByOrg(req, res, next) {
|
|
22963
23202
|
const org = req.params.org ?? "";
|
|
22964
|
-
const validation =
|
|
22965
|
-
org:
|
|
23203
|
+
const validation = Joi21.object({
|
|
23204
|
+
org: Joi21.string().hex().required()
|
|
22966
23205
|
});
|
|
22967
23206
|
const { error } = validation.validate({ org });
|
|
22968
23207
|
if (error) {
|
|
@@ -22977,8 +23216,8 @@ function usePaymentMethodController() {
|
|
|
22977
23216
|
}
|
|
22978
23217
|
async function getPaymentMethodById(req, res, next) {
|
|
22979
23218
|
const id = req.params.id ?? "";
|
|
22980
|
-
const validation =
|
|
22981
|
-
id:
|
|
23219
|
+
const validation = Joi21.object({
|
|
23220
|
+
id: Joi21.string().required()
|
|
22982
23221
|
});
|
|
22983
23222
|
const { error } = validation.validate({ id });
|
|
22984
23223
|
if (error) {
|
|
@@ -23056,22 +23295,27 @@ function usePaymentMethodController() {
|
|
|
23056
23295
|
|
|
23057
23296
|
// src/controllers/address.controller.ts
|
|
23058
23297
|
import { BadRequestError as BadRequestError42, NotFoundError as NotFoundError4 } from "@goweekdays/utils";
|
|
23059
|
-
import
|
|
23298
|
+
import Joi22 from "joi";
|
|
23060
23299
|
function useAddressController() {
|
|
23061
|
-
const {
|
|
23300
|
+
const {
|
|
23301
|
+
add: _add,
|
|
23302
|
+
getByUserId: _getByUserId,
|
|
23303
|
+
getByOrgId: _getByOrgId,
|
|
23304
|
+
updateById: _updateById
|
|
23305
|
+
} = useAddressRepo();
|
|
23062
23306
|
async function add(req, res, next) {
|
|
23063
23307
|
const value = req.body;
|
|
23064
|
-
const validation =
|
|
23065
|
-
type:
|
|
23066
|
-
user:
|
|
23067
|
-
org:
|
|
23068
|
-
country:
|
|
23069
|
-
address:
|
|
23070
|
-
continuedAddress:
|
|
23071
|
-
city:
|
|
23072
|
-
province:
|
|
23073
|
-
postalCode:
|
|
23074
|
-
taxId:
|
|
23308
|
+
const validation = Joi22.object({
|
|
23309
|
+
type: Joi22.string().required(),
|
|
23310
|
+
user: Joi22.string().hex().optional().allow("", null),
|
|
23311
|
+
org: Joi22.string().hex().optional().allow("", null),
|
|
23312
|
+
country: Joi22.string().required(),
|
|
23313
|
+
address: Joi22.string().required(),
|
|
23314
|
+
continuedAddress: Joi22.string().optional().allow("", null),
|
|
23315
|
+
city: Joi22.string().required(),
|
|
23316
|
+
province: Joi22.string().required(),
|
|
23317
|
+
postalCode: Joi22.string().required(),
|
|
23318
|
+
taxId: Joi22.string().optional().allow("", null)
|
|
23075
23319
|
});
|
|
23076
23320
|
const { error } = validation.validate(value);
|
|
23077
23321
|
if (error) {
|
|
@@ -23086,9 +23330,35 @@ function useAddressController() {
|
|
|
23086
23330
|
next(error2);
|
|
23087
23331
|
}
|
|
23088
23332
|
}
|
|
23333
|
+
async function updateById(req, res, next) {
|
|
23334
|
+
const id = req.params.id ?? "";
|
|
23335
|
+
const value = req.body;
|
|
23336
|
+
const validation = Joi22.object({
|
|
23337
|
+
id: Joi22.string().hex().required(),
|
|
23338
|
+
country: Joi22.string().required(),
|
|
23339
|
+
address: Joi22.string().required(),
|
|
23340
|
+
continuedAddress: Joi22.string().optional().allow("", null),
|
|
23341
|
+
city: Joi22.string().required(),
|
|
23342
|
+
province: Joi22.string().required(),
|
|
23343
|
+
postalCode: Joi22.string().required(),
|
|
23344
|
+
taxId: Joi22.string().optional().allow("", null)
|
|
23345
|
+
});
|
|
23346
|
+
const { error } = validation.validate({ id, ...value });
|
|
23347
|
+
if (error) {
|
|
23348
|
+
next(new BadRequestError42(error.message));
|
|
23349
|
+
return;
|
|
23350
|
+
}
|
|
23351
|
+
try {
|
|
23352
|
+
const message = await _updateById(id, value);
|
|
23353
|
+
res.json({ message });
|
|
23354
|
+
return;
|
|
23355
|
+
} catch (error2) {
|
|
23356
|
+
next(error2);
|
|
23357
|
+
}
|
|
23358
|
+
}
|
|
23089
23359
|
async function getByUserId(req, res, next) {
|
|
23090
23360
|
const user = req.params.user;
|
|
23091
|
-
const validation =
|
|
23361
|
+
const validation = Joi22.string().hex().required();
|
|
23092
23362
|
const { error } = validation.validate(user);
|
|
23093
23363
|
if (error) {
|
|
23094
23364
|
next(new BadRequestError42(error.message));
|
|
@@ -23105,9 +23375,30 @@ function useAddressController() {
|
|
|
23105
23375
|
next(error2);
|
|
23106
23376
|
}
|
|
23107
23377
|
}
|
|
23378
|
+
async function getByOrgId(req, res, next) {
|
|
23379
|
+
const id = req.params.id;
|
|
23380
|
+
const validation = Joi22.string().hex().required();
|
|
23381
|
+
const { error } = validation.validate(id);
|
|
23382
|
+
if (error) {
|
|
23383
|
+
next(new BadRequestError42(error.message));
|
|
23384
|
+
}
|
|
23385
|
+
try {
|
|
23386
|
+
const address = await _getByOrgId(id);
|
|
23387
|
+
if (!address) {
|
|
23388
|
+
next(new NotFoundError4("Address not found."));
|
|
23389
|
+
return;
|
|
23390
|
+
}
|
|
23391
|
+
res.json(address);
|
|
23392
|
+
return;
|
|
23393
|
+
} catch (error2) {
|
|
23394
|
+
next(error2);
|
|
23395
|
+
}
|
|
23396
|
+
}
|
|
23108
23397
|
return {
|
|
23109
23398
|
add,
|
|
23110
|
-
getByUserId
|
|
23399
|
+
getByUserId,
|
|
23400
|
+
getByOrgId,
|
|
23401
|
+
updateById
|
|
23111
23402
|
};
|
|
23112
23403
|
}
|
|
23113
23404
|
|
|
@@ -23169,20 +23460,20 @@ function useOrgService() {
|
|
|
23169
23460
|
|
|
23170
23461
|
// src/controllers/organization.controller.ts
|
|
23171
23462
|
import { BadRequestError as BadRequestError43 } from "@goweekdays/utils";
|
|
23172
|
-
import
|
|
23463
|
+
import Joi23 from "joi";
|
|
23173
23464
|
function useOrgController() {
|
|
23174
23465
|
const { createOrg: _createOrg } = useOrgService();
|
|
23175
23466
|
const { getOrgsByMembership } = useMemberRepo();
|
|
23176
23467
|
const { getByName: _getByName } = useOrgRepo();
|
|
23177
23468
|
async function createOrg(req, res, next) {
|
|
23178
23469
|
const value = req.body;
|
|
23179
|
-
const validation =
|
|
23180
|
-
name:
|
|
23181
|
-
type:
|
|
23182
|
-
email:
|
|
23183
|
-
contact:
|
|
23184
|
-
description:
|
|
23185
|
-
user:
|
|
23470
|
+
const validation = Joi23.object({
|
|
23471
|
+
name: Joi23.string().required(),
|
|
23472
|
+
type: Joi23.string().required(),
|
|
23473
|
+
email: Joi23.string().email().required(),
|
|
23474
|
+
contact: Joi23.string().required(),
|
|
23475
|
+
description: Joi23.string().required(),
|
|
23476
|
+
user: Joi23.string().hex().required()
|
|
23186
23477
|
});
|
|
23187
23478
|
const { error } = validation.validate(value);
|
|
23188
23479
|
if (error) {
|
|
@@ -23212,11 +23503,11 @@ function useOrgController() {
|
|
|
23212
23503
|
next(new BadRequestError43("Invalid limit number."));
|
|
23213
23504
|
return;
|
|
23214
23505
|
}
|
|
23215
|
-
const validation =
|
|
23216
|
-
user:
|
|
23217
|
-
page:
|
|
23218
|
-
limit:
|
|
23219
|
-
search:
|
|
23506
|
+
const validation = Joi23.object({
|
|
23507
|
+
user: Joi23.string().hex().required(),
|
|
23508
|
+
page: Joi23.number().min(1).optional().allow("", null),
|
|
23509
|
+
limit: Joi23.number().min(1).optional().allow("", null),
|
|
23510
|
+
search: Joi23.string().optional().allow("", null)
|
|
23220
23511
|
});
|
|
23221
23512
|
const { error } = validation.validate({ user, page, limit, search });
|
|
23222
23513
|
if (error) {
|
|
@@ -23233,8 +23524,8 @@ function useOrgController() {
|
|
|
23233
23524
|
}
|
|
23234
23525
|
async function getByName(req, res, next) {
|
|
23235
23526
|
const name = req.params.name;
|
|
23236
|
-
const validation =
|
|
23237
|
-
name:
|
|
23527
|
+
const validation = Joi23.object({
|
|
23528
|
+
name: Joi23.string().required()
|
|
23238
23529
|
});
|
|
23239
23530
|
const { error } = validation.validate({ name });
|
|
23240
23531
|
if (error) {
|
|
@@ -23257,7 +23548,7 @@ function useOrgController() {
|
|
|
23257
23548
|
}
|
|
23258
23549
|
|
|
23259
23550
|
// src/controllers/member.controller.ts
|
|
23260
|
-
import
|
|
23551
|
+
import Joi24 from "joi";
|
|
23261
23552
|
import { BadRequestError as BadRequestError44 } from "@goweekdays/utils";
|
|
23262
23553
|
function useMemberController() {
|
|
23263
23554
|
const {
|
|
@@ -23267,8 +23558,8 @@ function useMemberController() {
|
|
|
23267
23558
|
} = useMemberRepo();
|
|
23268
23559
|
async function getByUserId(req, res, next) {
|
|
23269
23560
|
const userId = req.params.id;
|
|
23270
|
-
const validation =
|
|
23271
|
-
id:
|
|
23561
|
+
const validation = Joi24.object({
|
|
23562
|
+
id: Joi24.string().hex().required()
|
|
23272
23563
|
});
|
|
23273
23564
|
const { error } = validation.validate({ id: userId });
|
|
23274
23565
|
if (error) {
|
|
@@ -23294,14 +23585,14 @@ function useMemberController() {
|
|
|
23294
23585
|
const org = req.query.org ?? "";
|
|
23295
23586
|
const type = req.query.type ?? "main";
|
|
23296
23587
|
const status = req.query.status ?? "active";
|
|
23297
|
-
const validation =
|
|
23298
|
-
limit:
|
|
23299
|
-
search:
|
|
23300
|
-
page:
|
|
23301
|
-
user:
|
|
23302
|
-
org:
|
|
23303
|
-
type:
|
|
23304
|
-
status:
|
|
23588
|
+
const validation = Joi24.object({
|
|
23589
|
+
limit: Joi24.number().min(10).max(50).required(),
|
|
23590
|
+
search: Joi24.string().optional().allow("", null),
|
|
23591
|
+
page: Joi24.number().required(),
|
|
23592
|
+
user: Joi24.string().hex().optional().allow("", null),
|
|
23593
|
+
org: Joi24.string().hex().optional().allow("", null),
|
|
23594
|
+
type: Joi24.string().required(),
|
|
23595
|
+
status: Joi24.string().required()
|
|
23305
23596
|
});
|
|
23306
23597
|
const { error } = validation.validate({
|
|
23307
23598
|
search,
|
|
@@ -23314,6 +23605,7 @@ function useMemberController() {
|
|
|
23314
23605
|
});
|
|
23315
23606
|
if (error) {
|
|
23316
23607
|
next(new BadRequestError44(error.message));
|
|
23608
|
+
return;
|
|
23317
23609
|
}
|
|
23318
23610
|
try {
|
|
23319
23611
|
const items = await _getAll({
|
|
@@ -23336,11 +23628,11 @@ function useMemberController() {
|
|
|
23336
23628
|
const search = req.query.search ?? "";
|
|
23337
23629
|
const page = Number(req.query.page) ?? 1;
|
|
23338
23630
|
const user = req.query.user ?? "";
|
|
23339
|
-
const validation =
|
|
23340
|
-
limit:
|
|
23341
|
-
search:
|
|
23342
|
-
page:
|
|
23343
|
-
user:
|
|
23631
|
+
const validation = Joi24.object({
|
|
23632
|
+
limit: Joi24.number().min(10).max(50).required(),
|
|
23633
|
+
search: Joi24.string().optional().allow("", null),
|
|
23634
|
+
page: Joi24.number().required(),
|
|
23635
|
+
user: Joi24.string().hex().optional().allow("", null)
|
|
23344
23636
|
});
|
|
23345
23637
|
const { error } = validation.validate({
|
|
23346
23638
|
search,
|
|
@@ -23378,7 +23670,7 @@ import {
|
|
|
23378
23670
|
InternalServerError as InternalServerError24,
|
|
23379
23671
|
NotFoundError as NotFoundError6
|
|
23380
23672
|
} from "@goweekdays/utils";
|
|
23381
|
-
import
|
|
23673
|
+
import Joi25 from "joi";
|
|
23382
23674
|
function usePromoCodeController() {
|
|
23383
23675
|
const {
|
|
23384
23676
|
add: _add,
|
|
@@ -23409,11 +23701,11 @@ function usePromoCodeController() {
|
|
|
23409
23701
|
const code = req.query.code;
|
|
23410
23702
|
const type = req.query.type;
|
|
23411
23703
|
const assigned = req.query.assigned === "true" ? true : req.query.assigned === "false" ? false : null;
|
|
23412
|
-
const validation =
|
|
23413
|
-
code:
|
|
23414
|
-
type:
|
|
23704
|
+
const validation = Joi25.object({
|
|
23705
|
+
code: Joi25.string().trim().required(),
|
|
23706
|
+
type: Joi25.string().optional(),
|
|
23415
23707
|
// true or false
|
|
23416
|
-
assigned:
|
|
23708
|
+
assigned: Joi25.boolean().optional().allow(null, "")
|
|
23417
23709
|
});
|
|
23418
23710
|
const { error } = validation.validate({ code, type, assigned });
|
|
23419
23711
|
if (error) {
|
|
@@ -23438,8 +23730,8 @@ function usePromoCodeController() {
|
|
|
23438
23730
|
}
|
|
23439
23731
|
async function getById(req, res, next) {
|
|
23440
23732
|
const id = req.params.id;
|
|
23441
|
-
const validation =
|
|
23442
|
-
id:
|
|
23733
|
+
const validation = Joi25.object({
|
|
23734
|
+
id: Joi25.string().hex().required()
|
|
23443
23735
|
});
|
|
23444
23736
|
const { error } = validation.validate({ id });
|
|
23445
23737
|
if (error) {
|
|
@@ -23467,11 +23759,11 @@ function usePromoCodeController() {
|
|
|
23467
23759
|
const limit = req.query.limit ? Number(req.query.limit) : 10;
|
|
23468
23760
|
const search = req.query.search;
|
|
23469
23761
|
const status = req.query.status;
|
|
23470
|
-
const validation =
|
|
23471
|
-
page:
|
|
23472
|
-
limit:
|
|
23473
|
-
search:
|
|
23474
|
-
status:
|
|
23762
|
+
const validation = Joi25.object({
|
|
23763
|
+
page: Joi25.number().required(),
|
|
23764
|
+
limit: Joi25.number().integer().optional().min(10).max(100),
|
|
23765
|
+
search: Joi25.string().optional().allow(""),
|
|
23766
|
+
status: Joi25.string().required()
|
|
23475
23767
|
});
|
|
23476
23768
|
const { error } = validation.validate({ page, limit, search, status });
|
|
23477
23769
|
if (error) {
|
|
@@ -23503,26 +23795,26 @@ function usePromoCodeController() {
|
|
|
23503
23795
|
import { ObjectId as ObjectId38 } from "mongodb";
|
|
23504
23796
|
|
|
23505
23797
|
// src/validations/order.schema.ts
|
|
23506
|
-
import
|
|
23507
|
-
var schema2 =
|
|
23508
|
-
_id:
|
|
23509
|
-
payment:
|
|
23510
|
-
user:
|
|
23511
|
-
org:
|
|
23512
|
-
type:
|
|
23513
|
-
amount:
|
|
23514
|
-
currency:
|
|
23515
|
-
description:
|
|
23516
|
-
metadata:
|
|
23517
|
-
subscriptionId:
|
|
23518
|
-
cycle:
|
|
23519
|
-
seats:
|
|
23520
|
-
promoCode:
|
|
23798
|
+
import Joi26 from "joi";
|
|
23799
|
+
var schema2 = Joi26.object({
|
|
23800
|
+
_id: Joi26.string().hex().optional().allow("", null),
|
|
23801
|
+
payment: Joi26.string().required(),
|
|
23802
|
+
user: Joi26.string().hex().optional().allow("", null),
|
|
23803
|
+
org: Joi26.string().hex().optional().allow("", null),
|
|
23804
|
+
type: Joi26.string().required(),
|
|
23805
|
+
amount: Joi26.number().positive().min(0).required(),
|
|
23806
|
+
currency: Joi26.string().required(),
|
|
23807
|
+
description: Joi26.string().optional().allow("", null),
|
|
23808
|
+
metadata: Joi26.object({
|
|
23809
|
+
subscriptionId: Joi26.string().hex().optional().allow("", null),
|
|
23810
|
+
cycle: Joi26.number().optional().allow("", null),
|
|
23811
|
+
seats: Joi26.number().optional().allow("", null),
|
|
23812
|
+
promoCode: Joi26.string().optional().allow("", null)
|
|
23521
23813
|
}).optional().allow("", null),
|
|
23522
|
-
status:
|
|
23523
|
-
createdAt:
|
|
23524
|
-
updatedAt:
|
|
23525
|
-
deletedAt:
|
|
23814
|
+
status: Joi26.string().optional().allow("", null),
|
|
23815
|
+
createdAt: Joi26.string().optional().allow("", null),
|
|
23816
|
+
updatedAt: Joi26.string().optional().allow("", null),
|
|
23817
|
+
deletedAt: Joi26.string().optional().allow("", null)
|
|
23526
23818
|
});
|
|
23527
23819
|
|
|
23528
23820
|
// src/models/order.model.ts
|
|
@@ -23666,7 +23958,7 @@ function useOrderRepo() {
|
|
|
23666
23958
|
|
|
23667
23959
|
// src/controllers/order.controller.ts
|
|
23668
23960
|
import { BadRequestError as BadRequestError48 } from "@goweekdays/utils";
|
|
23669
|
-
import
|
|
23961
|
+
import Joi27 from "joi";
|
|
23670
23962
|
function useOrderController() {
|
|
23671
23963
|
const { getOrders: _getOrders } = useOrderRepo();
|
|
23672
23964
|
async function getOrders(req, res, next) {
|
|
@@ -23675,12 +23967,12 @@ function useOrderController() {
|
|
|
23675
23967
|
const search = req.query.search ?? "";
|
|
23676
23968
|
const status = req.query.status ?? "succeeded";
|
|
23677
23969
|
const id = req.query.id ?? "";
|
|
23678
|
-
const validation =
|
|
23679
|
-
page:
|
|
23680
|
-
limit:
|
|
23681
|
-
search:
|
|
23682
|
-
status:
|
|
23683
|
-
id:
|
|
23970
|
+
const validation = Joi27.object({
|
|
23971
|
+
page: Joi27.number().required(),
|
|
23972
|
+
limit: Joi27.number().required().min(10),
|
|
23973
|
+
search: Joi27.string().optional().allow("", null),
|
|
23974
|
+
status: Joi27.string().optional().allow("", null),
|
|
23975
|
+
id: Joi27.string().hex().optional().allow("", null)
|
|
23684
23976
|
});
|
|
23685
23977
|
const { error } = validation.validate({ page, limit, search, status, id });
|
|
23686
23978
|
if (error) {
|
|
@@ -23889,7 +24181,7 @@ function useInvoiceService() {
|
|
|
23889
24181
|
|
|
23890
24182
|
// src/controllers/invoice.controller.ts
|
|
23891
24183
|
import { BadRequestError as BadRequestError50, NotFoundError as NotFoundError7 } from "@goweekdays/utils";
|
|
23892
|
-
import
|
|
24184
|
+
import Joi28 from "joi";
|
|
23893
24185
|
function useInvoiceController() {
|
|
23894
24186
|
const {
|
|
23895
24187
|
getBySubscriptionId: _getBySubscriptionId,
|
|
@@ -23901,11 +24193,11 @@ function useInvoiceController() {
|
|
|
23901
24193
|
const page = req.query.page ? Number(req.query.page) : 1;
|
|
23902
24194
|
const limit = req.query.limit ? Number(req.query.limit) : 10;
|
|
23903
24195
|
const search = req.query.search ?? "";
|
|
23904
|
-
const validation =
|
|
23905
|
-
id:
|
|
23906
|
-
page:
|
|
23907
|
-
limit:
|
|
23908
|
-
search:
|
|
24196
|
+
const validation = Joi28.object({
|
|
24197
|
+
id: Joi28.string().required(),
|
|
24198
|
+
page: Joi28.number().integer().min(1).default(1),
|
|
24199
|
+
limit: Joi28.number().integer().min(1).default(10),
|
|
24200
|
+
search: Joi28.string().optional().allow("", null)
|
|
23909
24201
|
});
|
|
23910
24202
|
const { error } = validation.validate({
|
|
23911
24203
|
id,
|
|
@@ -23932,7 +24224,7 @@ function useInvoiceController() {
|
|
|
23932
24224
|
}
|
|
23933
24225
|
async function getByNumber(req, res, next) {
|
|
23934
24226
|
const number = req.params.number;
|
|
23935
|
-
const validation =
|
|
24227
|
+
const validation = Joi28.string().required();
|
|
23936
24228
|
const { error } = validation.validate(number);
|
|
23937
24229
|
if (error) {
|
|
23938
24230
|
next(new BadRequestError50(error.message));
|
|
@@ -23952,9 +24244,9 @@ function useInvoiceController() {
|
|
|
23952
24244
|
async function getByDueDateStatus(req, res, next) {
|
|
23953
24245
|
const date = req.params.date;
|
|
23954
24246
|
const status = req.params.status;
|
|
23955
|
-
const validation =
|
|
23956
|
-
date:
|
|
23957
|
-
status:
|
|
24247
|
+
const validation = Joi28.object({
|
|
24248
|
+
date: Joi28.string().required(),
|
|
24249
|
+
status: Joi28.string().required()
|
|
23958
24250
|
});
|
|
23959
24251
|
const { error } = validation.validate({ date, status });
|
|
23960
24252
|
if (error) {
|
|
@@ -23981,7 +24273,7 @@ function useInvoiceController() {
|
|
|
23981
24273
|
|
|
23982
24274
|
// src/controllers/payment.controller.ts
|
|
23983
24275
|
import { BadRequestError as BadRequestError51 } from "@goweekdays/utils";
|
|
23984
|
-
import
|
|
24276
|
+
import Joi29 from "joi";
|
|
23985
24277
|
function usePaymentController() {
|
|
23986
24278
|
const { getPayments: _getPayments } = usePaymentRepo();
|
|
23987
24279
|
async function getPayments(req, res, next) {
|
|
@@ -23990,12 +24282,12 @@ function usePaymentController() {
|
|
|
23990
24282
|
const search = req.query.search ?? "";
|
|
23991
24283
|
const status = req.query.status ?? "succeeded";
|
|
23992
24284
|
const id = req.query.id ?? "";
|
|
23993
|
-
const validation =
|
|
23994
|
-
page:
|
|
23995
|
-
limit:
|
|
23996
|
-
search:
|
|
23997
|
-
status:
|
|
23998
|
-
id:
|
|
24285
|
+
const validation = Joi29.object({
|
|
24286
|
+
page: Joi29.number().required(),
|
|
24287
|
+
limit: Joi29.number().required().min(10),
|
|
24288
|
+
search: Joi29.string().optional().allow("", null),
|
|
24289
|
+
status: Joi29.string().optional().allow("", null),
|
|
24290
|
+
id: Joi29.string().hex().optional().allow("", null)
|
|
23999
24291
|
});
|
|
24000
24292
|
const { error } = validation.validate({ page, limit, search, status, id });
|
|
24001
24293
|
if (error) {
|
|
@@ -24101,6 +24393,7 @@ export {
|
|
|
24101
24393
|
VERIFICATION_USER_INVITE_DURATION,
|
|
24102
24394
|
XENDIT_BASE_URL,
|
|
24103
24395
|
XENDIT_SECRET_KEY,
|
|
24396
|
+
addressSchema,
|
|
24104
24397
|
isDev,
|
|
24105
24398
|
schema,
|
|
24106
24399
|
useAddressController,
|