fix
This commit is contained in:
@@ -19,7 +19,6 @@ import { ReserveStatus } from '../reserves/enums/reserve-status.enum';
|
|||||||
import { ReservesService } from '../reserves/reserves.service';
|
import { ReservesService } from '../reserves/reserves.service';
|
||||||
import { calculateSmsParts } from '../sms/helpers/sms-segment.helper';
|
import { calculateSmsParts } from '../sms/helpers/sms-segment.helper';
|
||||||
import { SmsService } from '../sms/sms.service';
|
import { SmsService } from '../sms/sms.service';
|
||||||
import { ReserveSmsService } from '../sms-settings/reserve-sms.service';
|
|
||||||
import { SmsDispatchService } from '../sms-settings/sms-dispatch.service';
|
import { SmsDispatchService } from '../sms-settings/sms-dispatch.service';
|
||||||
import { SmsScenarioKey } from '../sms-settings/enums/sms-scenario-key.enum';
|
import { SmsScenarioKey } from '../sms-settings/enums/sms-scenario-key.enum';
|
||||||
import { buildReserveSmsVariables } from '../sms-settings/utils/build-reserve-sms-variables.util';
|
import { buildReserveSmsVariables } from '../sms-settings/utils/build-reserve-sms-variables.util';
|
||||||
@@ -36,6 +35,8 @@ import { PaymentStatus } from './enums/payment-status.enum';
|
|||||||
import { PaymentType } from './enums/payment-type.enum';
|
import { PaymentType } from './enums/payment-type.enum';
|
||||||
|
|
||||||
const MIN_AMOUNT_TOMAN = 100;
|
const MIN_AMOUNT_TOMAN = 100;
|
||||||
|
/** Gives the reserve-created SMS time to reach the customer before the deposit link SMS. */
|
||||||
|
const DEPOSIT_SMS_DELAY_MS = 2_500;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CardToCardDepositService {
|
export class CardToCardDepositService {
|
||||||
@@ -50,7 +51,6 @@ export class CardToCardDepositService {
|
|||||||
private readonly authorizationService: AuthorizationService,
|
private readonly authorizationService: AuthorizationService,
|
||||||
private readonly salonFinancialSettingsService: SalonFinancialSettingsService,
|
private readonly salonFinancialSettingsService: SalonFinancialSettingsService,
|
||||||
private readonly uploaderService: UploaderService,
|
private readonly uploaderService: UploaderService,
|
||||||
private readonly reserveSmsService: ReserveSmsService,
|
|
||||||
private readonly smsDispatchService: SmsDispatchService,
|
private readonly smsDispatchService: SmsDispatchService,
|
||||||
private readonly smsService: SmsService,
|
private readonly smsService: SmsService,
|
||||||
private readonly shortLinksService: ShortLinksService,
|
private readonly shortLinksService: ShortLinksService,
|
||||||
@@ -148,9 +148,7 @@ export class CardToCardDepositService {
|
|||||||
const variables = buildReserveSmsVariables(reserve);
|
const variables = buildReserveSmsVariables(reserve);
|
||||||
const mobile = reserve.customer?.user?.mobile;
|
const mobile = reserve.customer?.user?.mobile;
|
||||||
if (mobile) {
|
if (mobile) {
|
||||||
if (!existingPending) {
|
await this.delay(DEPOSIT_SMS_DELAY_MS);
|
||||||
await this.reserveSmsService.sendReserveCreated(reserve.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.sendDepositSms(
|
await this.sendDepositSms(
|
||||||
SmsScenarioKey.DEPOSIT_PAYMENT_REQUEST,
|
SmsScenarioKey.DEPOSIT_PAYMENT_REQUEST,
|
||||||
@@ -382,6 +380,10 @@ export class CardToCardDepositService {
|
|||||||
return this.smsService.sendSms(mobile, message);
|
return this.smsService.sendSms(mobile, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private delay(ms: number): Promise<void> {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
private tomanToRial(amountToman: number): number {
|
private tomanToRial(amountToman: number): number {
|
||||||
return Math.round(amountToman * 10);
|
return Math.round(amountToman * 10);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,11 +104,7 @@ export class ReservesService {
|
|||||||
const saved = await this.reservesRepository.save(reserve);
|
const saved = await this.reservesRepository.save(reserve);
|
||||||
await this.customersService.linkToSalon(saved.salonId, saved.customerId);
|
await this.customersService.linkToSalon(saved.salonId, saved.customerId);
|
||||||
await this.logStatusChange(saved.id, null, saved.status, user.id);
|
await this.logStatusChange(saved.id, null, saved.status, user.id);
|
||||||
// When a deposit is required, the reserve-created SMS is sent from the
|
|
||||||
// deposit request flow so it always arrives before the payment link SMS.
|
|
||||||
if (saved.depositAmount <= 0) {
|
|
||||||
await this.reserveSmsService.sendReserveCreated(saved.id);
|
await this.reserveSmsService.sendReserveCreated(saved.id);
|
||||||
}
|
|
||||||
await this.salonNotificationsService.notifyReserveCreated(saved.id);
|
await this.salonNotificationsService.notifyReserveCreated(saved.id);
|
||||||
return this.findOne(saved.id, user);
|
return this.findOne(saved.id, user);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user