mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 12:36:57 +00:00
Database collection models
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { unstable_cache } from "next/cache";
|
||||
|
||||
import clientPromise from "@/lib/mongodb";
|
||||
import { Club, ClubData } from "@/types";
|
||||
import { collections, dbConnect } from "@/server/mongodb";
|
||||
import { Club } from "@/types";
|
||||
import { errorLog } from "@/utils/logger";
|
||||
|
||||
import ClubsDisplay from "./ClubsDisplay";
|
||||
@@ -10,13 +10,8 @@ export const revalidate = 3600; // Revalidate cache every 6 hours
|
||||
|
||||
const getClubs = async () => {
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("tournamentsFranceDB");
|
||||
const data = await db
|
||||
.collection("clubs")
|
||||
.find<ClubData>({})
|
||||
.sort({ name: 1 })
|
||||
.toArray();
|
||||
await dbConnect();
|
||||
const data = await collections.clubs!.find({}).sort({ name: 1 }).toArray();
|
||||
|
||||
return data
|
||||
.filter((c) => !!c.coordinates)
|
||||
|
||||
@@ -9,9 +9,9 @@ import { fr } from "date-fns/locale";
|
||||
import { groupBy } from "lodash";
|
||||
import { unstable_cache } from "next/cache";
|
||||
|
||||
import clientPromise from "@/lib/mongodb";
|
||||
import { TournamentData } from "@/types";
|
||||
import { TimeControl, Tournament, tcMap, tournamentDataSchema } from "@/types";
|
||||
import { tournamentModelSchema } from "@/server/models/tournamentModel";
|
||||
import { collections, dbConnect } from "@/server/mongodb";
|
||||
import { TimeControl, Tournament, tcMap } from "@/types";
|
||||
import { errorLog } from "@/utils/logger";
|
||||
|
||||
import TournamentsDisplay from "./TournamentsDisplay";
|
||||
@@ -20,11 +20,10 @@ setDefaultOptions({ locale: fr });
|
||||
|
||||
const getTournaments = async () => {
|
||||
try {
|
||||
const client = await clientPromise;
|
||||
const db = client.db("tournamentsFranceDB");
|
||||
const data = await db
|
||||
.collection("tournaments")
|
||||
.aggregate<TournamentData>([
|
||||
await dbConnect();
|
||||
|
||||
const data = await collections
|
||||
.tournaments!.aggregate([
|
||||
{
|
||||
$addFields: {
|
||||
dateParts: {
|
||||
@@ -52,7 +51,7 @@ const getTournaments = async () => {
|
||||
.toArray();
|
||||
|
||||
const bad = data.filter((t) => {
|
||||
const result = tournamentDataSchema.safeParse(t);
|
||||
const result = tournamentModelSchema.safeParse(t);
|
||||
if (result.success === false) {
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
console.log(JSON.stringify(t, null, 2));
|
||||
|
||||
Reference in New Issue
Block a user