chore: Remove over-usage of invariant (#3719)

This commit is contained in:
Tom Moor
2022-07-02 15:29:39 +03:00
committed by GitHub
parent 108b5b934a
commit c9cd424a8d
16 changed files with 34 additions and 55 deletions

View File

@@ -1,4 +1,3 @@
import invariant from "invariant";
import Router from "koa-router";
import { Op } from "sequelize";
import { MAX_AVATAR_DISPLAY } from "@shared/constants";
@@ -80,8 +79,7 @@ router.post("groups.create", auth(), async (ctx) => {
});
// reload to get default scope
const group = await Group.findByPk(g.id);
invariant(group, "group not found");
const group = await Group.findByPk(g.id, { rejectOnEmpty: true });
await Event.create({
name: "groups.create",
@@ -231,12 +229,11 @@ router.post("groups.add_user", auth(), async (ctx) => {
groupId: id,
userId,
},
rejectOnEmpty: true,
});
invariant(membership, "membership not found");
// reload to get default scope
group = await Group.findByPk(id);
invariant(group, "group not found");
group = await Group.findByPk(id, { rejectOnEmpty: true });
await Event.create({
name: "groups.add_user",
@@ -287,8 +284,7 @@ router.post("groups.remove_user", auth(), async (ctx) => {
});
// reload to get default scope
group = await Group.findByPk(id);
invariant(group, "group not found");
group = await Group.findByPk(id, { rejectOnEmpty: true });
ctx.body = {
data: {