This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
import { Migration } from '@mikro-orm/migrations';
|
||||||
|
|
||||||
|
export class Migration20260726120000_addEnableAiChatToRestaurants extends Migration {
|
||||||
|
override async up(): Promise<void> {
|
||||||
|
this.addSql(
|
||||||
|
`alter table "restaurants" add column "enable_ai_chat" boolean not null default false;`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
override async down(): Promise<void> {
|
||||||
|
this.addSql(`alter table "restaurants" drop column "enable_ai_chat";`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -602,6 +602,7 @@ export const enum AiMessage {
|
|||||||
NO_RESPONSE_FROM_AI_MODEL = 'خطا در دریافت پاسخ از مدل AI',
|
NO_RESPONSE_FROM_AI_MODEL = 'خطا در دریافت پاسخ از مدل AI',
|
||||||
LLM_SERVICE_ERROR = 'سرویس هوش مصنوعی موقتاً در دسترس نیست',
|
LLM_SERVICE_ERROR = 'سرویس هوش مصنوعی موقتاً در دسترس نیست',
|
||||||
INSUFFICIENT_CREDIT = 'اعتبار کیف پول رستوران برای استفاده از هوش مصنوعی کافی نیست',
|
INSUFFICIENT_CREDIT = 'اعتبار کیف پول رستوران برای استفاده از هوش مصنوعی کافی نیست',
|
||||||
|
AI_CHAT_DISABLED = 'چت هوش مصنوعی برای این رستوران فعال نیست',
|
||||||
MESSAGE_NOT_FOUND_OR_ACCESS_DENIED = 'ایمیل یافت نشد یا دسترسی آن را ندارید',
|
MESSAGE_NOT_FOUND_OR_ACCESS_DENIED = 'ایمیل یافت نشد یا دسترسی آن را ندارید',
|
||||||
EMAIL_CONTENT_IS_EMPTY_OR_COULD_NOT_BE_EXTRACTED = 'محتوای ایمیل خالی است یا قابل استخراج نیست',
|
EMAIL_CONTENT_IS_EMPTY_OR_COULD_NOT_BE_EXTRACTED = 'محتوای ایمیل خالی است یا قابل استخراج نیست',
|
||||||
DESCRIPTION_IS_REQUIRED = 'شرح و هدف قالب الزامی است',
|
DESCRIPTION_IS_REQUIRED = 'شرح و هدف قالب الزامی است',
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ export class AiService {
|
|||||||
|
|
||||||
async chat(dto: ChatDto, params: { restId?: string; userId?: string; slug?: string }): Promise<AiChatResult> {
|
async chat(dto: ChatDto, params: { restId?: string; userId?: string; slug?: string }): Promise<AiChatResult> {
|
||||||
const restaurant = await this.resolveRestaurant(params.restId, params.slug);
|
const restaurant = await this.resolveRestaurant(params.restId, params.slug);
|
||||||
|
|
||||||
|
if (!restaurant.enableAiChat) {
|
||||||
|
throw new BadRequestException(AiMessage.AI_CHAT_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
const user = params.userId ? await this.em.findOne(User, { id: params.userId }) : null;
|
const user = params.userId ? await this.em.findOne(User, { id: params.userId }) : null;
|
||||||
|
|
||||||
await this.ensureHasCredit(restaurant.id);
|
await this.ensureHasCredit(restaurant.id);
|
||||||
|
|||||||
@@ -52,4 +52,9 @@ export class CreateRestaurantDto {
|
|||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ example: false, description: 'فعال بودن چت هوش مصنوعی', default: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
enableAiChat?: boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,4 +51,9 @@ export class SetupRestaurantDto {
|
|||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ example: false, description: 'فعال بودن چت هوش مصنوعی', default: false })
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
enableAiChat?: boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ export class Restaurant extends BaseEntity {
|
|||||||
@Property({ default: true })
|
@Property({ default: true })
|
||||||
isActive: boolean = true;
|
isActive: boolean = true;
|
||||||
|
|
||||||
|
@Property({ default: false })
|
||||||
|
enableAiChat: boolean = false;
|
||||||
|
|
||||||
@Property({ nullable: true })
|
@Property({ nullable: true })
|
||||||
establishedYear?: number;
|
establishedYear?: number;
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ export class RestaurantsService {
|
|||||||
establishedYear: dto.establishedYear,
|
establishedYear: dto.establishedYear,
|
||||||
phones: dto.phone ? [dto.phone] : undefined,
|
phones: dto.phone ? [dto.phone] : undefined,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
|
enableAiChat: dto.enableAiChat ?? false,
|
||||||
plan: dto.plan,
|
plan: dto.plan,
|
||||||
domain: `https://dmenu.danakcorp.com/${slug}`,
|
domain: `https://dmenu.danakcorp.com/${slug}`,
|
||||||
subscriptionId: dto.subscriptionId,
|
subscriptionId: dto.subscriptionId,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export class RestaurantsSeeder {
|
|||||||
subscriptionStartDate: new Date('2026-01-01'),
|
subscriptionStartDate: new Date('2026-01-01'),
|
||||||
subscriptionEndDate: new Date('2026-01-07'),
|
subscriptionEndDate: new Date('2026-01-07'),
|
||||||
isActive: true,
|
isActive: true,
|
||||||
|
enableAiChat: false,
|
||||||
});
|
});
|
||||||
em.persist(restaurant);
|
em.persist(restaurant);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user