Skip to content

Commit 278351b

Browse files
committed
refactor: update entity types in DigestCron and SearchService for consistency and clarity
1 parent 8e5201b commit 278351b

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

api/src/digest/cron.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { captureException, cron } from "@sentry/node";
22

33
import { ContributionRepository } from "src/contribution/repository";
4+
import { ContributionRow } from "src/contribution/table";
45
import { ContributorRepository } from "src/contributor/repository";
6+
import { ContributorRow } from "src/contributor/table";
57
import { CronJob } from "cron";
68
import { DataService } from "src/data/service";
79
import { GithubService } from "src/github/service";
810
import { LoggerService } from "src/logger/service";
911
import { ProjectRepository } from "src/project/repository";
12+
import { ProjectRow } from "src/project/table";
1013
import { RepositoryRepository } from "src/repository/repository";
1114
import { SearchService } from "src/search/service";
1215
import { Service } from "typedi";
@@ -70,10 +73,10 @@ export class DigestCron {
7073
const projectsFromDataFolder = await this.dataService.listProjects();
7174

7275
for (const project of projectsFromDataFolder) {
73-
const projectEntity = {
74-
...project,
76+
const projectEntity: ProjectRow = {
7577
runId,
76-
id: project.slug.replace(/[.]/g, "-"), // MeiliSearch doesn't allow dots in ids,
78+
id: project.slug.replace(/[.]/g, "-"), // NOTE-OB: MeiliSearch doesn't allow dots in ids
79+
name: project.name,
7780
};
7881
const [{ id: projectId }] =
7982
await this.projectsRepository.upsert(projectEntity);
@@ -114,7 +117,7 @@ export class DigestCron {
114117

115118
if (githubUser.type !== "User") continue;
116119

117-
const contributorEntity = {
120+
const contributorEntity: ContributorRow = {
118121
name: githubUser.name || githubUser.login,
119122
username: githubUser.login,
120123
url: githubUser.html_url,
@@ -135,7 +138,7 @@ export class DigestCron {
135138
});
136139

137140
const type = issue.pull_request ? "PULL_REQUEST" : "ISSUE";
138-
const contributionEntity = {
141+
const contributionEntity: ContributionRow = {
139142
title: issue.title,
140143
type,
141144
updatedAt: issue.updated_at,
@@ -170,15 +173,17 @@ export class DigestCron {
170173
const contributor = await this.githubService.getUser({
171174
username: repoContributor.login,
172175
});
176+
const contributorEntity: ContributorRow = {
177+
name: contributor.name || contributor.login,
178+
username: contributor.login,
179+
url: contributor.html_url,
180+
avatarUrl: contributor.avatar_url,
181+
runId,
182+
id: `${provider}-${contributor.login}`,
183+
};
173184
const [{ id: contributorId }] =
174-
await this.contributorsRepository.upsert({
175-
name: contributor.name || contributor.login,
176-
username: contributor.login,
177-
url: contributor.html_url,
178-
avatarUrl: contributor.avatar_url,
179-
runId,
180-
id: `${provider}-${contributor.login}`,
181-
});
185+
await this.contributorsRepository.upsert(contributorEntity);
186+
await this.searchService.upsert("contributor", contributorEntity);
182187

183188
await this.contributorsRepository.upsertRelationWithRepository({
184189
contributorId,
@@ -209,9 +214,11 @@ export class DigestCron {
209214
await this.contributorsRepository.deleteAllButWithRunId(runId);
210215
await this.repositoriesRepository.deleteAllButWithRunId(runId);
211216
await this.projectsRepository.deleteAllButWithRunId(runId);
212-
await this.searchService.deleteAllButWithRunId("project", runId);
213-
await this.searchService.deleteAllButWithRunId("contribution", runId);
214-
await this.searchService.deleteAllButWithRunId("contributor", runId);
217+
await Promise.all([
218+
this.searchService.deleteAllButWithRunId("project", runId),
219+
this.searchService.deleteAllButWithRunId("contribution", runId),
220+
this.searchService.deleteAllButWithRunId("contributor", runId),
221+
]);
215222
} catch (error) {
216223
captureException(error, { tags: { type: "CRON" } });
217224
}

api/src/search/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SearchResults, SearchType } from "./types";
22

3-
import { BaseSearchItem } from "@dzcode.io/models/dist/_base";
3+
import { BaseEntity } from "@dzcode.io/models/dist/_base";
44
import { ConfigService } from "src/config/service";
55
import { LoggerService } from "src/logger/service";
66
import { MeiliSearch } from "meilisearch";
@@ -33,7 +33,7 @@ export class SearchService {
3333
};
3434
};
3535

36-
public upsert = async <T extends BaseSearchItem>(
36+
public upsert = async <T extends BaseEntity>(
3737
index: SearchType,
3838
data: T,
3939
): Promise<void> => {

packages/models/src/_base/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
export type BaseEntity = {
22
id: string;
3-
runId: string;
4-
};
5-
6-
export type BaseSearchItem = {
7-
id: string;
8-
runId: string;
3+
runId?: string;
94
};

0 commit comments

Comments
 (0)