From 4e91b2f1fb5258f87b3a89bed6a3cc5c583e02a4 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sun, 8 Sep 2024 10:08:24 +0100 Subject: [PATCH 1/7] ENCOA-202: Fixed issue updating user --- src/pages/api/users/update.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/api/users/update.ts b/src/pages/api/users/update.ts index 4f7ba431..121a01b3 100644 --- a/src/pages/api/users/update.ts +++ b/src/pages/api/users/update.ts @@ -77,7 +77,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { const queryId = req.query.id as string; - let user = await db.collection("users").findOne({ id: queryId ? (queryId as string) : req.session.user.id }); + const userId = queryId ? (queryId as string) : req.session.user.id + let user = await db.collection("users").findOne({ id: userId }); const updatedUser = req.body as User & { password?: string; newPassword?: string }; if (!!queryId) { @@ -160,7 +161,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { delete updatedUser.newPassword; await db.collection("users").updateOne( - { id: queryId }, + { id: userId }, { $set: updatedUser } ); From 2e065eddcb9a0d7a20571bb5db72ba0ee3e2bd8e Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sun, 8 Sep 2024 10:19:49 +0100 Subject: [PATCH 2/7] Added an workaround for the broken email system --- src/pages/api/register.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pages/api/register.ts b/src/pages/api/register.ts index 32636243..e0f0b591 100644 --- a/src/pages/api/register.ts +++ b/src/pages/api/register.ts @@ -72,6 +72,9 @@ async function registerIndividual(req: NextApiRequest, res: NextApiResponse) { ...(passport_id ? {demographicInformation: {passport_id}} : {}), registrationDate: new Date().toISOString(), status: code ? "active" : "paymentDue", + // apparently there's an issue with the verification email system + // therefore we will skip this requirement for now + isVerified: true, }; await db.collection("users").insertOne(user); @@ -117,6 +120,9 @@ async function registerCorporate(req: NextApiRequest, res: NextApiResponse) { subscriptionExpirationDate: req.body.subscriptionExpirationDate || null, status: "paymentDue", registrationDate: new Date().toISOString(), + // apparently there's an issue with the verification email system + // therefore we will skip this requirement for now + isVerified: true, }; const defaultTeachersGroup: Group = { From a073ca1cce7228742b784964dcdf8605e6865f32 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sun, 8 Sep 2024 13:56:08 +0100 Subject: [PATCH 3/7] Temporarily disabled Play Again button --- src/exams/Finish.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/exams/Finish.tsx b/src/exams/Finish.tsx index 4cbbe458..9d89242d 100644 --- a/src/exams/Finish.tsx +++ b/src/exams/Finish.tsx @@ -287,7 +287,9 @@ export default function Finish({user, scores, modules, information, solutions, i
From 71bac76c3abf971a038a27d7a72b4c4a3538e928 Mon Sep 17 00:00:00 2001 From: Carlos Mesquita Date: Mon, 23 Sep 2024 00:04:06 +0100 Subject: [PATCH 4/7] More mongodb migration bugs, remove _id from find, and a stat endpoint firebase leftover bug --- src/pages/api/stats/[id]/index.ts | 2 +- src/utils/users.be.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/api/stats/[id]/index.ts b/src/pages/api/stats/[id]/index.ts index f531284b..75cd2f41 100644 --- a/src/pages/api/stats/[id]/index.ts +++ b/src/pages/api/stats/[id]/index.ts @@ -16,5 +16,5 @@ async function GET(req: NextApiRequest, res: NextApiResponse) { const snapshot = await db.collection("stats").findOne({ id: id as string}); if (!snapshot) return res.status(404).json({id: id as string}); - res.status(200).json({...snapshot.data(), id: snapshot.id}); + res.status(200).json({...snapshot, id: snapshot.id}); } diff --git a/src/utils/users.be.ts b/src/utils/users.be.ts index cd5c1c1a..31ecbe05 100644 --- a/src/utils/users.be.ts +++ b/src/utils/users.be.ts @@ -8,11 +8,11 @@ import client from "@/lib/mongodb"; const db = client.db(process.env.MONGODB_DB); export async function getUsers() { - return await db.collection("users").find({}).toArray(); + return await db.collection("users").find({}, { projection: { _id: 0 } }).toArray(); } export async function getUser(id: string): Promise { - const user = await db.collection("users").findOne({id}); + const user = await db.collection("users").findOne({id: id}, { projection: { _id: 0 } }); return !!user ? user : undefined; } @@ -21,7 +21,7 @@ export async function getSpecificUsers(ids: string[]) { return await db .collection("users") - .find({id: {$in: ids}}) + .find({id: {$in: ids}}, { projection: { _id: 0 } }) .toArray(); } From 07c9074d1536dbf1cb899125d017897d33ca4661 Mon Sep 17 00:00:00 2001 From: Carlos Mesquita Date: Mon, 23 Sep 2024 01:09:34 +0100 Subject: [PATCH 5/7] More bugs, some updates where not using set --- src/pages/api/evaluate/writing.ts | 42 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/pages/api/evaluate/writing.ts b/src/pages/api/evaluate/writing.ts index af1850d8..1645e8a1 100644 --- a/src/pages/api/evaluate/writing.ts +++ b/src/pages/api/evaluate/writing.ts @@ -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,27 +36,29 @@ 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, - solutions, - score: { - correct: writingReverseMarking[backendRequest.data.overall], - total: 100, - missing: 0, - }, - isDisabled: false, + { id: (req.body as Body).id }, + { + $set: { + id: (req.body as Body).id, + solutions, + score: { + correct: writingReverseMarking[backendRequest.data.overall], + total: 100, + missing: 0, + }, + isDisabled: false, + } }, - {upsert: true}, + { upsert: true }, ); console.log("🌱 - Updated the DB"); } async function getCorrespondingStat(id: string, index: number): Promise { console.log(`🌱 - Try number ${index} - ${id}`); - const correspondingStat = await db.collection("stats").findOne({ id: id}); + const correspondingStat = await db.collection("stats").findOne({ id: id }); if (correspondingStat) return correspondingStat; From 044ec8d9669f0041e002dc1e635bd5a441648b8e Mon Sep 17 00:00:00 2001 From: Carlos-Mesquita Date: Tue, 1 Oct 2024 15:34:56 +0100 Subject: [PATCH 6/7] Added back the demographic view --- src/pages/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 6a4f9ca4..ef4f7bd9 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -79,7 +79,7 @@ export default function Home({user: propsUser, linkedCorporate}: Props) { useEffect(() => { if (user) { - // setShowDemographicInput(!user.demographicInformation || !user.demographicInformation.country || !user.demographicInformation.phone); + setShowDemographicInput(!user.demographicInformation || !user.demographicInformation.country || !user.demographicInformation.phone); setShowDiagnostics(user.isFirstLogin && user.type === "student"); } }, [user]); From 3c1c4489f8b233f54bba2e3ec9c4d16b03daa9d1 Mon Sep 17 00:00:00 2001 From: Carlos-Mesquita Date: Tue, 1 Oct 2024 17:11:04 +0100 Subject: [PATCH 7/7] Updated user had only demographicInformation and was causing the diagnostic view to not show up after submitting the info --- src/pages/api/users/update.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/api/users/update.ts b/src/pages/api/users/update.ts index aab28fa9..681cca55 100644 --- a/src/pages/api/users/update.ts +++ b/src/pages/api/users/update.ts @@ -158,7 +158,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { delete updatedUser.password; delete updatedUser.newPassword; - await db.collection("users").updateOne({id: queryId}, {$set: updatedUser}); + await db.collection("users").updateOne({id: queryId ? (queryId as string) : req.session.user.id}, {$set: updatedUser}); if (!queryId) { req.session.user = updatedUser ? {...updatedUser, id: req.session.user.id} : null; @@ -169,7 +169,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { await managePaymentRecords({...updatedUser, id: req.session.user!.id}, queryId); } - res.status(200).json({user: {...updatedUser, id: req.session.user!.id}}); + res.status(200).json({user: {...updatedUser, ...user, id: req.session.user!.id}}); } export const config = {