Skip to content

Commit

Permalink
Merge branch 'addGitCionScoreToDonationFlow' of github.com:GeneralMag…
Browse files Browse the repository at this point in the history
…icio/QAcc-BE into addTestsForKYCCaps
  • Loading branch information
ae2079 committed Nov 26, 2024
2 parents 3ebd200 + 0fa648d commit 73c0c68
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,5 @@ MONGO_DB_REPORT_DB_NAME=
GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE=
# 1 day
GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS=86400000
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY=
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD=
ACTIVATE_GITCOIN_SCORE_CHECK=
7 changes: 4 additions & 3 deletions src/constants/gitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS =
(+config.get('GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS') as number) || 86400000; // 1 day
export const GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE =
(+config.get('GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE') as number) || 50;
export const MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY =
(+config.get('MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY') as number) ||
1000;
export const MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD =
(+config.get(
'MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD',
) as number) || 1000;
7 changes: 5 additions & 2 deletions src/resolvers/qAccResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getProjectUserRecordAmount } from '../repositories/projectUserRecordRep
import qAccService from '../services/qAccService';
import { ApolloContext } from '../types/ApolloContext';
import { i18n, translationErrorMessagesKeys } from '../utils/errorMessages';
import { getUserById } from '../services/userService';
import { findUserById } from '../repositories/userRepository';

@ObjectType()
class ProjectUserRecordAmounts {
Expand Down Expand Up @@ -85,7 +85,10 @@ export class QAccResolver {
i18n.__(translationErrorMessagesKeys.AUTHENTICATION_REQUIRED),
);

const dbUser = await getUserById(user.userId);
const dbUser = await findUserById(user.userId);
if (!dbUser) {
throw new Error(`user not found with id ${user.userId}`);
}

const qAccCap = await qAccService.getQAccDonationCap({
projectId,
Expand Down
12 changes: 10 additions & 2 deletions src/services/qAccService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { updateUserGitcoinAnalysisScore } from './userService';
import {
GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS,
GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE,
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY,
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD,
} from '../constants/gitcoin';

const getEaProjectRoundRecord = async ({
Expand Down Expand Up @@ -226,8 +226,16 @@ const getUserRemainedCapBasedOnGitcoinScore = async ({
projectId,
userId: user.id,
});
const activeQfRound = await findActiveQfRound();
const qfTotalDonationAmount = userRecord.qfTotalDonationAmount;
return MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY - qfTotalDonationAmount;
if (!activeQfRound?.tokenPrice) {
throw new Error('active qf round does not have token price!');
}
return (
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD /
activeQfRound?.tokenPrice -
qfTotalDonationAmount
);
};

const validDonationAmountBasedOnKYCAndScore = async ({
Expand Down
13 changes: 1 addition & 12 deletions src/services/userService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { User } from '../entities/user';
import { Donation } from '../entities/donation';
import { logger } from '../utils/logger';
import {
findAdminUserByEmail,
findUserById,
} from '../repositories/userRepository';
import { findAdminUserByEmail } from '../repositories/userRepository';
import { getGitcoinAdapter } from '../adapters/adaptersFactory';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const bcrypt = require('bcrypt');
Expand Down Expand Up @@ -102,11 +99,3 @@ export const updateUserGitcoinAnalysisScore = async (user: User) => {
user.passportScoreUpdateTimestamp = new Date();
await user.save();
};

export const getUserById = async (userId: number) => {
const foundedUser = await findUserById(userId);
if (foundedUser) {
return foundedUser;
}
throw new Error(`user not found with id ${userId}`);
};

0 comments on commit 73c0c68

Please sign in to comment.