Refactored discounts and replaced my previous commit id queries to use id not _id

This commit is contained in:
Carlos Mesquita
2024-09-07 16:03:26 +01:00
parent 171231cd21
commit c07e3f86fb
13 changed files with 65 additions and 104 deletions

View File

@@ -1,7 +1,6 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type {NextApiRequest, NextApiResponse} from "next";
import client from "@/lib/mongodb";
import { ObjectId } from 'mongodb';
import {withIronSessionApiRoute} from "iron-session/next";
import {sessionOptions} from "@/lib/session";
@@ -26,7 +25,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
async function GET(req: NextApiRequest, res: NextApiResponse) {
const {id} = req.query;
const snapshot = await db.collection("assignments").findOne({ _id: new ObjectId(id as string) });
const snapshot = await db.collection("assignments").findOne({ id: id as string });
if (snapshot) {
res.status(200).json({...snapshot, id: snapshot._id});
@@ -37,7 +36,7 @@ async function DELETE(req: NextApiRequest, res: NextApiResponse) {
const {id} = req.query;
await db.collection("assignments").deleteOne(
{ _id: new ObjectId(id as string) }
{ id: id as string }
);
res.status(200).json({ok: true});
@@ -47,7 +46,7 @@ async function PATCH(req: NextApiRequest, res: NextApiResponse) {
const {id} = req.query;
await db.collection("assignments").updateOne(
{ _id: new ObjectId(id as string) },
{ id: id as string },
{ $set: {assigner: req.session.user?.id, ...req.body} }
);