fix: P0/P1 fixes (auth+limit+schema) + project audit docs
This commit is contained in:
+2
-2
@@ -29,8 +29,8 @@ function createApiRouter({ auth, q }) {
|
||||
|
||||
// Все /api/v1/* требуют Bearer — 401 JSON если нет токена
|
||||
router.use(requireBearer);
|
||||
// Валидация токена — переиспользуем auth.middleware из src/auth.js
|
||||
router.use(auth.middleware);
|
||||
// Валидация токена — Bearer-only (игнорирует сессию, всегда проверяет JWT)
|
||||
router.use(auth.bearerMiddleware);
|
||||
|
||||
router.use('/entries', createEntriesRouter({ q }));
|
||||
router.use('/', createAdminRouter({ q }));
|
||||
|
||||
@@ -26,15 +26,17 @@ function createAdminRouter({ q }) {
|
||||
|
||||
// PATCH /api/v1/companies/:id/limit — установить лимит (admin only)
|
||||
router.patch('/companies/:id/limit', apiRequireAdmin, json, async (req, res) => {
|
||||
const limit = parseInt((req.body || {}).limit, 10);
|
||||
if (isNaN(limit) || limit < 0) {
|
||||
return res.status(400).json({ error: 'limit must be non-negative integer' });
|
||||
const rawLimit = (req.body || {}).limit;
|
||||
const isReset = rawLimit === null || rawLimit === undefined;
|
||||
const limit = isReset ? null : parseInt(rawLimit, 10);
|
||||
if (!isReset && (isNaN(limit) || limit < 0)) {
|
||||
return res.status(400).json({ error: 'limit must be non-negative integer or null to reset' });
|
||||
}
|
||||
try {
|
||||
await q.setLimit(req.params.id, limit);
|
||||
res.json({ ok: true, limit });
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: e.message });
|
||||
res.status(e.status || 500).json({ error: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user