0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00
logto/packages/core/src/routes/setting.ts

29 lines
743 B
TypeScript

import { Settings } from '@logto/schemas';
import koaGuard from '@/middleware/koa-guard';
import { getSetting, updateSetting } from '@/queries/setting';
import { AuthedRouter } from './types';
export default function settingRoutes<T extends AuthedRouter>(router: T) {
router.get('/settings', async (ctx, next) => {
const { id, ...rest } = await getSetting();
ctx.body = rest;
return next();
});
router.patch(
'/settings',
koaGuard({
body: Settings.createGuard.omit({ id: true }).deepPartial(),
}),
async (ctx, next) => {
const { body: partialSettings } = ctx.guard;
const { id, ...rest } = await updateSetting(partialSettings);
ctx.body = rest;
return next();
}
);
}