Initial commit: NovinTrades website monorepo.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-07-24 17:16:53 +03:30
co-authored by Cursor
commit 722a520e68
147 changed files with 15748 additions and 0 deletions
+169
View File
@@ -0,0 +1,169 @@
/** Brand category tree sourced from Categories.docx (hierarchy preserved). */
export type CategoryNode = {
name: string;
children?: CategoryNode[];
};
export const brandCategoryTree: CategoryNode[] = [
{
name: "Oil, Energy & Feedstocks",
children: [
{
name: "Oil Products",
children: [
{
name: "Fuels",
children: [
{ name: "Gasoline" },
{ name: "Diesel (EN590)" },
{ name: "Jet Fuel" },
{ name: "Kerosene" },
{ name: "LPG" },
],
},
{
name: "Industrial & Base Oils",
children: [
{ name: "Base Oil" },
{ name: "Engine Oil" },
{ name: "Hydraulic Oil" },
],
},
{
name: "Heavy & Residual Products",
children: [
{
name: "Bitumen",
children: [
{ name: "Bitumen 60/70" },
{ name: "Bitumen 80/100" },
{ name: "Bitumen 40/50" },
{ name: "VG 30" },
{ name: "VG 40" },
],
},
{ name: "Petroleum Coke" },
],
},
{
name: "Light Distillates & Solvents",
children: [
{ name: "Naphtha" },
{
name: "Solvents",
children: [
{ name: "White Spirit" },
{ name: "Industrial Solvents" },
],
},
],
},
],
},
{
name: "Energy Products",
children: [{ name: "Crude Oil" }, { name: "LNG" }],
},
],
},
{
name: "Industrial and Consumer Materials",
children: [
{
name: "Medical & Pharmaceutical",
children: [
{ name: "Medicines" },
{ name: "Medical Equipment" },
{ name: "Healthcare Products" },
],
},
{
name: "Textile & Apparel",
children: [
{ name: "Raw Textiles" },
{ name: "Fabrics" },
{ name: "Garments" },
],
},
{
name: "Materials & Crafted Goods",
children: [
{ name: "Titanium Dioxide" },
{ name: "Carbon Black" },
{ name: "Silica Powder" },
{ name: "Timber & Paper" },
{ name: "Leather" },
],
},
{ name: "Handicrafts" },
{
name: "Technology & Innovation",
children: [
{ name: "AI Solutions" },
{ name: "Smart Trade Platforms" },
{ name: "Industrial Technologies" },
],
},
],
},
{
name: "Chemicals & Petrochemicals",
children: [
{ name: "Urea" },
{ name: "Sulfur" },
{ name: "Methanol" },
{ name: "Paint & Coatings Materials" },
{ name: "Industrial Chemicals" },
],
},
{
name: "Metals, Mining & Minerals",
children: [
{ name: "Iron & Steel" },
{ name: "Non-Ferrous Metals" },
{
name: "Jewelry & Precious Stones",
children: [
{ name: "Gold Jewelry" },
{ name: "Silver Jewelry" },
{ name: "Precious Stones" },
{ name: "Semi-Precious Stones" },
],
},
{
name: "Minerals",
children: [
{ name: "Potash" },
{ name: "Limestone" },
{ name: "Kaolinite" },
{ name: "Feldspar" },
],
},
],
},
{
name: "Food Products",
children: [
{ name: "Dates" },
{ name: "Saffron" },
{ name: "Honey" },
{ name: "Fruits" },
{ name: "Palm Oil" },
{ name: "Beverages" },
{ name: "Confectionery" },
{ name: "Low Sodium Salt" },
{
name: "Seafood & Aquaculture",
children: [
{ name: "Shrimp" },
{ name: "Fish" },
{ name: "Aquaculture Products" },
],
},
],
},
{
name: "Building Materials",
children: [{ name: "Construction Stones" }],
},
];
@@ -0,0 +1,193 @@
-- CreateEnum
CREATE TYPE "VerificationStatus" AS ENUM ('PENDING', 'APPROVED', 'REJECTED');
-- CreateEnum
CREATE TYPE "CategoryScope" AS ENUM ('CONTENT', 'BRAND');
-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"email" TEXT NOT NULL,
"passwordHash" TEXT NOT NULL,
"name" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Category" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"scope" "CategoryScope" NOT NULL,
"parentId" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Category_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Blog" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"abstract" TEXT,
"content" TEXT NOT NULL DEFAULT '',
"imageUrl" TEXT,
"tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
"verificationStatus" "VerificationStatus" NOT NULL DEFAULT 'PENDING',
"authorId" TEXT NOT NULL,
"publishedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Blog_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "BlogCategory" (
"blogId" TEXT NOT NULL,
"categoryId" TEXT NOT NULL,
CONSTRAINT "BlogCategory_pkey" PRIMARY KEY ("blogId","categoryId")
);
-- CreateTable
CREATE TABLE "Reportage" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"businessOwner" TEXT NOT NULL,
"abstract" TEXT,
"content" TEXT NOT NULL DEFAULT '',
"imageUrl" TEXT,
"tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
"verificationStatus" "VerificationStatus" NOT NULL DEFAULT 'PENDING',
"authorId" TEXT NOT NULL,
"publishedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Reportage_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "ReportageCategory" (
"reportageId" TEXT NOT NULL,
"categoryId" TEXT NOT NULL,
CONSTRAINT "ReportageCategory_pkey" PRIMARY KEY ("reportageId","categoryId")
);
-- CreateTable
CREATE TABLE "Brand" (
"id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"abstract" TEXT,
"content" TEXT NOT NULL DEFAULT '',
"imageUrl" TEXT,
"tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
"country" TEXT NOT NULL,
"address" TEXT,
"contacts" JSONB NOT NULL DEFAULT '[]',
"verificationStatus" "VerificationStatus" NOT NULL DEFAULT 'PENDING',
"authorId" TEXT NOT NULL,
"publishedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Brand_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "BrandCategory" (
"brandId" TEXT NOT NULL,
"categoryId" TEXT NOT NULL,
CONSTRAINT "BrandCategory_pkey" PRIMARY KEY ("brandId","categoryId")
);
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
-- CreateIndex
CREATE INDEX "Category_parentId_idx" ON "Category"("parentId");
-- CreateIndex
CREATE INDEX "Category_scope_idx" ON "Category"("scope");
-- CreateIndex
CREATE UNIQUE INDEX "Category_scope_slug_key" ON "Category"("scope", "slug");
-- CreateIndex
CREATE UNIQUE INDEX "Blog_slug_key" ON "Blog"("slug");
-- CreateIndex
CREATE INDEX "Blog_authorId_idx" ON "Blog"("authorId");
-- CreateIndex
CREATE INDEX "Blog_verificationStatus_idx" ON "Blog"("verificationStatus");
-- CreateIndex
CREATE INDEX "BlogCategory_categoryId_idx" ON "BlogCategory"("categoryId");
-- CreateIndex
CREATE UNIQUE INDEX "Reportage_slug_key" ON "Reportage"("slug");
-- CreateIndex
CREATE INDEX "Reportage_authorId_idx" ON "Reportage"("authorId");
-- CreateIndex
CREATE INDEX "Reportage_verificationStatus_idx" ON "Reportage"("verificationStatus");
-- CreateIndex
CREATE INDEX "ReportageCategory_categoryId_idx" ON "ReportageCategory"("categoryId");
-- CreateIndex
CREATE UNIQUE INDEX "Brand_slug_key" ON "Brand"("slug");
-- CreateIndex
CREATE INDEX "Brand_authorId_idx" ON "Brand"("authorId");
-- CreateIndex
CREATE INDEX "Brand_verificationStatus_idx" ON "Brand"("verificationStatus");
-- CreateIndex
CREATE INDEX "Brand_country_idx" ON "Brand"("country");
-- CreateIndex
CREATE INDEX "BrandCategory_categoryId_idx" ON "BrandCategory"("categoryId");
-- AddForeignKey
ALTER TABLE "Category" ADD CONSTRAINT "Category_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Category"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Blog" ADD CONSTRAINT "Blog_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BlogCategory" ADD CONSTRAINT "BlogCategory_blogId_fkey" FOREIGN KEY ("blogId") REFERENCES "Blog"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BlogCategory" ADD CONSTRAINT "BlogCategory_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Reportage" ADD CONSTRAINT "Reportage_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ReportageCategory" ADD CONSTRAINT "ReportageCategory_reportageId_fkey" FOREIGN KEY ("reportageId") REFERENCES "Reportage"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ReportageCategory" ADD CONSTRAINT "ReportageCategory_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Brand" ADD CONSTRAINT "Brand_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BrandCategory" ADD CONSTRAINT "BrandCategory_brandId_fkey" FOREIGN KEY ("brandId") REFERENCES "Brand"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "BrandCategory" ADD CONSTRAINT "BrandCategory_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Brand" ADD COLUMN "galleryUrls" TEXT[] DEFAULT ARRAY[]::TEXT[];
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Brand" ADD COLUMN "city" TEXT;
@@ -0,0 +1,80 @@
-- Merge duplicate categories that share the same slug across scopes,
-- then drop scope so one Category table serves blog, reportage, and brand.
CREATE TEMP TABLE category_keepers AS
SELECT DISTINCT ON (slug) id AS keeper_id, slug
FROM "Category"
ORDER BY slug, "createdAt" ASC, id ASC;
CREATE TEMP TABLE category_dupes AS
SELECT c.id AS dupe_id, k.keeper_id
FROM "Category" c
JOIN category_keepers k ON k.slug = c.slug
WHERE c.id <> k.keeper_id;
-- BlogCategory: remap to keeper when no conflict
UPDATE "BlogCategory" bc
SET "categoryId" = d.keeper_id
FROM category_dupes d
WHERE bc."categoryId" = d.dupe_id
AND NOT EXISTS (
SELECT 1
FROM "BlogCategory" x
WHERE x."blogId" = bc."blogId"
AND x."categoryId" = d.keeper_id
);
DELETE FROM "BlogCategory" bc
USING category_dupes d
WHERE bc."categoryId" = d.dupe_id;
-- ReportageCategory
UPDATE "ReportageCategory" rc
SET "categoryId" = d.keeper_id
FROM category_dupes d
WHERE rc."categoryId" = d.dupe_id
AND NOT EXISTS (
SELECT 1
FROM "ReportageCategory" x
WHERE x."reportageId" = rc."reportageId"
AND x."categoryId" = d.keeper_id
);
DELETE FROM "ReportageCategory" rc
USING category_dupes d
WHERE rc."categoryId" = d.dupe_id;
-- BrandCategory
UPDATE "BrandCategory" bc
SET "categoryId" = d.keeper_id
FROM category_dupes d
WHERE bc."categoryId" = d.dupe_id
AND NOT EXISTS (
SELECT 1
FROM "BrandCategory" x
WHERE x."brandId" = bc."brandId"
AND x."categoryId" = d.keeper_id
);
DELETE FROM "BrandCategory" bc
USING category_dupes d
WHERE bc."categoryId" = d.dupe_id;
-- Point children of duplicates at the keeper
UPDATE "Category" c
SET "parentId" = d.keeper_id
FROM category_dupes d
WHERE c."parentId" = d.dupe_id;
DELETE FROM "Category" c
USING category_dupes d
WHERE c.id = d.dupe_id;
DROP INDEX IF EXISTS "Category_scope_slug_key";
DROP INDEX IF EXISTS "Category_scope_idx";
ALTER TABLE "Category" DROP COLUMN "scope";
CREATE UNIQUE INDEX "Category_slug_key" ON "Category"("slug");
DROP TYPE "CategoryScope";
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"
+143
View File
@@ -0,0 +1,143 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum VerificationStatus {
PENDING
APPROVED
REJECTED
}
model User {
id String @id @default(cuid())
email String @unique
passwordHash String
name String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
blogs Blog[]
reportages Reportage[]
brands Brand[]
}
/// Shared categories for blog, reportage, and brand
model Category {
id String @id @default(cuid())
name String
slug String @unique
parentId String?
parent Category? @relation("CategoryTree", fields: [parentId], references: [id], onDelete: SetNull)
children Category[] @relation("CategoryTree")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
blogs BlogCategory[]
reportages ReportageCategory[]
brands BrandCategory[]
@@index([parentId])
}
model Blog {
id String @id @default(cuid())
title String
slug String @unique
abstract String?
content String @default("")
imageUrl String?
tags String[] @default([])
verificationStatus VerificationStatus @default(PENDING)
authorId String
author User @relation(fields: [authorId], references: [id], onDelete: Restrict)
categories BlogCategory[]
publishedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([authorId])
@@index([verificationStatus])
}
model BlogCategory {
blogId String
categoryId String
blog Blog @relation(fields: [blogId], references: [id], onDelete: Cascade)
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
@@id([blogId, categoryId])
@@index([categoryId])
}
model Reportage {
id String @id @default(cuid())
title String
slug String @unique
businessOwner String
abstract String?
content String @default("")
imageUrl String?
tags String[] @default([])
verificationStatus VerificationStatus @default(PENDING)
authorId String
author User @relation(fields: [authorId], references: [id], onDelete: Restrict)
categories ReportageCategory[]
publishedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([authorId])
@@index([verificationStatus])
}
model ReportageCategory {
reportageId String
categoryId String
reportage Reportage @relation(fields: [reportageId], references: [id], onDelete: Cascade)
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
@@id([reportageId, categoryId])
@@index([categoryId])
}
model Brand {
id String @id @default(cuid())
title String
slug String @unique
abstract String?
content String @default("")
imageUrl String?
galleryUrls String[] @default([])
tags String[] @default([])
country String
city String?
address String?
/// [{ type: "phone"|"email"|..., value: string }]
contacts Json @default("[]")
verificationStatus VerificationStatus @default(PENDING)
authorId String
author User @relation(fields: [authorId], references: [id], onDelete: Restrict)
categories BrandCategory[]
publishedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([authorId])
@@index([verificationStatus])
@@index([country])
}
model BrandCategory {
brandId String
categoryId String
brand Brand @relation(fields: [brandId], references: [id], onDelete: Cascade)
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
@@id([brandId, categoryId])
@@index([categoryId])
}
+84
View File
@@ -0,0 +1,84 @@
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
import {
brandCategoryTree,
type CategoryNode,
} from "./data/brand-categories.js";
const prisma = new PrismaClient();
function slugify(value: string): string {
return value
.trim()
.toLowerCase()
.replace(/['"]/g, "")
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "")
.slice(0, 120);
}
async function uniqueSlug(base: string): Promise<string> {
let slug = slugify(base) || "category";
let candidate = slug;
let i = 2;
while (await prisma.category.findUnique({ where: { slug: candidate } })) {
candidate = `${slug}-${i}`;
i += 1;
}
return candidate;
}
async function insertTree(
nodes: CategoryNode[],
parentId: string | null = null,
): Promise<number> {
let count = 0;
for (const node of nodes) {
const slug = await uniqueSlug(node.name);
const created = await prisma.category.create({
data: {
name: node.name,
slug,
parentId,
},
});
count += 1;
if (node.children?.length) {
count += await insertTree(node.children, created.id);
}
}
return count;
}
async function main() {
const passwordHash = await bcrypt.hash("admin123", 10);
const admin = await prisma.user.upsert({
where: { email: "admin@novintrades.com" },
update: {},
create: {
email: "admin@novintrades.com",
name: "Admin",
passwordHash,
},
});
await prisma.blogCategory.deleteMany();
await prisma.reportageCategory.deleteMany();
await prisma.brandCategory.deleteMany();
await prisma.category.deleteMany();
const treeCount = await insertTree(brandCategoryTree);
console.log(`Seeded admin: ${admin.email}`);
console.log(`Seeded ${treeCount} categories from Categories.docx hierarchy`);
}
main()
.catch((error) => {
console.error(error);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});