Merge branch 'migration-mongodb' of bitbucket.org:ecropdev/ielts-ui into migration-mongodb
This commit is contained in:
@@ -108,12 +108,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
{ id: codeRef.id },
|
||||
{
|
||||
$set: {
|
||||
id: codeRef.id,
|
||||
...codeInformation,
|
||||
email: email.trim().toLowerCase(),
|
||||
name: name.trim(),
|
||||
...(passport_id ? { passport_id: passport_id.trim() } : {}),
|
||||
}
|
||||
}
|
||||
},
|
||||
{ upsert: true }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,7 +127,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
// upsert: true -> if it doesnt exist insert
|
||||
await db.collection("codes").updateOne(
|
||||
{ id: code },
|
||||
{ $set: codeInformation },
|
||||
{ $set: { id: code, ...codeInformation} },
|
||||
{ upsert: true }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
await db.collection("discounts").updateOne(
|
||||
{ id: id },
|
||||
{ $set: req.body }
|
||||
{ $set: { id: id, ...req.body},
|
||||
{ upsert: true }
|
||||
);
|
||||
|
||||
res.status(200).json({ ok: true });
|
||||
|
||||
@@ -58,6 +58,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
{ id: fields.id },
|
||||
{
|
||||
$set: {
|
||||
id: fields.id,
|
||||
solutions,
|
||||
score: {
|
||||
correct: speakingReverseMarking[backendRequest.data.overall || 0] || 0,
|
||||
|
||||
@@ -54,6 +54,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
await db.collection("stats").updateOne(
|
||||
{ id: fields.id },
|
||||
{
|
||||
id: fields.id,
|
||||
solutions,
|
||||
score: {
|
||||
correct: speakingReverseMarking[backendRequest.data.overall || 0] || 0,
|
||||
|
||||
@@ -40,6 +40,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
await db.collection("stats").updateOne(
|
||||
{ id: (req.body as Body).id},
|
||||
{
|
||||
id: (req.body as Body).id,
|
||||
solutions,
|
||||
score: {
|
||||
correct: writingReverseMarking[backendRequest.data.overall],
|
||||
|
||||
@@ -48,7 +48,8 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (docSnap) {
|
||||
await db.collection(module).updateOne(
|
||||
{ id: id},
|
||||
{ $set: req.body }
|
||||
{ $set: { id: id, ...req.body }},
|
||||
{ upsert: true }
|
||||
);
|
||||
res.status(200).json({ok: true});
|
||||
} else {
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { app } from "@/firebase";
|
||||
import {
|
||||
getFirestore,
|
||||
collection,
|
||||
getDocs,
|
||||
getDoc,
|
||||
doc,
|
||||
deleteDoc,
|
||||
setDoc,
|
||||
} from "firebase/firestore";
|
||||
import client from "@/lib/mongodb";
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { Group } from "@/interfaces/user";
|
||||
import { updateExpiryDateOnGroup } from "@/utils/groups.be";
|
||||
|
||||
const db = getFirestore(app);
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -35,10 +26,10 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const { id } = req.query as { id: string };
|
||||
|
||||
const snapshot = await getDoc(doc(db, "groups", id));
|
||||
const snapshot = await db.collection("groups").findOne({ id: id});
|
||||
|
||||
if (snapshot.exists()) {
|
||||
res.status(200).json({ ...snapshot.data(), id: snapshot.id });
|
||||
if (snapshot) {
|
||||
res.status(200).json({ ...snapshot });
|
||||
} else {
|
||||
res.status(404).json(undefined);
|
||||
}
|
||||
@@ -51,9 +42,12 @@ async function del(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
const { id } = req.query as { id: string };
|
||||
const group = await db.collection("groups").findOne<Group>({id: id});
|
||||
|
||||
const snapshot = await getDoc(doc(db, "groups", id));
|
||||
const group = { ...snapshot.data(), id: snapshot.id } as Group;
|
||||
if (!group) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = req.session.user;
|
||||
if (
|
||||
@@ -61,7 +55,7 @@ async function del(req: NextApiRequest, res: NextApiResponse) {
|
||||
user.type === "developer" ||
|
||||
user.id === group.admin
|
||||
) {
|
||||
await deleteDoc(snapshot.ref);
|
||||
await db.collection("groups").deleteOne({ id: id });
|
||||
|
||||
res.status(200).json({ ok: true });
|
||||
return;
|
||||
@@ -78,8 +72,11 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const { id } = req.query as { id: string };
|
||||
|
||||
const snapshot = await getDoc(doc(db, "groups", id));
|
||||
const group = { ...snapshot.data(), id: snapshot.id } as Group;
|
||||
const group = await db.collection("groups").findOne<Group>({id: id});
|
||||
if (!group) {
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = req.session.user;
|
||||
if (
|
||||
@@ -98,7 +95,10 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
|
||||
);
|
||||
}
|
||||
|
||||
await setDoc(snapshot.ref, req.body, { merge: true });
|
||||
await db.collection("grading").updateOne(
|
||||
{ id: req.session.user.id },
|
||||
{ $set: req.body}
|
||||
);
|
||||
|
||||
res.status(200).json({ ok: true });
|
||||
return;
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import {app} from "@/firebase";
|
||||
import {getFirestore, collection, getDocs, setDoc, doc, query, where} from "firebase/firestore";
|
||||
import client from "@/lib/mongodb";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {Group} from "@/interfaces/user";
|
||||
import {v4} from "uuid";
|
||||
import {updateExpiryDateOnGroup, getGroupsForUser} from "@/utils/groups.be";
|
||||
import {uniq, uniqBy} from "lodash";
|
||||
import {getUser} from "@/utils/users.be";
|
||||
|
||||
const db = getFirestore(app);
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -41,10 +39,11 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
await Promise.all(body.participants.map(async (p) => await updateExpiryDateOnGroup(p, body.admin)));
|
||||
|
||||
await setDoc(doc(db, "groups", v4()), {
|
||||
name: body.name,
|
||||
admin: body.admin,
|
||||
participants: body.participants,
|
||||
});
|
||||
await db.collection("groups").insertOne({
|
||||
id: v4(),
|
||||
name: body.name,
|
||||
admin: body.admin,
|
||||
participants: body.participants,
|
||||
})
|
||||
res.status(200).json({ok: true});
|
||||
}
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { app } from "@/firebase";
|
||||
import {
|
||||
getFirestore,
|
||||
getDoc,
|
||||
doc,
|
||||
deleteDoc,
|
||||
setDoc,
|
||||
} from "firebase/firestore";
|
||||
import client from "@/lib/mongodb";
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { Ticket } from "@/interfaces/ticket";
|
||||
import { Invite } from "@/interfaces/invite";
|
||||
|
||||
const db = getFirestore(app);
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -33,10 +25,10 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const { id } = req.query as { id: string };
|
||||
|
||||
const snapshot = await getDoc(doc(db, "invites", id));
|
||||
const snapshot = await db.collection("invites").findOne({ id: id });
|
||||
|
||||
if (snapshot.exists()) {
|
||||
res.status(200).json({ ...snapshot.data(), id: snapshot.id });
|
||||
if (snapshot) {
|
||||
res.status(200).json(snapshot);
|
||||
} else {
|
||||
res.status(404).json(undefined);
|
||||
}
|
||||
@@ -50,12 +42,15 @@ async function del(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const { id } = req.query as { id: string };
|
||||
|
||||
const snapshot = await getDoc(doc(db, "invites", id));
|
||||
const data = snapshot.data() as Invite;
|
||||
const snapshot = await db.collection("invites").findOne<Invite>({ id: id });
|
||||
if(!snapshot){
|
||||
res.status(404);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = req.session.user;
|
||||
if (user.type === "admin" || user.type === "developer") {
|
||||
await deleteDoc(snapshot.ref);
|
||||
await db.collection("invites").deleteOne({ id: id });
|
||||
res.status(200).json({ ok: true });
|
||||
return;
|
||||
}
|
||||
@@ -70,11 +65,14 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
const { id } = req.query as { id: string };
|
||||
const snapshot = await getDoc(doc(db, "invites", id));
|
||||
|
||||
const user = req.session.user;
|
||||
|
||||
if (user.type === "admin" || user.type === "developer") {
|
||||
await setDoc(snapshot.ref, req.body, { merge: true });
|
||||
await db.collection("invites").updateOne(
|
||||
{ id: id },
|
||||
{ $set: {id: id, ...req.body} },
|
||||
{ upsert: true }
|
||||
);
|
||||
return res.status(200).json({ ok: true });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import {app} from "@/firebase";
|
||||
import {getFirestore, getDoc, doc, deleteDoc, setDoc, getDocs, collection, where, query} from "firebase/firestore";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {Ticket} from "@/interfaces/ticket";
|
||||
import {Invite} from "@/interfaces/invite";
|
||||
import {CorporateUser, Group, User} from "@/interfaces/user";
|
||||
import {v4} from "uuid";
|
||||
import {sendEmail} from "@/email";
|
||||
import {updateExpiryDateOnGroup} from "@/utils/groups.be";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import client from "@/lib/mongodb";
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { Invite } from "@/interfaces/invite";
|
||||
import { CorporateUser, Group, User } from "@/interfaces/user";
|
||||
import { v4 } from "uuid";
|
||||
import { sendEmail } from "@/email";
|
||||
import { updateExpiryDateOnGroup } from "@/utils/groups.be";
|
||||
|
||||
const db = getFirestore(app);
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -22,12 +20,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
async function addToInviterGroup(user: User, invitedBy: User) {
|
||||
const invitedByGroupsRef = await getDocs(query(collection(db, "groups"), where("admin", "==", invitedBy.id)));
|
||||
const invitedByGroups = invitedByGroupsRef.docs.map((g) => ({
|
||||
...g.data(),
|
||||
id: g.id,
|
||||
})) as Group[];
|
||||
|
||||
const invitedByGroups = await db.collection("groups").find<Group>({ admin: invitedBy.id }).toArray();
|
||||
const typeGroupName = user.type === "student" ? "Students" : user.type === "teacher" ? "Teachers" : undefined;
|
||||
|
||||
if (typeGroupName) {
|
||||
@@ -38,14 +31,18 @@ async function addToInviterGroup(user: User, invitedBy: User) {
|
||||
participants: [],
|
||||
disableEditing: true,
|
||||
};
|
||||
await setDoc(
|
||||
doc(db, "groups", typeGroup.id),
|
||||
|
||||
await db.collection("groups").updateOne(
|
||||
{ id: typeGroup.id },
|
||||
{
|
||||
...typeGroup,
|
||||
participants: [...typeGroup.participants.filter((x) => x !== user.id), user.id],
|
||||
$set: {
|
||||
...typeGroup,
|
||||
participants: [...typeGroup.participants.filter((x) => x !== user.id), user.id],
|
||||
},
|
||||
},
|
||||
{merge: true},
|
||||
{ upsert: true }
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
const invitationsGroup: Group = invitedByGroups.find((g) => g.name === "Invited") || {
|
||||
@@ -55,54 +52,58 @@ async function addToInviterGroup(user: User, invitedBy: User) {
|
||||
participants: [],
|
||||
disableEditing: true,
|
||||
};
|
||||
await setDoc(
|
||||
doc(db, "groups", invitationsGroup.id),
|
||||
|
||||
await db.collection("groups").updateOne(
|
||||
{ id: invitationsGroup.id },
|
||||
{
|
||||
...invitationsGroup,
|
||||
participants: [...invitationsGroup.participants.filter((x) => x !== user.id), user.id],
|
||||
},
|
||||
{
|
||||
merge: true,
|
||||
$set: {
|
||||
...invitationsGroup,
|
||||
participants: [...invitationsGroup.participants.filter((x) => x !== user.id), user.id],
|
||||
}
|
||||
},
|
||||
{ upsert: true }
|
||||
);
|
||||
}
|
||||
|
||||
async function deleteFromPreviousCorporateGroups(user: User, invitedBy: User) {
|
||||
const corporatesRef = await getDocs(query(collection(db, "users"), where("type", "==", "corporate")));
|
||||
const corporates = (corporatesRef.docs.map((x) => ({...x.data(), id: x.id})) as CorporateUser[]).filter((x) => x.id !== invitedBy.id);
|
||||
const corporatesRef = await db.collection("users").find<CorporateUser>({ type: "corporate" }).toArray();
|
||||
const corporates = corporatesRef.filter((x) => x.id !== invitedBy.id);
|
||||
|
||||
const userGroupsRef = await getDocs(query(collection(db, "groups"), where("participants", "array-contains", user.id)));
|
||||
const userGroups = userGroupsRef.docs.map((x) => ({...x.data(), id: x.id})) as Group[];
|
||||
const userGroups = await db.collection("groups").find<Group>({
|
||||
participants: user.id
|
||||
}).toArray();
|
||||
|
||||
const corporateGroups = userGroups.filter((x) => corporates.map((c) => c.id).includes(x.admin));
|
||||
await Promise.all(
|
||||
corporateGroups.map(async (group) => {
|
||||
await setDoc(doc(db, "groups", group.id), {participants: group.participants.filter((x) => x !== user.id)}, {merge: true});
|
||||
await db.collection("groups").updateOne(
|
||||
{ id: group.id },
|
||||
{ $set: { participants: group.participants.filter((x) => x !== user.id) } },
|
||||
{ upsert: true }
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!req.session.user) {
|
||||
res.status(401).json({ok: false});
|
||||
res.status(401).json({ ok: false });
|
||||
return;
|
||||
}
|
||||
|
||||
const {id} = req.query as {id: string};
|
||||
const snapshot = await getDoc(doc(db, "invites", id));
|
||||
const { id } = req.query as { id: string };
|
||||
const invite = await db.collection("invites").findOne<Invite>({ id: id});
|
||||
|
||||
if (snapshot.exists()) {
|
||||
const invite = {...snapshot.data(), id: snapshot.id} as Invite;
|
||||
if (invite.to !== req.session.user.id) return res.status(403).json({ok: false});
|
||||
if (invite) {
|
||||
if (invite.to !== req.session.user.id) return res.status(403).json({ ok: false });
|
||||
|
||||
await deleteDoc(snapshot.ref);
|
||||
const invitedByRef = await getDoc(doc(db, "users", invite.from));
|
||||
if (!invitedByRef.exists()) return res.status(404).json({ok: false});
|
||||
await db.collection("invites").deleteOne({ id: id });
|
||||
|
||||
const invitedBy = await db.collection("users").findOne<User>({ id: invite.from});
|
||||
if (!invitedBy) return res.status(404).json({ ok: false });
|
||||
|
||||
await updateExpiryDateOnGroup(invite.to, invite.from);
|
||||
|
||||
const invitedBy = {...invitedByRef.data(), id: invitedByRef.id} as User;
|
||||
|
||||
if (invitedBy.type === "corporate") await deleteFromPreviousCorporateGroups(req.session.user, invitedBy);
|
||||
await addToInviterGroup(req.session.user, invitedBy);
|
||||
|
||||
@@ -122,7 +123,7 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
res.status(200).json({ok: true});
|
||||
res.status(200).json({ ok: true });
|
||||
} else {
|
||||
res.status(404).json(undefined);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import {app} from "@/firebase";
|
||||
import {getFirestore, getDoc, doc, deleteDoc, setDoc, getDocs, collection, where, query} from "firebase/firestore";
|
||||
import client from "@/lib/mongodb";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {Ticket} from "@/interfaces/ticket";
|
||||
import {Invite} from "@/interfaces/invite";
|
||||
import {Group, User} from "@/interfaces/user";
|
||||
import {v4} from "uuid";
|
||||
import {User} from "@/interfaces/user";
|
||||
import {sendEmail} from "@/email";
|
||||
|
||||
const db = getFirestore(app);
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -27,17 +24,14 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
const {id} = req.query as {id: string};
|
||||
const snapshot = await getDoc(doc(db, "invites", id));
|
||||
const invite = await db.collection("invites").findOne<Invite>({ id: id});
|
||||
|
||||
if (snapshot.exists()) {
|
||||
const invite = {...snapshot.data(), id: snapshot.id} as Invite;
|
||||
if (invite) {
|
||||
if (invite.to !== req.session.user.id) return res.status(403).json({ok: false});
|
||||
|
||||
await deleteDoc(snapshot.ref);
|
||||
const invitedByRef = await getDoc(doc(db, "users", invite.from));
|
||||
if (!invitedByRef.exists()) return res.status(404).json({ok: false});
|
||||
|
||||
const invitedBy = {...invitedByRef.data(), id: invitedByRef.id} as User;
|
||||
await db.collection("invites").deleteOne({ id: id });
|
||||
const invitedBy = await db.collection("users").findOne<User>({ id: invite.from });
|
||||
if (!invitedBy) return res.status(404).json({ok: false});
|
||||
|
||||
try {
|
||||
await sendEmail(
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import {sendEmail} from "@/email";
|
||||
import {app} from "@/firebase";
|
||||
import {Invite} from "@/interfaces/invite";
|
||||
import {Ticket} from "@/interfaces/ticket";
|
||||
import {User} from "@/interfaces/user";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {collection, doc, getDoc, getDocs, getFirestore, setDoc} from "firebase/firestore";
|
||||
import client from "@/lib/mongodb";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import ShortUniqueId from "short-unique-id";
|
||||
|
||||
const db = getFirestore(app);
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -25,29 +24,20 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const snapshot = await getDocs(collection(db, "invites"));
|
||||
|
||||
res.status(200).json(
|
||||
snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
})),
|
||||
);
|
||||
const snapshot = await db.collection("invites").find({}).toArray();
|
||||
res.status(200).json(snapshot);
|
||||
}
|
||||
|
||||
async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const body = req.body as Invite;
|
||||
|
||||
const existingInvites = (await getDocs(collection(db, "invites"))).docs.map((x) => ({...x.data(), id: x.id})) as Invite[];
|
||||
const existingInvites = await db.collection("invites").find<Invite>({}).toArray();
|
||||
|
||||
const invitedRef = await getDoc(doc(db, "users", body.to));
|
||||
if (!invitedRef.exists()) return res.status(404).json({ok: false});
|
||||
const invited = await db.collection("users").findOne<User>({ id: body.to});
|
||||
if (!invited) return res.status(404).json({ok: false});
|
||||
|
||||
const invitedByRef = await getDoc(doc(db, "users", body.from));
|
||||
if (!invitedByRef.exists()) return res.status(404).json({ok: false});
|
||||
|
||||
const invited = {...invitedRef.data(), id: invitedRef.id} as User;
|
||||
const invitedBy = {...invitedByRef.data(), id: invitedByRef.id} as User;
|
||||
const invitedBy = await db.collection("users").findOne<User>({ id: body.from});
|
||||
if (!invitedBy) return res.status(404).json({ok: false});
|
||||
|
||||
try {
|
||||
await sendEmail(
|
||||
@@ -67,7 +57,11 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
if (existingInvites.filter((i) => i.to === body.to && i.from === body.from).length == 0) {
|
||||
const shortUID = new ShortUniqueId();
|
||||
await setDoc(doc(db, "invites", body.id || shortUID.randomUUID(8)), body);
|
||||
await db.collection("invites").updateOne(
|
||||
{ id: body.id || shortUID.randomUUID(8)},
|
||||
{ $set: body },
|
||||
{ upsert: true}
|
||||
);
|
||||
}
|
||||
|
||||
res.status(200).json({ok: true});
|
||||
|
||||
Reference in New Issue
Block a user