diff --git a/lib/defaults.ts b/lib/defaults.ts new file mode 100644 index 0000000..9f08499 --- /dev/null +++ b/lib/defaults.ts @@ -0,0 +1,69 @@ +import type { Category, Folder } from "./types" + +export const defaultCategories: Omit[] = [ + { + name: "Alimentation", + color: "#22c55e", + icon: "shopping-cart", + keywords: ["carrefour", "leclerc", "auchan", "lidl", "supermarche", "boulangerie", "restaurant"], + parentId: null, + }, + { + name: "Transport", + color: "#3b82f6", + icon: "car", + keywords: ["sncf", "ratp", "uber", "essence", "total", "parking", "peage"], + parentId: null, + }, + { + name: "Logement", + color: "#f59e0b", + icon: "home", + keywords: ["loyer", "edf", "engie", "eau", "assurance habitation"], + parentId: null, + }, + { + name: "Loisirs", + color: "#ec4899", + icon: "gamepad", + keywords: ["cinema", "netflix", "spotify", "fnac", "amazon"], + parentId: null, + }, + { + name: "Santé", + color: "#ef4444", + icon: "heart", + keywords: ["pharmacie", "medecin", "docteur", "hopital", "mutuelle"], + parentId: null, + }, + { + name: "Revenus", + color: "#10b981", + icon: "wallet", + keywords: ["salaire", "virement recu", "remboursement"], + parentId: null, + }, + { + name: "Abonnements", + color: "#8b5cf6", + icon: "repeat", + keywords: ["free", "orange", "sfr", "bouygues", "internet", "telephone"], + parentId: null, + }, + { + name: "Shopping", + color: "#06b6d4", + icon: "bag", + keywords: ["zara", "h&m", "decathlon", "ikea"], + parentId: null, + }, +] + +export const defaultRootFolder: Folder = { + id: "folder-root", + name: "Mes Comptes", + parentId: null, + color: "#6366f1", + icon: "folder", +} + diff --git a/lib/store.ts b/lib/store.ts index db63818..42c74b6 100644 --- a/lib/store.ts +++ b/lib/store.ts @@ -1,81 +1,15 @@ "use client" import type { BankingData, Account, Transaction, Folder, Category } from "./types" +import { defaultCategories, defaultRootFolder } from "./defaults" const STORAGE_KEY = "banking-app-data" -const defaultCategories: Category[] = [ - { - id: "cat-1", - name: "Alimentation", - color: "#22c55e", - icon: "shopping-cart", - keywords: ["carrefour", "leclerc", "auchan", "lidl", "supermarche", "boulangerie", "restaurant"], - parentId: null, - }, - { - id: "cat-2", - name: "Transport", - color: "#3b82f6", - icon: "car", - keywords: ["sncf", "ratp", "uber", "essence", "total", "parking", "peage"], - parentId: null, - }, - { - id: "cat-3", - name: "Logement", - color: "#f59e0b", - icon: "home", - keywords: ["loyer", "edf", "engie", "eau", "assurance habitation"], - parentId: null, - }, - { - id: "cat-4", - name: "Loisirs", - color: "#ec4899", - icon: "gamepad", - keywords: ["cinema", "netflix", "spotify", "fnac", "amazon"], - parentId: null, - }, - { - id: "cat-5", - name: "Santé", - color: "#ef4444", - icon: "heart", - keywords: ["pharmacie", "medecin", "docteur", "hopital", "mutuelle"], - parentId: null, - }, - { - id: "cat-6", - name: "Revenus", - color: "#10b981", - icon: "wallet", - keywords: ["salaire", "virement recu", "remboursement"], - parentId: null, - }, - { - id: "cat-7", - name: "Abonnements", - color: "#8b5cf6", - icon: "repeat", - keywords: ["free", "orange", "sfr", "bouygues", "internet", "telephone"], - parentId: null, - }, - { - id: "cat-8", - name: "Shopping", - color: "#06b6d4", - icon: "bag", - keywords: ["zara", "h&m", "decathlon", "ikea"], - parentId: null, - }, -] - const defaultData: BankingData = { accounts: [], transactions: [], - folders: [{ id: "folder-root", name: "Mes Comptes", parentId: null, color: "#6366f1", icon: "folder" }], - categories: defaultCategories, + folders: [defaultRootFolder], + categories: defaultCategories.map((cat, index) => ({ ...cat, id: `cat-${index + 1}` })), categoryRules: [], } diff --git a/prisma/seed.ts b/prisma/seed.ts index a1f8e58..5125747 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,80 +1,16 @@ import { PrismaClient } from "@prisma/client" +import { defaultCategories, defaultRootFolder } from "../lib/defaults" const prisma = new PrismaClient() -const defaultCategories = [ - { - name: "Alimentation", - color: "#22c55e", - icon: "shopping-cart", - keywords: ["carrefour", "leclerc", "auchan", "lidl", "supermarche", "boulangerie", "restaurant"], - parentId: null, - }, - { - name: "Transport", - color: "#3b82f6", - icon: "car", - keywords: ["sncf", "ratp", "uber", "essence", "total", "parking", "peage"], - parentId: null, - }, - { - name: "Logement", - color: "#f59e0b", - icon: "home", - keywords: ["loyer", "edf", "engie", "eau", "assurance habitation"], - parentId: null, - }, - { - name: "Loisirs", - color: "#ec4899", - icon: "gamepad", - keywords: ["cinema", "netflix", "spotify", "fnac", "amazon"], - parentId: null, - }, - { - name: "Santé", - color: "#ef4444", - icon: "heart", - keywords: ["pharmacie", "medecin", "docteur", "hopital", "mutuelle"], - parentId: null, - }, - { - name: "Revenus", - color: "#10b981", - icon: "wallet", - keywords: ["salaire", "virement recu", "remboursement"], - parentId: null, - }, - { - name: "Abonnements", - color: "#8b5cf6", - icon: "repeat", - keywords: ["free", "orange", "sfr", "bouygues", "internet", "telephone"], - parentId: null, - }, - { - name: "Shopping", - color: "#06b6d4", - icon: "bag", - keywords: ["zara", "h&m", "decathlon", "ikea"], - parentId: null, - }, -] - async function main() { console.log("Seeding database...") // Create root folder if it doesn't exist const rootFolder = await prisma.folder.upsert({ - where: { id: "folder-root" }, + where: { id: defaultRootFolder.id }, update: {}, - create: { - id: "folder-root", - name: "Mes Comptes", - parentId: null, - color: "#6366f1", - icon: "folder", - }, + create: defaultRootFolder, }) console.log("Root folder created:", rootFolder.name)