feat: dont inactive the old suport plan and after pay the invoice make it inactive

This commit is contained in:
mahyargdz
2025-05-07 11:44:04 +03:30
parent a0d916ae69
commit 9cd28e8130
5 changed files with 13 additions and 6 deletions
@@ -552,6 +552,14 @@ export class InvoicesService {
await this.addNotifyAdminForSubscriptionPaymentToQueue(invoice); await this.addNotifyAdminForSubscriptionPaymentToQueue(invoice);
// //
} else if (invoice.items[0]?.supportPlan) { } else if (invoice.items[0]?.supportPlan) {
const oldUserSupportPlan = await queryRunner.manager.findOne(UserSupportPlan, {
where: { user: { id: user.id }, status: UserSupportPlanStatus.ACTIVE },
});
if (oldUserSupportPlan) {
await queryRunner.manager.update(UserSupportPlan, oldUserSupportPlan.id, { status: UserSupportPlanStatus.INACTIVE });
}
const userSupportPlan = invoice.items[0].supportPlan; const userSupportPlan = invoice.items[0].supportPlan;
userSupportPlan.status = UserSupportPlanStatus.ACTIVE; userSupportPlan.status = UserSupportPlanStatus.ACTIVE;
@@ -492,7 +492,7 @@ export class NotificationsService {
async createNewCustomerNotification(recipientId: string, data: INewCustomerNotificationData, queryRunner: QueryRunner) { async createNewCustomerNotification(recipientId: string, data: INewCustomerNotificationData, queryRunner: QueryRunner) {
const message = NotificationMessage.NEW_CUSTOMER_MESSAGE.replace("[fullName]", data.fullName); const message = NotificationMessage.NEW_CUSTOMER_MESSAGE.replace("[fullName]", data.fullName);
await this.smsService.sendNewCustomerSms(data.userPhone, data.fullName); await this.smsService.sendNewCustomerSms(data.userPhone, data.mobile, data.fullName);
if (data.userEmail) { if (data.userEmail) {
await this.emailService.sendAdminNotificationEmail({ await this.emailService.sendAdminNotificationEmail({
userEmail: data.userEmail, userEmail: data.userEmail,
@@ -1,5 +1,4 @@
export enum UserSupportPlanStatus { export enum UserSupportPlanStatus {
ACTIVE = "ACTIVE", ACTIVE = "ACTIVE",
INACTIVE = "INACTIVE", INACTIVE = "INACTIVE",
CANCELLED = "CANCELLED",
} }
@@ -249,8 +249,8 @@ export class SupportPlansService {
upgradePrice.toNumber(), upgradePrice.toNumber(),
); );
// cancel old support plan // inactivate old support plan
currentUserSupportPlan.status = UserSupportPlanStatus.CANCELLED; // currentUserSupportPlan.status = UserSupportPlanStatus.INACTIVE;
await queryRunner.manager.save(this.userSupportPlanRepo.target, currentUserSupportPlan); await queryRunner.manager.save(this.userSupportPlanRepo.target, currentUserSupportPlan);
if (newSupportPlan.isFree) { if (newSupportPlan.isFree) {
+2 -2
View File
@@ -666,11 +666,11 @@ export class SmsService {
} }
//************************************************* */ //************************************************* */
async sendNewCustomerSms(mobile: string, fullName: string) { async sendNewCustomerSms(mobile: string, newCustomerMobile: string, fullName: string) {
const smsData: ISmsVerifyBody = { const smsData: ISmsVerifyBody = {
Parameters: [ Parameters: [
{ name: "fullName", value: fullName }, { name: "fullName", value: fullName },
{ name: "mobile", value: mobile }, { name: "mobile", value: newCustomerMobile },
], ],
Mobile: mobile, Mobile: mobile,
TemplateId: this.smsConfigs.SMS_PATTERN_NEW_CUSTOMER, TemplateId: this.smsConfigs.SMS_PATTERN_NEW_CUSTOMER,