phone ==.>phones
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-06-29 12:09:33 +03:30
parent 7e7f49a96b
commit f6d1716ad0
7 changed files with 224 additions and 99 deletions
@@ -1,6 +1,6 @@
import { Controller, Get, Post, Body, Patch, Param, UseGuards, Delete, Query } from '@nestjs/common';
import { RestaurantsService } from '../providers/restaurants.service';
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
import { SetupRestaurantDto } from '../dto/setup-restaurant.dto';
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
import { FindRestaurantsDto } from '../dto/find-restaurants.dto';
@@ -108,10 +108,11 @@ export class RestaurantsController {
@UseGuards(SuperAdminAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Create a new restaurant' })
@ApiOperation({ summary: 'Setup a new restaurant' })
@ApiBody({ type: SetupRestaurantDto })
@Post('super-admin/restaurants')
createRestaurant(@Body() createRestaurantDto: CreateRestaurantDto) {
return this.restaurantsService.setupRestuarant(createRestaurantDto);
setupRestaurant(@Body() setupRestaurantDto: SetupRestaurantDto) {
return this.restaurantsService.setupRestuarant(setupRestaurantDto);
}
@UseGuards(SuperAdminAuthGuard)
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsOptional, IsNumber, IsDate, IsEnum, IsBoolean } from 'class-validator';
import { IsString, IsOptional, IsNumber, IsDate, IsEnum, IsBoolean, IsArray } from 'class-validator';
import { Type } from 'class-transformer';
import { PlanEnum } from '../interface/plan.interface';
@@ -23,10 +23,11 @@ export class CreateRestaurantDto {
@IsNumber()
establishedYear: number;
@ApiPropertyOptional({ example: '09123456789', description: 'شماره تلفن' })
@ApiPropertyOptional({ example: ['09123456789', '09123456789'], description: 'شماره تلفن' })
@IsOptional()
@IsString()
phone: string;
@IsArray()
@IsString({ each: true })
phones?: string[];
@ApiProperty({ example: 'base', enum: PlanEnum, description: 'پلن رستوران' })
@IsEnum(PlanEnum)
@@ -0,0 +1,54 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsOptional, IsNumber, IsDate, IsEnum, IsBoolean } from 'class-validator';
import { Type } from 'class-transformer';
import { PlanEnum } from '../interface/plan.interface';
export class SetupRestaurantDto {
@ApiProperty({ example: 'کافه ژیوان', description: 'نام رستوران' })
@IsString()
name!: string;
@ApiPropertyOptional({ example: 'zhivan', description: 'شناسه (slug) رستوران، لاتین و بدون فاصله (اختیاری - در صورت عدم ارسال، از نام رستوران تولید می‌شود)' })
@IsOptional()
@IsString()
slug?: string;
@ApiPropertyOptional({ example: 'zhivan.dmenu.ir', description: 'دامنه اختصاصی رستوران' })
@IsOptional()
@IsString()
domain?: string;
@ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' })
@IsOptional()
@IsNumber()
establishedYear: number;
@ApiPropertyOptional({ example: '09123456789', description: 'شماره تلفن' })
@IsOptional()
@IsString()
phone?: string;
@ApiProperty({ example: 'base', enum: PlanEnum, description: 'پلن رستوران' })
@IsEnum(PlanEnum)
plan!: PlanEnum;
@ApiProperty({ example: 'sub_1234567890', description: 'شناسه اشتراک' })
@IsString()
subscriptionId!: string;
@ApiProperty({ example: '2025-12-26', description: 'تاریخ انقضای اشتراک' })
@Type(() => Date)
@IsDate()
subscriptionEndDate!: Date;
@ApiProperty({ example: '2025-12-26', description: 'تاریخ شروع اشتراک' })
@Type(() => Date)
@IsDate()
subscriptionStartDate!: Date;
@ApiProperty()
@IsBoolean()
isActive?: boolean;
}
@@ -43,8 +43,8 @@ export class Restaurant extends BaseEntity {
@Property({ nullable: true })
establishedYear?: number;
@Property({ nullable: true })
phone?: string;
@Property({ nullable: true, type: 'json' })
phones?: string[];
@Property({ nullable: true })
instagram?: string;
@@ -1,5 +1,5 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
import { SetupRestaurantDto } from '../dto/setup-restaurant.dto';
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
import { UpdateRestaurantBgDto } from '../dto/update-restaurant-bg.dto';
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
@@ -43,7 +43,7 @@ export class RestaurantsService {
private readonly cacheService: CacheService,
) { }
async setupRestuarant(dto: CreateRestaurantDto): Promise<Restaurant> {
async setupRestuarant(dto: SetupRestaurantDto): Promise<Restaurant> {
return await this.em.transactional(async (em) => {
// Generate or validate slug
const slug = slugify(dto.slug ?? dto.name, {
@@ -63,7 +63,7 @@ export class RestaurantsService {
name: dto.name,
slug,
establishedYear: dto.establishedYear,
phone: dto.phone,
phones: dto.phone ? [dto.phone] : undefined,
isActive: true,
plan: dto.plan,
domain: `https://dmenu.danakcorp.com/${slug}`,
@@ -79,7 +79,7 @@ export class RestaurantsService {
throw new BadRequestException(`Role not found for plan: ${dto.plan}`);
}
const normalizedPhone = normalizePhone(dto.phone);
const normalizedPhone = normalizePhone(dto.phone ?? '');
let admin = await em.findOne(Admin, { phone: normalizedPhone });
if (!admin) {
admin = em.create(Admin, {