mirror of
https://github.com/directus/directus.git
synced 2026-01-28 20:17:57 -05:00
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import express from 'express';
|
|
import asyncHandler from 'express-async-handler';
|
|
import { SettingsService } from '../services';
|
|
import { ForbiddenException } from '../exceptions';
|
|
import useCollection from '../middleware/use-collection';
|
|
import { respond } from '../middleware/respond';
|
|
|
|
const router = express.Router();
|
|
|
|
router.use(useCollection('directus_settings'));
|
|
|
|
router.get(
|
|
'/',
|
|
asyncHandler(async (req, res, next) => {
|
|
const service = new SettingsService({ accountability: req.accountability });
|
|
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 });
|
|
await service.upsertSingleton(req.body);
|
|
|
|
try {
|
|
const record = await service.readSingleton(req.sanitizedQuery);
|
|
res.locals.payload = { data: record || null };
|
|
} catch (error) {
|
|
if (error instanceof ForbiddenException) {
|
|
return next();
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
|
|
return next();
|
|
}),
|
|
respond
|
|
);
|
|
|
|
export default router;
|