Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy #65

Merged
merged 64 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
c4ad8ee
led charging
KATTA-00 Jan 23, 2024
e0849e1
Merge branch 'dev' of https://github.com/cepdnaclk/e19-3yp-impact-tra…
KATTA-00 Jan 23, 2024
dec9926
led fix
KATTA-00 Jan 23, 2024
49fd383
Update Wi-Fi and MQTT configurations
KATTA-00 Jan 25, 2024
cb531c3
config
KATTA-00 Jan 25, 2024
cff59e1
Add team analytics summary endpoint and related schema
hirushig Jan 25, 2024
8be833c
Merge pull request #63 from cepdnaclk/dev
KATTA-00 Jan 25, 2024
6d8fc76
buddy led
KATTA-00 Jan 25, 2024
2431852
Fix issue with PlayerActions component
mansithaeashwara Jan 25, 2024
a20dea8
Add BASE_URL constant for backend URL
mansithaeashwara Jan 25, 2024
c77aab3
Add BASE_URL constant for API endpoint
mansithaeashwara Jan 25, 2024
4753c43
Add BASE_URL constant for API endpoint
mansithaeashwara Jan 25, 2024
b2e7e2d
Add BASE_URL constant to SignupManager
mansithaeashwara Jan 25, 2024
6dbe878
Add BASE_URL constant for API endpoint
mansithaeashwara Jan 25, 2024
2b640c5
Add BASE_URL constant for API endpoint
mansithaeashwara Jan 25, 2024
99626ee
Add BASE_URL constant to config.ts
mansithaeashwara Jan 25, 2024
14aa907
Add BASE_URL constant for API endpoint
mansithaeashwara Jan 25, 2024
3aecf42
Refactor LoginManager component
mansithaeashwara Jan 25, 2024
2f3ef19
Remove unused code in SignupPlayer component
mansithaeashwara Jan 25, 2024
92f0395
Add useAppState import and comment out console.log statement
mansithaeashwara Jan 25, 2024
d48f5a1
Add console.log statements for debugging
mansithaeashwara Jan 25, 2024
888b920
Update isLoggedInPlayer and isLoggedInManager values
mansithaeashwara Jan 25, 2024
5036459
Remove unused import and commented code in httpClient.ts
mansithaeashwara Jan 25, 2024
3301896
Remove console.log statements from appState.ts
mansithaeashwara Jan 25, 2024
4d80fb5
Remove unnecessary code for setting access and refresh tokens
mansithaeashwara Jan 25, 2024
23c7c8c
Refactor setTokens function in profileState.ts
mansithaeashwara Jan 25, 2024
46d64b9
polling buddy status added
SanduniU Jan 25, 2024
3d17a0b
Merge branch 'main' of https://github.com/cepdnaclk/e19-3yp-impact-tr…
SanduniU Jan 25, 2024
08fea26
Add player API integration
mansithaeashwara Jan 25, 2024
efc74b6
Refactor player actions and update API calls
mansithaeashwara Jan 25, 2024
e7f2454
Fix import statement in httpClient.ts
mansithaeashwara Jan 25, 2024
18c0ffa
Remove unused import in httpClient.ts
mansithaeashwara Jan 25, 2024
00eb999
Remove unused import and commented code in PlayerActions.tsx
mansithaeashwara Jan 25, 2024
52e97e2
loggenIn status and route configuration
kaushithamsilva Jan 25, 2024
feed225
Merge branch 'main' of https://github.com/cepdnaclk/e19-3yp-impact-tr…
kaushithamsilva Jan 25, 2024
7278d14
Fix last name splitting in JoinTeam component
mansithaeashwara Jan 25, 2024
dd4f4f7
found error in log in with invalid credentials
kaushithamsilva Jan 25, 2024
561f28a
logout clear state and storage
kaushithamsilva Jan 25, 2024
1d4ac2b
Add isVerified parameter to addPlayer function
mansithaeashwara Jan 25, 2024
e84c7ad
Add console.log to display playersData
mansithaeashwara Jan 25, 2024
a3c6106
Add Verification component to appState
mansithaeashwara Jan 25, 2024
bc83be6
files for build, unused variables
kaushithamsilva Jan 25, 2024
00dbd59
Merge branch 'main' of https://github.com/cepdnaclk/e19-3yp-impact-tr…
kaushithamsilva Jan 25, 2024
df0fe78
Change analytics endpoint from team to manager
hirushig Jan 26, 2024
148891c
Add 'none' as an option for ImpactDirection
hirushig Jan 26, 2024
a990379
Add team analytics endpoint and controller method
hirushig Jan 26, 2024
4fe0a19
Add sweetalert2 package dependency
mansithaeashwara Jan 26, 2024
19bcb31
Add error popup for invalid credentials
mansithaeashwara Jan 26, 2024
3a394fd
Add error popup for invalid credentials
mansithaeashwara Jan 26, 2024
bfd8f1d
Add error popup for invalid credentials
mansithaeashwara Jan 26, 2024
1069e51
Add error popup for invalid credentials
mansithaeashwara Jan 26, 2024
dc0c01e
Add error popup for invalid credentials
mansithaeashwara Jan 26, 2024
0dc959e
Remove console.log statement in getPlayers function
mansithaeashwara Jan 26, 2024
f180866
Update formState.ts to disable login for players and managers
mansithaeashwara Jan 26, 2024
7a9588b
Add errorPopup utility function
mansithaeashwara Jan 26, 2024
902ed38
Add error popup when player already exists
mansithaeashwara Jan 26, 2024
0cfdb7c
Fix error message in PlayerManagement component
mansithaeashwara Jan 26, 2024
ab623e9
battery and led bugs
KATTA-00 Jan 26, 2024
733f2a3
Merge branch 'main' of https://github.com/cepdnaclk/e19-3yp-impact-tr…
KATTA-00 Jan 26, 2024
2dd2f4e
Update verification status to use string instead of boolean
hirushig Jan 26, 2024
8a3dd35
Update manager and player verification status
hirushig Jan 26, 2024
c43ada0
Fix player update bug and update player verification status
hirushig Jan 26, 2024
0263020
Update email links to use production URL
hirushig Jan 26, 2024
491e84e
Merge pull request #64 from cepdnaclk/1-player-session-endpoint
KATTA-00 Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions code/backend/src/controllers/manager.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import managersInTeamService from "../services/managers.in.team.service";
import { sendVerificationEmail } from "../email/managerVerifyEmail";
import { sendInvitationEmail } from "../email/managerInviteEmail";
import { v4 as uuidv4 } from "uuid";
import { TeamPlayerResponse } from "../types/types";
import { AnalyticsSummaryTeam, TeamPlayerResponse } from "../types/types";

