More bugs, some updates where not using set
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import client from "@/lib/mongodb";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import axios, {AxiosResponse} from "axios";
|
||||
import {Stat} from "@/interfaces/user";
|
||||
import {writingReverseMarking} from "@/utils/score";
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import axios, { AxiosResponse } from "axios";
|
||||
import { Stat } from "@/interfaces/user";
|
||||
import { writingReverseMarking } from "@/utils/score";
|
||||
|
||||
interface Body {
|
||||
question: string;
|
||||
@@ -24,7 +24,7 @@ export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!req.session.user) {
|
||||
res.status(401).json({ok: false});
|
||||
res.status(401).json({ ok: false });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,10 +36,11 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const correspondingStat = await getCorrespondingStat(req.body.id, 1);
|
||||
|
||||
const solutions = correspondingStat.solutions.map((x) => ({...x, evaluation: backendRequest.data}));
|
||||
const solutions = correspondingStat.solutions.map((x) => ({ ...x, evaluation: backendRequest.data }));
|
||||
await db.collection("stats").updateOne(
|
||||
{ id: (req.body as Body).id},
|
||||
{ id: (req.body as Body).id },
|
||||
{
|
||||
$set: {
|
||||
id: (req.body as Body).id,
|
||||
solutions,
|
||||
score: {
|
||||
@@ -48,15 +49,16 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
missing: 0,
|
||||
},
|
||||
isDisabled: false,
|
||||
}
|
||||
},
|
||||
{upsert: true},
|
||||
{ upsert: true },
|
||||
);
|
||||
console.log("🌱 - Updated the DB");
|
||||
}
|
||||
|
||||
async function getCorrespondingStat(id: string, index: number): Promise<Stat> {
|
||||
console.log(`🌱 - Try number ${index} - ${id}`);
|
||||
const correspondingStat = await db.collection("stats").findOne<Stat>({ id: id});
|
||||
const correspondingStat = await db.collection("stats").findOne<Stat>({ id: id });
|
||||
|
||||
if (correspondingStat) return correspondingStat;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user