Skip to content

Commit

Permalink
Merge pull request #51 from cepdnaclk/main
Browse files Browse the repository at this point in the history
deploy
  • Loading branch information
KATTA-00 authored Jan 13, 2024
2 parents 1fdc7f5 + 09f3f4b commit 366e292
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 24 deletions.
8 changes: 7 additions & 1 deletion code/backend/src/config/allowEndPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ const excludedRoutes = [
// Add more entries as needed
];

export default excludedRoutes;
const excludedRoutesStartWith = [
{ method: "GET", path: "/team/exists/teamId" },
{ method: "GET", path: "/manager/exists/email" },
// Add more entries as needed
];

export { excludedRoutes, excludedRoutesStartWith };
24 changes: 21 additions & 3 deletions code/backend/src/controllers/manager.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ class ManagerController {
throw error;
}
}
async checkManagerExistsInTeam(
email: string,
teamId: string
): Promise<boolean> {
try {
// const email = req.params.email;
// Call the function in service
const managerExists = await managerService.checkManagerExistsInTeam(
email,
teamId
);
// res.status(200).json(managerExists);
return managerExists;
} catch (error) {
console.error(error);
throw error;
}
}

async addNewManager(
managerEmail: string,
Expand All @@ -82,7 +100,7 @@ class ManagerController {
// Generate an invitation token
const invitationToken = generateInvitationToken();

// await createManagerTeam(newManagerEmail, teamId);
// await addManagerToTeam(newManagerEmail, teamId);

// Create the manager and set the invitation token
// const newManager: Manager = {
Expand All @@ -92,15 +110,15 @@ class ManagerController {
// };

const createdManagerResponse =
await managersInTeamService.createManagerTeam(newManagerEmail, teamId);
await managersInTeamService.addManagerToTeam(newManagerEmail, teamId);
const teamInstance = await TeamModel.findOne({ teamId });
const teamName = teamInstance?.teamName; // Add null check using optional chaining operator

// Send an invitation email
await sendInvitationEmail(newManagerEmail, invitationToken, teamName!);

// Add the new manager to the team
const managerTeamAdded = await managersInTeamService.createManagerTeam(
const managerTeamAdded = await managersInTeamService.addManagerToTeam(
newManagerEmail,
teamId
);
Expand Down
2 changes: 1 addition & 1 deletion code/backend/src/controllers/player.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PlayerController {
throw new Error(HttpMsg.MANAGER_DEOS_NOT_EXIST);
}

await playersInTeamService.createPlayerTeam(newManagerEmail, teamId);
await playersInTeamService.addPlayerToTeam(newManagerEmail, teamId);

return true;
} catch (error) {
Expand Down
10 changes: 7 additions & 3 deletions code/backend/src/middleware/auth.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { verifyRefreshToken, verifyAccessToken } from "../utils/jwt.token";
import { Request, Response, NextFunction } from "express";
import excludedRoutes from "../config/allowEndPoints";
import {
excludedRoutes,
excludedRoutesStartWith,
} from "../config/allowEndPoints";
import ROLES from "../config/roles";
import playerController from "../controllers/player.controller";
import teamController from "../controllers/team.controller";
Expand Down Expand Up @@ -31,8 +34,9 @@ export async function accessTokenMiddleware(
next: NextFunction
) {
if (
req.path.startsWith("/team/exists/teamId") ||
req.path.startsWith("/manager/exists/email")
excludedRoutesStartWith.some((route) => {
return req.path.startsWith(route.path) && req.method === route.method;
})
) {
// Skip token verification for specified routes
return next();
Expand Down
5 changes: 4 additions & 1 deletion code/backend/src/routes/manager.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ router.post("/", async (req: Request, res: Response) => {
}

// Check if a manager with the given email exists
const exists: boolean = await managerController.checkManagerExists(email);
const exists: boolean = await managerController.checkManagerExistsInTeam(
email,
teamId
);

if (exists) {
console.log(HttpMsg.MANAGER_EXISTS);
Expand Down
5 changes: 4 additions & 1 deletion code/backend/src/routes/team.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ router.post("/manager", async (req, res) => {
res.send(teamManagerResponse);
} catch (err) {
// Check if a manager with the given email exists
const exists: boolean = await managerController.checkManagerExists(email);
const exists: boolean = await managerController.checkManagerExistsInTeam(
email,
teamId
);

if (exists) {
await managerController.deleteManager(email, teamId);
Expand Down
2 changes: 1 addition & 1 deletion code/backend/src/services/managers.in.team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ManagerTeamModel from "../db/managers.in.team.schema";

class ManagersInTeamService {
// create team manager instance
async createManagerTeam(
async addManagerToTeam(
managerEmail: string,
teamId: string
): Promise<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion code/backend/src/services/players.in.team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PlayerTeamModel from "../db/players.in.team.schema";

class PlayerInTeamService {
// create team manager instance
async createPlayerTeam(
async addPlayerToTeam(
managerEmail: string,
teamId: string
): Promise<boolean> {
Expand Down
12 changes: 5 additions & 7 deletions code/backend/src/services/team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Team;
import TeamModel from "../db/team.schema";
import ManagerTeamModel from "../db/managers.in.team.schema";
import managersInTeamService from "./managers.in.team.service";

class TeamService {
// delete team
Expand Down Expand Up @@ -38,13 +39,10 @@ class TeamService {
// Save the manager to the database
const savedTeam = await teamInstance.save();

const managerTeamInstance = new ManagerTeamModel({
managerEmail: team.teamManager,
teamId: team.teamId,
});

// Save the manager to the database
const savedManager = await managerTeamInstance.save();
await managersInTeamService.addManagerToTeam(
team.teamManager,
team.teamId
);

// Create a TeamResponse object
const teamResponse = new TeamResponse({
Expand Down
2 changes: 1 addition & 1 deletion code/client/impax/src/services/mqttClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MqttClient {
private topics: string[];

private constructor() {
this.client = mqtt.connect("ws://192.168.8.151:8080/", {
this.client = mqtt.connect("ws://192.168.4.1:8080/", {
clientId: `impax-dashboard-${Date.now()}`,
reconnectPeriod: 2000,
keepalive: 60,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ssid=impax
channel=9
auth_algs=1
wpa=2
wpa_passphrase=impax12345
wpa_passphrase=impax12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ sudo systemctl status hubService

sudo systemctl restart hubService

/etc/systemd/system/

/root/impax/e19-3yp-impact-tracker/code/backend
sudo nano /etc/systemd/system/hubService.service

0 comments on commit 366e292

Please sign in to comment.