iceshrimp/src/server/api/endpoints/i/update_mobile_home.ts
2018-06-18 09:54:53 +09:00

25 lines
589 B
TypeScript

import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user';
import event from '../../../../publishers/stream';
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'home' parameter
const [home, homeErr] = $.arr(
$.obj.strict()
.have('name', $.str)
.have('id', $.str)
.have('data', $.obj))
.get(params.home);
if (homeErr) return rej('invalid home param');
await User.update(user._id, {
$set: {
'clientSettings.mobileHome': home
}
});
res();
event(user._id, 'mobile_home_updated', home);
});