feat: resolve doctors query error, add FAQ, testimonials, blog preview, and full menu management
Deploy Canina / deploy (push) Successful in 1m41s

This commit is contained in:
parsa aghaei committed 2026-08-19 17:20:01 +03:30
1 parent 70d58e7086
commit 2c452215c3
31 files changed
+1987 -76

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
import {
Controller,
Get,
Post,
Put,
Delete,
Body,
Param,
Query,
UseGuards,
} from '@nestjs/common';
import { MenuService } from './menu.service';
import {
ApiTags,
ApiOperation,
ApiBearerAuth,
ApiQuery,
} from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';
@ApiTags('Menu - مدیریت منو')
@Controller('menu')
export class MenuController {
constructor(private readonly menuService: MenuService) {}
@Get()
@ApiOperation({ summary: 'دریافت منو عمومی بر اساس نوع' })
@ApiQuery({
name: 'type',
required: true,
description: 'HEADER | FOOTER_COL1 | FOOTER_COL2 | FOOTER_COL3',
})
findByType(@Query('type') type: string) {
return this.menuService.findByType(type);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Get('admin')
@ApiOperation({ summary: 'دریافت تمام آیتم‌های منو (ادمین)' })
@ApiQuery({ name: 'type', required: false })
findAllAdmin(@Query('type') type?: string) {
return this.menuService.findAllAdmin(type);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Post()
@ApiOperation({ summary: 'ایجاد آیتم منو جدید' })
create(
@Body()
body: {
menuType: string;
label: string;
href: string;
parentId?: string;
order?: number;
isActive?: boolean;
isExternal?: boolean;
icon?: string;
badge?: string;
},
) {
return this.menuService.create(body);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Put('reorder')
@ApiOperation({ summary: 'مرتب‌سازی آیتم‌های منو' })
reorder(@Body() body: { items: { id: string; order: number }[] }) {
return this.menuService.reorder(body.items);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Put(':id')
@ApiOperation({ summary: 'ویرایش آیتم منو' })
update(
@Param('id') id: string,
@Body()
body: Partial<{
menuType: string;
label: string;
href: string;
parentId: string | null;
order: number;
isActive: boolean;
isExternal: boolean;
icon: string;
badge: string;
}>,
) {
return this.menuService.update(id, body);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Delete(':id')
@ApiOperation({ summary: 'حذف آیتم منو' })
remove(@Param('id') id: string) {
return this.menuService.remove(id);
}
}
+10
View File
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { MenuController } from './menu.controller';
import { MenuService } from './menu.service';
@Module({
controllers: [MenuController],
providers: [MenuService],
exports: [MenuService],
})
export class MenuModule {}
+145
View File
@@ -0,0 +1,145 @@
import { Injectable, NotFoundException, OnModuleInit } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
export type MenuType = 'HEADER' | 'FOOTER_COL1' | 'FOOTER_COL2' | 'FOOTER_COL3';
@Injectable()
export class MenuService implements OnModuleInit {
constructor(private prisma: PrismaService) {}
async onModuleInit() {
await this.seedIfEmpty();
}
private async seedIfEmpty() {
const count = await this.prisma.menuItem.count();
if (count > 0) return;
// Seed with current site navigation
const headerItems = [
{ label: 'راهکارهای درمانی', href: '/shop?view=symptoms', order: 1 },
{ label: 'محصولات تخصصی', href: '/shop', order: 2 },
{ label: 'دانشنامه علمی', href: '/wiki', order: 3 },
{ label: 'مجله سلامت پت', href: '/blog', order: 4 },
{ label: 'شناسنامه پت‌ها', href: '/dashboard/pets', order: 5 },
{ label: 'ویدیوها', href: '/videos', order: 6 },
];
const footerCol1 = [
{ label: 'درباره کنینا آلمان', href: '/about', order: 1 },
{ label: 'تماس با ما', href: '/contact', order: 2 },
{ label: 'مجوزها و گواهی‌ها', href: '/trust-seals', order: 3 },
{ label: 'حریم خصوصی', href: '/privacy', order: 4 },
];
const footerCol2 = [
{ label: 'فروشگاه تخصصی', href: '/shop', order: 1 },
{ label: 'دستهٔ‌بندی درمانی', href: '/shop?view=symptoms', order: 2 },
{ label: 'دانشنامه علمی', href: '/wiki', order: 3 },
{ label: 'مجله سلامت پت', href: '/blog', order: 4 },
];
const footerCol3 = [
{ label: 'شناسنامه پت‌ها', href: '/dashboard/pets', order: 1 },
{ label: 'سفارشات من', href: '/dashboard/orders', order: 2 },
{ label: 'ردیابی سفارش', href: '/track', order: 3 },
{ label: 'ورود / ثبت‌نام', href: '/?login=1', order: 4 },
];
const createItems = (items: typeof headerItems, menuType: MenuType) =>
items.map((item) => ({
...item,
menuType,
isActive: true,
isExternal: false,
}));
await this.prisma.menuItem.createMany({
data: [
...createItems(headerItems, 'HEADER'),
...createItems(footerCol1, 'FOOTER_COL1'),
...createItems(footerCol2, 'FOOTER_COL2'),
...createItems(footerCol3, 'FOOTER_COL3'),
],
});
}
async findByType(menuType: string) {
const items = await this.prisma.menuItem.findMany({
where: { menuType, isActive: true, parentId: null },
orderBy: { order: 'asc' },
include: {
children: {
where: { isActive: true },
orderBy: { order: 'asc' },
},
},
});
return items;
}
async findAllAdmin(menuType?: string) {
return this.prisma.menuItem.findMany({
where: menuType ? { menuType } : undefined,
orderBy: [{ menuType: 'asc' }, { order: 'asc' }],
include: {
children: {
orderBy: { order: 'asc' },
},
},
});
}
async create(data: {
menuType: string;
label: string;
href: string;
parentId?: string;
order?: number;
isActive?: boolean;
isExternal?: boolean;
icon?: string;
badge?: string;
}) {
return this.prisma.menuItem.create({ data });
}
async update(
id: string,
data: Partial<{
menuType: string;
label: string;
href: string;
parentId: string | null;
order: number;
isActive: boolean;
isExternal: boolean;
icon: string;
badge: string;
}>,
) {
const item = await this.prisma.menuItem.findUnique({ where: { id } });
if (!item) throw new NotFoundException('Menu item not found');
return this.prisma.menuItem.update({ where: { id }, data });
}
async remove(id: string) {
const item = await this.prisma.menuItem.findUnique({ where: { id } });
if (!item) throw new NotFoundException('Menu item not found');
// Delete children first
await this.prisma.menuItem.deleteMany({ where: { parentId: id } });
return this.prisma.menuItem.delete({ where: { id } });
}
async reorder(items: { id: string; order: number }[]) {
await Promise.all(
items.map((item) =>
this.prisma.menuItem.update({
where: { id: item.id },
data: { order: item.order },
}),
),
);
return { success: true };
}
}