SPB Git

Repository Public

index.ts 903 B 18 lines typescript

1import type { FastifyInstance } from 'fastify';2import { AosSettings } from '@aos/shared';3import { authOf, parse, type Ctx } from '../../http.js';4import { getSettings, putSettings } from './store.js';56export default async function settingsPlugin(app: FastifyInstance, ctx: Ctx): Promise<void> {7  app.get('/settings', { config: { doc: { summary: 'User settings (defaults merged)', response: AosSettings, responseName: 'AosSettings' } } }, (req) =>8    getSettings(ctx.db, authOf(req).userId),9  );10  app.put('/settings', { config: { doc: { summary: 'Replace user settings', body: AosSettings, bodyName: 'AosSettings', response: AosSettings, responseName: 'AosSettings' } } }, async (req) => {11    const a = authOf(req);12    const settings = parse(AosSettings, req.body);13    await putSettings(ctx.db, a.userId, settings);14    await ctx.audit.req(req, 'settings.update');15    return settings;16  });17}18
Files main
Menu

Theme