diff --git a/client/pages/api/admin/auction/clan.ts b/client/pages/api/admin/auction/clan.ts new file mode 100644 index 0000000..95a8cd4 --- /dev/null +++ b/client/pages/api/admin/auction/clan.ts @@ -0,0 +1,40 @@ +import type { NextApiRequest, NextApiResponse } from "next"; +import { ClanCol } from "@/util/types"; +import { clientPromise } from "@/util/DB"; +import { getServerSession } from "next-auth/next" + +export default async function handler( + req: NextApiRequest, + res: NextApiResponse +) { + + if (req.method === "GET") { + return GET(req, res); + } else if (req.method === "POST") { + return POST(req, res); + } else { + return res.status(400).send(`Method ${req.method} is not supported!`); + } +} + +async function GET(req: NextApiRequest, res: NextApiResponse) { + const db = (await clientPromise).db("coc-portal"); + const clans = db.collection("Clans"); + + const fields = await clans.find(); + return res.json(fields); +} + +async function POST(req: NextApiRequest, res: NextApiResponse ) { + const {name,amount,admin} = req.body; + const db = (await clientPromise).db("coc-portal"); + const clans = db.collection("Clans"); + + await clans.insertOne({ + name:name, + balance:amount, + admin:admin, + }) + + return res.status(200).json({message:"team saved"}); +} \ No newline at end of file diff --git a/client/pages/api/auth/[...nextauth]/index.ts b/client/pages/api/auth/[...nextauth]/index.ts index e7acfde..afdf02c 100644 --- a/client/pages/api/auth/[...nextauth]/index.ts +++ b/client/pages/api/auth/[...nextauth]/index.ts @@ -46,4 +46,4 @@ const handler = NextAuth({ }, }); -export default handler; +export default handler; \ No newline at end of file diff --git a/client/pages/clan/add-clan.tsx b/client/pages/clan/add-clan.tsx new file mode 100644 index 0000000..67ed32a --- /dev/null +++ b/client/pages/clan/add-clan.tsx @@ -0,0 +1,66 @@ +'use client' +import React, { useState } from "react"; + +const Clan = () => { + const [name, setName] = useState(""); + const [amount, setAmount] = useState(""); + const [admin, setAdmin] = useState(""); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + try { + const response = await fetch('/api/admin/auction/clan', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + name, + amount, + admin, + }), + }); + + if (response.status === 200) { + setName(""); + setAmount(""); + setAdmin(""); + } + } catch (error) { + console.error("Error:", error); + } + }; + + return ( +
+
+ setName(e.target.value)} + /> + setAmount(e.target.value)} + /> + setAdmin(e.target.value)} + /> +
+ +
+
+
+ ); +}; + +export default Clan; \ No newline at end of file diff --git a/client/util/types.ts b/client/util/types.ts index aaeae2a..c128c09 100644 --- a/client/util/types.ts +++ b/client/util/types.ts @@ -3,7 +3,21 @@ import { ObjectId } from "mongodb"; export type UserCol = { name: string; email: string; - + rank?:number; + clan?:string; + soldPrice?:number + qualifOne?:number; + qualifTwo?:number; role: "Admin" | "Leader" | "Co-leader" | "Elder" | "Member" | null; _id?: ObjectId; }; + +export type ClanCol = { + name:string; + balance:string; + members?:ObjectId[]; + matchScores?:{[matchName:string]: number}; + admin:string; + adminId?:string | ObjectId; + _id?:ObjectId; +} \ No newline at end of file