sharkey/src/server/api/endpoints/users/lists/update.ts

57 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-09-02 17:44:49 +09:00
import $ from 'cafy';
2018-11-02 03:32:24 +09:00
import ID, { transform } from '../../../../../misc/cafy-id';
import UserList, { pack } from '../../../../../models/user-list';
2018-11-02 13:47:44 +09:00
import define from '../../../define';
export const meta = {
desc: {
'ja-JP': '指定したユーザーリストを更新します。',
'en-US': 'Update a user list'
},
requireCredential: true,
kind: 'account-write',
params: {
2018-11-02 03:32:24 +09:00
listId: {
validator: $.type(ID),
transform: transform,
desc: {
'ja-JP': '対象となるユーザーリストのID',
'en-US': 'ID of target user list'
}
2018-11-02 03:32:24 +09:00
},
title: {
validator: $.str.range(1, 100),
desc: {
'ja-JP': 'このユーザーリストの名前',
'en-US': 'name of this user list'
}
2018-11-02 03:32:24 +09:00
}
}
};
2018-11-02 13:47:44 +09:00
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
// 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));
2018-11-02 13:47:44 +09:00
}));