diff --git a/schema.graphql b/schema.graphql index 38f5cc0..63e17fb 100644 --- a/schema.graphql +++ b/schema.graphql @@ -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 diff --git a/src/features/import-projects/gitcoin/constants.ts b/src/features/import-projects/gitcoin/constants.ts index 105fc42..a90cc2a 100644 --- a/src/features/import-projects/gitcoin/constants.ts +++ b/src/features/import-projects/gitcoin/constants.ts @@ -11,6 +11,6 @@ export const gitcoinSourceConfig: SourceConfig = { idField: "id", titleField: "title", descriptionField: "description", - slugField: "slug", imageField: "image", + urlField: "url", }; diff --git a/src/features/import-projects/gitcoin/helpers.ts b/src/features/import-projects/gitcoin/helpers.ts index 6a9ea68..1d2d6e2 100644 --- a/src/features/import-projects/gitcoin/helpers.ts +++ b/src/features/import-projects/gitcoin/helpers.ts @@ -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 ( @@ -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) : "", diff --git a/src/features/import-projects/giveth/constants.ts b/src/features/import-projects/giveth/constants.ts index 98055c5..b13c48d 100644 --- a/src/features/import-projects/giveth/constants.ts +++ b/src/features/import-projects/giveth/constants.ts @@ -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", }; diff --git a/src/features/import-projects/giveth/helpers.ts b/src/features/import-projects/giveth/helpers.ts index 4044dce..5da05ee 100644 --- a/src/features/import-projects/giveth/helpers.ts +++ b/src/features/import-projects/giveth/helpers.ts @@ -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); } }; diff --git a/src/features/import-projects/giveth/service.ts b/src/features/import-projects/giveth/service.ts index 7825140..1b3a7ca 100644 --- a/src/features/import-projects/giveth/service.ts +++ b/src/features/import-projects/giveth/service.ts @@ -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 @@ -24,7 +23,6 @@ export const fetchGivethProjectsBatch = async (limit: number, skip: number) => { { limit, skip, - sortingBy: "Newest", } ); diff --git a/src/features/import-projects/helpers.ts b/src/features/import-projects/helpers.ts index 35156e5..20722ea 100644 --- a/src/features/import-projects/helpers.ts +++ b/src/features/import-projects/helpers.ts @@ -11,7 +11,7 @@ export const updateOrCreateProject = async ( idField, titleField, descriptionField, - slugField, + urlField, imageField, } = sourConfig; @@ -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) { @@ -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, }); @@ -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, diff --git a/src/features/import-projects/rf4/constants.ts b/src/features/import-projects/rf4/constants.ts index 1c2d504..715a3d2 100644 --- a/src/features/import-projects/rf4/constants.ts +++ b/src/features/import-projects/rf4/constants.ts @@ -6,6 +6,6 @@ export const rf4SourceConfig: SourceConfig = { idField: "id", titleField: "name", descriptionField: "description", - slugField: "url", imageField: "bannerImageUrl", + urlField: "url", }; diff --git a/src/features/import-projects/rf4/helpers.ts b/src/features/import-projects/rf4/helpers.ts new file mode 100644 index 0000000..4089325 --- /dev/null +++ b/src/features/import-projects/rf4/helpers.ts @@ -0,0 +1,6 @@ +import { type Rf4ProjectInfo } from "./type"; + +export const generateRf4Url = (project: Rf4ProjectInfo) => { + return `/project/${project.id}`; +}; + diff --git a/src/features/import-projects/rf4/index.ts b/src/features/import-projects/rf4/index.ts index 87429ef..60db499 100644 --- a/src/features/import-projects/rf4/index.ts +++ b/src/features/import-projects/rf4/index.ts @@ -1,5 +1,6 @@ import { updateOrCreateProject } from "../helpers"; import { rf4SourceConfig } from "./constants"; +import { generateRf4Url } from "./helpers"; import { fetchRf4Projects } from "./service"; export const fetchAndProcessRf4Projects = async () => { @@ -7,7 +8,11 @@ export const fetchAndProcessRf4Projects = async () => { 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); diff --git a/src/features/import-projects/rpgf/constants.ts b/src/features/import-projects/rpgf/constants.ts index e912b1c..bf7d641 100644 --- a/src/features/import-projects/rpgf/constants.ts +++ b/src/features/import-projects/rpgf/constants.ts @@ -6,6 +6,6 @@ export const rpgf3SourceConfig: SourceConfig = { idField: "RPGF3Id", titleField: "name", descriptionField: "impactDescription", - slugField: "url", + urlField: "url", imageField: "image", }; diff --git a/src/features/import-projects/types.ts b/src/features/import-projects/types.ts index 33351d4..ccdbb74 100644 --- a/src/features/import-projects/types.ts +++ b/src/features/import-projects/types.ts @@ -3,6 +3,6 @@ interface SourceConfig { idField: string; titleField: string; descriptionField: string; - slugField: string; + urlField: string; imageField: string; } diff --git a/src/model/generated/project.model.ts b/src/model/generated/project.model.ts index 0abce05..74e898b 100644 --- a/src/model/generated/project.model.ts +++ b/src/model/generated/project.model.ts @@ -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