feat(frontend): API client modules + backend GET /api/cards/:id
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user