You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
760 B

import {
ensureKnownConfigKey,
setCurrentUserConfigValue,
} from "#server/service/config";
import { toPublicConfigError } from "#server/service/config/errors";
type UpdateMyConfigBody = {
key: string;
value: unknown;
};
export default defineWrappedResponseHandler(async (event) => {
try {
const user = await event.context.auth.requireUser();
const body = await readBody<UpdateMyConfigBody>(event);
const key = ensureKnownConfigKey(body.key);
await setCurrentUserConfigValue(user.id, key, body.value);
const value = await event.context.config.get(key);
return R.success({
key,
value,
});
} catch (err) {
throw toPublicConfigError(err);
}
});