class ManagerController {
async createManager(
Expand All @@ -16,7 +16,7 @@ class ManagerController {
// Create a manager with an invitation token
const invitationToken = generateInvitationToken();
manager.invitationToken = invitationToken;
manager.isVerified = false; // Initially set to false
manager.isVerified = "pending"; // Initially set to pending

// const teamName = teamResponse.teamName;

Expand Down Expand Up @@ -178,6 +178,28 @@ class ManagerController {
}

}

//get Team Analytics
async getTeamAnalytics(teamId: string, duration:string): Promise<AnalyticsSummaryTeam> {

// 'Last Week' , 'Last Month' , 'All Time'
let durationNumber: number = 0;

if (duration == "All Time"){
durationNumber = Date.now();
} else if (duration == "Last Month"){
durationNumber = 30 * 24 * 60 * 60 * 1000;
} else if (duration == "Last Week"){
durationNumber = 7 * 24 * 60 * 60 * 1000;
}
try {
const response = await managersInTeamService.getTeamAnalytics(teamId, durationNumber);
return response;
} catch (error) {
console.error(error);
throw error;
}
}
}

function generateInvitationToken(): string {
Expand Down
26 changes: 26 additions & 0 deletions code/backend/src/controllers/team.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ class TeamController {
}
return false;
}

async getAnalyticsSummary(
teamId: string,
duration: string
): Promise<void>{
// 'Last Week' , 'Last Month' , 'All Time'
let durationNumber: number = 0;

if (duration == "All Time"){
durationNumber = Date.now();
} else if (duration == "Last Month"){
durationNumber = 30 * 24 * 60 * 60 * 1000;
} else if (duration == "Last Week"){
durationNumber = 7 * 24 * 60 * 60 * 1000;
}
// console.log(durationNumber);

try {
const analyticsSummary = await teamService.getAnalyticsSummary(teamId, durationNumber);
// return analyticsSummary;
} catch (error) {
console.error(error);
throw new Error("Error in player service");
}

}
}

