Refactored discounts and replaced my previous commit id queries to use id not _id
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { app, storage } from "@/firebase";
|
||||
import { storage } from "@/firebase";
|
||||
import client from "@/lib/mongodb";
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import ReactPDF from "@react-pdf/renderer";
|
||||
@@ -100,8 +99,8 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.session.user) {
|
||||
const { id } = req.query as { id: string };
|
||||
|
||||
const data = await db.collection("assignments").findOne({ _id: new ObjectId(id) }) as {
|
||||
_id: ObjectId;
|
||||
const data = await db.collection("assignments").findOne({ id: id }) as {
|
||||
id: string;
|
||||
assigner: string;
|
||||
assignees: string[];
|
||||
results: any;
|
||||
@@ -127,7 +126,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await db.collection("users").findOne<User>({ _id: new ObjectId(req.session.user.id) });
|
||||
const user = await db.collection("users").findOne<User>({ id: req.session.user.id });
|
||||
|
||||
// we'll need the user in order to get the user data (name, email, focus, etc);
|
||||
if (user) {
|
||||
@@ -145,7 +144,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
}, []) as Stat[];
|
||||
|
||||
const users = await db.collection("users").find<User>({
|
||||
_id: { $in: data.assignees.map(id => new ObjectId(id)) }
|
||||
id: { $in: data.assignees.map(id => id) }
|
||||
}).toArray();
|
||||
|
||||
const flattenResultsWithGrade = flattenResults.map((e) => {
|
||||
@@ -299,7 +298,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const getInstitution = async () => {
|
||||
try {
|
||||
// due to database inconsistencies, I'll be overprotective here
|
||||
const assignerUser = await db.collection("users").findOne<User>({ _id: new ObjectId(data.assigner) });
|
||||
const assignerUser = await db.collection("users").findOne<User>({ id: data.assigner });
|
||||
|
||||
// we'll need the user in order to get the user data (name, email, focus, etc);
|
||||
if (assignerUser) {
|
||||
@@ -311,7 +310,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
if (groups.length > 0) {
|
||||
const admins = await db.collection("users")
|
||||
.find<CorporateUser>({ _id: { $in: groups.map(g => g.admin).map(id => new ObjectId(id))} })
|
||||
.find<CorporateUser>({ id: { $in: groups.map(g => g.admin).map(id => id)} })
|
||||
.toArray();
|
||||
|
||||
const adminData = admins.find((a) => a.corporateInformation?.companyInformation?.name);
|
||||
@@ -372,7 +371,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
// update the stats entries with the pdf url to prevent duplication
|
||||
await db.collection("assignments").updateOne(
|
||||
{ _id: new ObjectId(data._id) },
|
||||
{ id: data.id },
|
||||
{
|
||||
$set: {
|
||||
pdf: {
|
||||
@@ -401,7 +400,7 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.session.user) {
|
||||
const { id } = req.query as { id: string };
|
||||
|
||||
const data = await db.collection("assignments").findOne({ _id: new ObjectId(id) });
|
||||
const data = await db.collection("assignments").findOne({ id: id });
|
||||
if (!data) {
|
||||
res.status(400).end();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user