Skip to content

Commit

Permalink
Add estimatedMatching to qfRoundHistoryResolver response
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadranjbarz committed Jul 6, 2023
1 parent 0a168fc commit d4bea06
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
13 changes: 1 addition & 12 deletions src/entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
getProjectDonationsSqrtRootSum,
getQfRoundTotalProjectsDonationsSum,
} from '../repositories/qfRoundRepository';
import { EstimatedMatching } from '../types/qfTypes';
// tslint:disable-next-line:no-var-requires
const moment = require('moment');

Expand Down Expand Up @@ -121,18 +122,6 @@ export enum ReviewStatus {
NotListed = 'Not Listed',
}

@ObjectType()
class EstimatedMatching {
@Field(type => Float)
projectDonationsSqrtRootSum: number;

@Field(type => Float)
allProjectsSum: number;

@Field(type => Float)
matchingPool: number;
}

@Entity()
@ObjectType()
export class Project extends BaseEntity {
Expand Down
28 changes: 28 additions & 0 deletions src/entities/qfRoundHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import {
} from 'typeorm';
import { Project } from './project';
import { QfRound } from './qfRound';
import {
findQfRoundById,
getProjectDonationsSqrtRootSum,
getQfRoundTotalProjectsDonationsSum,
} from '../repositories/qfRoundRepository';
import { EstimatedMatching } from '../types/qfTypes';

@Entity()
@ObjectType()
Expand Down Expand Up @@ -70,4 +76,26 @@ export class QfRoundHistory extends BaseEntity {

@CreateDateColumn()
createdAt: Date;

// In your main class
@Field(type => EstimatedMatching, { nullable: true })
async estimatedMatching(): Promise<EstimatedMatching | null> {
const projectDonationsSqrtRootSum = await getProjectDonationsSqrtRootSum(
this.projectId,
this.qfRoundId,
);

const allProjectsSum = await getQfRoundTotalProjectsDonationsSum(
this.qfRoundId,
);
const qfRound = await findQfRoundById(this.qfRoundId);

const matchingPool = qfRound!.allocatedFund;

return {
projectDonationsSqrtRootSum: projectDonationsSqrtRootSum.sqrtRootSum,
allProjectsSum: allProjectsSum.sum,
matchingPool,
};
}
}
5 changes: 5 additions & 0 deletions src/resolvers/qfRoundHistoryResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,10 @@ function getQfRoundHistoryTestCases() {
assert.equal(qfRoundHistory.donationsCount, 2);
assert.equal(qfRoundHistory.uniqueDonors, 1);
assert.equal(qfRoundHistory.raisedFundInUsd, 25);
assert.exists(qfRoundHistory.estimatedMatching);
assert.equal(
qfRoundHistory.estimatedMatching.matchingPool,
qfRound.allocatedFund,
);
});
}
13 changes: 13 additions & 0 deletions src/types/qfTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Field, Float, ObjectType } from 'type-graphql';

@ObjectType()
export class EstimatedMatching {
@Field(type => Float)
projectDonationsSqrtRootSum: number;

@Field(type => Float)
allProjectsSum: number;

@Field(type => Float)
matchingPool: number;
}
5 changes: 5 additions & 0 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,11 @@ export const getQfRoundHistoryQuery = `
matchingFund
distributedFundNetwork
distributedFundTxHash
estimatedMatching {
projectDonationsSqrtRootSum
allProjectsSum
matchingPool
}
}
}
`;
Expand Down

0 comments on commit d4bea06

Please sign in to comment.