Skip to content

Commit

Permalink
Merge pull request #27 from SpaghettiDB/userLogin
Browse files Browse the repository at this point in the history
update user / team indof
  • Loading branch information
Mohamed-khattab authored Jun 21, 2024
2 parents 453a084 + 26061bf commit 8fe23a8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .env.example

This file was deleted.

5 changes: 3 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import express from "express";
import cors from "cors";
import userRoute from "./routes/userRoute.js";
Expand All @@ -6,10 +7,10 @@ import { tokenAuth } from "./middlewares/authMiddleware.js";
import projectRoute from "./routes/projectRoute.js";
import DatabaseRoute from "./routes/databaseRoute.js";
import teamRoute from "./routes/teamRoute.js";

import cors from "cors";
const app = express();
const port = 3000;

app.use(cors());
app.use(express.json());
app.use(
cors({
Expand Down
13 changes: 13 additions & 0 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const registerController = async (req, res) => {
.status(201)
.json({ message: `User ${createdUser.email} created successfully` });
} catch (err) {
console.log(err)
res.status(500).json({ error: err });
}
}
Expand All @@ -62,3 +63,15 @@ export const grantController = async (req, res) => {
await updateMember(team_id, user_id);
res.status(200).json({ message: `Successfully updated the role` });
};

export const updateUserController = async (req, res) => {
const { email, userData } = req.body;
await updateUser(email, userData);
res.status(200).json({ message: "User data updated successfully" });
};
export const getController = async (req, res) => {
const user = req.user;
user_info=await userModel.getUser(user.email);
res.status(200).json({user_info: user_info });
};

14 changes: 10 additions & 4 deletions src/routes/userRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import {
registerController,
logoutController,
grantController,
updateUserController,
getController

} from "../controllers/userController.js";
//import { tokenAuth } from "../middlewares/authMiddleware.js";
const route = express.Router();

route.post("/login", loginController);
route.post("/register", registerController);
route.post("/logout", logoutController);
route.post("/grant", grantController);
route.post("/login",loginController);
route.post("/register", registerController);
route.post("/logout", logoutController);
route.post("/grant", grantController);
route.put("/update",updateUserController)
route.get("/",getController)

export default route;

0 comments on commit 8fe23a8

Please sign in to comment.