This commit is contained in:
syuilo 2020-02-15 01:03:59 +09:00
parent 84958af4ce
commit 65c0b6c7da
10 changed files with 123 additions and 9 deletions

View file

@ -2,7 +2,7 @@ import $ from 'cafy';
import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import { ApiError } from '../../error';
import { Antennas, UserLists } from '../../../../models';
import { Antennas, UserLists, UserGroupJoinings } from '../../../../models';
export const meta = {
tags: ['antennas'],
@ -21,13 +21,17 @@ export const meta = {
},
src: {
validator: $.str.or(['home', 'all', 'users', 'list'])
validator: $.str.or(['home', 'all', 'users', 'list', 'group'])
},
userListId: {
validator: $.nullable.optional.type(ID),
},
userGroupId: {
validator: $.nullable.optional.type(ID),
},
keywords: {
validator: $.arr($.arr($.str))
},
@ -64,6 +68,12 @@ export const meta = {
message: 'No such user list.',
code: 'NO_SUCH_USER_LIST',
id: '1c6b35c9-943e-48c2-81e4-2844989407f7'
},
noSuchUserGroup: {
message: 'No such user group.',
code: 'NO_SUCH_USER_GROUP',
id: '109ed789-b6eb-456e-b8a9-6059d567d385'
}
}
};
@ -80,6 +90,7 @@ export default define(meta, async (ps, user) => {
}
let userList;
let userGroupJoining;
if (ps.src === 'list') {
userList = await UserLists.findOne({
@ -90,12 +101,22 @@ export default define(meta, async (ps, user) => {
if (userList == null) {
throw new ApiError(meta.errors.noSuchUserList);
}
} else if (ps.src === 'group') {
userGroupJoining = await UserGroupJoinings.findOne({
userGroupId: ps.userGroupId,
userId: user.id,
});
if (userGroupJoining == null) {
throw new ApiError(meta.errors.noSuchUserGroup);
}
}
await Antennas.update(antenna.id, {
name: ps.name,
src: ps.src,
userListId: userList ? userList.id : null,
userGroupJoiningId: userGroupJoining ? userGroupJoining.id : null,
keywords: ps.keywords,
users: ps.users,
caseSensitive: ps.caseSensitive,