( yearString: string, )
| 410 | } |
| 411 | |
| 412 | export async function getTestActivityCalendar( |
| 413 | yearString: string, |
| 414 | ): Promise<TestActivityCalendar | undefined> { |
| 415 | if (!isAuthenticated() || dbSnapshot === undefined) return undefined; |
| 416 | |
| 417 | if (yearString === "current") return dbSnapshot.testActivity; |
| 418 | |
| 419 | const currentYear = new Date().getFullYear().toString(); |
| 420 | if (yearString === currentYear) { |
| 421 | return dbSnapshot.testActivity?.getFullYearCalendar(); |
| 422 | } |
| 423 | |
| 424 | if (dbSnapshot.testActivityByYear === undefined) { |
| 425 | showLoaderBar(); |
| 426 | const response = await Ape.users.getTestActivity(); |
| 427 | if (response.status !== 200) { |
| 428 | showErrorNotification("Error getting test activities", { response }); |
| 429 | hideLoaderBar(); |
| 430 | return undefined; |
| 431 | } |
| 432 | |
| 433 | dbSnapshot.testActivityByYear = {}; |
| 434 | for (const year in response.body.data) { |
| 435 | if (year === currentYear) continue; |
| 436 | const testsByDays = response.body.data[year] ?? []; |
| 437 | const lastDay = Dates.addDays( |
| 438 | new Date(parseInt(year), 0, 1), |
| 439 | testsByDays.length, |
| 440 | ); |
| 441 | |
| 442 | dbSnapshot.testActivityByYear[year] = new TestActivityCalendar( |
| 443 | testsByDays, |
| 444 | lastDay, |
| 445 | firstDayOfTheWeek, |
| 446 | true, |
| 447 | ); |
| 448 | } |
| 449 | hideLoaderBar(); |
| 450 | } |
| 451 | |
| 452 | return dbSnapshot.testActivityByYear[yearString]; |
| 453 | } |
no test coverage detected