This commit is contained in:
syuilo 2019-05-18 22:54:02 +09:00
parent 318d7f2652
commit 9dbe12135d
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69

View file

@ -2,7 +2,7 @@ import $ from 'cafy';
import { ID } from '../../../../../misc/cafy-id'; import { ID } from '../../../../../misc/cafy-id';
import define from '../../../define'; import define from '../../../define';
import { ApiError } from '../../../error'; import { ApiError } from '../../../error';
import { UserGroups } from '../../../../../models'; import { UserGroups, UserGroupJoinings } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema'; import { types, bool } from '../../../../../misc/schema';
export const meta = { export const meta = {
@ -42,12 +42,20 @@ export default define(meta, async (ps, me) => {
// Fetch the group // Fetch the group
const userGroup = await UserGroups.findOne({ const userGroup = await UserGroups.findOne({
id: ps.groupId, id: ps.groupId,
userId: me.id,
}); });
if (userGroup == null) { if (userGroup == null) {
throw new ApiError(meta.errors.noSuchGroup); throw new ApiError(meta.errors.noSuchGroup);
} }
const joining = await UserGroupJoinings.findOne({
userId: me.id,
userGroupId: userGroup.id
});
if (joining == null && userGroup.userId !== me.id) {
throw new ApiError(meta.errors.noSuchGroup);
}
return await UserGroups.pack(userGroup); return await UserGroups.pack(userGroup);
}); });