Skip to content

Commit

Permalink
fix deconflict error
Browse files Browse the repository at this point in the history
  • Loading branch information
germainetan committed Oct 17, 2024
1 parent d01f650 commit b6eab1d
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 47 deletions.
13 changes: 6 additions & 7 deletions backend/dist/controllers/accountsGamificationController.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function () { return m[k]; } };
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function (o, m, k, k2) {
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) {
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
Expand All @@ -35,8 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateStreaksFromUnit = exports.updateStreaksFromLogin = exports.updatePoints = exports.getGamificationData = exports.getTop5Accounts = void 0;
exports.updatePoints = exports.getBadges = exports.getGamificationData = exports.getTop5Accounts = void 0;
exports.updateStreaksFromUnit = exports.updateStreaksFromLogin = exports.updatePoints = exports.getBadges = exports.getGamificationData = exports.getTop5Accounts = void 0;
const accountsGamificationService = __importStar(require("../services/accountsGamificationService"));
const errorHandling_1 = __importDefault(require("../errors/errorHandling"));
/* READ */
Expand Down
37 changes: 19 additions & 18 deletions backend/dist/services/accountsGamificationService.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function () { return m[k]; } };
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function (o, m, k, k2) {
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) {
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
Expand Down Expand Up @@ -52,13 +52,13 @@ exports.getBadges = getBadges;
exports.updatePoints = updatePoints;
exports.updateStreaksFromUnit = updateStreaksFromUnit;
exports.updateStreaksFromLogin = updateStreaksFromLogin;
const resultService = __importStar(require("../services/resultService"));
const unitService = __importStar(require("../services/unitService"));
const sectionService = __importStar(require("../services/sectionService"));
const accountsGamificationModel_1 = require("../models/accountsGamificationModel");
const resultModel_1 = require("../models/resultModel");
const resultService_1 = require("./resultService");
const supabaseConfig_1 = __importDefault(require("../config/supabaseConfig"));
const resultService = __importStar(require("../services/resultService"));
const unitService = __importStar(require("../services/unitService"));
const sectionService = __importStar(require("../services/sectionService"));
/* READ */
function getTop5Accounts(userID) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -89,9 +89,9 @@ function getTop5Accounts(userID) {
const filteredData = rankedData
.filter((record) => record.rank <= 5 || record.userID === userID)
.map((_a) => {
var { userID } = _a, rest = __rest(_a, ["userID"]);
return rest;
});
var { userID } = _a, rest = __rest(_a, ["userID"]);
return rest;
});
return filteredData;
}
});
Expand All @@ -118,6 +118,7 @@ function getGamificationData(userID) {
}
function getBadges(userID) {
return __awaiter(this, void 0, void 0, function* () {
const completedUnit = yield resultService.getNoOfCompletedUnit(userID);
const { data: storageBadges, error } = yield supabaseConfig_1.default.storage
.from("badges")
.list();
Expand All @@ -128,8 +129,8 @@ function getBadges(userID) {
if (storageBadges.length === 0) {
throw new Error("Badge Not Found");
}
const totalSection = yield sectionService.getAllSections();
let badges = [];
const totalSection = yield sectionService.getAllSections();
for (let i = totalSection.length - 1; i >= 0; i--) {
const section = totalSection[i];
let unitBadges = [];
Expand Down Expand Up @@ -190,8 +191,8 @@ function updatePoints(userID, points) {
const { status, statusText, error } = yield supabaseConfig_1.default
.from("accountsgamification")
.update({
points: accountGamificationData.getPoints() + points,
})
points: accountGamificationData.getPoints() + points,
})
.eq("userID", userID);
if (error) {
console.error(error);
Expand Down Expand Up @@ -255,8 +256,8 @@ function updateStreaksFromUnit(userID, quizID) {
const { status, statusText, error } = yield supabaseConfig_1.default
.from("accountsgamification")
.update({
streaks: currentStreak,
})
streaks: currentStreak,
})
.eq("userID", userID);
}
}
Expand Down Expand Up @@ -294,8 +295,8 @@ function updateStreaksFromLogin(userID) {
const { status, statusText, error } = yield supabaseConfig_1.default
.from("accountsgamification")
.update({
streaks: currentStreak,
})
streaks: currentStreak,
})
.eq("userID", userID);
}
}
Expand Down
11 changes: 11 additions & 0 deletions backend/dist/services/sectionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ exports.getAllSections = getAllSections;
exports.getSectionDetails = getSectionDetails;
const supabaseConfig_1 = __importDefault(require("../config/supabaseConfig"));
const videoService = __importStar(require("./videoService"));
const getSectionDuration = (sectionID) => __awaiter(void 0, void 0, void 0, function* () {
const { data, error } = yield supabaseConfig_1.default
.from("lesson")
.select("lessonDuration")
.eq("sectionID", sectionID);
if (error) {
console.error(error);
throw error;
}
return Math.ceil(data.reduce((acc, curr) => acc + curr.lessonDuration, 0));
});
/* READ */
function getAllSections() {
return __awaiter(this, void 0, void 0, function* () {
Expand Down
90 changes: 69 additions & 21 deletions backend/src/services/accountsGamificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export async function getGamificationData(userID: string) {
}

export async function getBadges(userID: string) {
const completedUnit = await resultService.getNoOfCompletedUnit(userID);

let badges = [];
const completedUnit = await resultService.getNoOfCompletedUnit(userID);

const { data: storageBadges, error } = await supabase.storage
.from("badges")
.list();


if (error) {
console.error(error);
Expand All @@ -92,33 +92,81 @@ export async function getBadges(userID: string) {
throw new Error("Badge Not Found");
}

const designed = storageBadges
.map((badge) => badge.name)
.filter((badge) => badge.includes("badge"));

const withoutBadge = Math.max(0, completedUnit - designed.length);
const minBadges = completedUnit - withoutBadge;
let badges = [];

const totalSection = await sectionService.getAllSections();

for (let i = totalSection.length - 1; i >= 0; i--) {

const section = totalSection[i];
let unitBadges = [];

const totalUnit = await unitService.getAllUnitsBySection(
section.sectionID
);

const completedUnit = await resultService.getUserProgress(
userID,
section.sectionID
);

const lockedUnit = Math.max(totalUnit.length - completedUnit, 0);

for (let i = 0; i < withoutBadge; i++) {
const { data: publicUrlData } = await supabase.storage
.from("badges")
.getPublicUrl(`placeholder.png`);
for (let i = 0; i < lockedUnit; i++) {
const { data: publicUrlData } = await supabase.storage
.from("badges")
.getPublicUrl(`locked.png`);

if (publicUrlData) {
badges.push(publicUrlData.publicUrl);
if (publicUrlData) {
unitBadges.push({
unitName: "LOCKED",
badgeUrl: publicUrlData.publicUrl
});
}
}

const withoutBadge = Math.max(0, completedUnit - storageBadges.length);
const minBadges = completedUnit - withoutBadge;

for (let i = 0; i < withoutBadge; i++) {
const { data: publicUrlData } = await supabase.storage
.from("badges")
.getPublicUrl(`placeholder.png`);

if (publicUrlData) {
unitBadges.push({
unitName: "PLACEHOLDER",
badgeUrl: publicUrlData.publicUrl,
});
}
}
}

for (let i = minBadges; i > 0; i--) {
const { data: publicUrlData } = await supabase.storage
.from("badges")
.getPublicUrl(`badge${i}.png`);
for (let i = minBadges; i > 0; i--) {
const { data: publicUrlData } = await supabase.storage
.from("badges")
.getPublicUrl(`${section.sectionID}/unit${i}.png`);

if (publicUrlData) {
badges.push(publicUrlData.publicUrl);
if (publicUrlData) {
unitBadges.push({
unitName: "UNIT",
badgeUrl: publicUrlData.publicUrl,
});
}
}
}

for (let i = totalUnit.length - 1; i >= 0; i--) {
const unit = totalUnit[i];
unitBadges[i].unitName = unit.unitName;
}


badges.push({
sectionID: section.sectionID,
badges: unitBadges,
});

}
return badges;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/iQMA-Skills-Builder/app/screens/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ProfilePage: React.FC = () => {

console.log('sectionDetails:', sectionDetails);
console.log('userDetails:', userDetails);
// console.log('badges:', badges);
console.log('badges:', badges);

setAllSectionDetails(sectionDetails);
// Testing
Expand Down

0 comments on commit b6eab1d

Please sign in to comment.