Skip to content

Commit

Permalink
feat: add check for empty statistics for the day gf-464
Browse files Browse the repository at this point in the history
  • Loading branch information
s1rserg committed Sep 23, 2024
1 parent b45a741 commit b76401f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scripts/analytics/src/modules/analytics/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { type GITService } from "~/libs/modules/git-service/git-service.js";
import { logger } from "~/libs/modules/logger/logger.js";

import { type analyticsApi } from "./analytics.js";
import { COMMIT_REGEX } from "./libs/constants/constants.js";
import {
COMMIT_REGEX,
EMPTY_LENGTH,
FIRST_ARRAY_INDEX,
} from "./libs/constants/constants.js";
import {
type ActivityLogCreateItemRequestDto,
type CommitStatistics,
Expand Down Expand Up @@ -83,6 +87,15 @@ class AnalyticsService {
await this.fetchRepository();
const stats = await this.collectStatsByRepository();

if (
stats[FIRST_ARRAY_INDEX] &&
stats[FIRST_ARRAY_INDEX].items.length === EMPTY_LENGTH
) {
logger.info("There are no statistics for this day.");

return;
}

await this.analyticsApi.sendAnalytics(this.apiKey, {
items: stats,
userId: Number(this.userId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { COMMIT_REGEX } from "./commit-regex.constant.js";
export { FIRST_ARRAY_INDEX } from "./first-array-index.constant.js";
export { EMPTY_LENGTH } from "@git-fit/shared";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const FIRST_ARRAY_INDEX = 0;

export { FIRST_ARRAY_INDEX };

0 comments on commit b76401f

Please sign in to comment.