From be33d9a96f48abd9a5ca5e57504bb841d4030425 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sun, 15 Feb 2026 09:33:38 +0330 Subject: [PATCH] category --- src/modules/auth/dto/direct-login.dto.ts | 2 ++ src/modules/auth/dto/request-otp.dto.ts | 2 ++ src/modules/auth/dto/verify-otp.dto.ts | 2 ++ src/modules/auth/services/auth.service.ts | 6 ++++++ src/modules/products/controllers/category.controller.ts | 2 +- src/modules/products/providers/category.service.ts | 2 +- 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/auth/dto/direct-login.dto.ts b/src/modules/auth/dto/direct-login.dto.ts index 93eeede..9aac473 100644 --- a/src/modules/auth/dto/direct-login.dto.ts +++ b/src/modules/auth/dto/direct-login.dto.ts @@ -1,5 +1,6 @@ import { IsNotEmpty, IsString, IsMobilePhone } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer/types/decorators/transform.decorator'; export class DirectLoginDto { @IsNotEmpty() @@ -10,6 +11,7 @@ export class DirectLoginDto { @IsNotEmpty() @IsString() + @Transform(({ value }: { value: string }) => value.toLowerCase()) @ApiProperty({ example: 'zhivan', description: 'Shop slug' }) slug: string; } diff --git a/src/modules/auth/dto/request-otp.dto.ts b/src/modules/auth/dto/request-otp.dto.ts index fbbb505..1ccdba7 100644 --- a/src/modules/auth/dto/request-otp.dto.ts +++ b/src/modules/auth/dto/request-otp.dto.ts @@ -1,5 +1,6 @@ import { IsNotEmpty, IsString, IsMobilePhone } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; export class RequestOtpDto { @IsNotEmpty() @@ -10,6 +11,7 @@ export class RequestOtpDto { @IsNotEmpty() @IsString() + @Transform(({ value }: { value: string }) => value.toLowerCase()) @ApiProperty({ example: 'boote', description: 'shop slug' }) slug: string; } diff --git a/src/modules/auth/dto/verify-otp.dto.ts b/src/modules/auth/dto/verify-otp.dto.ts index 920f5bc..7918b4c 100644 --- a/src/modules/auth/dto/verify-otp.dto.ts +++ b/src/modules/auth/dto/verify-otp.dto.ts @@ -1,5 +1,6 @@ import { IsNotEmpty, IsString, Length, IsMobilePhone } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; export class VerifyOtpDto { @IsNotEmpty() @@ -16,6 +17,7 @@ export class VerifyOtpDto { @IsNotEmpty() @IsString() + @Transform(({ value }: { value: string }) => value.toLowerCase()) @ApiProperty({ example: 'boote', description: 'shop slug' }) slug: string; } diff --git a/src/modules/auth/services/auth.service.ts b/src/modules/auth/services/auth.service.ts index 614b42d..2d4815d 100644 --- a/src/modules/auth/services/auth.service.ts +++ b/src/modules/auth/services/auth.service.ts @@ -42,6 +42,12 @@ export class AuthService { async requestOtp(dto: RequestOtpDto, isAdmin: boolean) { const { phone, slug } = dto; const normalizedPhone = normalizePhone(phone); + if (isAdmin) { + const admin = await this.adminRepository.findOne({ phone: normalizedPhone, roles: { shop: { slug } } }); + if (!admin) { + throw new BadRequestException(AuthMessage.ADMIN_NOT_FOUND); + } + } const code = this.generateOtpCode(); const key = isAdmin ? this.adminOtpKey(slug, normalizedPhone) : this.userOtpKey(slug, normalizedPhone); await this.cacheService.set(key, code, this.OTP_EXPIRATION_TIME); diff --git a/src/modules/products/controllers/category.controller.ts b/src/modules/products/controllers/category.controller.ts index 7309998..1623a26 100644 --- a/src/modules/products/controllers/category.controller.ts +++ b/src/modules/products/controllers/category.controller.ts @@ -44,7 +44,7 @@ export class CategoryController { @UseGuards(AdminAuthGuard) @ApiBearerAuth() findAll(@ShopId() shopId: string) { - return this.categoryService.findAllByShopId(shopId); + return this.categoryService.findAlTreelByShopId(shopId); } @Get('admin/categories/:id') diff --git a/src/modules/products/providers/category.service.ts b/src/modules/products/providers/category.service.ts index 735d11b..c24c056 100644 --- a/src/modules/products/providers/category.service.ts +++ b/src/modules/products/providers/category.service.ts @@ -50,7 +50,7 @@ export class CategoryService { { orderBy: { order: 'ASC' }, populate: ['children', 'parent'] }); } - async findAllByShopId(shopId: string): Promise { + async findAlTreelByShopId(shopId: string): Promise { return this.categoryRepository.find( { shop: { id: shopId }, parent: null }, { orderBy: { createdAt: 'DESC' }, populate: ['children', 'parent'] });