feat(sprint-5.5): add NestJS API, BlockMetaBar, block components + fix Vercel build
- Add vercel.json to build only apps/web (fix Vercel build failure) - NestJS API: BlocksModule, BlocksController, BlocksService with Prisma 7 - PostgreSQL migration: Block model (path, version, isInPreview) - BlockMetaBar component: inline version edit, API fetch with offline fallback - New block components: CeoBlock, ContactFormsBlock, FooterBlock, NewsBlock, ReviewsBlock - PreviewClient: fetch isInPreview from API, block visibility toggle - Pages updated: hero, doctors, ceo, contact-forms, contact, news, reviews - docker-compose: PostgreSQL on port 5434 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { BlocksModule } from './blocks/blocks.module';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
imports: [BlocksModule],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Controller, Get, Patch, Query, Body } from '@nestjs/common';
|
||||
import { BlocksService } from './blocks.service';
|
||||
|
||||
@Controller('blocks')
|
||||
export class BlocksController {
|
||||
constructor(private blocks: BlocksService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.blocks.findAll();
|
||||
}
|
||||
|
||||
@Get('by-path')
|
||||
findByPath(@Query('path') path: string) {
|
||||
return this.blocks.findByPath(path);
|
||||
}
|
||||
|
||||
@Patch('by-path')
|
||||
update(
|
||||
@Query('path') path: string,
|
||||
@Body() body: { version?: string; isInPreview?: boolean },
|
||||
) {
|
||||
return this.blocks.update(path, body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { BlocksController } from './blocks.controller';
|
||||
import { BlocksService } from './blocks.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Module({
|
||||
controllers: [BlocksController],
|
||||
providers: [BlocksService, PrismaService],
|
||||
})
|
||||
export class BlocksModule {}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class BlocksService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
findAll() {
|
||||
return this.prisma.block.findMany({ orderBy: { createdAt: 'asc' } });
|
||||
}
|
||||
|
||||
async findByPath(path: string) {
|
||||
const existing = await this.prisma.block.findUnique({ where: { path } });
|
||||
if (existing) return existing;
|
||||
return this.prisma.block.create({
|
||||
data: { path, name: path, version: 'v0.1', isInPreview: false },
|
||||
});
|
||||
}
|
||||
|
||||
update(path: string, data: { version?: string; isInPreview?: boolean }) {
|
||||
return this.prisma.block.update({ where: { path }, data });
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dotenv/config';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.enableCors({ origin: 'http://localhost:3001' });
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||
constructor() {
|
||||
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
||||
super({ adapter });
|
||||
}
|
||||
|
||||
async onModuleInit() {
|
||||
await this.$connect();
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
await this.$disconnect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user