diff --git a/scripts/analytics/src/modules/analytics/analytics.service.ts b/scripts/analytics/src/modules/analytics/analytics.service.ts index 27da91b02..ced41fa1b 100644 --- a/scripts/analytics/src/modules/analytics/analytics.service.ts +++ b/scripts/analytics/src/modules/analytics/analytics.service.ts @@ -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, @@ -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), diff --git a/scripts/analytics/src/modules/analytics/libs/constants/constants.ts b/scripts/analytics/src/modules/analytics/libs/constants/constants.ts index 47ea2b19b..489510ee2 100644 --- a/scripts/analytics/src/modules/analytics/libs/constants/constants.ts +++ b/scripts/analytics/src/modules/analytics/libs/constants/constants.ts @@ -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"; diff --git a/scripts/analytics/src/modules/analytics/libs/constants/first-array-index.constant.ts b/scripts/analytics/src/modules/analytics/libs/constants/first-array-index.constant.ts new file mode 100644 index 000000000..6358aa4ef --- /dev/null +++ b/scripts/analytics/src/modules/analytics/libs/constants/first-array-index.constant.ts @@ -0,0 +1,3 @@ +const FIRST_ARRAY_INDEX = 0; + +export { FIRST_ARRAY_INDEX };