trashposs/src/server/api/endpoints/i/update_client_setting.ts
syuilo 6de16eb71e Improve error handling of API (#4345)
* wip

* wip

* wip

* Update attached_notes.ts

* wip

* Refactor

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update call.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* ✌️

* Fix
2019-02-22 11:46:58 +09:00

38 lines
618 B
TypeScript

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