Solved some issues with the redirect as well as adding a way to create entities
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {createEntity, getEntities, getEntitiesWithRoles} from "@/utils/entities.be";
|
||||
import {addUsersToEntity, addUserToEntity, createEntity, getEntities, getEntitiesWithRoles} from "@/utils/entities.be";
|
||||
import {Entity} from "@/interfaces/entity";
|
||||
import {v4} from "uuid";
|
||||
import { requestUser } from "@/utils/api";
|
||||
@@ -39,6 +39,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
label: req.body.label,
|
||||
};
|
||||
|
||||
await createEntity(entity)
|
||||
const members = req.body.members as string[] | undefined || []
|
||||
console.log(members)
|
||||
|
||||
const roles = await createEntity(entity)
|
||||
console.log(roles)
|
||||
|
||||
await addUserToEntity(user.id, entity.id, roles.admin.id)
|
||||
if (members.length > 0) await addUsersToEntity(members, entity.id, roles.default.id)
|
||||
|
||||
return res.status(200).json(entity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user