This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Programming-Club-Ahmedabad-University/auc…
…tionPart clan and user db schemas and methods to add and get clans
- Loading branch information
Showing
4 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ClanCol>("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<ClanCol>("Clans"); | ||
|
||
await clans.insertOne({ | ||
name:name, | ||
balance:amount, | ||
admin:admin, | ||
}) | ||
|
||
return res.status(200).json({message:"team saved"}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,4 @@ const handler = NextAuth({ | |
}, | ||
}); | ||
|
||
export default handler; | ||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div> | ||
<form | ||
style={{ display: 'flex', justifyContent: 'center', flexDirection: "column", gap: "10px" }} | ||
> | ||
<input | ||
type="text" | ||
placeholder="Enter clan name..." | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
/> | ||
<input | ||
type="number" | ||
placeholder="Enter budget" | ||
value={amount} | ||
onChange={(e) => setAmount(e.target.value)} | ||
/> | ||
<input | ||
type="text" | ||
placeholder="clan admin registered e-mail id" | ||
value={admin} | ||
onChange={(e) => setAdmin(e.target.value)} | ||
/> | ||
<div style={{ display: 'flex', justifyContent: 'center', alignItems: "center" }}> | ||
<button onClick={(e) => handleSubmit(e)}>Add</button> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Clan; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters