feat(sms): add WALLET_CHARGED sms trigger for online topup, manual admin credit, refund, and cashback
Deploy Canina / deploy (push) Successful in 43s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 0s

This commit is contained in:
parsa aghaei committed 2026-09-05 14:06:23 +03:30
1 parent 7093978e27
commit e15c25dae1
5 files changed
+168 -3

No files matched your search

+29 -2
View File
@@ -2,9 +2,11 @@ import {
Injectable,
BadRequestException,
NotFoundException,
Optional,
} from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../prisma/prisma.service';
import { SmsService } from '../common/services/sms.service';
import * as bcrypt from 'bcryptjs';
import { normalizeMobile } from '../common/utils/phone.utils';
import { UpdateProfileDto } from './dto/update-profile.dto';
@@ -22,7 +24,10 @@ export interface UserAddressInput {
@Injectable()
export class UsersService {
constructor(private prisma: PrismaService) {}
constructor(
private prisma: PrismaService,
@Optional() private smsService?: SmsService,
) {}
async findById(id: string) {
if (id === '12345678-1234-1234-1234-123456789012') {
@@ -277,7 +282,7 @@ export class UsersService {
throw new Error('مبلغ شارژ باید بزرگتر از صفر باشد');
}
const [transaction] = await this.prisma.$transaction([
const [transaction, updatedUser] = await this.prisma.$transaction([
this.prisma.walletTransaction.create({
data: {
userId,
@@ -293,6 +298,28 @@ export class UsersService {
}),
]);
if (this.smsService && updatedUser.mobile) {
try {
const customerFullName = (
updatedUser.firstName
? `${updatedUser.firstName} ${updatedUser.lastName || ''}`
: 'کاربر گرامی'
).trim();
const topupData = {
customerName: customerFullName,
customerPhone: updatedUser.mobile,
amount: Number(amount || 0).toLocaleString('fa-IR'),
balance: Number(updatedUser.walletBalance || 0).toLocaleString('fa-IR'),
reason: 'افزایش موجودی کیف پول',
date: new Date().toLocaleDateString('fa-IR'),
};
this.smsService.triggerEvent('WALLET_CHARGED', topupData).catch(() => {});
} catch (err) {
// Silently catch SMS error
}
}
return transaction;
}