From 60a7f7f1463135939440dce7f5fd03467d3e2183 Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Sat, 2 Jun 2018 16:27:24 +0900
Subject: [PATCH] wip

---
 src/server/api/endpoints/i/update.ts | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts
index 5aff6da103..b94f073d2c 100644
--- a/src/server/api/endpoints/i/update.ts
+++ b/src/server/api/endpoints/i/update.ts
@@ -28,22 +28,22 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
 	// Get 'location' parameter
 	const [location, locationErr] = $.str.optional().nullable().pipe(isValidLocation).get(params.location);
 	if (locationErr) return rej('invalid location param');
-	if (location !== undefined) updates.profile.location = location;
+	if (location !== undefined) updates['profile.location'] = location;
 
 	// Get 'birthday' parameter
 	const [birthday, birthdayErr] = $.str.optional().nullable().pipe(isValidBirthday).get(params.birthday);
 	if (birthdayErr) return rej('invalid birthday param');
-	if (birthday !== undefined) updates.profile.birthday = birthday;
+	if (birthday !== undefined) updates['profile.birthday'] = birthday;
 
 	// Get 'avatarId' parameter
-	const [avatarId, avatarIdErr] = $.type(ID).optional().get(params.avatarId);
+	const [avatarId, avatarIdErr] = $.type(ID).optional().nullable().get(params.avatarId);
 	if (avatarIdErr) return rej('invalid avatarId param');
-	if (avatarId) updates.avatarId = avatarId;
+	if (avatarId !== undefined) updates.avatarId = avatarId;
 
 	// Get 'bannerId' parameter
-	const [bannerId, bannerIdErr] = $.type(ID).optional().get(params.bannerId);
+	const [bannerId, bannerIdErr] = $.type(ID).optional().nullable().get(params.bannerId);
 	if (bannerIdErr) return rej('invalid bannerId param');
-	if (bannerId) updates.bannerId = bannerId;
+	if (bannerId !== undefined) updates.bannerId = bannerId;
 
 	// Get 'isLocked' parameter
 	const [isLocked, isLockedErr] = $.bool.optional().get(params.isLocked);
@@ -63,7 +63,7 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
 	// Get 'autoWatch' parameter
 	const [autoWatch, autoWatchErr] = $.bool.optional().get(params.autoWatch);
 	if (autoWatchErr) return rej('invalid autoWatch param');
-	if (autoWatch != null) updates.settings.autoWatch = autoWatch;
+	if (autoWatch != null) updates['settings.autoWatch'] = autoWatch;
 
 	if (avatarId) {
 		const avatar = await DriveFile.findOne({
@@ -90,7 +90,7 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
 	});
 
 	// Serialize
-	const iObj = await pack(user, user, {
+	const iObj = await pack(user._id, user, {
 		detail: true,
 		includeSecrets: isSecure
 	});
@@ -98,7 +98,7 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
 	// Send response
 	res(iObj);
 
-	// Publish i updated event
+	// Publish meUpdated event
 	event(user._id, 'meUpdated', iObj);
 
 	// 鍵垢を解除したとき、溜まっていたフォローリクエストがあるならすべて承認