- Backend: POST /suggestions (público) + GET /suggestions (JWT admin) - Admin: página pública /sugerencias con formulario de sugerencias - schema.prisma: modelo suggestions - AuthGuard + Sidebar: /sugerencias como ruta pública Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
27 lines
714 B
TypeScript
27 lines
714 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
|
|
@Injectable()
|
|
export class SuggestionsService {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
create(data: { name?: string; message: string }) {
|
|
return this.prisma.suggestions.create({ data });
|
|
}
|
|
|
|
findAll(page = 1, limit = 50) {
|
|
const skip = (page - 1) * limit;
|
|
return Promise.all([
|
|
this.prisma.suggestions.findMany({
|
|
skip,
|
|
take: limit,
|
|
orderBy: { created_at: 'desc' },
|
|
}),
|
|
this.prisma.suggestions.count(),
|
|
]).then(([data, total]) => ({
|
|
data,
|
|
meta: { total, page, limit, totalPages: Math.ceil(total / limit) || 1 },
|
|
}));
|
|
}
|
|
}
|