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

48 lines
1,000 B
TypeScript
Raw Normal View History

2018-09-02 11:59:42 +02:00
import $ from 'cafy';
2018-11-01 19:32:24 +01:00
import ID, { transform } from '../../../../../misc/cafy-id';
import UserList from '../../../../../models/user-list';
2018-09-02 11:59:42 +02:00
import { ILocalUser } from '../../../../../models/user';
import getParams from '../../../get-params';
export const meta = {
desc: {
'ja-JP': '指定したユーザーリストを削除します。',
'en-US': 'Delete 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 11:59:42 +02:00
desc: {
'ja-JP': '対象となるユーザーリストのID',
'en-US': 'ID of target user list'
}
2018-11-01 19:32:24 +01:00
}
2018-09-02 11:59:42 +02:00
}
};
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const userList = await UserList.findOne({
_id: ps.listId,
userId: user._id
});
if (userList == null) {
return rej('list not found');
}
await UserList.remove({
_id: userList._id
});
2018-09-02 11:59:42 +02:00
res();
});