Skip to content

Commit

Permalink
Merge pull request #66 from Giveth/update-url
Browse files Browse the repository at this point in the history
Update url
  • Loading branch information
MohammadPCh committed Jun 6, 2024
2 parents 51abcbb + e8d0cc9 commit 421d9eb
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Project @entity {
totalFlags: Int!
"Total attests"
totalAttests: Int!
"Slug of the project"
"Url of the project"
url: String
"Image of the project"
image: String
Expand Down
2 changes: 1 addition & 1 deletion src/features/import-projects/gitcoin/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const gitcoinSourceConfig: SourceConfig = {
idField: "id",
titleField: "title",
descriptionField: "description",
slugField: "slug",
imageField: "image",
urlField: "url",
};
4 changes: 2 additions & 2 deletions src/features/import-projects/gitcoin/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { GitcoinProjectInfo } from "./type";
import { updateOrCreateProject } from "../helpers";
import { IPFS_GATEWAY, gitcoinSourceConfig } from "./constants";

const generateGitcoinSlug = (project: GitcoinProjectInfo) => {
const generateGitcoinUrl = (project: GitcoinProjectInfo) => {
const application = project.applications[0];

if (
Expand Down Expand Up @@ -30,7 +30,7 @@ export const processProjectsBatch = async (
id: project.id,
title: project.name || project.metadata?.title,
description: project.metadata?.description,
url: generateGitcoinSlug(project),
url: generateGitcoinUrl(project),
image: project.metadata?.bannerImg
? convertIpfsHashToHttps(project.metadata?.bannerImg)
: "",
Expand Down
4 changes: 2 additions & 2 deletions src/features/import-projects/giveth/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export const GIVETH_API_URL =
process.env.GIVETH_API_URL || "https://mainnet.serve.giveth.io/graphql";

export const GIVETH_API_LIMIT = 100;
export const GIVETH_API_LIMIT = 50;

export const givethSourceConfig: SourceConfig = {
source: "giveth",
idField: "id",
titleField: "title",
descriptionField: "descriptionSummary",
slugField: "slug",
urlField: "url",
imageField: "image",
};
10 changes: 9 additions & 1 deletion src/features/import-projects/giveth/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import { type GivethProjectInfo } from "./type";
import { updateOrCreateProject } from "../helpers";
import { givethSourceConfig } from "./constants";

export const generateGivethUrl = (project: GivethProjectInfo) => {
return `/project/${project.slug}`;
};

export const processProjectsBatch = async (
projectsBatch: GivethProjectInfo[]
) => {
for (const project of projectsBatch) {
await updateOrCreateProject(project, givethSourceConfig);
const processedProject = {
...project,
url: generateGivethUrl(project),
};
await updateOrCreateProject(processedProject, givethSourceConfig);
}
};
6 changes: 2 additions & 4 deletions src/features/import-projects/giveth/service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { graphQLRequest } from "../../../helpers/request";
import { GIVETH_API_URL } from "./constants";
import { GivethProjectInfo } from "./type";

export const fetchGivethProjectsBatch = async (limit: number, skip: number) => {
try {
const res = await graphQLRequest(
GIVETH_API_URL,
`query ($limit: Int, $skip: Int, $sortingBy: SortingField) {
`query ($limit: Int, $skip: Int) {
allProjects(
limit: $limit
skip: $skip
sortingBy: $sortingBy
sortingBy: Newest
) {
projects {
id
Expand All @@ -24,7 +23,6 @@ export const fetchGivethProjectsBatch = async (limit: number, skip: number) => {
{
limit,
skip,
sortingBy: "Newest",
}
);

Expand Down
8 changes: 4 additions & 4 deletions src/features/import-projects/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const updateOrCreateProject = async (
idField,
titleField,
descriptionField,
slugField,
urlField,
imageField,
} = sourConfig;

Expand All @@ -36,7 +36,7 @@ export const updateOrCreateProject = async (
const isUpdated =
existingProject.title !== project[titleField] ||
existingProject.description !== project[descriptionField] ||
existingProject.url !== project[slugField] ||
existingProject.url !== project[urlField] ||
existingProject.image !== project[imageField];

if (isUpdated) {
Expand All @@ -45,7 +45,7 @@ export const updateOrCreateProject = async (
title: project[titleField],
description: project[descriptionField],
image: project[imageField],
url: project[slugField],
url: project[urlField],
lastUpdatedTimestamp: new Date(),
imported: true,
});
Expand All @@ -67,7 +67,7 @@ export const updateOrCreateProject = async (
title: project[titleField],
description: project[descriptionField],
image: project[imageField],
url: project[slugField],
url: project[urlField],
projectId: projectId,
source: source,
totalVouches: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/features/import-projects/rf4/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export const rf4SourceConfig: SourceConfig = {
idField: "id",
titleField: "name",
descriptionField: "description",
slugField: "url",
imageField: "bannerImageUrl",
urlField: "url",
};
6 changes: 6 additions & 0 deletions src/features/import-projects/rf4/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type Rf4ProjectInfo } from "./type";

export const generateRf4Url = (project: Rf4ProjectInfo) => {
return `/project/${project.id}`;
};

7 changes: 6 additions & 1 deletion src/features/import-projects/rf4/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { updateOrCreateProject } from "../helpers";
import { rf4SourceConfig } from "./constants";
import { generateRf4Url } from "./helpers";
import { fetchRf4Projects } from "./service";

export const fetchAndProcessRf4Projects = async () => {
try {
const data = await fetchRf4Projects();
if (!data) return;
for (const project of data) {
await updateOrCreateProject(project, rf4SourceConfig);
const processedProject = {
...project,
url: generateRf4Url(project),
}
await updateOrCreateProject(processedProject, rf4SourceConfig);
}
} catch (error: any) {
console.log("error on fetchAndProcessRf4Projects", error.message);
Expand Down
2 changes: 1 addition & 1 deletion src/features/import-projects/rpgf/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export const rpgf3SourceConfig: SourceConfig = {
idField: "RPGF3Id",
titleField: "name",
descriptionField: "impactDescription",
slugField: "url",
urlField: "url",
imageField: "image",
};
2 changes: 1 addition & 1 deletion src/features/import-projects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ interface SourceConfig {
idField: string;
titleField: string;
descriptionField: string;
slugField: string;
urlField: string;
imageField: string;
}
2 changes: 1 addition & 1 deletion src/model/generated/project.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Project {
totalAttests!: number

/**
* Slug of the project
* Url of the project
*/
@Column_("text", {nullable: true})
url!: string | undefined | null
Expand Down

0 comments on commit 421d9eb

Please sign in to comment.