Merged in develop (pull request #162)
Implemented limit 5 sessions per User
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
useReactTable,
|
useReactTable,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { BsArrowDown, BsArrowUp } from "react-icons/bs";
|
import { BsArrowDown, BsArrowUp } from "react-icons/bs";
|
||||||
import Button from "../Low/Button";
|
import Button from "../Low/Button";
|
||||||
|
|
||||||
|
|||||||
@@ -48,4 +48,9 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
await db.collection("sessions").updateOne({ id: session.id }, { $set: session }, { upsert: true });
|
await db.collection("sessions").updateOne({ id: session.id }, { $set: session }, { upsert: true });
|
||||||
|
|
||||||
res.status(200).json({ ok: true });
|
res.status(200).json({ ok: true });
|
||||||
|
const sessions = await db.collection("sessions").find<Session>({ user: session.user }, { projection: { id: 1 } }).sort({ date: 1 }).toArray();
|
||||||
|
// Delete old sessions
|
||||||
|
if (sessions.length > 5) {
|
||||||
|
await db.collection("sessions").deleteOne({ id: { $in: sessions.slice(0, sessions.length - 5).map(x => x.id) } });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user