sharkey/src/server/api/endpoints/i/update_client_setting.ts
2018-11-02 13:47:44 +09:00

38 lines
629 B
TypeScript

import $ from 'cafy';
import User from '../../../../models/user';
import { publishMainStream } from '../../../../stream';
import define from '../../define';
export const meta = {
requireCredential: true,
secure: true,
params: {
name: {
validator: $.str
},
value: {
validator: $.any.nullable
}
}
};
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const x: any = {};
x[`clientSettings.${name}`] = ps.value;
await User.update(user._id, {
$set: x
});
res();
// Publish event
publishMainStream(user._id, 'clientSettingUpdated', {
key: name,
value: ps.value
});
}));