export default new TeamController();
9 changes: 7 additions & 2 deletions code/backend/src/db/manager.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ interface ManagerDocument extends Document {
lastName: string;
email: string;
invitationToken: string;
isVerified: boolean;
isVerified: string;
}
const verificationStatusValidator = function(value: string) {
if (!['pending', 'verified', 'rejected'].includes(value)) {
throw new Error('Invalid verification status');
}
};

const managerSchema = new Schema({
teamId: String,
firstName: String,
lastName: String,
email: String,
invitationToken: String,
isVerified: Boolean,
isVerified: { type: String, validate: verificationStatusValidator },
});

const ManagerModel = mongoose.model<ManagerDocument>("Manager", managerSchema);
Expand Down
10 changes: 8 additions & 2 deletions code/backend/src/db/managers.in.team.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import mongoose, { Document, Schema } from "mongoose";
interface ManagerTeamDocument extends Document {
managerEmail: string;
teamId: string;
accepted: boolean;
accepted: string;
}

const verificationStatusValidator = function(value: string) {
if (!['pending', 'verified', 'rejected'].includes(value)) {
throw new Error('Invalid verification status');
}
};

const managerTeamSchema = new Schema({
managerEmail: String,
teamId: String,
accepted: Boolean,
accepted: { type: String, validate: verificationStatusValidator },
});

