ENCOA-217: Adapted the invite system to now work based on Entities instead of Users/Groups
This commit is contained in:
@@ -8,6 +8,8 @@ import client from "@/lib/mongodb";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import ShortUniqueId from "short-unique-id";
|
||||
import { Entity } from "@/interfaces/entity";
|
||||
import { getEntity } from "@/utils/entities.be";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
@@ -36,20 +38,19 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const invited = await db.collection("users").findOne<User>({ id: body.to});
|
||||
if (!invited) return res.status(404).json({ok: false});
|
||||
|
||||
const invitedBy = await db.collection("users").findOne<User>({ id: body.from});
|
||||
if (!invitedBy) return res.status(404).json({ok: false});
|
||||
const entity = await getEntity(body.entity)
|
||||
if (!entity) return res.status(404).json({ok: false});
|
||||
|
||||
try {
|
||||
await sendEmail(
|
||||
"receivedInvite",
|
||||
{
|
||||
name: invited.name,
|
||||
corporateName:
|
||||
invitedBy.type === "corporate" ? invitedBy.corporateInformation?.companyInformation?.name || invitedBy.name : invitedBy.name,
|
||||
entity: entity.label,
|
||||
environment: process.env.ENVIRONMENT,
|
||||
},
|
||||
[invited.email],
|
||||
"You have been invited to a group!",
|
||||
"You have been invited to an entity!",
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
||||
Reference in New Issue
Block a user