297 lines
7.0 KiB
TypeScript
297 lines
7.0 KiB
TypeScript
const { PrismaClient } = require("@prisma/client");
|
|
const prisma = new PrismaClient();
|
|
// Navigation data structure
|
|
const navItemDatas = [
|
|
{
|
|
title: "Dashboard",
|
|
url: "/dashboard",
|
|
slug: "dashboard",
|
|
orderSeq: 1,
|
|
icon: "IconHome",
|
|
isActive: true,
|
|
subItems: [],
|
|
},
|
|
{
|
|
title: "Crime Management",
|
|
url: "/crime-management",
|
|
slug: "crime-management",
|
|
orderSeq: 2,
|
|
icon: "IconAlertTriangle",
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "Crime Overview",
|
|
url: "/crime-management/crime-overview",
|
|
slug: "crime-overview",
|
|
icon: "IconAlertTriangle",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
},
|
|
{
|
|
title: "Crime Categories",
|
|
url: "/crime-management/crime-categories",
|
|
slug: "crime-categories",
|
|
icon: "IconSettings",
|
|
orderSeq: 2,
|
|
isActive: true,
|
|
},
|
|
{
|
|
title: "Cases",
|
|
url: "/crime-management/crime-cases",
|
|
slug: "crime-cases",
|
|
icon: "IconAlertTriangle",
|
|
orderSeq: 3,
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "New Case",
|
|
url: "/crime-management/crime-cases/case-new",
|
|
slug: "new-case",
|
|
icon: "IconAlertTriangle",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
},
|
|
{
|
|
title: "Active Cases",
|
|
url: "/crime-management/crime-cases/case-active",
|
|
slug: "active-cases",
|
|
icon: "IconAlertTriangle",
|
|
orderSeq: 2,
|
|
isActive: true,
|
|
},
|
|
{
|
|
title: "Resolved Cases",
|
|
url: "/crime-management/crime-cases/case-closed",
|
|
slug: "resolved-cases",
|
|
icon: "IconAlertTriangle",
|
|
orderSeq: 3,
|
|
isActive: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: "Geographic Data",
|
|
url: "/geographic-data",
|
|
slug: "geographic-data",
|
|
orderSeq: 3,
|
|
icon: "IconMap",
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "Locations",
|
|
url: "/geographic-data/locations",
|
|
slug: "locations",
|
|
icon: "IconMap",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "Cities",
|
|
url: "/geographic-data/cities",
|
|
slug: "cities",
|
|
icon: "IconMap",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
},
|
|
{
|
|
title: "Districts",
|
|
url: "/geographic-data/districts",
|
|
slug: "districts",
|
|
icon: "IconMap",
|
|
orderSeq: 2,
|
|
isActive: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: "Geographic Info",
|
|
url: "/geographic-data/geographic-info",
|
|
slug: "geographic-info",
|
|
icon: "IconMap",
|
|
orderSeq: 3,
|
|
isActive: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: "Demographics",
|
|
url: "/demographics",
|
|
slug: "demographics",
|
|
orderSeq: 4,
|
|
icon: "IconDatabase",
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "Demographics Data",
|
|
url: "/demographics/demographics-data",
|
|
slug: "demographics-data",
|
|
icon: "IconDatabase",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: "User Management",
|
|
url: "/user-management",
|
|
slug: "user-management",
|
|
orderSeq: 5,
|
|
icon: "IconUsers",
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "Users",
|
|
url: "/user-management/users",
|
|
slug: "users",
|
|
icon: "IconUsers",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: "Communication",
|
|
url: "/communication",
|
|
slug: "communication",
|
|
orderSeq: 6,
|
|
icon: "IconMessageCircle",
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "Contact Messages",
|
|
url: "/communication/contact-messages",
|
|
slug: "contact-messages",
|
|
icon: "IconMessageCircle",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: "Settings",
|
|
url: "/settings",
|
|
slug: "settings",
|
|
orderSeq: 7,
|
|
icon: "IconSettings",
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "Navigation",
|
|
url: "/settings/navigation",
|
|
slug: "navigation",
|
|
icon: "IconMenu2",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
subItems: [
|
|
{
|
|
title: "Nav Items",
|
|
url: "/settings/navigation/nav-items",
|
|
slug: "nav-items",
|
|
icon: "IconMenu2",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
subSubItems: [
|
|
{
|
|
title: "Nav Sub Items",
|
|
url: "/settings/navigation/nav-sub-items",
|
|
slug: "nav-sub-items",
|
|
icon: "IconMenu2",
|
|
orderSeq: 1,
|
|
isActive: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
// Helper function to create path
|
|
const createPath = (currentPath: string, orderSeq: number): string => {
|
|
return currentPath ? `${currentPath}.${orderSeq}` : `${orderSeq}`;
|
|
};
|
|
|
|
// Helper function to calculate level from path
|
|
const calculateLevel = (path: string): number => {
|
|
return path.split(".").length - 1;
|
|
};
|
|
|
|
// Helper function to process navigation items recursively
|
|
const processNavigationItems = (
|
|
items: any[],
|
|
parentPath: string = ""
|
|
): any[] => {
|
|
const processed: any[] = [];
|
|
|
|
items.forEach((item) => {
|
|
const currentPath = createPath(parentPath, item.orderSeq);
|
|
|
|
const navigationItem = {
|
|
title: item.title,
|
|
url: item.url,
|
|
slug: item.slug,
|
|
icon: item.icon,
|
|
path: currentPath,
|
|
level: calculateLevel(currentPath),
|
|
isActive: item.isActive,
|
|
orderSeq: item.orderSeq,
|
|
};
|
|
|
|
processed.push(navigationItem);
|
|
|
|
// Process subItems if they exist
|
|
if (item.subItems && item.subItems.length > 0) {
|
|
const subItems = processNavigationItems(item.subItems, currentPath);
|
|
processed.push(...subItems);
|
|
}
|
|
|
|
// Process subSubItems if they exist (for backward compatibility)
|
|
if (item.subSubItems && item.subSubItems.length > 0) {
|
|
const subSubItems = processNavigationItems(item.subSubItems, currentPath);
|
|
processed.push(...subSubItems);
|
|
}
|
|
});
|
|
|
|
return processed;
|
|
};
|
|
|
|
async function main() {
|
|
// First, delete all existing navigation items
|
|
await prisma.navSubItem.deleteMany({});
|
|
await prisma.navItem.deleteMany({});
|
|
await prisma.navigationItem.deleteMany({});
|
|
|
|
// Process the navigation data
|
|
const navigationItems = processNavigationItems(navItemDatas);
|
|
|
|
// Create all navigation items
|
|
for (const item of navigationItems) {
|
|
await prisma.navigationItem.create({
|
|
data: {
|
|
title: item.title,
|
|
url: item.url,
|
|
slug: item.slug,
|
|
icon: item.icon,
|
|
path: item.path,
|
|
level: item.level,
|
|
isActive: item.isActive,
|
|
orderSeq: item.orderSeq,
|
|
},
|
|
});
|
|
}
|
|
|
|
console.log(`Created ${navigationItems.length} navigation items`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|