- added settings page and function

- add Role Ring for avatar and display role for user nav
This commit is contained in:
2026-01-06 21:37:53 +07:00
parent 8146565d2c
commit a4e96fe045
64 changed files with 2828 additions and 726 deletions

22
prisma/data.ts Normal file
View File

@@ -0,0 +1,22 @@
export const settingsData = [
{
key: 'site_language',
value: 'en',
description: 'The language of the site',
},
{
key: 'site_name',
value: 'Fuware',
description: 'The name of the site',
},
{
key: 'site_description',
value: 'Fuware is a platform for creating and sharing stories',
description: 'The description of the site',
},
{
key: 'site_keywords',
value: 'story, line, share, stories',
description: 'The keywords of the site',
},
];

View File

@@ -0,0 +1,15 @@
-- CreateTable
CREATE TABLE "setting" (
"id" TEXT NOT NULL,
"key" TEXT NOT NULL,
"value" TEXT NOT NULL,
"description" TEXT NOT NULL,
"relation" TEXT NOT NULL DEFAULT 'admin',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "setting_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "setting_key_key" ON "setting"("key");

View File

@@ -9,7 +9,7 @@ datasource db {
}
model User {
id String @id
id String @id @default(uuid())
name String
email String
emailVerified Boolean @default(false)
@@ -32,7 +32,7 @@ model User {
}
model Session {
id String @id
id String @id @default(uuid())
expiresAt DateTime
token String
createdAt DateTime @default(now())
@@ -52,7 +52,7 @@ model Session {
}
model Account {
id String @id
id String @id @default(uuid())
accountId String
providerId String
userId String
@@ -72,7 +72,7 @@ model Account {
}
model Verification {
id String @id
id String @id @default(uuid())
identifier String
value String
expiresAt DateTime
@@ -84,7 +84,7 @@ model Verification {
}
model Organization {
id String @id
id String @id @default(uuid())
name String
slug String
logo String?
@@ -100,7 +100,7 @@ model Organization {
}
model Member {
id String @id
id String @id @default(uuid())
organizationId String
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
userId String
@@ -114,7 +114,7 @@ model Member {
}
model Invitation {
id String @id
id String @id @default(uuid())
organizationId String
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
email String
@@ -129,3 +129,16 @@ model Invitation {
@@index([email])
@@map("invitation")
}
model Setting {
id String @id @default(uuid())
key String @unique
value String
description String
relation String @default("admin")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("setting")
}

View File

@@ -1,25 +1,42 @@
import { PrismaPg } from '@prisma/adapter-pg'
import { PrismaClient } from '../src/generated/prisma/client.js'
import { auth } from '@/lib/auth'
import { auth } from '@/lib/auth';
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '../src/generated/prisma/client.js';
import { settingsData } from './data.js';
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL!,
})
});
const prisma = new PrismaClient({ adapter })
const prisma = new PrismaClient({ adapter });
async function main() {
console.log('🌱 Seeding database...')
console.log('🌱 Seeding database...');
// add admin user
await auth.api.createUser({
body: {
// check mail exists
const mailExists = await prisma.user.findFirst({
where: {
email: 'luu.dat.tham@gmail.com',
password: 'Th@m!S@m!040390',
name: 'Sam',
role: 'admin',
},
})
});
if (!mailExists) {
// add admin user
await auth.api.createUser({
body: {
email: 'luu.dat.tham@gmail.com',
password: 'Th@m!S@m!040390',
name: 'Sam',
role: 'admin',
},
});
}
console.log('---------------Created admin user-----------------');
await prisma.setting.deleteMany();
await prisma.setting.createMany({
data: settingsData,
skipDuplicates: true,
});
// // Clear existing todos
// await prisma.todo.deleteMany()
@@ -38,9 +55,9 @@ async function main() {
main()
.catch((e) => {
console.error('❌ Error seeding database:', e)
process.exit(1)
console.error('❌ Error seeding database:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect()
})
await prisma.$disconnect();
});