module provinces
This commit is contained in:
@@ -14,6 +14,7 @@ import * as bcrypt from 'bcrypt';
|
||||
import { Repository, IsNull } from 'typeorm';
|
||||
import { Customer } from '../customers/entities/customer.entity';
|
||||
import { Salon } from '../salons/entities/salon.entity';
|
||||
import { ProvincesService } from '../provinces/provinces.service';
|
||||
import { SmsService } from '../sms/sms.service';
|
||||
import { SalonSubscription } from '../subscriptions/entities/salon-subscription.entity';
|
||||
import { SalonSubscriptionsService } from '../subscriptions/salon-subscriptions.service';
|
||||
@@ -69,6 +70,7 @@ export class AuthService {
|
||||
private readonly customersRepository: Repository<Customer>,
|
||||
@InjectRepository(Salon)
|
||||
private readonly salonsRepository: Repository<Salon>,
|
||||
private readonly provincesService: ProvincesService,
|
||||
private readonly usersService: UsersService,
|
||||
private readonly salonSubscriptionsService: SalonSubscriptionsService,
|
||||
private readonly smsService: SmsService,
|
||||
@@ -274,6 +276,7 @@ export class AuthService {
|
||||
dto: VerifySalonOtpDto,
|
||||
): Promise<SalonAuthResponse> {
|
||||
this.validateSalonSignupFields(dto);
|
||||
await this.validateSalonLocation(dto.salonProvinceId!, dto.salonCityId!);
|
||||
|
||||
const user = await this.usersService.create({
|
||||
firstName: dto.firstName!,
|
||||
@@ -287,6 +290,8 @@ export class AuthService {
|
||||
description: dto.salonDescription ?? null,
|
||||
address: dto.salonAddress!,
|
||||
phone: dto.salonPhone!,
|
||||
provinceId: dto.salonProvinceId!,
|
||||
cityId: dto.salonCityId!,
|
||||
ownerId: user.id,
|
||||
});
|
||||
|
||||
@@ -301,6 +306,8 @@ export class AuthService {
|
||||
'salonName',
|
||||
'salonAddress',
|
||||
'salonPhone',
|
||||
'salonProvinceId',
|
||||
'salonCityId',
|
||||
];
|
||||
|
||||
const missingFields = requiredFields.filter((field) => !dto[field]);
|
||||
@@ -312,6 +319,16 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
private async validateSalonLocation(
|
||||
provinceId: string,
|
||||
cityId: string,
|
||||
): Promise<void> {
|
||||
const city = await this.provincesService.findCity(provinceId, cityId);
|
||||
if (!city) {
|
||||
throw new BadRequestException('شهر انتخابشده با استان مطابقت ندارد');
|
||||
}
|
||||
}
|
||||
|
||||
async verifyOtp(dto: VerifyOtpDto): Promise<AuthTokensResponse> {
|
||||
await this.consumeOtp(dto.mobile, dto.code);
|
||||
|
||||
@@ -390,6 +407,7 @@ export class AuthService {
|
||||
if (user.role === UserRole.SALON) {
|
||||
response.salons = await this.salonsRepository.find({
|
||||
where: { ownerId: user.id },
|
||||
relations: { province: true, city: true },
|
||||
order: { createdAt: 'ASC' },
|
||||
});
|
||||
response.activeSubscription =
|
||||
|
||||
Reference in New Issue
Block a user