Skip to content

Commit

Permalink
fix:backend
Browse files Browse the repository at this point in the history
  • Loading branch information
nsavinda committed Jan 3, 2024
1 parent 7ae169e commit 3f6e0a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGO=

11 changes: 8 additions & 3 deletions backend/src/Controllers/sessionReg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Session from "../Model/session";
import{ Request, Response } from "express";

export const register = async (req: Request, res: Response) => {
console.log("aaaa", req.body)
// console.log("", req.body)
try {
const newSession = new Session({
email: req.body.email,
Expand All @@ -12,8 +12,13 @@ export const register = async (req: Request, res: Response) => {
year: req.body.year,
});
await newSession.save();
res.status(200).send("newSession has been created");
res.status(200).send("Session has been created");

res.status(200).json({
success: true,
message: "Registered successfully",
data: newSession,
});

} catch (err) {
res.send(err)
console.log(err)
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express,{ Express , Request, Response} from "express";
import cors from "cors";
import mongoose from "mongoose";
import dotenv from "dotenv";
import authRoute from "../src/Routes/auth";
import sessionRegRoute from "./Routes/sessionReg";
dotenv.config();

const URL = process.env.MONGO || "";
Expand All @@ -25,11 +25,11 @@ app.use(cors(
// res.send(response);
// });

app.use("/api/register", authRoute);
app.use("/api/register", sessionRegRoute);

const connect = async () => {
try {
await mongoose.connect("mongodb+srv://udeeshaprabhashana123:[email protected]/?retryWrites=true&w=majority");
await mongoose.connect(URL);
console.log("Connect to mongoDB");
} catch (error) {
throw error;
Expand Down

0 comments on commit 3f6e0a9

Please sign in to comment.