2018-09-02 10:44:49 +02:00
|
|
|
import $ from 'cafy';
|
2018-11-01 19:32:24 +01:00
|
|
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
2018-09-02 04:25:33 +02:00
|
|
|
import UserList, { pack } from '../../../../../models/user-list';
|
2018-11-02 05:47:44 +01:00
|
|
|
import define from '../../../define';
|
2019-02-22 03:46:58 +01:00
|
|
|
import { ApiError } from '../../../error';
|
2018-09-02 04:25:33 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
|
|
|
'ja-JP': '指定したユーザーリストを更新します。',
|
|
|
|
'en-US': 'Update a user list'
|
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'account-write',
|
|
|
|
|
|
|
|
params: {
|
2018-11-01 19:32:24 +01:00
|
|
|
listId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
2018-09-02 04:25:33 +02:00
|
|
|
desc: {
|
|
|
|
'ja-JP': '対象となるユーザーリストのID',
|
|
|
|
'en-US': 'ID of target user list'
|
|
|
|
}
|
2018-11-01 19:32:24 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
title: {
|
|
|
|
validator: $.str.range(1, 100),
|
2018-09-02 04:25:33 +02:00
|
|
|
desc: {
|
|
|
|
'ja-JP': 'このユーザーリストの名前',
|
|
|
|
'en-US': 'name of this user list'
|
|
|
|
}
|
2018-11-01 19:32:24 +01:00
|
|
|
}
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchList: {
|
|
|
|
message: 'No such list.',
|
|
|
|
code: 'NO_SUCH_LIST',
|
|
|
|
id: '796666fe-3dff-4d39-becb-8a5932c1d5b7'
|
|
|
|
},
|
2018-09-02 04:25:33 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
export default define(meta, async (ps, user) => {
|
2018-09-02 04:25:33 +02:00
|
|
|
// Fetch the list
|
|
|
|
const userList = await UserList.findOne({
|
|
|
|
_id: ps.listId,
|
|
|
|
userId: user._id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (userList == null) {
|
2019-02-22 03:46:58 +01:00
|
|
|
throw new ApiError(meta.errors.noSuchList);
|
2018-09-02 04:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await UserList.update({ _id: userList._id }, {
|
|
|
|
$set: {
|
|
|
|
title: ps.title
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
return await pack(userList._id);
|
|
|
|
});
|