Skip to content

Commit

Permalink
Merge pull request #123 from Giveth/feat/add-created-date
Browse files Browse the repository at this point in the history
Feat/add created date
  • Loading branch information
MohammadPCh authored Oct 8, 2024
2 parents e824186 + d3a6c83 commit c04674f
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 3 deletions.
11 changes: 11 additions & 0 deletions db/migrations/1728304303227-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = class Data1728304303227 {
name = 'Data1728304303227'

async up(db) {
await db.query(`ALTER TABLE "project" ADD "source_created_at" TIMESTAMP WITH TIME ZONE`)
}

async down(db) {
await db.query(`ALTER TABLE "project" DROP COLUMN "source_created_at"`)
}
}
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type Project @entity {
attestedOrganisations: [OrganisationProject!]! @derivedFrom(field: "project")
"Rounds in which the project is included"
rfRounds: [Int!]
"Source Creation Timestamp"
sourceCreatedAt: DateTime
}

type OrganisationProject @entity {
Expand Down
1 change: 1 addition & 0 deletions src/features/import-projects/gitcoin/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export const gitcoinSourceConfig: SourceConfig = {
imageField: "image",
urlField: "url",
descriptionHtmlField: "descriptionHtml",
sourceCreatedAtField: "creationDate",
};
3 changes: 3 additions & 0 deletions src/features/import-projects/gitcoin/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export const processProjectsBatch = async (
descriptionHtml: description
? converter.makeHtml(description)
: undefined,
creationDate: project.metadata.createdAt
? new Date(project.metadata.createdAt * 1000).toISOString() // Convert to ISO 8601
: null,
};
await updateOrCreateProject(processedProject, gitcoinSourceConfig);
}
Expand Down
1 change: 1 addition & 0 deletions src/features/import-projects/giveth/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const givethSourceConfig: SourceConfig = {
descriptionField: "description",
urlField: "url",
imageField: "image",
sourceCreatedAtField: "creationDate",
};
1 change: 1 addition & 0 deletions src/features/import-projects/giveth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const fetchGivethProjectsBatch = async (limit: number, skip: number) => {
image
slug
description
creationDate
}
}
}`,
Expand Down
1 change: 1 addition & 0 deletions src/features/import-projects/giveth/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export type GivethProjectInfo = {
description: string;
slug: string;
image: string;
creationDate: string;
};
7 changes: 6 additions & 1 deletion src/features/import-projects/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const updateOrCreateProject = async (
imageField,
rfRoundField,
prelimResult,
sourceCreatedAtField,
} = sourceConfig;

const projectId = project[idField].toLowerCase();
Expand All @@ -44,6 +45,7 @@ export const updateOrCreateProject = async (
const image = project[imageField];
const descriptionHtml = descriptionHtmlField && project[descriptionHtmlField];
const rfRound = rfRoundField && project[rfRoundField];
const sourceCreatedAt = sourceCreatedAtField && project[sourceCreatedAtField];

// Skip project if prelimResult is "Remove"
if (prelimResult && project[prelimResult] === "Remove") {
Expand All @@ -61,7 +63,8 @@ export const updateOrCreateProject = async (
existingProject.image !== image ||
(rfRound && !existingProject.rfRounds?.some((rfr) => rfr === rfRound)) ||
existingProject.descriptionHtml != descriptionHtml ||
(!existingProject.descriptionSummary && description);
(!existingProject.descriptionSummary && description) ||
existingProject.sourceCreatedAt != sourceCreatedAt;

if (isUpdated) {
// Add the current round to rfRounds if not already present
Expand All @@ -79,6 +82,7 @@ export const updateOrCreateProject = async (
descriptionSummary,
lastUpdatedTimestamp: new Date(),
rfRounds: Array.from(rfRoundsSet),
sourceCreatedAt,
imported: true,
};

Expand Down Expand Up @@ -115,6 +119,7 @@ export const updateOrCreateProject = async (
totalVouches: 0,
totalFlags: 0,
totalAttests: 0,
sourceCreatedAt,
lastUpdatedTimestamp: new Date(),
imported: true,
});
Expand Down
2 changes: 0 additions & 2 deletions src/features/import-projects/retroList/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export const fetchAndProcessRlProjects = async (round: number) => {
const data = await fetchRlProjects(round);
if (!data) return;

const processedProjectIds: string[] = [];

for (const project of data) {
const processedProject = {
...project,
Expand Down
1 change: 1 addition & 0 deletions src/features/import-projects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface SourceConfig {
imageField: string;
rfRoundField?: string;
prelimResult?: string;
sourceCreatedAtField?: string;
}
6 changes: 6 additions & 0 deletions src/model/generated/project.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ export class Project {
*/
@Column_("int4", {array: true, nullable: true})
rfRounds!: (number)[] | undefined | null

/**
* Source Creation Timestamp
*/
@Column_("timestamp with time zone", {nullable: true})
sourceCreatedAt!: Date | undefined | null
}

0 comments on commit c04674f

Please sign in to comment.