Mark-Lasfar commited on
Commit ·
41e454e
1
Parent(s): 770f5a7
Add GraphQL
Browse files
server.js
CHANGED
|
@@ -18441,7 +18441,7 @@ app.get('/api/users/:userId/contributions/:date', async (req, res) => {
|
|
| 18441 |
// ============================================
|
| 18442 |
async function buildContributionGraph(userId, year) {
|
| 18443 |
if (!userId) {
|
| 18444 |
-
return { total: 0,
|
| 18445 |
}
|
| 18446 |
|
| 18447 |
const targetYear = year || new Date().getFullYear();
|
|
@@ -18484,41 +18484,26 @@ async function buildContributionGraph(userId, year) {
|
|
| 18484 |
merge(shares);
|
| 18485 |
merge(applications);
|
| 18486 |
|
|
|
|
| 18487 |
let total = 0;
|
| 18488 |
-
const
|
| 18489 |
-
let week = [];
|
| 18490 |
|
| 18491 |
-
for (
|
| 18492 |
-
|
| 18493 |
-
const count = daily.get(date) || 0;
|
| 18494 |
total += count;
|
| 18495 |
-
|
| 18496 |
-
let level = 0;
|
| 18497 |
-
if (count > 0 && count <= 2) level = 1;
|
| 18498 |
-
else if (count <= 5) level = 2;
|
| 18499 |
-
else if (count <= 10) level = 3;
|
| 18500 |
-
else if (count > 10) level = 4;
|
| 18501 |
-
|
| 18502 |
-
// ✅ من غير activities
|
| 18503 |
-
week.push({ date, count, level });
|
| 18504 |
-
|
| 18505 |
-
if (d.getDay() === 6) {
|
| 18506 |
-
weeks.push(week);
|
| 18507 |
-
week = [];
|
| 18508 |
-
}
|
| 18509 |
}
|
| 18510 |
|
| 18511 |
return {
|
| 18512 |
total,
|
| 18513 |
year: targetYear,
|
| 18514 |
-
|
| 18515 |
months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
| 18516 |
weekDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
| 18517 |
};
|
| 18518 |
|
| 18519 |
} catch (error) {
|
| 18520 |
console.error('Error in buildContributionGraph:', error);
|
| 18521 |
-
return { total: 0,
|
| 18522 |
}
|
| 18523 |
}
|
| 18524 |
|
|
|
|
| 18441 |
// ============================================
|
| 18442 |
async function buildContributionGraph(userId, year) {
|
| 18443 |
if (!userId) {
|
| 18444 |
+
return { total: 0, days: {}, year: year || new Date().getFullYear(), months: [], weekDays: [] };
|
| 18445 |
}
|
| 18446 |
|
| 18447 |
const targetYear = year || new Date().getFullYear();
|
|
|
|
| 18484 |
merge(shares);
|
| 18485 |
merge(applications);
|
| 18486 |
|
| 18487 |
+
// ✅ حساب total وتحويل Map إلى Object (الأيام النشطة بس)
|
| 18488 |
let total = 0;
|
| 18489 |
+
const days = {};
|
|
|
|
| 18490 |
|
| 18491 |
+
for (const [date, count] of daily) {
|
| 18492 |
+
days[date] = count;
|
|
|
|
| 18493 |
total += count;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18494 |
}
|
| 18495 |
|
| 18496 |
return {
|
| 18497 |
total,
|
| 18498 |
year: targetYear,
|
| 18499 |
+
days, // ← بس الأيام اللي فيها نشاط!
|
| 18500 |
months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
| 18501 |
weekDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
| 18502 |
};
|
| 18503 |
|
| 18504 |
} catch (error) {
|
| 18505 |
console.error('Error in buildContributionGraph:', error);
|
| 18506 |
+
return { total: 0, days: {}, year: targetYear, months: [], weekDays: [] };
|
| 18507 |
}
|
| 18508 |
}
|
| 18509 |
|