wip
This commit is contained in:
@ -194,6 +194,11 @@ const endpoints: Endpoint[] = [
|
||||
withCredential: true,
|
||||
secure: true
|
||||
},
|
||||
{
|
||||
name: 'i/update_client_setting',
|
||||
withCredential: true,
|
||||
secure: true
|
||||
},
|
||||
{
|
||||
name: 'i/pin',
|
||||
kind: 'account-write'
|
||||
|
@ -46,19 +46,13 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
||||
if (bannerIdErr) return rej('invalid banner_id param');
|
||||
if (bannerId) user.banner_id = bannerId;
|
||||
|
||||
// Get 'show_donation' parameter
|
||||
const [showDonation, showDonationErr] = $(params.show_donation).optional.boolean().$;
|
||||
if (showDonationErr) return rej('invalid show_donation param');
|
||||
if (showDonation) user.client_settings.show_donation = showDonation;
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
name: user.name,
|
||||
description: user.description,
|
||||
avatar_id: user.avatar_id,
|
||||
banner_id: user.banner_id,
|
||||
profile: user.profile,
|
||||
'client_settings.show_donation': user.client_settings.show_donation
|
||||
profile: user.profile
|
||||
}
|
||||
});
|
||||
|
||||
|
43
src/api/endpoints/i/update_client_setting.ts
Normal file
43
src/api/endpoints/i/update_client_setting.ts
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import User, { pack } from '../../models/user';
|
||||
import event from '../../event';
|
||||
|
||||
/**
|
||||
* Update myself
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).string().$;
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'value' parameter
|
||||
const [value, valueErr] = $(params.value).nullable.any().$;
|
||||
if (valueErr) return rej('invalid value param');
|
||||
|
||||
const x = {};
|
||||
x[`client_settings.${name}`] = value;
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: x
|
||||
});
|
||||
|
||||
// Serialize
|
||||
user.client_settings[name] = value;
|
||||
const iObj = await pack(user, user, {
|
||||
detail: true,
|
||||
includeSecrets: true
|
||||
});
|
||||
|
||||
// Send response
|
||||
res(iObj);
|
||||
|
||||
// Publish i updated event
|
||||
event(user._id, 'i_updated', iObj);
|
||||
});
|
Reference in New Issue
Block a user