summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/i/update_home.ts
blob: ffca9b90b3f1a3bb34b34820c7b035325e44221c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user';
import { publishUserStream } from '../../../../stream';

export const meta = {
	requireCredential: true,
	secure: true
};

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');

	await User.update(user._id, {
		$set: {
			'clientSettings.home': home
		}
	});

	res();

	publishUserStream(user._id, 'home_updated', home);
});