category
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { IsNotEmpty, IsString, IsMobilePhone } from 'class-validator';
|
import { IsNotEmpty, IsString, IsMobilePhone } from 'class-validator';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Transform } from 'class-transformer/types/decorators/transform.decorator';
|
||||||
|
|
||||||
export class DirectLoginDto {
|
export class DirectLoginDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@@ -10,6 +11,7 @@ export class DirectLoginDto {
|
|||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@Transform(({ value }: { value: string }) => value.toLowerCase())
|
||||||
@ApiProperty({ example: 'zhivan', description: 'Shop slug' })
|
@ApiProperty({ example: 'zhivan', description: 'Shop slug' })
|
||||||
slug: string;
|
slug: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { IsNotEmpty, IsString, IsMobilePhone } from 'class-validator';
|
import { IsNotEmpty, IsString, IsMobilePhone } from 'class-validator';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Transform } from 'class-transformer';
|
||||||
|
|
||||||
export class RequestOtpDto {
|
export class RequestOtpDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@@ -10,6 +11,7 @@ export class RequestOtpDto {
|
|||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@Transform(({ value }: { value: string }) => value.toLowerCase())
|
||||||
@ApiProperty({ example: 'boote', description: 'shop slug' })
|
@ApiProperty({ example: 'boote', description: 'shop slug' })
|
||||||
slug: string;
|
slug: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { IsNotEmpty, IsString, Length, IsMobilePhone } from 'class-validator';
|
import { IsNotEmpty, IsString, Length, IsMobilePhone } from 'class-validator';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Transform } from 'class-transformer';
|
||||||
|
|
||||||
export class VerifyOtpDto {
|
export class VerifyOtpDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@@ -16,6 +17,7 @@ export class VerifyOtpDto {
|
|||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@Transform(({ value }: { value: string }) => value.toLowerCase())
|
||||||
@ApiProperty({ example: 'boote', description: 'shop slug' })
|
@ApiProperty({ example: 'boote', description: 'shop slug' })
|
||||||
slug: string;
|
slug: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ export class AuthService {
|
|||||||
async requestOtp(dto: RequestOtpDto, isAdmin: boolean) {
|
async requestOtp(dto: RequestOtpDto, isAdmin: boolean) {
|
||||||
const { phone, slug } = dto;
|
const { phone, slug } = dto;
|
||||||
const normalizedPhone = normalizePhone(phone);
|
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 code = this.generateOtpCode();
|
||||||
const key = isAdmin ? this.adminOtpKey(slug, normalizedPhone) : this.userOtpKey(slug, normalizedPhone);
|
const key = isAdmin ? this.adminOtpKey(slug, normalizedPhone) : this.userOtpKey(slug, normalizedPhone);
|
||||||
await this.cacheService.set(key, code, this.OTP_EXPIRATION_TIME);
|
await this.cacheService.set(key, code, this.OTP_EXPIRATION_TIME);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export class CategoryController {
|
|||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
findAll(@ShopId() shopId: string) {
|
findAll(@ShopId() shopId: string) {
|
||||||
return this.categoryService.findAllByShopId(shopId);
|
return this.categoryService.findAlTreelByShopId(shopId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('admin/categories/:id')
|
@Get('admin/categories/:id')
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export class CategoryService {
|
|||||||
{ orderBy: { order: 'ASC' }, populate: ['children', 'parent'] });
|
{ orderBy: { order: 'ASC' }, populate: ['children', 'parent'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllByShopId(shopId: string): Promise<Category[]> {
|
async findAlTreelByShopId(shopId: string): Promise<Category[]> {
|
||||||
return this.categoryRepository.find(
|
return this.categoryRepository.find(
|
||||||
{ shop: { id: shopId }, parent: null },
|
{ shop: { id: shopId }, parent: null },
|
||||||
{ orderBy: { createdAt: 'DESC' }, populate: ['children', 'parent'] });
|
{ orderBy: { createdAt: 'DESC' }, populate: ['children', 'parent'] });
|
||||||
|
|||||||
Reference in New Issue
Block a user