mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
@@ -17,6 +17,7 @@ import relationsRouter from './routes/relations';
|
||||
import revisionsRouter from './routes/revisions';
|
||||
import rolesRouter from './routes/roles';
|
||||
import usersRouter from './routes/users';
|
||||
import settingsRouter from './routes/settings';
|
||||
|
||||
import notFoundHandler from './routes/not-found';
|
||||
|
||||
@@ -34,6 +35,7 @@ const app = express()
|
||||
.use('/revisions', revisionsRouter)
|
||||
.use('/roles', rolesRouter)
|
||||
.use('/users', usersRouter)
|
||||
.use('/settings', settingsRouter)
|
||||
.use(notFoundHandler)
|
||||
.use(errorHandler);
|
||||
|
||||
|
||||
31
src/routes/settings.ts
Normal file
31
src/routes/settings.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import validateQuery from '../middleware/validate-query';
|
||||
import * as SettingsService from '../services/settings';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get(
|
||||
'/',
|
||||
sanitizeQuery,
|
||||
validateQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const records = await SettingsService.readSettings(1, res.locals.query);
|
||||
return res.json({ data: records });
|
||||
})
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/',
|
||||
asyncHandler(async (req, res) => {
|
||||
const records = await SettingsService.updateSettings(
|
||||
req.params.pk /** @TODO Singleton */,
|
||||
req.body,
|
||||
res.locals.query
|
||||
);
|
||||
return res.json({ data: records });
|
||||
})
|
||||
);
|
||||
|
||||
export default router;
|
||||
16
src/services/settings.ts
Normal file
16
src/services/settings.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Query } from '../types/query';
|
||||
import * as ItemsService from './items';
|
||||
|
||||
export const readSettings = async (pk: string | number, query: Query) => {
|
||||
/** @TODO only fetch the one item that exists, or default to default values if it doesn't */
|
||||
return await ItemsService.readItem('directus_settings', pk, query);
|
||||
};
|
||||
|
||||
export const updateSettings = async (
|
||||
pk: string | number,
|
||||
data: Record<string, any>,
|
||||
query: Query
|
||||
) => {
|
||||
/** @NOTE I guess this can technically update _all_ items, as we expect there to only be one */
|
||||
return await ItemsService.updateItem('directus_settings', pk, data, query);
|
||||
};
|
||||
Reference in New Issue
Block a user