add editable menu items for companies
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "MenuItemType" AS ENUM (
|
||||
'INTERNAL_PAGE',
|
||||
'EXTERNAL_LINK',
|
||||
'PARENT_MENU',
|
||||
'SECTION_LABEL',
|
||||
'DIVIDER'
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "menu_items" (
|
||||
"id" TEXT NOT NULL,
|
||||
"systemKey" TEXT,
|
||||
"label" TEXT NOT NULL,
|
||||
"itemType" "MenuItemType" NOT NULL DEFAULT 'INTERNAL_PAGE',
|
||||
"routeOrUrl" TEXT,
|
||||
"icon" TEXT,
|
||||
"parentId" TEXT,
|
||||
"displayOrder" INTEGER NOT NULL DEFAULT 0,
|
||||
"openInNewTab" BOOLEAN NOT NULL DEFAULT false,
|
||||
"isRequired" BOOLEAN NOT NULL DEFAULT false,
|
||||
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdBy" TEXT,
|
||||
"updatedBy" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "menu_items_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "subscription_menu_items" (
|
||||
"id" TEXT NOT NULL,
|
||||
"plan" "Plan" NOT NULL,
|
||||
"menuItemId" TEXT NOT NULL,
|
||||
"displayOrder" INTEGER NOT NULL DEFAULT 0,
|
||||
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "subscription_menu_items_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "company_menu_items" (
|
||||
"id" TEXT NOT NULL,
|
||||
"companyId" TEXT NOT NULL,
|
||||
"menuItemId" TEXT NOT NULL,
|
||||
"displayOrder" INTEGER NOT NULL DEFAULT 0,
|
||||
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "company_menu_items_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "menu_item_role_visibility" (
|
||||
"id" TEXT NOT NULL,
|
||||
"menuItemId" TEXT NOT NULL,
|
||||
"role" "EmployeeRole" NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "menu_item_role_visibility_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "menu_items_systemKey_key" ON "menu_items"("systemKey");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "menu_items_parentId_idx" ON "menu_items"("parentId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "menu_items_isActive_displayOrder_idx" ON "menu_items"("isActive", "displayOrder");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "subscription_menu_items_plan_menuItemId_key" ON "subscription_menu_items"("plan", "menuItemId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "subscription_menu_items_menuItemId_idx" ON "subscription_menu_items"("menuItemId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "subscription_menu_items_plan_displayOrder_idx" ON "subscription_menu_items"("plan", "displayOrder");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "company_menu_items_companyId_menuItemId_key" ON "company_menu_items"("companyId", "menuItemId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "company_menu_items_menuItemId_idx" ON "company_menu_items"("menuItemId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "company_menu_items_companyId_displayOrder_idx" ON "company_menu_items"("companyId", "displayOrder");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "menu_item_role_visibility_menuItemId_role_key" ON "menu_item_role_visibility"("menuItemId", "role");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "menu_item_role_visibility_role_idx" ON "menu_item_role_visibility"("role");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "menu_items"
|
||||
ADD CONSTRAINT "menu_items_parentId_fkey"
|
||||
FOREIGN KEY ("parentId") REFERENCES "menu_items"("id")
|
||||
ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "subscription_menu_items"
|
||||
ADD CONSTRAINT "subscription_menu_items_menuItemId_fkey"
|
||||
FOREIGN KEY ("menuItemId") REFERENCES "menu_items"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "company_menu_items"
|
||||
ADD CONSTRAINT "company_menu_items_companyId_fkey"
|
||||
FOREIGN KEY ("companyId") REFERENCES "companies"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "company_menu_items"
|
||||
ADD CONSTRAINT "company_menu_items_menuItemId_fkey"
|
||||
FOREIGN KEY ("menuItemId") REFERENCES "menu_items"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "menu_item_role_visibility"
|
||||
ADD CONSTRAINT "menu_item_role_visibility_menuItemId_fkey"
|
||||
FOREIGN KEY ("menuItemId") REFERENCES "menu_items"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
WITH canonical_menu_items ("systemKey", "label", "itemType", "routeOrUrl", "icon", "displayOrder", "isRequired", "isActive") AS (
|
||||
VALUES
|
||||
('dashboard', 'Dashboard', 'INTERNAL_PAGE'::"MenuItemType", '/', 'LayoutDashboard', 10, true, true),
|
||||
('fleet', 'Fleet', 'INTERNAL_PAGE'::"MenuItemType", '/fleet', 'Car', 20, true, true),
|
||||
('reservations', 'Booking', 'INTERNAL_PAGE'::"MenuItemType", '/reservations', 'Calendar', 30, true, true),
|
||||
('customers', 'Customers', 'INTERNAL_PAGE'::"MenuItemType", '/customers', 'Users', 40, false, true),
|
||||
('subscription', 'Subscription', 'INTERNAL_PAGE'::"MenuItemType", '/subscription', 'CreditCard', 50, true, true),
|
||||
('contracts', 'Contracts', 'INTERNAL_PAGE'::"MenuItemType", '/contracts', 'FileText', 60, false, true),
|
||||
('notifications', 'Notifications', 'INTERNAL_PAGE'::"MenuItemType", '/notifications', 'Bell', 70, false, true),
|
||||
('settings', 'Settings', 'INTERNAL_PAGE'::"MenuItemType", '/settings', 'Settings', 80, false, true),
|
||||
('onlineReservations', 'Online Reservations', 'INTERNAL_PAGE'::"MenuItemType", '/online-reservations', 'Globe', 90, false, true),
|
||||
('team', 'Team', 'INTERNAL_PAGE'::"MenuItemType", '/team', 'UserPlus', 100, false, true),
|
||||
('offers', 'Offers', 'INTERNAL_PAGE'::"MenuItemType", '/offers', 'Tag', 110, false, true),
|
||||
('reports', 'Reports', 'INTERNAL_PAGE'::"MenuItemType", '/reports', 'BarChart2', 120, false, true),
|
||||
('billing', 'Customer Billing', 'INTERNAL_PAGE'::"MenuItemType", '/billing', 'CreditCard', 130, false, true),
|
||||
('reviews', 'Reviews', 'INTERNAL_PAGE'::"MenuItemType", '/reviews', 'Star', 140, false, true),
|
||||
('complaints', 'Complaints', 'INTERNAL_PAGE'::"MenuItemType", '/complaints', 'AlertTriangle', 150, false, true)
|
||||
)
|
||||
INSERT INTO "menu_items" (
|
||||
"id",
|
||||
"systemKey",
|
||||
"label",
|
||||
"itemType",
|
||||
"routeOrUrl",
|
||||
"icon",
|
||||
"displayOrder",
|
||||
"openInNewTab",
|
||||
"isRequired",
|
||||
"isActive",
|
||||
"createdBy",
|
||||
"updatedBy"
|
||||
)
|
||||
SELECT
|
||||
'menu_' || "systemKey",
|
||||
"systemKey",
|
||||
"label",
|
||||
"itemType",
|
||||
"routeOrUrl",
|
||||
"icon",
|
||||
"displayOrder",
|
||||
false,
|
||||
"isRequired",
|
||||
"isActive",
|
||||
'system',
|
||||
'system'
|
||||
FROM canonical_menu_items
|
||||
ON CONFLICT ("systemKey") DO UPDATE
|
||||
SET
|
||||
"label" = EXCLUDED."label",
|
||||
"itemType" = EXCLUDED."itemType",
|
||||
"routeOrUrl" = EXCLUDED."routeOrUrl",
|
||||
"icon" = EXCLUDED."icon",
|
||||
"displayOrder" = EXCLUDED."displayOrder",
|
||||
"isRequired" = EXCLUDED."isRequired",
|
||||
"isActive" = EXCLUDED."isActive",
|
||||
"updatedBy" = 'system',
|
||||
"updatedAt" = CURRENT_TIMESTAMP;
|
||||
|
||||
DELETE FROM "subscription_menu_items"
|
||||
WHERE "menuItemId" IN (
|
||||
SELECT "id"
|
||||
FROM "menu_items"
|
||||
WHERE "systemKey" IN (
|
||||
'dashboard',
|
||||
'fleet',
|
||||
'reservations',
|
||||
'customers',
|
||||
'subscription',
|
||||
'contracts',
|
||||
'notifications',
|
||||
'settings',
|
||||
'onlineReservations',
|
||||
'team',
|
||||
'offers',
|
||||
'reports',
|
||||
'billing',
|
||||
'reviews',
|
||||
'complaints'
|
||||
)
|
||||
);
|
||||
|
||||
WITH canonical_subscription_assignments ("systemKey", "plan", "displayOrder") AS (
|
||||
VALUES
|
||||
('dashboard', 'STARTER'::"Plan", 10),
|
||||
('fleet', 'STARTER'::"Plan", 20),
|
||||
('reservations', 'STARTER'::"Plan", 30),
|
||||
('customers', 'STARTER'::"Plan", 40),
|
||||
('subscription', 'STARTER'::"Plan", 50),
|
||||
('contracts', 'STARTER'::"Plan", 60),
|
||||
('notifications', 'STARTER'::"Plan", 70),
|
||||
('settings', 'STARTER'::"Plan", 80),
|
||||
|
||||
('dashboard', 'GROWTH'::"Plan", 10),
|
||||
('fleet', 'GROWTH'::"Plan", 20),
|
||||
('reservations', 'GROWTH'::"Plan", 30),
|
||||
('customers', 'GROWTH'::"Plan", 40),
|
||||
('subscription', 'GROWTH'::"Plan", 50),
|
||||
('contracts', 'GROWTH'::"Plan", 60),
|
||||
('notifications', 'GROWTH'::"Plan", 70),
|
||||
('settings', 'GROWTH'::"Plan", 80),
|
||||
('onlineReservations', 'GROWTH'::"Plan", 90),
|
||||
('team', 'GROWTH'::"Plan", 100),
|
||||
('offers', 'GROWTH'::"Plan", 110),
|
||||
('reports', 'GROWTH'::"Plan", 120),
|
||||
('billing', 'GROWTH'::"Plan", 130),
|
||||
('reviews', 'GROWTH'::"Plan", 140),
|
||||
('complaints', 'GROWTH'::"Plan", 150),
|
||||
|
||||
('dashboard', 'PRO'::"Plan", 10),
|
||||
('fleet', 'PRO'::"Plan", 20),
|
||||
('reservations', 'PRO'::"Plan", 30),
|
||||
('customers', 'PRO'::"Plan", 40),
|
||||
('subscription', 'PRO'::"Plan", 50),
|
||||
('contracts', 'PRO'::"Plan", 60),
|
||||
('notifications', 'PRO'::"Plan", 70),
|
||||
('settings', 'PRO'::"Plan", 80),
|
||||
('onlineReservations', 'PRO'::"Plan", 90),
|
||||
('team', 'PRO'::"Plan", 100),
|
||||
('offers', 'PRO'::"Plan", 110),
|
||||
('reports', 'PRO'::"Plan", 120),
|
||||
('billing', 'PRO'::"Plan", 130),
|
||||
('reviews', 'PRO'::"Plan", 140),
|
||||
('complaints', 'PRO'::"Plan", 150)
|
||||
)
|
||||
INSERT INTO "subscription_menu_items" (
|
||||
"id",
|
||||
"plan",
|
||||
"menuItemId",
|
||||
"displayOrder",
|
||||
"isActive"
|
||||
)
|
||||
SELECT
|
||||
'menu_sub_' || lower(csa."plan"::text) || '_' || csa."systemKey",
|
||||
csa."plan",
|
||||
mi."id",
|
||||
csa."displayOrder",
|
||||
true
|
||||
FROM canonical_subscription_assignments csa
|
||||
JOIN "menu_items" mi ON mi."systemKey" = csa."systemKey";
|
||||
|
||||
DELETE FROM "menu_item_role_visibility"
|
||||
WHERE "menuItemId" IN (
|
||||
SELECT "id"
|
||||
FROM "menu_items"
|
||||
WHERE "systemKey" IN (
|
||||
'dashboard',
|
||||
'fleet',
|
||||
'reservations',
|
||||
'customers',
|
||||
'subscription',
|
||||
'contracts',
|
||||
'notifications',
|
||||
'settings',
|
||||
'onlineReservations',
|
||||
'team',
|
||||
'offers',
|
||||
'reports',
|
||||
'billing',
|
||||
'reviews',
|
||||
'complaints'
|
||||
)
|
||||
);
|
||||
|
||||
WITH canonical_role_visibilities ("systemKey", "role") AS (
|
||||
VALUES
|
||||
('dashboard', 'OWNER'::"EmployeeRole"),
|
||||
('dashboard', 'MANAGER'::"EmployeeRole"),
|
||||
('dashboard', 'AGENT'::"EmployeeRole"),
|
||||
('fleet', 'OWNER'::"EmployeeRole"),
|
||||
('fleet', 'MANAGER'::"EmployeeRole"),
|
||||
('fleet', 'AGENT'::"EmployeeRole"),
|
||||
('reservations', 'OWNER'::"EmployeeRole"),
|
||||
('reservations', 'MANAGER'::"EmployeeRole"),
|
||||
('reservations', 'AGENT'::"EmployeeRole"),
|
||||
('customers', 'OWNER'::"EmployeeRole"),
|
||||
('customers', 'MANAGER'::"EmployeeRole"),
|
||||
('customers', 'AGENT'::"EmployeeRole"),
|
||||
('subscription', 'OWNER'::"EmployeeRole"),
|
||||
('contracts', 'OWNER'::"EmployeeRole"),
|
||||
('contracts', 'MANAGER'::"EmployeeRole"),
|
||||
('contracts', 'AGENT'::"EmployeeRole"),
|
||||
('notifications', 'OWNER'::"EmployeeRole"),
|
||||
('notifications', 'MANAGER'::"EmployeeRole"),
|
||||
('notifications', 'AGENT'::"EmployeeRole"),
|
||||
('settings', 'OWNER'::"EmployeeRole"),
|
||||
('onlineReservations', 'OWNER'::"EmployeeRole"),
|
||||
('onlineReservations', 'MANAGER'::"EmployeeRole"),
|
||||
('onlineReservations', 'AGENT'::"EmployeeRole"),
|
||||
('team', 'OWNER'::"EmployeeRole"),
|
||||
('team', 'MANAGER'::"EmployeeRole"),
|
||||
('team', 'AGENT'::"EmployeeRole"),
|
||||
('offers', 'OWNER'::"EmployeeRole"),
|
||||
('offers', 'MANAGER'::"EmployeeRole"),
|
||||
('reports', 'OWNER'::"EmployeeRole"),
|
||||
('reports', 'MANAGER'::"EmployeeRole"),
|
||||
('billing', 'OWNER'::"EmployeeRole"),
|
||||
('billing', 'MANAGER'::"EmployeeRole"),
|
||||
('reviews', 'OWNER'::"EmployeeRole"),
|
||||
('reviews', 'MANAGER'::"EmployeeRole"),
|
||||
('reviews', 'AGENT'::"EmployeeRole"),
|
||||
('complaints', 'OWNER'::"EmployeeRole"),
|
||||
('complaints', 'MANAGER'::"EmployeeRole"),
|
||||
('complaints', 'AGENT'::"EmployeeRole")
|
||||
)
|
||||
INSERT INTO "menu_item_role_visibility" (
|
||||
"id",
|
||||
"menuItemId",
|
||||
"role"
|
||||
)
|
||||
SELECT
|
||||
'menu_role_' || lower(crv."role"::text) || '_' || crv."systemKey",
|
||||
mi."id",
|
||||
crv."role"
|
||||
FROM canonical_role_visibilities crv
|
||||
JOIN "menu_items" mi ON mi."systemKey" = crv."systemKey";
|
||||
@@ -170,6 +170,14 @@ enum EmployeeRole {
|
||||
AGENT
|
||||
}
|
||||
|
||||
enum MenuItemType {
|
||||
INTERNAL_PAGE
|
||||
EXTERNAL_LINK
|
||||
PARENT_MENU
|
||||
SECTION_LABEL
|
||||
DIVIDER
|
||||
}
|
||||
|
||||
enum VehicleStatus {
|
||||
AVAILABLE
|
||||
RESERVED
|
||||
@@ -513,6 +521,7 @@ model Company {
|
||||
pricingRules PricingRule[]
|
||||
notifications Notification[] @relation("CompanyNotifications")
|
||||
complaints Complaint[]
|
||||
companyMenuItems CompanyMenuItem[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
@@ -1804,6 +1813,80 @@ model PlanFeature {
|
||||
@@map("plan_features")
|
||||
}
|
||||
|
||||
model MenuItem {
|
||||
id String @id @default(cuid())
|
||||
systemKey String? @unique
|
||||
label String
|
||||
itemType MenuItemType @default(INTERNAL_PAGE)
|
||||
routeOrUrl String?
|
||||
icon String?
|
||||
parentId String?
|
||||
parent MenuItem? @relation("MenuItemHierarchy", fields: [parentId], references: [id], onDelete: SetNull)
|
||||
children MenuItem[] @relation("MenuItemHierarchy")
|
||||
displayOrder Int @default(0)
|
||||
openInNewTab Boolean @default(false)
|
||||
isRequired Boolean @default(false)
|
||||
isActive Boolean @default(true)
|
||||
createdBy String?
|
||||
updatedBy String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
subscriptionAssignments SubscriptionMenuItem[]
|
||||
companyAssignments CompanyMenuItem[]
|
||||
roleVisibilities MenuItemRoleVisibility[]
|
||||
|
||||
@@index([parentId])
|
||||
@@index([isActive, displayOrder])
|
||||
@@map("menu_items")
|
||||
}
|
||||
|
||||
model SubscriptionMenuItem {
|
||||
id String @id @default(cuid())
|
||||
plan Plan
|
||||
menuItemId String
|
||||
menuItem MenuItem @relation(fields: [menuItemId], references: [id], onDelete: Cascade)
|
||||
displayOrder Int @default(0)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([plan, menuItemId])
|
||||
@@index([menuItemId])
|
||||
@@index([plan, displayOrder])
|
||||
@@map("subscription_menu_items")
|
||||
}
|
||||
|
||||
model CompanyMenuItem {
|
||||
id String @id @default(cuid())
|
||||
companyId String
|
||||
company Company @relation(fields: [companyId], references: [id], onDelete: Cascade)
|
||||
menuItemId String
|
||||
menuItem MenuItem @relation(fields: [menuItemId], references: [id], onDelete: Cascade)
|
||||
displayOrder Int @default(0)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([companyId, menuItemId])
|
||||
@@index([menuItemId])
|
||||
@@index([companyId, displayOrder])
|
||||
@@map("company_menu_items")
|
||||
}
|
||||
|
||||
model MenuItemRoleVisibility {
|
||||
id String @id @default(cuid())
|
||||
menuItemId String
|
||||
menuItem MenuItem @relation(fields: [menuItemId], references: [id], onDelete: Cascade)
|
||||
role EmployeeRole
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([menuItemId, role])
|
||||
@@index([role])
|
||||
@@map("menu_item_role_visibility")
|
||||
}
|
||||
|
||||
model PricingPromotion {
|
||||
id String @id @default(cuid())
|
||||
code String @unique
|
||||
|
||||
Reference in New Issue
Block a user