test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -0,0 +1,187 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { MenuController } from "./menu.controller";
|
||||
import { MenuService } from "./menu.service";
|
||||
|
||||
describe("MenuController", () => {
|
||||
let controller: MenuController;
|
||||
let service: MenuService;
|
||||
|
||||
const mockMenuItems = [
|
||||
{
|
||||
id: "menu-item-1",
|
||||
menuType: "HEADER",
|
||||
label: "محصولات مکمل سگ",
|
||||
href: "/category/dog-supplements",
|
||||
parentId: null,
|
||||
order: 1,
|
||||
isActive: true,
|
||||
isExternal: false,
|
||||
icon: "dog-icon",
|
||||
badge: "جدید",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
id: "menu-item-2",
|
||||
menuType: "HEADER",
|
||||
label: "مشاوره آنلاین هوشمند",
|
||||
href: "/smart-advisor",
|
||||
parentId: null,
|
||||
order: 2,
|
||||
isActive: true,
|
||||
isExternal: false,
|
||||
icon: "sparkles",
|
||||
badge: null,
|
||||
children: [],
|
||||
},
|
||||
];
|
||||
|
||||
const mockMenuService = {
|
||||
findByType: jest.fn(),
|
||||
findAllAdmin: jest.fn(),
|
||||
create: jest.fn(),
|
||||
reorder: jest.fn(),
|
||||
update: jest.fn(),
|
||||
remove: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [MenuController],
|
||||
providers: [
|
||||
{
|
||||
provide: MenuService,
|
||||
useValue: mockMenuService,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<MenuController>(MenuController);
|
||||
service = module.get<MenuService>(MenuService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(controller).toBeDefined();
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe("findByType (Query param)", () => {
|
||||
it("should return menu items for given type", async () => {
|
||||
mockMenuService.findByType.mockResolvedValue(mockMenuItems);
|
||||
|
||||
const result = await controller.findByType("HEADER");
|
||||
|
||||
expect(service.findByType).toHaveBeenCalledWith("HEADER");
|
||||
expect(result).toEqual(mockMenuItems);
|
||||
expect(result).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("findByTypeParam (Path param)", () => {
|
||||
it("should return menu items for given path param type", async () => {
|
||||
mockMenuService.findByType.mockResolvedValue([mockMenuItems[0]]);
|
||||
|
||||
const result = await controller.findByTypeParam("FOOTER_COL1");
|
||||
|
||||
expect(service.findByType).toHaveBeenCalledWith("FOOTER_COL1");
|
||||
expect(result).toEqual([mockMenuItems[0]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("findAllAdmin", () => {
|
||||
it("should return all menu items when type query is provided", async () => {
|
||||
mockMenuService.findAllAdmin.mockResolvedValue(mockMenuItems);
|
||||
|
||||
const result = await controller.findAllAdmin("HEADER");
|
||||
|
||||
expect(service.findAllAdmin).toHaveBeenCalledWith("HEADER");
|
||||
expect(result).toEqual(mockMenuItems);
|
||||
});
|
||||
|
||||
it("should return all menu items when type query is undefined", async () => {
|
||||
mockMenuService.findAllAdmin.mockResolvedValue(mockMenuItems);
|
||||
|
||||
const result = await controller.findAllAdmin(undefined);
|
||||
|
||||
expect(service.findAllAdmin).toHaveBeenCalledWith(undefined);
|
||||
expect(result).toEqual(mockMenuItems);
|
||||
});
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
it("should create a new menu item", async () => {
|
||||
const createBody = {
|
||||
menuType: "HEADER",
|
||||
label: "درباره کانینا آلمان",
|
||||
href: "/about-us",
|
||||
parentId: undefined,
|
||||
order: 3,
|
||||
isActive: true,
|
||||
isExternal: false,
|
||||
icon: "info",
|
||||
badge: "معرفی",
|
||||
};
|
||||
|
||||
const createdItem = { id: "menu-item-3", ...createBody };
|
||||
mockMenuService.create.mockResolvedValue(createdItem);
|
||||
|
||||
const result = await controller.create(createBody);
|
||||
|
||||
expect(service.create).toHaveBeenCalledWith(createBody);
|
||||
expect(result).toEqual(createdItem);
|
||||
});
|
||||
});
|
||||
|
||||
describe("reorder", () => {
|
||||
it("should reorder menu items", async () => {
|
||||
const reorderBody = {
|
||||
items: [
|
||||
{ id: "menu-item-1", order: 2 },
|
||||
{ id: "menu-item-2", order: 1 },
|
||||
],
|
||||
};
|
||||
|
||||
mockMenuService.reorder.mockResolvedValue({ success: true, count: 2 });
|
||||
|
||||
const result = await controller.reorder(reorderBody);
|
||||
|
||||
expect(service.reorder).toHaveBeenCalledWith(reorderBody.items);
|
||||
expect(result).toEqual({ success: true, count: 2 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("update", () => {
|
||||
it("should update an existing menu item", async () => {
|
||||
const updateBody = {
|
||||
label: "محصولات تقویتی و درمانی سگ",
|
||||
order: 5,
|
||||
isActive: true,
|
||||
};
|
||||
|
||||
const updatedItem = { ...mockMenuItems[0], ...updateBody };
|
||||
mockMenuService.update.mockResolvedValue(updatedItem);
|
||||
|
||||
const result = await controller.update("menu-item-1", updateBody);
|
||||
|
||||
expect(service.update).toHaveBeenCalledWith("menu-item-1", updateBody);
|
||||
expect(result).toEqual(updatedItem);
|
||||
});
|
||||
});
|
||||
|
||||
describe("remove", () => {
|
||||
it("should remove a menu item by ID", async () => {
|
||||
mockMenuService.remove.mockResolvedValue({
|
||||
success: true,
|
||||
id: "menu-item-1",
|
||||
});
|
||||
|
||||
const result = await controller.remove("menu-item-1");
|
||||
|
||||
expect(service.remove).toHaveBeenCalledWith("menu-item-1");
|
||||
expect(result).toEqual({ success: true, id: "menu-item-1" });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -8,55 +8,55 @@ import {
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { MenuService } from './menu.service';
|
||||
} 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';
|
||||
} 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')
|
||||
@ApiTags("Menu - مدیریت منو")
|
||||
@Controller("menu")
|
||||
export class MenuController {
|
||||
constructor(private readonly menuService: MenuService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'دریافت منو عمومی بر اساس نوع' })
|
||||
@ApiOperation({ summary: "دریافت منو عمومی بر اساس نوع" })
|
||||
@ApiQuery({
|
||||
name: 'type',
|
||||
name: "type",
|
||||
required: true,
|
||||
description: 'HEADER | FOOTER_COL1 | FOOTER_COL2 | FOOTER_COL3',
|
||||
description: "HEADER | FOOTER_COL1 | FOOTER_COL2 | FOOTER_COL3",
|
||||
})
|
||||
findByType(@Query('type') type: string) {
|
||||
findByType(@Query("type") type: string) {
|
||||
return this.menuService.findByType(type);
|
||||
}
|
||||
|
||||
@Get('type/:type')
|
||||
@ApiOperation({ summary: 'دریافت منو عمومی با پارامتر مسیر' })
|
||||
findByTypeParam(@Param('type') type: string) {
|
||||
@Get("type/:type")
|
||||
@ApiOperation({ summary: "دریافت منو عمومی با پارامتر مسیر" })
|
||||
findByTypeParam(@Param("type") type: string) {
|
||||
return this.menuService.findByType(type);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@Roles("Admin")
|
||||
@ApiBearerAuth()
|
||||
@Get('admin')
|
||||
@ApiOperation({ summary: 'دریافت تمام آیتمهای منو (ادمین)' })
|
||||
@ApiQuery({ name: 'type', required: false })
|
||||
findAllAdmin(@Query('type') type?: string) {
|
||||
@Get("admin")
|
||||
@ApiOperation({ summary: "دریافت تمام آیتمهای منو (ادمین)" })
|
||||
@ApiQuery({ name: "type", required: false })
|
||||
findAllAdmin(@Query("type") type?: string) {
|
||||
return this.menuService.findAllAdmin(type);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@Roles("Admin")
|
||||
@ApiBearerAuth()
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'ایجاد آیتم منو جدید' })
|
||||
@ApiOperation({ summary: "ایجاد آیتم منو جدید" })
|
||||
create(
|
||||
@Body()
|
||||
body: {
|
||||
@@ -75,21 +75,21 @@ export class MenuController {
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@Roles("Admin")
|
||||
@ApiBearerAuth()
|
||||
@Put('reorder')
|
||||
@ApiOperation({ summary: 'مرتبسازی آیتمهای منو' })
|
||||
@Put("reorder")
|
||||
@ApiOperation({ summary: "مرتبسازی آیتمهای منو" })
|
||||
reorder(@Body() body: { items: { id: string; order: number }[] }) {
|
||||
return this.menuService.reorder(body.items);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@Roles("Admin")
|
||||
@ApiBearerAuth()
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: 'ویرایش آیتم منو' })
|
||||
@Put(":id")
|
||||
@ApiOperation({ summary: "ویرایش آیتم منو" })
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
@Param("id") id: string,
|
||||
@Body()
|
||||
body: Partial<{
|
||||
menuType: string;
|
||||
@@ -107,11 +107,11 @@ export class MenuController {
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@Roles("Admin")
|
||||
@ApiBearerAuth()
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'حذف آیتم منو' })
|
||||
remove(@Param('id') id: string) {
|
||||
@Delete(":id")
|
||||
@ApiOperation({ summary: "حذف آیتم منو" })
|
||||
remove(@Param("id") id: string) {
|
||||
return this.menuService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MenuController } from './menu.controller';
|
||||
import { MenuService } from './menu.service';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { MenuController } from "./menu.controller";
|
||||
import { MenuService } from "./menu.service";
|
||||
|
||||
@Module({
|
||||
controllers: [MenuController],
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { MenuService } from "./menu.service";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
import { NotFoundException } from "@nestjs/common";
|
||||
|
||||
describe("MenuService", () => {
|
||||
let service: MenuService;
|
||||
|
||||
const mockPrisma = {
|
||||
menuItem: {
|
||||
count: jest.fn(),
|
||||
findMany: jest.fn(),
|
||||
findUnique: jest.fn(),
|
||||
create: jest.fn(),
|
||||
createMany: jest.fn(),
|
||||
update: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
deleteMany: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
MenuService,
|
||||
{
|
||||
provide: PrismaService,
|
||||
useValue: mockPrisma,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<MenuService>(MenuService);
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe("findByType", () => {
|
||||
it("should return active parent menu items with active children ordered by order", async () => {
|
||||
const items = [
|
||||
{
|
||||
id: "m1",
|
||||
label: "محصولات",
|
||||
children: [{ id: "m1-1", label: "مفاصل" }],
|
||||
},
|
||||
];
|
||||
mockPrisma.menuItem.findMany.mockResolvedValue(items);
|
||||
|
||||
const result = await service.findByType("HEADER");
|
||||
expect(mockPrisma.menuItem.findMany).toHaveBeenCalledWith({
|
||||
where: { menuType: "HEADER", isActive: true, parentId: null },
|
||||
orderBy: { order: "asc" },
|
||||
include: {
|
||||
children: {
|
||||
where: { isActive: true },
|
||||
orderBy: { order: "asc" },
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(result).toEqual(items);
|
||||
});
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
it("should create menu item", async () => {
|
||||
const dto = { menuType: "HEADER", label: "درباره ما", href: "/about" };
|
||||
mockPrisma.menuItem.create.mockResolvedValue({ id: "m2", ...dto });
|
||||
|
||||
const result = await service.create(dto);
|
||||
expect(mockPrisma.menuItem.create).toHaveBeenCalledWith({ data: dto });
|
||||
expect(result.id).toBe("m2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("update", () => {
|
||||
it("should throw NotFoundException if item does not exist", async () => {
|
||||
mockPrisma.menuItem.findUnique.mockResolvedValue(null);
|
||||
await expect(
|
||||
service.update("invalid-id", { label: "تست" }),
|
||||
).rejects.toThrow(NotFoundException);
|
||||
});
|
||||
|
||||
it("should update menu item successfully", async () => {
|
||||
mockPrisma.menuItem.findUnique.mockResolvedValue({ id: "m1" });
|
||||
mockPrisma.menuItem.update.mockResolvedValue({ id: "m1", label: "جدید" });
|
||||
|
||||
const result = await service.update("m1", { label: "جدید" });
|
||||
expect(result.label).toBe("جدید");
|
||||
});
|
||||
});
|
||||
|
||||
describe("remove", () => {
|
||||
it("should throw NotFoundException if item does not exist", async () => {
|
||||
mockPrisma.menuItem.findUnique.mockResolvedValue(null);
|
||||
await expect(service.remove("invalid-id")).rejects.toThrow(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
|
||||
it("should delete children first and then delete parent item", async () => {
|
||||
mockPrisma.menuItem.findUnique.mockResolvedValue({ id: "m1" });
|
||||
mockPrisma.menuItem.deleteMany.mockResolvedValue({ count: 2 });
|
||||
mockPrisma.menuItem.delete.mockResolvedValue({ id: "m1" });
|
||||
|
||||
const result = await service.remove("m1");
|
||||
expect(mockPrisma.menuItem.deleteMany).toHaveBeenCalledWith({
|
||||
where: { parentId: "m1" },
|
||||
});
|
||||
expect(mockPrisma.menuItem.delete).toHaveBeenCalledWith({
|
||||
where: { id: "m1" },
|
||||
});
|
||||
expect(result.id).toBe("m1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("reorder", () => {
|
||||
it("should update orders for all items", async () => {
|
||||
mockPrisma.menuItem.update.mockResolvedValue({});
|
||||
const items = [
|
||||
{ id: "m1", order: 1 },
|
||||
{ id: "m2", order: 2 },
|
||||
];
|
||||
|
||||
const result = await service.reorder(items);
|
||||
expect(mockPrisma.menuItem.update).toHaveBeenCalledTimes(2);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable, NotFoundException, OnModuleInit } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { Injectable, NotFoundException, OnModuleInit } from "@nestjs/common";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
|
||||
export type MenuType = 'HEADER' | 'FOOTER_COL1' | 'FOOTER_COL2' | 'FOOTER_COL3';
|
||||
export type MenuType = "HEADER" | "FOOTER_COL1" | "FOOTER_COL2" | "FOOTER_COL3";
|
||||
|
||||
@Injectable()
|
||||
export class MenuService implements OnModuleInit {
|
||||
@@ -12,7 +12,7 @@ export class MenuService implements OnModuleInit {
|
||||
await this.seedIfEmpty();
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
'[MenuService] seedIfEmpty skipped during module init:',
|
||||
"[MenuService] seedIfEmpty skipped during module init:",
|
||||
err?.message || err,
|
||||
);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ export class MenuService implements OnModuleInit {
|
||||
if (count > 0) return;
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
'[MenuService] menuItem table not accessible yet:',
|
||||
"[MenuService] menuItem table not accessible yet:",
|
||||
err?.message || err,
|
||||
);
|
||||
return;
|
||||
@@ -33,104 +33,104 @@ export class MenuService implements OnModuleInit {
|
||||
// Seed with comprehensive hierarchical site navigation matching application
|
||||
const headerGroups = [
|
||||
{
|
||||
label: 'دستهبندی درمانی محصولات',
|
||||
href: '/shop?view=symptoms',
|
||||
label: "دستهبندی درمانی محصولات",
|
||||
href: "/shop?view=symptoms",
|
||||
order: 1,
|
||||
icon: 'Pill',
|
||||
icon: "Pill",
|
||||
children: [
|
||||
{ label: 'مفاصل و استخوان', href: '/shop?category=joints', order: 1 },
|
||||
{ label: "مفاصل و استخوان", href: "/shop?category=joints", order: 1 },
|
||||
{
|
||||
label: 'تقویت سیستم ایمنی و گوارش',
|
||||
href: '/shop?category=immune',
|
||||
label: "تقویت سیستم ایمنی و گوارش",
|
||||
href: "/shop?category=immune",
|
||||
order: 2,
|
||||
},
|
||||
{
|
||||
label: 'ویتامینها و انرژیبخشها',
|
||||
href: '/shop?category=energy',
|
||||
label: "ویتامینها و انرژیبخشها",
|
||||
href: "/shop?category=energy",
|
||||
order: 3,
|
||||
},
|
||||
{
|
||||
label: 'مراقبتهای ویژه (پوست، دندان و چشم)',
|
||||
href: '/shop?category=special-care',
|
||||
label: "مراقبتهای ویژه (پوست، دندان و چشم)",
|
||||
href: "/shop?category=special-care",
|
||||
order: 4,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'فروشگاه و محصولات',
|
||||
href: '/shop',
|
||||
label: "فروشگاه و محصولات",
|
||||
href: "/shop",
|
||||
order: 2,
|
||||
icon: 'ShoppingBag',
|
||||
icon: "ShoppingBag",
|
||||
children: [
|
||||
{ label: 'فروشگاه تخصصی محصولات کنینا', href: '/shop', order: 1 },
|
||||
{ label: "فروشگاه تخصصی محصولات کنینا", href: "/shop", order: 1 },
|
||||
{
|
||||
label: 'کاتالوگ دیجیتال و راهنمای بالینی',
|
||||
href: '/catalog',
|
||||
label: "کاتالوگ دیجیتال و راهنمای بالینی",
|
||||
href: "/catalog",
|
||||
order: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'دانشنامه و آکادمی',
|
||||
href: '/wiki',
|
||||
label: "دانشنامه و آکادمی",
|
||||
href: "/wiki",
|
||||
order: 3,
|
||||
icon: 'BookOpen',
|
||||
icon: "BookOpen",
|
||||
children: [
|
||||
{ label: 'دانشنامه علمی کنینا', href: '/wiki', order: 1 },
|
||||
{ label: 'مجله سلامت پت (وبلاگ)', href: '/blog', order: 2 },
|
||||
{ label: "دانشنامه علمی کنینا", href: "/wiki", order: 1 },
|
||||
{ label: "مجله سلامت پت (وبلاگ)", href: "/blog", order: 2 },
|
||||
{
|
||||
label: 'آکادمی ویدئویی و مشاوره دامپزشک',
|
||||
href: '/videos',
|
||||
label: "آکادمی ویدئویی و مشاوره دامپزشک",
|
||||
href: "/videos",
|
||||
order: 3,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'ابزارهای هوشمند',
|
||||
href: '/profile',
|
||||
label: "ابزارهای هوشمند",
|
||||
href: "/profile",
|
||||
order: 4,
|
||||
icon: 'Sparkles',
|
||||
icon: "Sparkles",
|
||||
children: [
|
||||
{ label: 'شناسنامه و سوابق سلامت پت', href: '/profile', order: 1 },
|
||||
{ label: 'پایش هوشمند مصرف مکملها', href: '/dashboard', order: 2 },
|
||||
{ label: "شناسنامه و سوابق سلامت پت", href: "/profile", order: 1 },
|
||||
{ label: "پایش هوشمند مصرف مکملها", href: "/dashboard", order: 2 },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'درباره کنینا و تماس',
|
||||
href: '/about',
|
||||
label: "درباره کنینا و تماس",
|
||||
href: "/about",
|
||||
order: 5,
|
||||
icon: 'Building2',
|
||||
icon: "Building2",
|
||||
children: [
|
||||
{ label: 'درباره کمپانی کنینا آلمان', href: '/about', order: 1 },
|
||||
{ label: "درباره کمپانی کنینا آلمان", href: "/about", order: 1 },
|
||||
{
|
||||
label: 'نمادهای اعتماد و مجوزهای رسمی',
|
||||
href: '/trust-seals',
|
||||
label: "نمادهای اعتماد و مجوزهای رسمی",
|
||||
href: "/trust-seals",
|
||||
order: 2,
|
||||
},
|
||||
{ label: 'تماس با مرکز پشتیبانی', href: '/contact', order: 3 },
|
||||
{ label: "تماس با مرکز پشتیبانی", href: "/contact", order: 3 },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const footerCol1 = [
|
||||
{ label: 'درباره کنینا آلمان', href: '/about', order: 1 },
|
||||
{ label: 'تماس با ما', href: '/contact', order: 2 },
|
||||
{ label: 'مجوزها و گواهیها', href: '/trust-seals', order: 3 },
|
||||
{ label: 'حریم خصوصی', href: '/privacy', order: 4 },
|
||||
{ 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: '/catalog', order: 2 },
|
||||
{ label: 'دانشنامه علمی', href: '/wiki', order: 3 },
|
||||
{ label: 'مجله سلامت پت (وبلاگ)', href: '/blog', order: 4 },
|
||||
{ label: "محصولات تخصصی", href: "/shop", order: 1 },
|
||||
{ label: "کاتالوگ دیجیتال", href: "/catalog", order: 2 },
|
||||
{ label: "دانشنامه علمی", href: "/wiki", order: 3 },
|
||||
{ label: "مجله سلامت پت (وبلاگ)", href: "/blog", order: 4 },
|
||||
];
|
||||
|
||||
const footerCol3 = [
|
||||
{ label: 'شناسنامه پتها', href: '/profile', order: 1 },
|
||||
{ label: 'سفارشات من', href: '/dashboard/orders', order: 2 },
|
||||
{ label: 'ردیابی سفارش', href: '/track', order: 3 },
|
||||
{ label: 'ورود / ثبتنام', href: '/?login=1', order: 4 },
|
||||
{ label: "شناسنامه پتها", href: "/profile", order: 1 },
|
||||
{ label: "سفارشات من", href: "/dashboard/orders", order: 2 },
|
||||
{ label: "ردیابی سفارش", href: "/track", order: 3 },
|
||||
{ label: "ورود / ثبتنام", href: "/?login=1", order: 4 },
|
||||
];
|
||||
|
||||
for (const group of headerGroups) {
|
||||
@@ -140,7 +140,7 @@ export class MenuService implements OnModuleInit {
|
||||
href: group.href,
|
||||
order: group.order,
|
||||
icon: group.icon,
|
||||
menuType: 'HEADER',
|
||||
menuType: "HEADER",
|
||||
isActive: true,
|
||||
isExternal: false,
|
||||
},
|
||||
@@ -153,7 +153,7 @@ export class MenuService implements OnModuleInit {
|
||||
href: child.href,
|
||||
order: child.order,
|
||||
parentId: parent.id,
|
||||
menuType: 'HEADER',
|
||||
menuType: "HEADER",
|
||||
isActive: true,
|
||||
isExternal: false,
|
||||
})),
|
||||
@@ -171,9 +171,9 @@ export class MenuService implements OnModuleInit {
|
||||
|
||||
await this.prisma.menuItem.createMany({
|
||||
data: [
|
||||
...createFooterItems(footerCol1, 'FOOTER_COL1'),
|
||||
...createFooterItems(footerCol2, 'FOOTER_COL2'),
|
||||
...createFooterItems(footerCol3, 'FOOTER_COL3'),
|
||||
...createFooterItems(footerCol1, "FOOTER_COL1"),
|
||||
...createFooterItems(footerCol2, "FOOTER_COL2"),
|
||||
...createFooterItems(footerCol3, "FOOTER_COL3"),
|
||||
],
|
||||
});
|
||||
}
|
||||
@@ -181,11 +181,11 @@ export class MenuService implements OnModuleInit {
|
||||
async findByType(menuType: string) {
|
||||
const items = await this.prisma.menuItem.findMany({
|
||||
where: { menuType, isActive: true, parentId: null },
|
||||
orderBy: { order: 'asc' },
|
||||
orderBy: { order: "asc" },
|
||||
include: {
|
||||
children: {
|
||||
where: { isActive: true },
|
||||
orderBy: { order: 'asc' },
|
||||
orderBy: { order: "asc" },
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -195,10 +195,10 @@ export class MenuService implements OnModuleInit {
|
||||
async findAllAdmin(menuType?: string) {
|
||||
return this.prisma.menuItem.findMany({
|
||||
where: menuType ? { menuType } : undefined,
|
||||
orderBy: [{ menuType: 'asc' }, { order: 'asc' }],
|
||||
orderBy: [{ menuType: "asc" }, { order: "asc" }],
|
||||
include: {
|
||||
children: {
|
||||
orderBy: { order: 'asc' },
|
||||
orderBy: { order: "asc" },
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -233,13 +233,13 @@ export class MenuService implements OnModuleInit {
|
||||
}>,
|
||||
) {
|
||||
const item = await this.prisma.menuItem.findUnique({ where: { id } });
|
||||
if (!item) throw new NotFoundException('Menu item not found');
|
||||
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');
|
||||
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 } });
|
||||
|
||||
Reference in new issue
Block a user