This commit is contained in:
syuilo
2018-11-02 12:49:08 +09:00
parent befc35a3ac
commit a7e6b766be
26 changed files with 434 additions and 354 deletions

View File

@@ -1,29 +1,36 @@
import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user';
import { publishMainStream } from '../../../../stream';
import getParams from '../../get-params';
export const meta = {
requireCredential: true,
secure: true
secure: true,
params: {
home: {
validator: $.arr($.obj({
name: $.str,
id: $.str,
place: $.str,
data: $.obj()
}).strict())
}
}
};
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'home' parameter
const [home, homeErr] = $.arr($.obj({
name: $.str,
id: $.str,
place: $.str,
data: $.obj()
}).strict()).get(params.home);
if (homeErr) return rej('invalid home param');
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
await User.update(user._id, {
$set: {
'clientSettings.home': home
'clientSettings.home': ps.home
}
});
res();
publishMainStream(user._id, 'homeUpdated', home);
publishMainStream(user._id, 'homeUpdated', ps.home);
});