diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-03 08:56:07 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-03 08:56:07 +0900 |
| commit | dc45055f2ffcea2369f12d104999746220b22c90 (patch) | |
| tree | d3ec8f4a03076fe804c906cd60656e197f3010f2 /src/api/endpoints/i/update.js | |
| parent | wip (diff) | |
| download | misskey-dc45055f2ffcea2369f12d104999746220b22c90.tar.gz misskey-dc45055f2ffcea2369f12d104999746220b22c90.tar.bz2 misskey-dc45055f2ffcea2369f12d104999746220b22c90.zip | |
wip
Diffstat (limited to 'src/api/endpoints/i/update.js')
| -rw-r--r-- | src/api/endpoints/i/update.js | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/src/api/endpoints/i/update.js b/src/api/endpoints/i/update.js deleted file mode 100644 index 4abb4fcb7b..0000000000 --- a/src/api/endpoints/i/update.js +++ /dev/null @@ -1,119 +0,0 @@ -'use strict'; - -/** - * Module dependencies - */ -import * as mongo from 'mongodb'; -import User from '../../models/user'; -import { isValidName, isValidBirthday } from '../../models/user'; -import serialize from '../../serializers/user'; -import event from '../../event'; -import config from '../../../conf'; - -/** - * Update myself - * - * @param {any} params - * @param {any} user - * @param {any} _ - * @param {boolean} isSecure - * @return {Promise<any>} - */ -module.exports = async (params, user, _, isSecure) => - new Promise(async (res, rej) => -{ - // Get 'name' parameter - const name = params.name; - if (name !== undefined && name !== null) { - if (typeof name != 'string') { - return rej('name must be a string'); - } - - if (!isValidName(name)) { - return rej('invalid name'); - } - - user.name = name; - } - - // Get 'description' parameter - const description = params.description; - if (description !== undefined && description !== null) { - if (description.length > 500) { - return rej('too long description'); - } - - user.description = description; - } - - // Get 'location' parameter - const location = params.location; - if (location !== undefined && location !== null) { - if (location.length > 50) { - return rej('too long location'); - } - - user.profile.location = location; - } - - // Get 'birthday' parameter - const birthday = params.birthday; - if (birthday != null) { - if (!isValidBirthday(birthday)) { - return rej('invalid birthday'); - } - - user.profile.birthday = birthday; - } else { - user.profile.birthday = null; - } - - // Get 'avatar_id' parameter - const avatar = params.avatar_id; - if (avatar !== undefined && avatar !== null) { - user.avatar_id = new mongo.ObjectID(avatar); - } - - // Get 'banner_id' parameter - const banner = params.banner_id; - if (banner !== undefined && banner !== null) { - user.banner_id = new mongo.ObjectID(banner); - } - - 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 - } - }); - - // Serialize - const iObj = await serialize(user, user, { - detail: true, - includeSecrets: isSecure - }); - - // Send response - res(iObj); - - // Publish i updated event - event(user._id, 'i_updated', iObj); - - // Update search index - if (config.elasticsearch.enable) { - const es = require('../../../db/elasticsearch'); - - es.index({ - index: 'misskey', - type: 'user', - id: user._id.toString(), - body: { - name: user.name, - bio: user.bio - } - }); - } -}); |