Skip to content

Commit

Permalink
Undo Adding matchingFund to totalDonation amount of projects
Browse files Browse the repository at this point in the history
related to #1186
  • Loading branch information
mohammadranjbarz committed Dec 5, 2023
2 parents 2c8d77a + 9be23d0 commit 3b76a85
Show file tree
Hide file tree
Showing 25 changed files with 470 additions and 114 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/develop-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
OPTIMISTIC_SCAN_API_KEY: ${{ secrets.OPTIMISTIC_SCAN_API_KEY }}
CELO_SCAN_API_KEY: ${{ secrets.CELO_SCAN_API_KEY }}
CELO_ALFAJORES_SCAN_API_KEY: ${{ secrets.CELO_ALFAJORES_SCAN_API_KEY }}
MORDOR_ETC_TESTNET: ${{ secrets.MORDOR_ETC_TESTNET }}
ETC_NODE_HTTP_URL: ${{ secrets.ETC_NODE_HTTP_URL }}

publish:
needs: test
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/master-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
OPTIMISTIC_SCAN_API_KEY: ${{ secrets.OPTIMISTIC_SCAN_API_KEY }}
CELO_SCAN_API_KEY: ${{ secrets.CELO_SCAN_API_KEY }}
CELO_ALFAJORES_SCAN_API_KEY: ${{ secrets.CELO_ALFAJORES_SCAN_API_KEY }}
MORDOR_ETC_TESTNET: ${{ secrets.MORDOR_ETC_TESTNET }}
ETC_NODE_HTTP_URL: ${{ secrets.ETC_NODE_HTTP_URL }}

publish:
needs: test
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/staging-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ jobs:
OPTIMISTIC_SCAN_API_KEY: ${{ secrets.OPTIMISTIC_SCAN_API_KEY }}
CELO_SCAN_API_KEY: ${{ secrets.CELO_SCAN_API_KEY }}
CELO_ALFAJORES_SCAN_API_KEY: ${{ secrets.CELO_ALFAJORES_SCAN_API_KEY }}
MORDOR_ETC_TESTNET: ${{ secrets.MORDOR_ETC_TESTNET }}
ETC_NODE_HTTP_URL: ${{ secrets.ETC_NODE_HTTP_URL }}
DROP_DATABASE: ${{ secrets.DROP_DATABASE }}

publish:
Expand Down
2 changes: 1 addition & 1 deletion config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ THIRD_PARTY_PROJECTS_ADMIN_USER_ID=4
PROJECT_FILTERS_THREADS_POOL_CONCURRENCY=1
PROJECT_FILTERS_THREADS_POOL_NAME=ProjectFiltersThreadPool
PROJECT_FILTERS_THREADS_POOL_SIZE=1
PROJECT_FILTERS_THREADS_POOL_DURATION=600
PROJECT_FILTERS_THREADS_POOL_DURATION=1

# OPTIONAL - force logging to stdout when the value is true
LOG_STDOUT=false
Expand Down
33 changes: 33 additions & 0 deletions migration/1700998774661-add_slug_to_qf_round.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddSlugToQfRound1700998774661 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
// Adding the 'slug' column with a default value
await queryRunner.query(
`ALTER TABLE qf_round ADD COLUMN slug TEXT NOT NULL DEFAULT ''`,
);

// Update the 'slug' column to use the 'id' for existing records
await queryRunner.query(`UPDATE qf_round SET slug = id::text`);

// Add a unique constraint to ensure slug uniqueness
await queryRunner.query(
`ALTER TABLE qf_round ADD CONSTRAINT qf_round_slug_unique UNIQUE (slug)`,
);

// Remove the default empty string now that all slugs have been set
await queryRunner.query(
`ALTER TABLE qf_round ALTER COLUMN slug DROP DEFAULT`,
);
}

