mirror of
https://github.com/directus/directus.git
synced 2026-01-28 18:38:10 -05:00
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.
52 lines
1.2 KiB
TypeScript
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;
|