Skip to content

Commit

Permalink
adding backend logic
Browse files Browse the repository at this point in the history
  • Loading branch information
charlotteconze committed Oct 24, 2024
1 parent 29ffb85 commit 79589af
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 36 deletions.
File renamed without changes.
Empty file.
36 changes: 0 additions & 36 deletions api/src/index.ts

This file was deleted.

40 changes: 40 additions & 0 deletions api/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import user from "./user"

export { user }

// import express, { Request, Response, Application } from "express"
// import cors from "cors"
// import dbConnect from "./config/dbConnect"
// import mongoose from "mongoose"

// import { Group, IGroup } from "./model/Group"
// import { User, IUser } from "./model/User"
// import { Expense } from "./model/Expense"
// import { populate } from "dotenv"

// dbConnect()

// const app: Application = express()
// app.use(cors())
// app.use(express.json()) // To parse JSON bodies
// const port = process.env.PORT || 8000

// // Test POST endpoint
// app.post("/test", (req: Request, res: Response) => {
// console.log(req.body) // Log the request body to check what you are receiving

// const { key } = req.body // Extract "key" from the request body
// if (!key) {
// return res.status(400).json({ message: "No key provided" })
// }

// return res.status(200).json({
// message: "Data received successfully",
// receivedKey: key,
// })
// })

// // Start the server
// app.listen(port, () => {
// console.log(`Server running at http://localhost:${port}`)
// })
33 changes: 33 additions & 0 deletions api/src/routes/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import express from "express"

const router = express.Router()
const axios = require("axios").default

router.post("/create-group", async (req, res) => {
const { groupName, groupMembers } = req.body

console.log("Received group data:", req.body)

// Validate request body
if (!groupName || !groupMembers) {
return res.status(400).json({
message: "Invalid data. Please provide group name and group members.",
})
}

// Log the received data for debugging
console.log("Received group data:", {
groupName,
groupMembers,
})

// Create a new group
const response = await axios.post("http://localhost:3001/api/group", {
groupName,
groupMembers,
})

return res.status(response.status).json(response.data)
})

export default router

0 comments on commit 79589af

Please sign in to comment.