Files
directus/api/src/controllers/settings.ts
Nicola Krumschmidt d64ca14348 Explicitly set catch parameters to any type (#7654)
This fixes not being able to build the repo due to type issues
introduced by the Typescript 4.4 option "useUnknownInCatchVariables",
which is enabled by default in strict mode.
2021-08-27 10:33:30 -04:00

52 lines
1.2 KiB
TypeScript

import express from 'express';
import { ForbiddenException } from '../exceptions';
import { respond } from '../middleware/respond';
import useCollection from '../middleware/use-collection';
import { SettingsService } from '../services';
import asyncHandler from '../utils/async-handler';
const router = express.Router();
router.use(useCollection('directus_settings'));
router.get(
'/',
asyncHandler(async (req, res, next) => {
const service = new SettingsService({
accountability: req.accountability,
schema: req.schema,
});
const records = await service.readSingleton(req.sanitizedQuery);
res.locals.payload = { data: records || null };
return next();
}),
respond
);
router.patch(
'/',
asyncHandler(async (req, res, next) => {
const service = new SettingsService({
accountability: req.accountability,
schema: req.schema,
});
await service.upsertSingleton(req.body);
try {
const record = await service.readSingleton(req.sanitizedQuery);
res.locals.payload = { data: record || null };
} catch (error: any) {
if (error instanceof ForbiddenException) {
return next();
}
throw error;
}
return next();
}),
respond
);
export default router;