Sharkey/src/server/api/endpoints/users/lists/delete.ts

51 lines
1,008 B
TypeScript
Raw Normal View History

2018-09-02 18:59:42 +09:00
import $ from 'cafy';
2018-11-02 03:32:24 +09:00
import ID, { transform } from '../../../../../misc/cafy-id';
import UserList from '../../../../../models/user-list';
2018-11-02 13:47:44 +09:00
import define from '../../../define';
import { ApiError } from '../../../error';
2018-09-02 18:59:42 +09:00
export const meta = {
desc: {
'ja-JP': '指定したユーザーリストを削除します。',
'en-US': 'Delete a user list'
},
requireCredential: true,
kind: 'account-write',
params: {
2018-11-02 03:32:24 +09:00
listId: {
validator: $.type(ID),
transform: transform,
2018-09-02 18:59:42 +09:00
desc: {
'ja-JP': '対象となるユーザーリストのID',
'en-US': 'ID of target user list'
}
2018-11-02 03:32:24 +09:00
}
},
errors: {
noSuchList: {
message: 'No such list.',
code: 'NO_SUCH_LIST',
id: '78436795-db79-42f5-b1e2-55ea2cf19166'
}
2018-09-02 18:59:42 +09:00
}
};
export default define(meta, async (ps, user) => {
2018-09-02 18:59:42 +09:00
const userList = await UserList.findOne({
_id: ps.listId,
userId: user._id
});
if (userList == null) {
throw new ApiError(meta.errors.noSuchList);
2018-09-02 18:59:42 +09:00
}
await UserList.remove({
_id: userList._id
});
});