first commit

This commit is contained in:
NAME
2026-05-14 08:42:03 +00:00
commit 5f16ed135d
167 changed files with 29178 additions and 0 deletions
@@ -0,0 +1,26 @@
-- CreateTable
CREATE TABLE "Post" (
"id" SERIAL NOT NULL,
"title" TEXT NOT NULL,
"prompt" TEXT NOT NULL,
"content" TEXT NOT NULL,
"imageUrl" TEXT,
"style" TEXT NOT NULL DEFAULT 'general',
"status" TEXT NOT NULL DEFAULT 'pending',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Config" (
"id" SERIAL NOT NULL,
"key" TEXT NOT NULL,
"value" TEXT NOT NULL,
CONSTRAINT "Config_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Config_key_key" ON "Config"("key");
@@ -0,0 +1,11 @@
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"email" TEXT NOT NULL,
"name" TEXT,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
@@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE "Post" ADD COLUMN "isFbPostState" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "isTiktokPostState" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "isTwitterPostState" INTEGER NOT NULL DEFAULT 0;
@@ -0,0 +1,28 @@
-- CreateTable
CREATE TABLE "Trend" (
"id" SERIAL NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT,
"url" TEXT,
"score" INTEGER NOT NULL DEFAULT 0,
"source" TEXT NOT NULL,
"category" TEXT,
"tags" JSONB,
"engagement" JSONB,
"raw" JSONB,
"fingerprint" VARCHAR,
"sourceTimestamp" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Trend_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "Trend_score_idx" ON "Trend"("score");
-- CreateIndex
CREATE INDEX "Trend_category_idx" ON "Trend"("category");
-- CreateIndex
CREATE INDEX "Trend_sourceTimestamp_idx" ON "Trend"("sourceTimestamp");
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Trend" ALTER COLUMN "updatedAt" DROP NOT NULL,
ALTER COLUMN "updatedAt" SET DEFAULT CURRENT_TIMESTAMP;
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Trend" ADD COLUMN "geo" VARCHAR;
@@ -0,0 +1,2 @@
-- CreateIndex
CREATE INDEX "Trend_geo_idx" ON "Trend"("geo");
@@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE "Post" ADD COLUMN "draft" TEXT,
ADD COLUMN "model" TEXT,
ADD COLUMN "reviewNotes" TEXT,
ADD COLUMN "tokensUsed" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "tone" TEXT DEFAULT '';
+3
View File
@@ -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"
+14
View File
@@ -0,0 +1,14 @@
import {Global, Module} from '@nestjs/common';
import {PrismaService} from "./prisma.service";
@Global()
@Module({
imports: [],
providers: [
PrismaService,
],
exports: [PrismaService],
})
export class PrismaModule {
}
+39
View File
@@ -0,0 +1,39 @@
// src/prisma/prisma.service.ts
import {Injectable, OnModuleInit, OnModuleDestroy} from '@nestjs/common';
import {PrismaClient} from '../src/generated/prisma/client';
import {PrismaPg} from "@prisma/adapter-pg";
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
constructor() {
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL!,
});
super({adapter});
}
async onModuleInit() {
try {
await this.$connect();
console.log('✅ Đã kết nối Database thành công');
} catch (error) {
console.error('❌ Lỗi kết nối Database:', error);
}
}
async getManyAndCount<T>(
model: any,
args: any
) {
const [data, total] = await this.$transaction([
model.findMany(args),
model.count({ where: args.where }),
]);
return { data, total };
}
async onModuleDestroy() {
await this.$disconnect(); // Ngắt kết nối khi tắt app
}
}
+67
View File
@@ -0,0 +1,67 @@
// prisma/schema.prisma
generator client {
provider = "prisma-client"
moduleFormat = "cjs"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
model Post {
id Int @id @default(autoincrement())
title String
prompt String
content String @db.Text
imageUrl String?
style String @default("general")
tone String? @default("")
isFbPostState Int @default(0)
isTwitterPostState Int @default(0)
isTiktokPostState Int @default(0)
draft String? @db.Text
tokensUsed Int @default(0)
model String?
reviewNotes String?
status String @default("pending") // Các trạng thái: pending, approved, published, rejected
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Config {
id Int @id @default(autoincrement())
key String @unique
value String
}
model Trend {
id Int @id @default(autoincrement())
title String
description String? @db.Text
url String?
score Int @default(0)
source String @db.Text
category String?
geo String? @db.VarChar()
tags Json?
engagement Json?
raw Json?
fingerprint String? @db.VarChar()
sourceTimestamp DateTime?
createdAt DateTime @default(now())
updatedAt DateTime? @default(now())
@@index([score]) // Tạo index cho cột name
@@index([category]) // Tạo index cho cột name
@@index([geo]) // Tạo index cho cột name
@@index([sourceTimestamp]) // Tạo index cho cột name
}