async down(queryRunner: QueryRunner): Promise<void> {
// If you need to revert the migration, remove the unique constraint
await queryRunner.query(
`ALTER TABLE qf_round DROP CONSTRAINT qf_round_slug_unique`,
);

// Then drop the 'slug' column
await queryRunner.query(`ALTER TABLE qf_round DROP COLUMN slug`);
}
}
6 changes: 6 additions & 0 deletions src/entities/qfRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RelationId,
UpdateDateColumn,
CreateDateColumn,
Index,
} from 'typeorm';
import { Project } from './project';
import { MainCategory } from './mainCategory';
Expand All @@ -24,6 +25,11 @@ export class QfRound extends BaseEntity {
@Column('text', { nullable: true })
name: string;

@Field()
@Index({ unique: true })
@Column('text')
slug: string;

@Field({ nullable: true })
@Column({ nullable: true })
isActive: boolean;
Expand Down
15 changes: 6 additions & 9 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,33 +148,30 @@ export function getProvider(networkId: number) {
let options;
switch (networkId) {
case NETWORK_IDS.MORDOR_ETC_TESTNET:
// url = config.get('MORDOR_ETC_TESTNET_NODE_HTTP_URL') as string;
url = 'https://rpc.mordor.etccooperative.org';
url = process.env.MORDOR_ETC_TESTNET as string;
break;
case NETWORK_IDS.ETC:
// url = config.get('ETC_NODE_HTTP_URL') as string;
url =
'https://etc.getblock.io/78a7319e-6790-4a58-b1b4-43d16e400527/mainnet';
url = process.env.ETC_NODE_HTTP_URL as string;
break;
case NETWORK_IDS.XDAI:
url = config.get('XDAI_NODE_HTTP_URL') as string;
url = process.env.XDAI_NODE_HTTP_URL as string;
break;

case NETWORK_IDS.BSC:
// 'https://bsc-dataseed.binance.org/'
url = config.get('BSC_NODE_HTTP_URL') as string;
url = process.env.BSC_NODE_HTTP_URL as string;
options = { name: NETWORK_NAMES.BSC, chainId: NETWORK_IDS.BSC };
break;

case NETWORK_IDS.CELO:
url =
(config.get('CELO_NODE_HTTP_URL') as string) ||
(process.env.CELO_NODE_HTTP_URL as string) ||
`https://celo-mainnet.infura.io/v3/${INFURA_ID}`;
break;

case NETWORK_IDS.CELO_ALFAJORES:
url =
(config.get('CELO_ALFAJORES_NODE_HTTP_URL') as string) ||
(process.env.CELO_ALFAJORES_NODE_HTTP_URL as string) ||
`https://celo-alfajores.infura.io/v3/${INFURA_ID}`;
break;

Expand Down
18 changes: 18 additions & 0 deletions src/repositories/donationRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function fillQfRoundDonationsUserScoresTestCases() {
name: 'test',
allocatedFund: 100,
minimumPassportScore: 8,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().subtract(10, 'days').toDate(),
});
Expand Down Expand Up @@ -142,6 +143,7 @@ function estimatedMatchingTestCases() {
name: 'test',
allocatedFund: 100,
minimumPassportScore: 8,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
});
Expand Down Expand Up @@ -538,6 +540,7 @@ function countUniqueDonorsForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: new Date(),
}).save();
Expand Down Expand Up @@ -567,6 +570,7 @@ function countUniqueDonorsForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: new Date(),
}).save();
Expand Down Expand Up @@ -619,6 +623,7 @@ function countUniqueDonorsForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: moment().subtract(3, 'days').toDate(),
endDate: moment().subtract(1, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -663,6 +668,7 @@ function countUniqueDonorsForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -711,6 +717,7 @@ function countUniqueDonorsForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -881,6 +888,7 @@ function sumDonationValueUsdForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: new Date(),
}).save();
Expand Down Expand Up @@ -912,6 +920,7 @@ function sumDonationValueUsdForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: new Date(),
}).save();
Expand Down Expand Up @@ -969,6 +978,7 @@ function sumDonationValueUsdForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: new Date(),
}).save();
Expand Down Expand Up @@ -1015,6 +1025,7 @@ function sumDonationValueUsdForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: new Date(),
}).save();
Expand Down Expand Up @@ -1064,6 +1075,7 @@ function sumDonationValueUsdForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -1112,6 +1124,7 @@ function sumDonationValueUsdForActiveQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -1290,6 +1303,7 @@ function isVerifiedDonationExistsInQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -1327,6 +1341,7 @@ function isVerifiedDonationExistsInQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -1364,6 +1379,7 @@ function isVerifiedDonationExistsInQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -1401,6 +1417,7 @@ function isVerifiedDonationExistsInQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down Expand Up @@ -1438,6 +1455,7 @@ function isVerifiedDonationExistsInQfRoundTestCases() {
name: new Date().toString(),
allocatedFund: 100,
minimumPassportScore: 12,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
}).save();
Expand Down
9 changes: 4 additions & 5 deletions src/repositories/projectRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,10 @@ function updateProjectWithVerificationFormTestCases() {
...createProjectData(),
admin: String(user.id),
verified: false,
networkId: NETWORK_IDS.GOERLI,
});
const fetchedProject = await findProjectById(project.id);
assert.equal(
fetchedProject?.addresses?.length,
Object.keys(NETWORK_IDS).length,
);
assert.equal(fetchedProject?.addresses?.length, 1);
assert.equal(fetchedProject?.addresses?.[0].address, project.walletAddress);
const projectVerificationForm = await createProjectVerificationForm({
projectId: project.id,
Expand All @@ -282,9 +280,10 @@ function updateProjectWithVerificationFormTestCases() {

await updateProjectWithVerificationForm(projectVerificationForm, project);
const fetchedProject2 = await findProjectById(project.id);

assert.equal(
fetchedProject2?.addresses?.length,
Object.keys(NETWORK_IDS).length + 1,
fetchedProject!.addresses!.length + 1,
);
assert.isOk(
fetchedProject2?.addresses?.find(
Expand Down
17 changes: 13 additions & 4 deletions src/repositories/projectRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type FilterProjectQueryInputParams = {
sortingBy?: SortingField;
qfRoundId?: number;
activeQfRoundId?: number;
qfRoundSlug?: string;
};
export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
const {
Expand All @@ -81,6 +82,7 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
sortingBy,
slugArray,
qfRoundId,
qfRoundSlug,
activeQfRoundId,
} = params;

Expand Down Expand Up @@ -118,6 +120,13 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
'qf_rounds.id = :qfRoundId',
{ qfRoundId: qfRoundId ? qfRoundId : activeQfRoundId },
);
} else if (qfRoundSlug) {
query.innerJoinAndSelect(
'project.qfRounds',
'qf_rounds',
`qf_rounds.slug = :qfRoundSlug`,
{ qfRoundSlug },
);
}
if (!sortingBy || sortingBy === SortingField.InstantBoosting) {
query = query
Expand Down Expand Up @@ -294,10 +303,10 @@ export const updateProjectWithVerificationForm = async (
isRecipient: false,
}).save();
}

project.contacts = verificationForm.projectContacts;
await project.save();
return (await findProjectById(project.id)) as Project;
const fetchedProject = await findProjectById(verificationForm.projectId);
fetchedProject!.contacts = verificationForm.projectContacts;
await fetchedProject!.save();
return fetchedProject!;
};

export const verifyProject = async (params: {
Expand Down
2 changes: 2 additions & 0 deletions src/repositories/qfRoundHistoryRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function fillQfRoundHistoryTestCases() {
name: 'test',
allocatedFund: 100,
minimumPassportScore: 8,
slug: new Date().getTime().toString(),
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
});
Expand Down Expand Up @@ -336,6 +337,7 @@ function getQfRoundHistoriesThatDontHaveRelatedDonationsTestCases() {
isActive: true,
name: 'test',
allocatedFund: 100,
slug: new Date().getTime().toString(),
minimumPassportScore: 8,
beginDate: new Date(),
endDate: moment().add(10, 'days').toDate(),
Expand Down
Loading

0 comments on commit 3b76a85

Please sign in to comment.