Skip to content

Commit

Permalink
Refactor login and team services
Browse files Browse the repository at this point in the history
  • Loading branch information
hirushig committed Jan 29, 2024
1 parent 35b29d3 commit 3506eb9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
17 changes: 9 additions & 8 deletions code/backend/src/controllers/login.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ class LoginController {
}

const email = loginReq.userName;
const manager = await ManagerModel.findOne({ email });
const manager = await ManagerModel.findOne({
teamId: loginReq.teamId,
email: email,
});
console.log(300);
console.log(manager);

console.log(manager?.isVerified);

if (manager?.isVerified == "pending" || manager?.isVerified == "rejected") {
throw new Error(HttpMsg.MANAGER_NOT_VERIFIED);
}




try {
// create refresh token
const refreshToken = createRefreshTokenManager(loginReq, role);
Expand Down Expand Up @@ -84,9 +89,6 @@ class LoginController {
loginReq.password
);




if (!isMatch) {
throw new Error(HttpMsg.PASSWORD_INCORRECT);
}
Expand All @@ -97,7 +99,6 @@ class LoginController {
throw new Error(HttpMsg.PLAYER_NOT_VERIFIED);
}


try {
// create refresh token
const refreshToken = createRefreshToken(loginReq, role);
Expand Down
31 changes: 15 additions & 16 deletions code/backend/src/services/team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ Team;
import TeamModel from "../db/team.schema";
// import ManagerTeamModel from "../db/managers.in.team.schema";
import managersInTeamService from "./managers.in.team.service";
import { AnalyticsSummaryTeam, ImpactStats, ImpactDirection } from "../types/types";
import {
AnalyticsSummaryTeam,
ImpactStats,
ImpactDirection,
} from "../types/types";
import SessionModel from "../db/session.schema";
import ManagerModel from "../db/manager.schema";

Expand Down Expand Up @@ -43,11 +47,11 @@ class TeamService {
// Save the manager to the database
const savedTeam = await teamInstance.save();

await managersInTeamService.addManagerToTeam(
team.teamManager,
team.teamId,
"accessToken"
);
// await managersInTeamService.addManagerToTeam(
// team.teamManager,
// team.teamId,
// "accessToken"
// );

// Create a TeamResponse object
const teamResponse = new TeamResponse({
Expand Down Expand Up @@ -103,18 +107,14 @@ class TeamService {
// }

// Initialize response with both flags set to false
const teamIdEmailExistsResponseWithIsVerified = new TeamIdEmailExistsResponseWithIsVerified(
false,
false,
"pending"
);
const teamIdEmailExistsResponseWithIsVerified =
new TeamIdEmailExistsResponseWithIsVerified(false, false, "pending");

try {
// Check if team exists
// const team = await TeamModel.findOne({ teamId: teamId , managerEmail: email});
// console.log(team, email, teamId);


// const teams = await ManagerModel.find({ email: email });

// const team = teams.find(team => team.teamId === teamId);
Expand All @@ -123,7 +123,7 @@ class TeamService {
if (team) {
console.log(team);
} else {
console.log('Team not found');
console.log("Team not found");
}
if (team) {
teamIdEmailExistsResponseWithIsVerified.teamExists = true;
Expand All @@ -135,7 +135,8 @@ class TeamService {
});
if (manager) {
teamIdEmailExistsResponseWithIsVerified.managerExists = true;
teamIdEmailExistsResponseWithIsVerified.isVerified = manager.isVerified;
teamIdEmailExistsResponseWithIsVerified.isVerified =
manager.isVerified;
}
}
} catch (error) {
Expand Down Expand Up @@ -165,7 +166,5 @@ class TeamService {

return teamIdExistsResponse;
}


}
export default new TeamService();

0 comments on commit 3506eb9

Please sign in to comment.