Frontend:
- apps/web (Vite+TS, TanStack Router/Query, shadcn/ui @cfdm/ui base-nova)
- 10 страниц в routes/_auth/, Recharts через shadcn Chart, lucide-react
- формы на RHF + Zod (FormSheet/FormField)
- удалены Tabler, Chart.js, react-router-dom
Backend (параллельный трек):
- apps/api (Fastify 5 + Drizzle + better-sqlite3)
- packages/db: Drizzle-схема и repositories по сущностям
- packages/shared: Zod-контракты
- роуты с валидацией и единым форматом ошибок { error: { code, message } }
- sync/backup — заглушки 501 (billmanager-адаптеры переносятся отдельно)
- legacy Express оставлен как runtime по умолчанию (RUNTIME=express)
Infra:
- Dockerfile multi-stage под pnpm workspaces
- .dockerignore и docker-compose обновлены под monorepo
Rules:
- удалены нерелевантные правила (rust, cloudflare, server/frontend-conventions)
- project-structure.mdc и AGENTS.md переписаны под monorepo
- frontend-shadcn.mdc, shadcn-ui-production.mdc, sqlite.mdc обновлены
Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import type { FastifyPluginAsync } from 'fastify'
|
|
import { providersRepository } from '@cfdm/db/repositories/providers'
|
|
import { providerSchema } from '@cfdm/shared/contracts/provider'
|
|
|
|
export const providersRoutes: FastifyPluginAsync = async (app) => {
|
|
app.get('/api/providers', async () => providersRepository.list())
|
|
|
|
app.post('/api/providers', async (req, reply) => {
|
|
const parsed = providerSchema.safeParse(req.body)
|
|
if (!parsed.success) {
|
|
return reply.code(400).send({ error: { code: 'VALIDATION', message: parsed.error.message } })
|
|
}
|
|
const created = providersRepository.create(parsed.data)
|
|
return reply.code(201).send(created)
|
|
})
|
|
|
|
app.put<{ Params: { id: string } }>('/api/providers/:id', async (req, reply) => {
|
|
const parsed = providerSchema.partial().safeParse(req.body)
|
|
if (!parsed.success) {
|
|
return reply.code(400).send({ error: { code: 'VALIDATION', message: parsed.error.message } })
|
|
}
|
|
const updated = providersRepository.update(req.params.id, parsed.data)
|
|
if (!updated) {
|
|
return reply.code(404).send({ error: { code: 'NOT_FOUND', message: 'Not found' } })
|
|
}
|
|
return updated
|
|
})
|
|
|
|
app.delete<{ Params: { id: string } }>('/api/providers/:id', async (req, reply) => {
|
|
const ok = providersRepository.delete(req.params.id)
|
|
if (!ok) {
|
|
return reply.code(404).send({ error: { code: 'NOT_FOUND', message: 'Not found' } })
|
|
}
|
|
return reply.code(204).send()
|
|
})
|
|
}
|