const ManagerTeamModel = mongoose.model<ManagerTeamDocument>(
Expand Down
8 changes: 7 additions & 1 deletion code/backend/src/db/player.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ interface PlayerDocument extends Document {
isVerified: string;
}

const verificationStatusValidator = function(value: string) {
if (!['pending', 'verified', 'rejected'].includes(value)) {
throw new Error('Invalid verification status');
}
};

const playerSchema = new Schema({
email: String,
invitationToken: String,
isVerified: String,
isVerified: { type: String, validate: verificationStatusValidator },
});

const PlayerModel = mongoose.model<PlayerDocument>("Player", playerSchema);
Expand Down
7 changes: 6 additions & 1 deletion code/backend/src/db/players.in.team.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ interface PlayerTeamDocument extends Document {
isVerified: string;
}

const verificationStatusValidator = function(value: string) {
if (!['pending', 'verified', 'rejected'].includes(value)) {
throw new Error('Invalid verification status');
}
};
const playerTeamSchema = new Schema({
playerEmail: String,
teamId: String,
jerseyId: Number,
fullName: String,
invitationToken: String,
isVerified: String,
isVerified: { type: String, validate: verificationStatusValidator },

});

Expand Down
2 changes: 1 addition & 1 deletion code/backend/src/email/managerInviteEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function sendInvitationEmail(
<p>Hello,</p>
<p>You've been invited to join the team ${teamName}! Click the following link to accept the invitation:</p>

<a href="http://localhost:5000/manager/accept-invitation/token/${invitationToken}"
<a href="http://16.170.235.219:5000/manager/accept-invitation/token/${invitationToken}"
style="display: inline-block; padding: 10px 20px; background-color: #4CAF50; color: #ffffff;
text-decoration: none; border-radius: 5px;">Accept Invitation</a><br><br>

Expand Down
4 changes: 2 additions & 2 deletions code/backend/src/email/managerVerifyEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export async function sendVerificationEmail(
html: `
<p>Hello,</p>

<p>You've been created the team ${teamName}! Click the following link to verify your email:</p>
<p>To confirm creation of the team ${teamName}, click the button and verify your email address</p>

<a href="http://localhost:5000/manager/accept-invitation/token/${invitationToken}"
<a href="http://16.170.235.219:5000/manager/accept-invitation/token/${invitationToken}"
style="display: inline-block; padding: 10px 20px; background-color: #4CAF50; color: #ffffff;
text-decoration: none; border-radius: 5px;">Verify Email Here</a><br><br>

Expand Down
4 changes: 2 additions & 2 deletions code/backend/src/email/playerInviteEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export async function sendInvitationEmail(
html: `
<p>Hello ${fullName},</p>

<p>You've been invited to join the team ${teamName}! </p>
<p>You've been invited to join the team ${teamName}! Click the following link to accept the invitation:</p>

<a href="http://localhost:5000/player/accept-invitation/token/${invitationToken}"
<a href="http://16.170.235.219:5000/player/accept-invitation/token/${invitationToken}"
style="display: inline-block; padding: 10px 20px; background-color: #4CAF50; color: #ffffff;
text-decoration: none; border-radius: 5px;">Accept Invitation</a><br><br>

Expand Down
5 changes: 2 additions & 3 deletions code/backend/src/email/playerVerifyEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ export async function sendVerificationEmail(
html: `
<p>Hello,</p>

<p>Thank you for registering with Impax!</p>
<p>You've been created the account successfully! </p>
<p>Your account has been created successfully! To log in to account verify your email address</p>

<a href="http://localhost:5000/player/verify-email/token/${invitationToken}"
<a href="http://16.170.235.219:5000/player/verify-email/token/${invitationToken}"
style="display: inline-block; padding: 10px 20px; background-color: #4CAF50; color: #ffffff;
text-decoration: none; border-radius: 5px;">Verify Email Here</a><br><br>

Expand Down
1 change: 1 addition & 0 deletions code/backend/src/exceptions/http.codes.mgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum HttpMsg {
MANAGER_LOGIN_FAILED = "Login failed",
MANAGER_ADD_SUCCESS = "Manager added successfully",
MANAGER_ADD_FAILED = "Manager added failed",
MANAGER_NOT_FOUND = "Manager not found",
TEAM_NOT_FOUND = "Team not found",
MANAGER_DEOS_NOT_EXIST = "Manager does not exist",
PLAYER_EXIT_ERROR = "Player exited error",
Expand Down
10 changes: 5 additions & 5 deletions code/backend/src/models/manager.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Manager {
public email: string;
public password: string;
public invitationToken: string;
public isVerified: boolean;
public isVerified: string;

public constructor(
teamId: string,
Expand All @@ -22,7 +22,7 @@ class Manager {
email: string,
password: string,
invitationToken: string,
isVerified: boolean
isVerified: string
) {
this.teamId = teamId;
this.firstName = firstName;
Expand All @@ -39,7 +39,7 @@ class ManagerResponse {
public firstName: string;
public lastName: string;
public email: string;
public isVerified: boolean;
public isVerified: string;

public constructor(manager: ManagerResponse) {
this.teamId = manager.teamId;
Expand All @@ -57,7 +57,7 @@ class ManagerRequestBody {
public email: string;
public password: string;
public invitationToken: string;
public isVerified: boolean;
public isVerified: string;

public constructor(
teamId: string,
Expand All @@ -66,7 +66,7 @@ class ManagerRequestBody {
email: string,
password: string,
invitationToken: string,
isVerified: boolean
isVerified: string
) {
this.teamId = teamId;
this.firstName = firstName;
Expand Down
51 changes: 46 additions & 5 deletions code/backend/src/routes/manager.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ router.post("/", async (req: Request, res: Response) => {
email,
password,
"", // Initially set to empty string
false // Initially set to false
"pending" // Initially set to pending
);

// Create the manager and get the response
Expand Down Expand Up @@ -255,19 +255,60 @@ router.get("/getTeamPlayers",async (req:Request, res: Response) => {
}
});

// Endpoint to get Team Analytics
router.get("/analytics-summary/:duration", async (req: Request, res: Response) => {
const managerEmail = req.body.userName;
const teamId = req.body.teamId;
// check the request comes from the manager
if (req.body.role != ROLES.MANAGER) {
console.log(HttpMsg.UNAUTHORIZED);
res.status(HttpCode.UNAUTHORIZED).send({ message: HttpMsg.BAD_REQUEST });
return;
}

if (!managerEmail) {
console.log(HttpMsg.BAD_REQUEST);
res.status(HttpCode.BAD_REQUEST).send({ message: HttpMsg.BAD_REQUEST });
return;
}

try {
const managerExists = await managerController.checkManagerExistsInTeam(
managerEmail,
teamId
);

if (managerExists) {
const teamAnalyticsResponse =
await managerController.getTeamAnalytics(teamId, req.params.duration);
res.send(teamAnalyticsResponse);
} else {
throw new Error(HttpMsg.MANAGER_DEOS_NOT_EXIST);
}
} catch (err) {
if (err instanceof Error) {
// If 'err' is an instance of Error, send the error message
res.status(HttpCode.BAD_REQUEST).send({ message: err.message });
} else {
// If 'err' is of unknown type, send a generic error message
res.status(HttpCode.BAD_REQUEST).send({ message: HttpMsg.BAD_REQUEST });
}
}
});

// Endpoint Accept Invitation
router.get("/accept-invitation/token/:token", async (req, res) => {
const token = req.params.token;
const manager = await ManagerModel.findOne({ invitationToken: token });
const managerInTeam = await ManagerTeamModel.findOne({ invitationToken: token });
if (manager && !manager.isVerified) {
if (manager && (manager.isVerified == "pending")) {
// Update manager status
manager.isVerified = true;
manager.isVerified = "verified";
await manager.save();
res.send("Invitation accepted successfully!");
} else if (managerInTeam && !managerInTeam.accepted){
} else if (managerInTeam && (managerInTeam.accepted == "pending")){
// Update manager status
managerInTeam.accepted = true;
managerInTeam.accepted = "verified";
await managerInTeam.save();
} else{
res.status(400).send("Invalid or expired token.");
Expand Down
12 changes: 7 additions & 5 deletions code/backend/src/routes/player.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ router.put("/update", async (req: Request, res: Response) => {
}

try {
const player = await PlayerTeamModel.findOne({
const player = await PlayerTeamModel.find({
jesryId: jerseyId,
teamId: teamId });

console.log(player );

const playerTeamRequest = new PlayerTeamRequest(
newPlayerEmail,
jerseyId,
Expand Down Expand Up @@ -308,9 +310,9 @@ router.get("/accept-invitation/token/:token", async (req, res) => {
const token = req.params.token;
// const player = await PlayerModel.findOne({ invitationToken: token });
const playerInTeam = await PlayerTeamModel.findOne({ invitationToken: token });
if (playerInTeam && playerInTeam.isVerified == "Pending") {
if (playerInTeam && playerInTeam.isVerified == "pending") {
// Update player status
playerInTeam.isVerified = "Accepted";
playerInTeam.isVerified = "verified";
await playerInTeam.save();
res.send("Invitation accepted successfully!");
}
Expand All @@ -324,9 +326,9 @@ router.get("/verify-email/token/:token", async (req, res) => {
const token = req.params.token;
const player = await PlayerModel.findOne({ invitationToken: token });
// const playerInTeam = await PlayerTeamModel.findOne({ invitationToken: token });
if (player && player.isVerified == "Pending") {
if (player && player.isVerified == "pending") {
// Update player status
player.isVerified = "Accepted";
player.isVerified = "verified";
await player.save();
res.send("Invitation accepted successfully!");
}
Expand Down
3 changes: 2 additions & 1 deletion code/backend/src/routes/team.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ router.post("/manager", async (req, res) => {
email,
password,
"",
false
"pending"
);

// Create the Team and get the response
Expand Down Expand Up @@ -277,5 +277,6 @@ router.get("/:id", async (req: Request, res: Response) => {
}
});


// Export the router for use in other files
export default router;
Loading
Loading