Skip to content

Commit

Permalink
edit calculation to count once only
Browse files Browse the repository at this point in the history
  • Loading branch information
rrachea committed Oct 21, 2024
1 parent 259cea9 commit 165c8bb
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 42 deletions.
24 changes: 24 additions & 0 deletions frontend/iQMA-Skills-Builder/app/Assessment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ export default function Assessment() {
currentUser.sub,
questions[currentQnsIdx].quizID
);

try {
const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`;

let points = await AsyncStorage.getItem(
'totalPoints'
);
const numPoints = parseInt(points as string);

const data = {
userID: currentUser.sub,
points: numPoints,
};

const response = await axios.patch(url, data);
const result = await response.data;
console.log('Points successfully updated:', result);
AsyncStorage.setItem('totalPoints', '0');
} catch (error: any) {
console.error(
'Error updating points:',
error.response.data
);
}
}
} catch (error) {
console.error('Error in Assessment:', error);
Expand Down
23 changes: 1 addition & 22 deletions frontend/iQMA-Skills-Builder/app/KeyTakeaway.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function KeyTakeaway() {
});
}, [navigation]);

const handlePress = () => {
const handlePress = async () => {
let nextLessonIdx = parseInt(currentLessonIdx as string) + 1;
let pathName = 'Lesson';

Expand Down Expand Up @@ -108,27 +108,6 @@ export default function KeyTakeaway() {
totalLesson
) {
(async () => {
try {
const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`;

let points = await AsyncStorage.getItem('totalPoints');
const numPoints = parseInt(points as string);

const data = {
userID: currentUser.sub,
points: numPoints,
};

const response = await axios.patch(url, data);
const result = await response.data;
console.log('Points successfully updated:', result);
AsyncStorage.setItem('totalPoints', '0');
} catch (error: any) {
console.error(
'Error updating points:',
error.response.data
);
}
try {
const unitDetails = await unitEndpoints.getUnitDetails(
sectionID as string,
Expand Down
40 changes: 20 additions & 20 deletions frontend/iQMA-Skills-Builder/app/SelfReflection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,6 @@ export default function SelfReflection() {
startTimer();
if (sectionID && unitID) {
(async () => {
try {
const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`;

let points = await AsyncStorage.getItem('totalPoints');
const numPoints = parseInt(points as string);

const data = {
userID: currentUser.sub,
points: numPoints,
};

const response = await axios.patch(url, data);

AsyncStorage.setItem('totalPoints', '0');
} catch (error: any) {
console.error(
'Error updating points:',
error.response.data
);
}
try {
const unitDetails = await unitEndpoints.getUnitDetails(
sectionID as string,
Expand Down Expand Up @@ -114,6 +94,26 @@ export default function SelfReflection() {
currentUser.sub,
parseInt(quizID as string)
);
try {
const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`;

let points = await AsyncStorage.getItem('totalPoints');
const numPoints = parseInt(points as string);

const data = {
userID: currentUser.sub,
points: numPoints,
};

const response = await axios.patch(url, data);

AsyncStorage.setItem('totalPoints', '0');
} catch (error: any) {
console.error(
'Error updating points:',
error.response.data
);
}
}
} catch (error) {
console.error(
Expand Down
22 changes: 22 additions & 0 deletions frontend/iQMA-Skills-Builder/app/VideoQuiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ export default function VideoQuiz() {
currentUser.sub,
questions[currentQnsIdx].quizID
);

try {
const url = `${process.env.EXPO_PUBLIC_LOCALHOST_URL}/accounts/updatepoints`;

let points = await AsyncStorage.getItem('totalPoints');
const numPoints = parseInt(points as string);

const data = {
userID: currentUser.sub,
points: numPoints,
};

const response = await axios.patch(url, data);
const result = await response.data;
console.log('Points successfully updated:', result);
AsyncStorage.setItem('totalPoints', '0');
} catch (error: any) {
console.error(
'Error updating points:',
error.response.data
);
}
}

let pathName = 'KeyTakeaway';
Expand Down

0 comments on commit 165c8bb

Please sign in to comment.