-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
running migration to set project banners appropriately for endaoment … (
#1778) * running migration to set project banners appropriately for endaoment projects * chore: correcting tab spaces for syntax * fix: linter errors * Modify add banner to endaoment projects migration (#1791) related to #1600 * Fix lint errors * Fix running tests * Fix projectResolver test cases * Fix donationResolver test cases * skip should renew the expiration date of the draft donation test case --------- Co-authored-by: Hrithik Sampson <[email protected]> Co-authored-by: mohammadranjbarz <[email protected]>
- Loading branch information
1 parent
b510db1
commit 394ef30
Showing
8 changed files
with
130 additions
and
17 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
migration/1724368995904-add_banner_endaoment_projects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { endaomentProjects } from './data/importedEndaomentProjects'; | ||
import { endaomentProjectCategoryMapping } from './data/endaomentProjectCategoryMapping'; | ||
import { NETWORK_IDS } from '../src/provider'; | ||
|
||
export class AddBannerEndaomentProjects1724368995904 | ||
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: 'community', | ||
'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', | ||
}; | ||
|
||
for (const project of endaomentProjects) { | ||
const mainnetAddress = project.mainnetAddress; | ||
const projectAddresses = await queryRunner.query( | ||
`SELECT * FROM project_address WHERE LOWER(address) = $1 AND "networkId" = $2 LIMIT 1`, | ||
[mainnetAddress!.toLowerCase(), NETWORK_IDS.MAIN_NET], | ||
); | ||
|
||
const projectAddress = await projectAddresses?.[0]; | ||
|
||
if (!projectAddress) { | ||
// eslint-disable-next-line no-console | ||
console.log(`Could not find project address for ${mainnetAddress}`); | ||
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) | ||
: []; | ||
}; | ||
if (!project.nteeCode) { | ||
// eslint-disable-next-line no-console | ||
console.log(`Could not find nteeCode for ${mainnetAddress}`); | ||
continue; | ||
} | ||
const categoryNames = getCategoryNames(String(project.nteeCode)); | ||
const bannerImage = `/images/defaultProjectImages/${imageCategoryMapping[categoryNames[1]] || '1'}.png`; | ||
await queryRunner.query(`UPDATE project SET image = $1 WHERE id = $2`, [ | ||
bannerImage, | ||
projectAddress.projectId, | ||
]); | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
`Updated project ${projectAddress.projectId} with image ${bannerImage}`, | ||
); | ||
} | ||
} | ||
|
||
public async down(_queryRunner: QueryRunner): Promise<void> { | ||
// No down migration | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters