Skip to content

Commit

Permalink
Merge pull request #14 from KinanaDB/userLogin
Browse files Browse the repository at this point in the history
new login with jwt plus the grant task
  • Loading branch information
Mohamed-khattab authored Feb 23, 2024
2 parents 4de2e9e + db42415 commit 66ee8d4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import bcrypt from "bcrypt";
const secretKey = process.env.SECRET_KEY;
import * as userModel from "../models/userModel.js";
import * as teamModel from "../models/teamModel.js";
import { memberExist, updateMember } from "../models/teamModel";

export const loginController = async (req, res) => {
const { email, password } = req.body;
Expand Down Expand Up @@ -55,3 +56,14 @@ export const logoutController = async (req, res) => {
res.clearCookie("access-token");
res.status(200).json({ message: `Logged out successfully` });
};

export const grantController = async (req, res) => {
const { team_id, user_id} = req.body;
const existingMember = await memberExist(team_id, user_id);

if (!existingMember) {
console.log('No team member with the given user id');
}
await updateMember(team_id, user_id);
console.log('Successfully updated the role');
};
13 changes: 13 additions & 0 deletions src/models/teamModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,16 @@ export async function joinTeam(token, userId) {
}
return false;
}

export async function updateMember(team_id, user_id) {
await prisma.teamMembers.update({
where: {
teamId_userId: {
teamId: team_id,
userId: user_id.id
},
role:'LEADER'
}
})
return true
}
11 changes: 11 additions & 0 deletions src/models/userModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ export async function updateUser(e_mail, userData) {
}
return false
}
export async function userRole (e_mail) {
const user_Role = await prisma.user.findUnique({
where: {
email: e_mail
},
select: {
role: true
}
})
return user_Role
}
1 change: 1 addition & 0 deletions src/routes/userRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ const route = express.Router();
route.post("/login", loginController);
route.post("/register", registerController);
route.post("/logout", logoutController);
route.post('/grant', grantController);

export default route;

0 comments on commit 66ee8d4

Please sign in to comment.