@goweekdays/core 2.11.13 → 2.11.14
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 -1
- package/dist/index.js +43 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6040,6 +6040,15 @@ function modelSubscriptionTransaction(data) {
|
|
|
6040
6040
|
throw new BadRequestError28("Invalid createdBy ID.");
|
|
6041
6041
|
}
|
|
6042
6042
|
}
|
|
6043
|
+
if (data.metadata) {
|
|
6044
|
+
if (data.metadata.plan && typeof data.metadata.plan === "string" && data.metadata.plan.length === 24) {
|
|
6045
|
+
try {
|
|
6046
|
+
data.metadata.plan = new ObjectId17(data.metadata.plan);
|
|
6047
|
+
} catch (error2) {
|
|
6048
|
+
throw new BadRequestError28("Invalid plan ID in metadata.");
|
|
6049
|
+
}
|
|
6050
|
+
}
|
|
6051
|
+
}
|
|
6043
6052
|
return {
|
|
6044
6053
|
_id: data._id,
|
|
6045
6054
|
subscription: data.subscription,
|
|
@@ -7897,7 +7906,7 @@ var schemaPromoUsage = Joi34.object({
|
|
|
7897
7906
|
function modelPromoUsage(value) {
|
|
7898
7907
|
const { error } = schemaPromoUsage.validate(value);
|
|
7899
7908
|
if (error) {
|
|
7900
|
-
throw new
|
|
7909
|
+
throw new BadRequestError37(`Invalid Promo Usage model: ${error.message}`);
|
|
7901
7910
|
}
|
|
7902
7911
|
if (value._id && typeof value._id === "string") {
|
|
7903
7912
|
try {
|
|
@@ -7980,6 +7989,9 @@ function usePromoUsageRepo() {
|
|
|
7980
7989
|
delCachedData();
|
|
7981
7990
|
return "Successfully added promo usage.";
|
|
7982
7991
|
} catch (error) {
|
|
7992
|
+
if (error instanceof AppError18) {
|
|
7993
|
+
throw error;
|
|
7994
|
+
}
|
|
7983
7995
|
throw new InternalServerError21("Failed to add promo usage.");
|
|
7984
7996
|
}
|
|
7985
7997
|
}
|
|
@@ -8420,7 +8432,6 @@ function useSubscriptionService() {
|
|
|
8420
8432
|
const { getById: getOrgById, updateStatusById: updateOrgStatusById } = useOrgRepo();
|
|
8421
8433
|
const { getByCode: getPromoByCode } = usePromoRepo();
|
|
8422
8434
|
const {
|
|
8423
|
-
countByPromoId,
|
|
8424
8435
|
add: addPromoUsage,
|
|
8425
8436
|
updateStatusByOrgId: updatePromoUsageStatusByOrgId
|
|
8426
8437
|
} = usePromoUsageRepo();
|
|
@@ -8535,7 +8546,7 @@ function useSubscriptionService() {
|
|
|
8535
8546
|
"Cannot change promo code while increasing seats. Perform actions separately."
|
|
8536
8547
|
);
|
|
8537
8548
|
}
|
|
8538
|
-
const effectivePromoCode = isPromoChange ? value.promoCode : existingSubscription?.promoCode;
|
|
8549
|
+
const effectivePromoCode = isNew ? value.promoCode : isPromoChange ? value.promoCode : existingSubscription?.promoCode;
|
|
8539
8550
|
const promo = effectivePromoCode ? await getPromoByCode(effectivePromoCode) : null;
|
|
8540
8551
|
const monthlyAmount = computeMonthlyAmount(value.seats, plan.price, promo);
|
|
8541
8552
|
let proratedAmount = 0;
|
|
@@ -8744,6 +8755,29 @@ function useSubscriptionService() {
|
|
|
8744
8755
|
session
|
|
8745
8756
|
);
|
|
8746
8757
|
}
|
|
8758
|
+
if (!seatIncreased) {
|
|
8759
|
+
await addTransaction(
|
|
8760
|
+
{
|
|
8761
|
+
type: "remove-seat",
|
|
8762
|
+
description: `Removed ${subscription.seats - value.seats} seats.`,
|
|
8763
|
+
amount: 0,
|
|
8764
|
+
currency,
|
|
8765
|
+
subscription: subscription._id?.toString() ?? "",
|
|
8766
|
+
createdBy: value.user,
|
|
8767
|
+
createdByName: `${userData.firstName} ${userData.lastName}`,
|
|
8768
|
+
metadata: {
|
|
8769
|
+
seats: subscription.seats - value.seats,
|
|
8770
|
+
paidSeats,
|
|
8771
|
+
plan: value.plan ?? "",
|
|
8772
|
+
promoCode: subscription.promoCode ?? "",
|
|
8773
|
+
nextPromoCode: subscription.nextPromoCode ?? "",
|
|
8774
|
+
billingPeriodStart: subscription.billingPeriodStart,
|
|
8775
|
+
nextBillingDate: subscription.nextBillingDate
|
|
8776
|
+
}
|
|
8777
|
+
},
|
|
8778
|
+
session
|
|
8779
|
+
);
|
|
8780
|
+
}
|
|
8747
8781
|
await session.commitTransaction();
|
|
8748
8782
|
return "Successfully updated subscription seats.";
|
|
8749
8783
|
} catch (error2) {
|
|
@@ -8796,12 +8830,6 @@ function useSubscriptionService() {
|
|
|
8796
8830
|
if (!plan) {
|
|
8797
8831
|
throw new BadRequestError41("Plan not found.");
|
|
8798
8832
|
}
|
|
8799
|
-
const { subscriptionAmount, currency } = await computeFee({
|
|
8800
|
-
seats: subscription.seats,
|
|
8801
|
-
promoCode: value.promoCode ?? "",
|
|
8802
|
-
plan: plan._id?.toString() ?? "",
|
|
8803
|
-
org: value.org
|
|
8804
|
-
});
|
|
8805
8833
|
await updateById(
|
|
8806
8834
|
subscription._id?.toString() ?? "",
|
|
8807
8835
|
{ nextPromoCode: value.promoCode ?? "" },
|
|
@@ -8815,7 +8843,7 @@ function useSubscriptionService() {
|
|
|
8815
8843
|
{
|
|
8816
8844
|
promo: promo._id,
|
|
8817
8845
|
org: value.org,
|
|
8818
|
-
usedBy:
|
|
8846
|
+
usedBy: userData.email
|
|
8819
8847
|
},
|
|
8820
8848
|
session
|
|
8821
8849
|
);
|
|
@@ -8920,9 +8948,11 @@ function useSubscriptionService() {
|
|
|
8920
8948
|
}
|
|
8921
8949
|
for (let index = 0; index < subscriptions.length; index++) {
|
|
8922
8950
|
const subscription = subscriptions[index];
|
|
8923
|
-
const
|
|
8924
|
-
|
|
8925
|
-
|
|
8951
|
+
const now = /* @__PURE__ */ new Date();
|
|
8952
|
+
if (now < new Date(subscription.nextBillingDate)) {
|
|
8953
|
+
continue;
|
|
8954
|
+
}
|
|
8955
|
+
if ((subscription.retry ?? 0) >= retry) {
|
|
8926
8956
|
continue;
|
|
8927
8957
|
}
|
|
8928
8958
|
try {
|