feat(frontend): API client modules + backend GET /api/cards/:id

This commit is contained in:
2026-05-20 21:12:38 +02:00
parent 480ee15df9
commit 1c977c4743
6 changed files with 114 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ import multer from 'multer';
import { cardCreateSchema, cardUpdateSchema } from '@flashcard/shared';
import type { Db } from '../db/client.js';
import { ApiError } from '../lib/errors.js';
import { createCard, deleteCard, listCardsByLesson, updateCard } from '../services/cards.js';
import { createCard, deleteCard, getCard, listCardsByLesson, updateCard } from '../services/cards.js';
import { exportCardsToBuffer, importCardsFromBuffer } from '../services/import.js';
export function cardsRouter(db: Db): Router {
@@ -21,6 +21,10 @@ export function cardsRouter(db: Db): Router {
} catch (e) { next(e); }
});
r.get('/cards/:id', async (req, res, next) => {
try { res.json(await getCard(db, Number(req.params.id))); } catch (e) { next(e); }
});
r.patch('/cards/:id', async (req, res, next) => {
try {
const input = cardUpdateSchema.parse(req.body);