Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IshavSohal committed Dec 16, 2023
1 parent add4b12 commit 27d0f19
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 54 deletions.
12 changes: 6 additions & 6 deletions backend/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_user(user_id: str) -> Response:
@users.route("/get_top_users", methods=['POST'])
@carbon_auth.auth.login_required
def get_top_users() -> Response:
try:
#try:
count = request.get_json()["count"]

# Monthly
Expand Down Expand Up @@ -78,8 +78,8 @@ def get_top_users() -> Response:
'top_yearly_users': top_yearly_users,
'top_overall_users': top_overall_users,
})
except CarbonTrackError as e:
abort(code=400, description=f"{e}")
#except CarbonTrackError as e:
# abort(code=400, description=f"{e}")


@users.route("/user_email/<user_email>", methods=['GET'])
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_current_user() -> Response:
@users.route("/user", methods=["PUT"])
@carbon_auth.auth.login_required
def create_user() -> Response:
try:
#try:
res: dict = request.get_json()["user"]
user = User.from_json(res)
user.email = user.email.lower()
Expand All @@ -147,8 +147,8 @@ def create_user() -> Response:
return jsonify(
{"error": "User Already Exits With Same Email, Please Log In"}
)
except CarbonTrackError as e:
abort(code=400, description=f"{e}")
# except CarbonTrackError as e:
# abort(code=400, description=f"{e}")


@users.route("/user/<user_id>", methods=["DELETE"])
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/FirebaseAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from models.user import User
from mongodb_api.carbon_track_db import CarbonTrackDB

cred = credentials.Certificate(dict(os.environ))
cred = credentials.Certificate("secrets.json")
APP = firebase_admin.initialize_app(cred)


Expand Down
6 changes: 3 additions & 3 deletions frontend/src/APIs/FLASK_API.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";
import firebaseService from "../utilities/firebase";
const FLASK_LOCAL_ADDRESS: string = "http://10.0.0.72:6050";
import axios from 'axios';
import firebaseService from '../utilities/firebase';
const FLASK_LOCAL_ADDRESS: string = 'http://10.0.0.95:6050';

// Function to get the Firebase authentication token
const getFirebaseAuthToken = async (): Promise<string | null> => {
Expand Down
85 changes: 42 additions & 43 deletions frontend/src/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
import { type ObjectId } from 'mongodb';

export interface User {
_id: ObjectId
uid: string;
full_name: string
email: string
badges: string[]
friends: ObjectId[]
overall_score: number
province: string
household: number
fuel_efficiency: number
photoURL: string;
_id: ObjectId;
uid: string;
full_name: string;
email: string;
badges: string[];
friends: ObjectId[];
monthly_score: number;
yearly_score: number;
overall_score: number;
province: string;
household: number;
fuel_efficiency: number;
photoURL: string;
}


export interface RankUser {
rank: number;
name: string;
footprint: number;
score: number;
}

rank: number;
name: string;
footprint: number;
score: number;
}

export interface TopUsersLists {
top_monthly_users: RankUser[]
top_yearly_users: RankUser[]
top_overall_users: RankUser[]
top_monthly_users: RankUser[];
top_yearly_users: RankUser[];
top_overall_users: RankUser[];
}


export function getUserLevel(score: number): number {
if (score < 250) {
return 1;
} else if (score < 500) {
return 2;
} else if (score < 1000) {
return 3;
} else if (score < 2000) {
return 4;
} else if (score < 4000) {
return 5;
} else if (score < 8000) {
return 6;
} else if (score < 16000) {
return 7;
} else if (score < 32000) {
return 8;
} else if (score < 64000) {
return 9;
} else {
return 10;
}
if (score < 250) {
return 1;
} else if (score < 500) {
return 2;
} else if (score < 1000) {
return 3;
} else if (score < 2000) {
return 4;
} else if (score < 4000) {
return 5;
} else if (score < 8000) {
return 6;
} else if (score < 16000) {
return 7;
} else if (score < 32000) {
return 8;
} else if (score < 64000) {
return 9;
} else {
return 10;
}
}
3 changes: 2 additions & 1 deletion frontend/src/screens/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export default function SignUp(): JSX.Element {
email,
badges: [],
friends: [],
monthly_score: 0,
yearly_score: 0,
overall_score: 0,
province: '',
household: 0,
Expand All @@ -74,7 +76,6 @@ export default function SignUp(): JSX.Element {
}
} catch (err) {
console.error('[signup.tsx - handleSignUp] User not created in Flask:', err);

}
};

Expand Down

0 comments on commit 27d0f19

Please sign in to comment.