Compare commits
11 Commits
release/as
...
bugfix/mon
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c1c4489f8 | ||
|
|
044ec8d966 | ||
|
|
07c9074d15 | ||
|
|
71bac76c3a | ||
|
|
fb293dc98c | ||
|
|
5153c3d5f1 | ||
|
|
392eac2ef9 | ||
|
|
a073ca1cce | ||
|
|
7e30ca5750 | ||
|
|
2e065eddcb | ||
|
|
4e91b2f1fb |
@@ -287,7 +287,9 @@ export default function Finish({user, scores, modules, information, solutions, i
|
||||
<div className="flex w-fit cursor-pointer flex-col items-center gap-1">
|
||||
<button
|
||||
onClick={() => window.location.reload()}
|
||||
disabled={user.type === "admin"}
|
||||
// disabled={user.type === "admin"}
|
||||
// TODO: temporarily disabled
|
||||
disabled
|
||||
className="bg-mti-purple-light hover:bg-mti-purple flex h-11 w-11 items-center justify-center rounded-full transition duration-300 ease-in-out">
|
||||
<BsArrowCounterclockwise className="h-7 w-7 text-white" />
|
||||
</button>
|
||||
|
||||
@@ -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<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;
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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<User>({}).toArray();
|
||||
return await db.collection("users").find<User>({}, { projection: { _id: 0 } }).toArray();
|
||||
}
|
||||
|
||||
export async function getUser(id: string): Promise<User | undefined> {
|
||||
const user = await db.collection("users").findOne<User>({id});
|
||||
const user = await db.collection("users").findOne<User>({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<User>({id: {$in: ids}})
|
||||
.find<User>({id: {$in: ids}}, { projection: { _id: 0 } })
|
||||
.toArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user