Skip to content

Commit

Permalink
Make sure all Endaoment projects have been added to our DB (#1751)
Browse files Browse the repository at this point in the history
* Make sure all Endaoment projects have been added to our DB

related to #1598 (comment)

* Fix eslint errors

* Add appropriate banner images for imported endaoment projects

related to #1600 (comment)
  • Loading branch information
mohammadranjbarz authored Aug 7, 2024
1 parent 50bfd89 commit f6eb385
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 197 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { ORGANIZATION_LABELS } from '../../src/entities/organization';
import { NETWORK_IDS } from '../../src/provider';
import { ORGANIZATION_LABELS } from '../src/entities/organization';
import { NETWORK_IDS } from '../src/provider';

export class AddEndaomentOrganization1719740230650
implements MigrationInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ export class CreateEndaomentsCategories1719808494903
await queryRunner.query(`
INSERT INTO "category" ("name", "value", "source", "mainCategoryId", "isActive")
VALUES
('Endaoment', 'endaoment', '', ${ngoMainCategory[0].id}, true),
('Religious', 'religious', '', ${artCultureMainCategory[0].id}, true),
('Disaster Relief', 'disaster-relief', '', ${ngoMainCategory[0].id}, true),
('Recreation', 'recreation', '', ${healthWellnessMainCategory[0].id}, true),
('Financial Services', 'financial-services', '', ${financeMainCategory[0].id}, true),
('International Aid', 'international-aid', '', ${ngoMainCategory[0].id}, true);
('endaoment', 'Endaoment', '', ${ngoMainCategory[0].id}, true),
('religious', 'Religious', '', ${artCultureMainCategory[0].id}, true),
('disaster-relief', 'Disaster Relief', '', ${ngoMainCategory[0].id}, true),
('recreation', 'Recreation', '', ${healthWellnessMainCategory[0].id}, true),
('financial-services', 'Financial Services', '', ${financeMainCategory[0].id}, true),
('international-aid', 'International Aid', '', ${ngoMainCategory[0].id}, true);
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
// Delete Sub-Categories
await queryRunner.query(
`DELETE FROM "category" WHERE "value" IN ('endaoment', 'religious', 'disaster-relief', 'recreation', 'financial-services', 'international-aid')`,
`DELETE FROM "category" WHERE "name" IN ('endaoment', 'religious', 'disaster-relief', 'recreation', 'financial-services', 'international-aid')`,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { endaomentProjectCategoryMapping } from '../data/endaomentProjectCategoryMapping';
import { endaomentProjects } from '../data/importedEndaomentProjects';
import { NETWORK_IDS } from '../../src/provider';
import { ReviewStatus } from '../../src/entities/project';
import { endaomentProjectCategoryMapping } from './data/endaomentProjectCategoryMapping';
import { endaomentProjects } from './data/importedEndaomentProjects';
import { NETWORK_IDS } from '../src/provider';
import { ReviewStatus } from '../src/entities/project';
import {
creteSlugFromProject,
titleWithoutSpecialCharacters,
} from '../src/utils/utils';

export class AddEndaomentsProjects1719808494904 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const imageCategoryMapping = {
'Public Goods': 'community',
'Peace & Justice': 'community',
'Sustainable Cities & Communities': 'nature',
Housing: 'community',
'Social Services': 'community',
'Family & Children': 'community',
'Health Care': 'community',
'Registered Non-profits': 'non-profit',
Research: 'education',
'Mental Health': 'health-wellness',
Animals: 'nature',
Nutrition: 'health-wellness',
Religious: 'community',
Art: 'art-culture',
Food: 'health-wellness',
'Disaster Relief': 'non-profit',
'Conservation & Biodiversity': 'nature',
Education: 'education',
'Industry & Innovation': 'economics-infrastructure',
'Financial Services': 'finance',
Schooling: 'education',
Inclusion: 'equality',
Climate: 'nature',
'Water & Sanitation': 'community',
Tech: 'technology',
Employment: 'finance',
Infrastructure: 'economics-infrastructure',
'International Aid': 'non-profit',
Other: '1',
Recreation: 'community',
culture: 'art-culture',
Recycling: 'nature',
Agriculture: 'nature',
Grassroots: 'community',
'BIPOC Communities': 'equality',
Fundraising: 'non-profit',
'Registred Non-profits': 'non-profit',
'Gender Equality': 'equality',
};
// Insert the Endaoment organization if it doesn't exist
await queryRunner.query(`
INSERT INTO "organization" ("name", "disableNotifications", "disableRecurringDonations", "disableUpdateEnforcement", "label", "website", "supportCustomTokens")
Expand Down Expand Up @@ -44,26 +88,43 @@ export class AddEndaomentsProjects1719808494904 implements MigrationInterface {
// Insert projects and their addresses
for (const project of endaomentProjects) {
// Prepare slug and quality score
const slugBase = project.name.replace(/[*+~.,()'"!:@]/g, '');
const slug = slugBase
.toLowerCase()
.replace(/ /g, '-')
.replace('/', '-')
.replace('\\', '-');
const title = titleWithoutSpecialCharacters(project.name);
const slugBase = creteSlugFromProject(title);
// const slug = await getAppropriateSlug(slugBase)
const slug = slugBase;

// Insert the project-category relationship in a single query
const getCategoryNames = (nteeCode: string): string[] => {
const mapping = endaomentProjectCategoryMapping.find(
category => category.nteeCode === nteeCode,
);
return mapping
? [
mapping.category1,
mapping.category2,
mapping.category3,
mapping.category4,
].filter(Boolean)
: [];
};
const categoryNames = getCategoryNames(String(project.nteeCode));

const bannerImage = `/images/defaultProjectImages/${imageCategoryMapping[categoryNames[1]] || '1'}.png`;

// Insert the project
await queryRunner.query(`
INSERT INTO "project" (
"title", "description", "organizationId", "walletAddress", "creationDate", "slug", "image", "slugHistory", "statusId", "totalDonations", "totalReactions", "totalProjectUpdates", "listed", "reviewStatus", "verified", "giveBacks", "isImported", "adminUserId"
"title", "description", "descriptionSummary", "organizationId", "walletAddress", "creationDate", "slug", "image", "slugHistory", "statusId", "totalDonations", "totalReactions", "totalProjectUpdates", "listed", "reviewStatus", "verified", "giveBacks", "isImported", "adminUserId"
)
VALUES (
'${project.name.replace(/'/g, '')}',
'${title}',
'${project.description.replace(/'/g, '')}',
'${project.description.replace(/'/g, '')}',
${endaomentOrgId},
'${project.mainnetAddress || ''}',
NOW(),
'${slug}',
'/images/defaultProjectImages/1.png', -- Default image
'${bannerImage}',
'{}', -- Empty slug history
5, -- statusId 5 is 'Active'
0,
Expand All @@ -76,39 +137,23 @@ export class AddEndaomentsProjects1719808494904 implements MigrationInterface {
true,
${adminUser?.id}
)
ON CONFLICT ("slug") DO NOTHING; -- Handle conflict on unique constraint
`);
// ON CONFLICT ("slug") DO NOTHING; -- Handle conflict on unique constraint

// Get the inserted project's ID
const projectIdResult = await queryRunner.query(`
SELECT "id" FROM "project" WHERE "title" = '${project.name.replace(/'/g, '')}' AND "organizationId" = ${endaomentOrgId};
SELECT "id" FROM "project" WHERE "slug" = '${slug}' AND "organizationId" = ${endaomentOrgId};
`);
const projectId = projectIdResult[0]?.id;
if (!projectId) {
// It means we have project with same slug so the creation has failed
continue;
}

// Insert the project-category relationship in a single query
const getCategoryNames = (nteeCode: string): string[] => {
const mapping = endaomentProjectCategoryMapping.find(
category => category.nteeCode === nteeCode,
);
return mapping
? [
mapping.category1,
mapping.category2,
mapping.category3,
mapping.category4,
].filter(Boolean)
: [];
};
const categoryNames = getCategoryNames(String(project.nteeCode));

for (const categoryName of categoryNames) {
const categoryIdResult = await queryRunner.query(`
SELECT "id" FROM "category" WHERE "name" = '${categoryName.replace(/'/g, "''")}' LIMIT 1;
SELECT "id" FROM "category" WHERE "value" = '${categoryName.replace(/'/g, "''")}' LIMIT 1;
`);
const categoryId = categoryIdResult[0]?.id;

Expand Down Expand Up @@ -153,7 +198,7 @@ export class AddEndaomentsProjects1719808494904 implements MigrationInterface {
await queryRunner.query(`
INSERT INTO "project_update" ("userId", "projectId", "content", "title", "createdAt", "isMain")
VALUES (
(SELECT "id" FROM "user" WHERE "email" = '${adminUser?.email || ''}' LIMIT 1),
${adminUser?.id},
${projectId},
'',
'',
Expand Down
12 changes: 6 additions & 6 deletions migration/data/importedEndaomentProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13148,7 +13148,7 @@ export const endaomentProjects: EndaomentProject[] = [
baseAddress: '0x5838d2ff1d0ca706df1470d6c66903c88ff9fce0',
},
{
name: 'National Network of Abortion Funds',
name: 'National Network of Abortion Funds 2',
description:
'Texas Equal Access Fund helps low-income people in northern Texas who want an abortion and cannot afford it.',
logoUrl: '',
Expand Down Expand Up @@ -18362,7 +18362,7 @@ export const endaomentProjects: EndaomentProject[] = [
baseAddress: '0x9089d131eec13cf7d04960931156c7396a4418f9',
},
{
name: 'The Fred Hollows Foundation',
name: 'The Fred Hollows Foundation 2',
description:
"The Fred Hollows Foundation is a international development organisation working to restore sight to people who are blind or vision impaired. Globally there are 1.1 billion people who are blind or vision impaired. 90% of these cases are preventable or avoidable. You can help restore sight for as little as $25 and change someone's life forever.",
logoUrl: 'https://www.globalgiving.org/pfil/organ/99197/orglogo.png',
Expand Down Expand Up @@ -28154,7 +28154,7 @@ export const endaomentProjects: EndaomentProject[] = [
baseAddress: '0x958c4a1a7ee17e4a83523538f9d64edc9372d865',
},
{
name: 'Impact Church',
name: 'Impact Church 2',
description:
'Impact Church is dedicated to rebuilding the spirit of the community with Jesus Christ as its cornerstone.',
logoUrl:
Expand Down Expand Up @@ -30891,7 +30891,7 @@ export const endaomentProjects: EndaomentProject[] = [
baseAddress: '0x9f89cab43ad0a29f4b5c1748c32478f3c85c5217',
},
{
name: 'Transformation Church Inc',
name: 'Transformation Church Inc 2',
description:
'We exist to Re-Present God to the lost and found for transformation in Christ. We are a multi-church. Meaning we are a multi-generational, multi-ethnic, multi-plying, and multi-campus.',
logoUrl:
Expand Down Expand Up @@ -36110,7 +36110,7 @@ export const endaomentProjects: EndaomentProject[] = [
baseAddress: '0x1645ed004fa10bf611674d8f9354f41aa4ba0e07',
},
{
name: 'Choose Love',
name: 'Choose Love 2',
description:
'We are pioneering a new movement in humanitarian aid: fast, flexible, transparent and accountable.<br><br>We are a lean, passionate team driving a fast-paced global movement across 15 countries.<br><br>We have raised millions to support refugees and created a movement of people putting love into action around the world.',
logoUrl:
Expand Down Expand Up @@ -38654,7 +38654,7 @@ export const endaomentProjects: EndaomentProject[] = [
baseAddress: '0x9f3413edebf38d27182b59b81be67d11c5db55ae',
},
{
name: "St. Jude Children's Research Hospital",
name: "St. Jude Children's Research Hospital 2",
description:
'St. Jude Children’s Research Hospital is leading the way the world understands, treats and defeats childhood cancer and other life-threatening diseases. Our purpose is clear: Finding cures. Saving children.®<br><br>We are the only National Cancer Institute-designated Comprehensive Cancer Center devoted solely to children. Treatments invented at St. Jude have helped push the overall childhood cancer survival rate from 20 percent to more than 80 percent since we opened more than 50 years ago. And we won’t stop until no child dies from cancer.<br><br>Families never receive a bill from St. Jude for treatment, travel, housing or food – because all a family should worry about is helping their child live.',
logoUrl:
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit f6eb385

Please sign in to comment.