summaryrefslogtreecommitdiff
path: root/src/server/api
diff options
context:
space:
mode:
authorMarihachi <marihachi0620@gmail.com>2018-09-02 11:25:33 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-09-02 11:25:32 +0900
commitf6217d96d20905024a5780fd4b3e7320eb41e3c6 (patch)
treee1007dbba14a24781e0911a14a60169ab3fb7fab /src/server/api
parent8.21.1 (diff)
downloadsharkey-f6217d96d20905024a5780fd4b3e7320eb41e3c6.tar.gz
sharkey-f6217d96d20905024a5780fd4b3e7320eb41e3c6.tar.bz2
sharkey-f6217d96d20905024a5780fd4b3e7320eb41e3c6.zip
add an endpoint users/lists/update (#2585)
* add an endpoint users/lists/update * add meta params * fix packing
Diffstat (limited to 'src/server/api')
-rw-r--r--src/server/api/endpoints/users/lists/update.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/server/api/endpoints/users/lists/update.ts b/src/server/api/endpoints/users/lists/update.ts
new file mode 100644
index 0000000000..b80d648122
--- /dev/null
+++ b/src/server/api/endpoints/users/lists/update.ts
@@ -0,0 +1,55 @@
+import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
+import UserList, { pack } from '../../../../../models/user-list';
+import { ILocalUser } from '../../../../../models/user';
+import getParams from '../../../get-params';
+
+export const meta = {
+ desc: {
+ 'ja-JP': '指定したユーザーリストを更新します。',
+ 'en-US': 'Update a user list'
+ },
+
+ requireCredential: true,
+
+ kind: 'account-write',
+
+ params: {
+ listId: $.type(ID).note({
+ desc: {
+ 'ja-JP': '対象となるユーザーリストのID',
+ 'en-US': 'ID of target user list'
+ }
+ }),
+ title: $.str.range(1, 100).note({
+ desc: {
+ 'ja-JP': 'このユーザーリストの名前',
+ 'en-US': 'name of this user list'
+ }
+ })
+ }
+};
+
+export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
+
+ // Fetch the list
+ const userList = await UserList.findOne({
+ _id: ps.listId,
+ userId: user._id
+ });
+
+ if (userList == null) {
+ return rej('list not found');
+ }
+
+ // update
+ await UserList.update({ _id: userList._id }, {
+ $set: {
+ title: ps.title
+ }
+ });
+
+ // Response
+ res(await pack(userList._id));
+});