@goweekdays/core 2.11.2 → 2.11.3
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 +1 -0
- package/dist/index.js +102 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -94
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5403,6 +5403,7 @@ var schema2 = {
|
|
|
5403
5403
|
var schemaSubscription = Joi20.object({
|
|
5404
5404
|
...schema2,
|
|
5405
5405
|
org: Joi20.string().hex().length(24).required(),
|
|
5406
|
+
orgName: Joi20.string().optional().allow("", null),
|
|
5406
5407
|
currency: Joi20.string().length(3).required(),
|
|
5407
5408
|
billingCycle: Joi20.string().valid("monthly", "yearly").required()
|
|
5408
5409
|
});
|
|
@@ -5441,6 +5442,7 @@ function modelSubscription(data) {
|
|
|
5441
5442
|
return {
|
|
5442
5443
|
_id: data._id,
|
|
5443
5444
|
org: data.org,
|
|
5445
|
+
orgName: data.orgName ?? "",
|
|
5444
5446
|
seats: data.seats,
|
|
5445
5447
|
paidSeats: data.paidSeats,
|
|
5446
5448
|
amount: data.amount,
|
|
@@ -8306,7 +8308,6 @@ function usePromoController() {
|
|
|
8306
8308
|
// src/resources/subscription/subscription.service.ts
|
|
8307
8309
|
function useSubscriptionService() {
|
|
8308
8310
|
const {
|
|
8309
|
-
getById,
|
|
8310
8311
|
updateById,
|
|
8311
8312
|
getByStatus,
|
|
8312
8313
|
updateStatusById,
|
|
@@ -8458,34 +8459,38 @@ function useSubscriptionService() {
|
|
|
8458
8459
|
if (error) {
|
|
8459
8460
|
throw new BadRequestError41(`Invalid subscription data: ${error.message}`);
|
|
8460
8461
|
}
|
|
8461
|
-
const existingSubscription = await getByOrg(value.org);
|
|
8462
|
-
if (existingSubscription) {
|
|
8463
|
-
throw new BadRequestError41("Organization already has a subscription.");
|
|
8464
|
-
}
|
|
8465
|
-
const plan = await getPlanById(value.plan);
|
|
8466
|
-
if (!plan) {
|
|
8467
|
-
throw new BadRequestError41("Plan not found.");
|
|
8468
|
-
}
|
|
8469
|
-
const userData = await getUserById(value.user);
|
|
8470
|
-
if (!userData) {
|
|
8471
|
-
throw new BadRequestError41("User not found.");
|
|
8472
|
-
}
|
|
8473
|
-
const membership = await getMembershipByApp({
|
|
8474
|
-
user: value.user,
|
|
8475
|
-
org: value.org,
|
|
8476
|
-
app: "org"
|
|
8477
|
-
});
|
|
8478
|
-
if (!membership) {
|
|
8479
|
-
throw new BadRequestError41("User is not a member of the organization.");
|
|
8480
|
-
}
|
|
8481
|
-
const nextBillingDate = /* @__PURE__ */ new Date();
|
|
8482
|
-
nextBillingDate.setMonth(nextBillingDate.getMonth() + 1);
|
|
8483
8462
|
const session = useAtlas18.getClient()?.startSession();
|
|
8484
8463
|
if (!session) {
|
|
8485
8464
|
throw new InternalServerError22("Unable to start database session.");
|
|
8486
8465
|
}
|
|
8487
8466
|
try {
|
|
8488
8467
|
session.startTransaction();
|
|
8468
|
+
const org = await getOrgById(value.org);
|
|
8469
|
+
if (!org) {
|
|
8470
|
+
throw new BadRequestError41("Organization not found.");
|
|
8471
|
+
}
|
|
8472
|
+
const existingSubscription = await getByOrg(value.org);
|
|
8473
|
+
if (existingSubscription) {
|
|
8474
|
+
throw new BadRequestError41("Organization already has a subscription.");
|
|
8475
|
+
}
|
|
8476
|
+
const plan = await getPlanById(value.plan);
|
|
8477
|
+
if (!plan) {
|
|
8478
|
+
throw new BadRequestError41("Plan not found.");
|
|
8479
|
+
}
|
|
8480
|
+
const userData = await getUserById(value.user);
|
|
8481
|
+
if (!userData) {
|
|
8482
|
+
throw new BadRequestError41("User not found.");
|
|
8483
|
+
}
|
|
8484
|
+
const membership = await getMembershipByApp({
|
|
8485
|
+
user: value.user,
|
|
8486
|
+
org: value.org,
|
|
8487
|
+
app: "org"
|
|
8488
|
+
});
|
|
8489
|
+
if (!membership) {
|
|
8490
|
+
throw new BadRequestError41("User is not a member of the organization.");
|
|
8491
|
+
}
|
|
8492
|
+
const nextBillingDate = /* @__PURE__ */ new Date();
|
|
8493
|
+
nextBillingDate.setMonth(nextBillingDate.getMonth() + 1);
|
|
8489
8494
|
const { subscriptionAmount, currency } = await computeFee({
|
|
8490
8495
|
seats: value.seats,
|
|
8491
8496
|
promoCode: value.promoCode,
|
|
@@ -8495,6 +8500,7 @@ function useSubscriptionService() {
|
|
|
8495
8500
|
const subId = await _add(
|
|
8496
8501
|
{
|
|
8497
8502
|
org: value.org,
|
|
8503
|
+
orgName: org.name,
|
|
8498
8504
|
seats: value.seats,
|
|
8499
8505
|
paidSeats: value.seats,
|
|
8500
8506
|
// Initial seats are considered "paid" for proration purposes
|
|
@@ -8539,42 +8545,44 @@ function useSubscriptionService() {
|
|
|
8539
8545
|
if (error) {
|
|
8540
8546
|
throw new BadRequestError41(error.message);
|
|
8541
8547
|
}
|
|
8542
|
-
const subscription = await getByOrg(value.org);
|
|
8543
|
-
if (!subscription) {
|
|
8544
|
-
throw new BadRequestError41("Subscription not found");
|
|
8545
|
-
}
|
|
8546
|
-
if (subscription.seats === value.seats) {
|
|
8547
|
-
throw new BadRequestError41(
|
|
8548
|
-
"Failed to update subscription, no changes detected."
|
|
8549
|
-
);
|
|
8550
|
-
}
|
|
8551
|
-
const userData = await getUserById(value.user);
|
|
8552
|
-
if (!userData) {
|
|
8553
|
-
throw new BadRequestError41("User not found.");
|
|
8554
|
-
}
|
|
8555
|
-
const membership = await getMembershipByApp({
|
|
8556
|
-
user: value.user,
|
|
8557
|
-
org: value.org,
|
|
8558
|
-
app: "org"
|
|
8559
|
-
});
|
|
8560
|
-
if (!membership) {
|
|
8561
|
-
throw new BadRequestError41("User is not a member of the organization.");
|
|
8562
|
-
}
|
|
8563
|
-
const { subscriptionAmount, proratedAmount, currency } = await computeFee({
|
|
8564
|
-
seats: value.seats,
|
|
8565
|
-
promoCode: value.promoCode ?? "",
|
|
8566
|
-
plan: value.plan ?? "",
|
|
8567
|
-
org: value.org
|
|
8568
|
-
});
|
|
8569
8548
|
const session = useAtlas18.getClient()?.startSession();
|
|
8570
8549
|
if (!session) {
|
|
8571
8550
|
throw new InternalServerError22("Unable to start database session.");
|
|
8572
8551
|
}
|
|
8573
|
-
const seatIncreased = value.seats > subscription.paidSeats;
|
|
8574
|
-
const additionalSeats = value.seats - subscription.paidSeats;
|
|
8575
|
-
const paidSeats = seatIncreased ? value.seats : subscription.paidSeats;
|
|
8576
8552
|
try {
|
|
8577
8553
|
session.startTransaction();
|
|
8554
|
+
const subscription = await getByOrg(value.org);
|
|
8555
|
+
if (!subscription) {
|
|
8556
|
+
throw new BadRequestError41("Subscription not found");
|
|
8557
|
+
}
|
|
8558
|
+
if (subscription.seats === value.seats) {
|
|
8559
|
+
throw new BadRequestError41(
|
|
8560
|
+
"Failed to update subscription, no changes detected."
|
|
8561
|
+
);
|
|
8562
|
+
}
|
|
8563
|
+
const userData = await getUserById(value.user);
|
|
8564
|
+
if (!userData) {
|
|
8565
|
+
throw new BadRequestError41("User not found.");
|
|
8566
|
+
}
|
|
8567
|
+
const membership = await getMembershipByApp({
|
|
8568
|
+
user: value.user,
|
|
8569
|
+
org: value.org,
|
|
8570
|
+
app: "org"
|
|
8571
|
+
});
|
|
8572
|
+
if (!membership) {
|
|
8573
|
+
throw new BadRequestError41("User is not a member of the organization.");
|
|
8574
|
+
}
|
|
8575
|
+
const { subscriptionAmount, proratedAmount, currency } = await computeFee(
|
|
8576
|
+
{
|
|
8577
|
+
seats: value.seats,
|
|
8578
|
+
promoCode: value.promoCode ?? "",
|
|
8579
|
+
plan: value.plan ?? "",
|
|
8580
|
+
org: value.org
|
|
8581
|
+
}
|
|
8582
|
+
);
|
|
8583
|
+
const seatIncreased = value.seats > subscription.paidSeats;
|
|
8584
|
+
const additionalSeats = value.seats - subscription.paidSeats;
|
|
8585
|
+
const paidSeats = seatIncreased ? value.seats : subscription.paidSeats;
|
|
8578
8586
|
await updateById(
|
|
8579
8587
|
subscription._id?.toString() ?? "",
|
|
8580
8588
|
{ seats: value.seats, amount: subscriptionAmount, paidSeats },
|
|
@@ -8608,53 +8616,53 @@ function useSubscriptionService() {
|
|
|
8608
8616
|
if (error) {
|
|
8609
8617
|
throw new BadRequestError41(error.message);
|
|
8610
8618
|
}
|
|
8611
|
-
const subscription = await getByOrg(value.org);
|
|
8612
|
-
if (!subscription) {
|
|
8613
|
-
throw new BadRequestError41("Subscription not found");
|
|
8614
|
-
}
|
|
8615
|
-
if (subscription.promoCode === value.promoCode) {
|
|
8616
|
-
throw new BadRequestError41(
|
|
8617
|
-
"Failed to update subscription, no changes detected."
|
|
8618
|
-
);
|
|
8619
|
-
}
|
|
8620
|
-
let promo = null;
|
|
8621
|
-
if (value.promoCode) {
|
|
8622
|
-
promo = await getPromoByCode(value.promoCode);
|
|
8623
|
-
if (!promo) {
|
|
8624
|
-
throw new BadRequestError41("Promo code not found.");
|
|
8625
|
-
}
|
|
8626
|
-
}
|
|
8627
|
-
const userData = await getUserById(value.user);
|
|
8628
|
-
if (!userData) {
|
|
8629
|
-
throw new BadRequestError41("User not found.");
|
|
8630
|
-
}
|
|
8631
|
-
const membership = await getMembershipByApp({
|
|
8632
|
-
user: value.user,
|
|
8633
|
-
org: value.org,
|
|
8634
|
-
app: "org"
|
|
8635
|
-
});
|
|
8636
|
-
if (!membership) {
|
|
8637
|
-
throw new BadRequestError41("User is not a member of the organization.");
|
|
8638
|
-
}
|
|
8639
|
-
const plan = await getDefaultPlan();
|
|
8640
|
-
if (!plan) {
|
|
8641
|
-
throw new BadRequestError41("Plan not found.");
|
|
8642
|
-
}
|
|
8643
|
-
const { subscriptionAmount, currency } = await computeFee(
|
|
8644
|
-
{
|
|
8645
|
-
seats: subscription.seats,
|
|
8646
|
-
promoCode: value.promoCode ?? "",
|
|
8647
|
-
plan: plan._id?.toString() ?? "",
|
|
8648
|
-
org: value.org
|
|
8649
|
-
},
|
|
8650
|
-
true
|
|
8651
|
-
);
|
|
8652
8619
|
const session = useAtlas18.getClient()?.startSession();
|
|
8653
8620
|
if (!session) {
|
|
8654
8621
|
throw new InternalServerError22("Unable to start database session.");
|
|
8655
8622
|
}
|
|
8656
8623
|
try {
|
|
8657
8624
|
session.startTransaction();
|
|
8625
|
+
const subscription = await getByOrg(value.org);
|
|
8626
|
+
if (!subscription) {
|
|
8627
|
+
throw new BadRequestError41("Subscription not found");
|
|
8628
|
+
}
|
|
8629
|
+
if (subscription.promoCode === value.promoCode) {
|
|
8630
|
+
throw new BadRequestError41(
|
|
8631
|
+
"Failed to update subscription, no changes detected."
|
|
8632
|
+
);
|
|
8633
|
+
}
|
|
8634
|
+
let promo = null;
|
|
8635
|
+
if (value.promoCode) {
|
|
8636
|
+
promo = await getPromoByCode(value.promoCode);
|
|
8637
|
+
if (!promo) {
|
|
8638
|
+
throw new BadRequestError41("Promo code not found.");
|
|
8639
|
+
}
|
|
8640
|
+
}
|
|
8641
|
+
const userData = await getUserById(value.user);
|
|
8642
|
+
if (!userData) {
|
|
8643
|
+
throw new BadRequestError41("User not found.");
|
|
8644
|
+
}
|
|
8645
|
+
const membership = await getMembershipByApp({
|
|
8646
|
+
user: value.user,
|
|
8647
|
+
org: value.org,
|
|
8648
|
+
app: "org"
|
|
8649
|
+
});
|
|
8650
|
+
if (!membership) {
|
|
8651
|
+
throw new BadRequestError41("User is not a member of the organization.");
|
|
8652
|
+
}
|
|
8653
|
+
const plan = await getDefaultPlan();
|
|
8654
|
+
if (!plan) {
|
|
8655
|
+
throw new BadRequestError41("Plan not found.");
|
|
8656
|
+
}
|
|
8657
|
+
const { subscriptionAmount, currency } = await computeFee(
|
|
8658
|
+
{
|
|
8659
|
+
seats: subscription.seats,
|
|
8660
|
+
promoCode: value.promoCode ?? "",
|
|
8661
|
+
plan: plan._id?.toString() ?? "",
|
|
8662
|
+
org: value.org
|
|
8663
|
+
},
|
|
8664
|
+
true
|
|
8665
|
+
);
|
|
8658
8666
|
await updateById(
|
|
8659
8667
|
subscription._id?.toString() ?? "",
|
|
8660
8668
|
{ promoCode: value.promoCode ?? "", amount: subscriptionAmount },
|