Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement recurringDonationsByProjectId webservice #1283

Merged
merged 10 commits into from
Feb 7, 2024
27 changes: 27 additions & 0 deletions migration/1707045732631-modify_recurring_donation_table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class ModifyRecurringDonationTable1707045732631
implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> {
// Add amount, anonymous, interval, and currency columns with default values
await queryRunner.query(`
ALTER TABLE recurring_donation
ADD COLUMN IF NOT EXISTS amount INT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS interval text NOT NULL DEFAULT 'monthly',
ADD COLUMN IF NOT EXISTS currency text NOT NULL DEFAULT 'USD'
ADD COLUMN IF NOT EXISTS status text NOT NULL DEFAULT 'pending'
`);
}

async down(queryRunner: QueryRunner): Promise<void> {
// Remove the columns if the migration is rolled back
await queryRunner.query(`
ALTER TABLE recurring_donation
DROP COLUMN amount,
DROP COLUMN status,
DROP COLUMN interval,
DROP COLUMN currency
`);
}
}
40 changes: 29 additions & 11 deletions src/entities/recurringDonation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,33 @@ export class RecurringDonation extends BaseEntity {
readonly id: number;

@Field()
@Column()
@Column({ nullable: false })
networkId: number;

@Field()
@Column({ nullable: false })
amount: number;

// daily, weekly, monthly, yearly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add an ENUM for this

@Field()
@Column({ nullable: false })
interval: string;

@Index()
@Field()
@Column()
@Column({ nullable: false })
txHash: string;

@Index()
@Field()
@Column({ nullable: false })
currency: string;

@Index()
@Field()
@Column({ nullable: false, default: 'pending' })
status: string;

@Index()
@Field(type => Project)
@ManyToOne(type => Project)
Expand All @@ -50,9 +69,14 @@ export class RecurringDonation extends BaseEntity {
@Column({ nullable: true })
projectId: number;

@Column({ nullable: true })
@Column({ nullable: true, default: false })
@Field({ nullable: true })
finished: boolean;

@Column({ nullable: true, default: false })
@Field({ nullable: true })
anonymous: boolean;

@Index()
@Field(type => AnchorContractAddress)
@ManyToOne(type => AnchorContractAddress)
Expand All @@ -74,17 +98,11 @@ export class RecurringDonation extends BaseEntity {
@Column({ nullable: true })
donorId: number;

@Field({ nullable: true })
@Column('text', { default: RECURRING_DONATION_STATUS.PENDING })
status: string;

@Field({ nullable: true })
@Column({ nullable: true })
anonymous: boolean;

@UpdateDateColumn()
@Field()
updatedAt: Date;

@CreateDateColumn()
@Field()
createdAt: Date;
}
3 changes: 0 additions & 3 deletions src/repositories/campaignRepository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { Campaign } from '../entities/campaign';
import { findProjectBySlug } from './projectRepository';
import { errorMessages } from '../utils/errorMessages';
import { Project } from '../entities/project';

export const findAllActiveCampaigns = async (): Promise<Campaign[]> => {
return Campaign.createQueryBuilder('campaign')
Expand Down
3 changes: 3 additions & 0 deletions src/repositories/recurringDonationRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function createNewRecurringDonationTestCases() {
networkId: NETWORK_IDS.OPTIMISTIC,
donor: creator,
anchorContractAddress,
amount: 100,
currency: 'USD',
interval: 'monthly',
project,
});

Expand Down
6 changes: 6 additions & 0 deletions src/repositories/recurringDonationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ export const createNewRecurringDonation = async (params: {
anchorContractAddress: AnchorContractAddress;
networkId: number;
txHash: string;
interval: string;
amount: number;
currency: string;
}): Promise<RecurringDonation> => {
const recurringDonation = await RecurringDonation.create({
project: params.project,
donor: params.donor,
anchorContractAddress: params.anchorContractAddress,
networkId: params.networkId,
txHash: params.txHash,
currency: params.currency,
interval: params.interval,
amount: params.amount,
});
return recurringDonation.save();
};
Expand Down
Loading
Loading