diff --git a/src/entities/project.ts b/src/entities/project.ts index ff5155eae..3d2e853bf 100644 --- a/src/entities/project.ts +++ b/src/entities/project.ts @@ -467,6 +467,7 @@ export class Project extends BaseEntity { // causeProjects?: CauseProject[]; @Field(_type => [CauseProject], { nullable: true }) + @OneToMany(_type => CauseProject, causeProject => causeProject.project) causeProjects?: CauseProject[]; @Field(_type => [Project], { nullable: true }) @@ -834,6 +835,7 @@ export class Cause extends Project { projectType: string = 'cause'; @Field(_type => [CauseProject], { nullable: true }) + @OneToMany(_type => CauseProject, causeProject => causeProject.cause) causeProjects?: CauseProject[]; // Internal method for loading cause projects with filtering diff --git a/src/entities/user.ts b/src/entities/user.ts index b7fd85a81..fe0d6ae99 100644 --- a/src/entities/user.ts +++ b/src/entities/user.ts @@ -38,6 +38,8 @@ export const publicSelectionFields = [ 'user.ownedCausesCount', 'user.totalCausesRaised', 'user.totalCausesDistributed', + 'user.causesTotalEarned', + 'user.causesTotalEarnedUsdValue', ]; export enum UserRole { @@ -286,18 +288,3 @@ export class User extends BaseEntity { @Column({ type: 'float', default: 0 }) causesTotalEarnedUsdValue: number; } - -@ObjectType() -export class UserPublicData extends BaseEntity { - @Field(_type => String, { nullable: true }) - firstName?: string; - - @Field(_type => String, { nullable: true }) - lastName?: string; - - @Field(_type => String, { nullable: true }) - name?: string; - - @Field(_type => String, { nullable: true }) - walletAddress?: string; -} diff --git a/src/resolvers/userResolver.test.ts b/src/resolvers/userResolver.test.ts index 53ce3c32a..efd643014 100644 --- a/src/resolvers/userResolver.test.ts +++ b/src/resolvers/userResolver.test.ts @@ -17,7 +17,6 @@ import { SEED_DATA, } from '../../test/testUtils'; import { - allUsersBasicDataQuery, refreshUserScores, updateUser, userByAddress, @@ -36,7 +35,6 @@ describe('updateUser() test cases', updateUserTestCases); describe('userByAddress() test cases', userByAddressTestCases); describe('refreshUserScores() test cases', refreshUserScoresTestCases); describe('userEmailVerification() test cases', userEmailVerification); -describe('allUsersBasicData() test cases', allUsersBasicData); describe('isValidEmail() test cases', isValidEmailTestCases); // TODO I think we can delete addUserVerification query // describe('addUserVerification() test cases', addUserVerificationTestCases); @@ -1180,85 +1178,6 @@ function userEmailVerification() { }); } -function allUsersBasicData() { - describe('allUsersBasicData Test Cases', () => { - it('should return the default number of users when no limit or skip is provided', async () => { - // Create sample users - await saveUserDirectlyToDb(generateRandomEtheriumAddress()); - await saveUserDirectlyToDb(generateRandomEtheriumAddress()); - - // Execute the query - const result = await axios.post(graphqlUrl, { - query: allUsersBasicDataQuery, - }); - - // Assertions - const { users, totalCount } = result.data.data.allUsersBasicData; - assert.isArray(users, 'Users should be an array'); - assert.isTrue(users.length > 0, 'Should return at least one user'); - assert.isNumber(totalCount, 'Total count should be a number'); - }); - - it('should return a limited number of users when a limit is specified', async () => { - // Create sample users - await saveUserDirectlyToDb(generateRandomEtheriumAddress()); - await saveUserDirectlyToDb(generateRandomEtheriumAddress()); - - // Execute the query with a limit - const result = await axios.post(graphqlUrl, { - query: allUsersBasicDataQuery, - variables: { limit: 1 }, - }); - - // Assertions - const { users } = result.data.data.allUsersBasicData; - assert.isArray(users, 'Users should be an array'); - assert.equal(users.length, 1, 'Should return only one user'); - }); - - it('should skip the specified number of users', async () => { - await saveUserDirectlyToDb(generateRandomEtheriumAddress()); - await saveUserDirectlyToDb(generateRandomEtheriumAddress()); - - // Execute the query with skip - const result = await axios.post(graphqlUrl, { - query: allUsersBasicDataQuery, - variables: { skip: 1, limit: 1 }, - }); - - // Assertions - const { users } = result.data.data.allUsersBasicData; - assert.isArray(users, 'Users should be an array'); - assert.equal(users.length, 1, 'Should return only one user'); - }); - - it('should not include sensitive fields like email in the response', async () => { - // Execute the query - const result = await axios.post(graphqlUrl, { - query: allUsersBasicDataQuery, - variables: { skip: 0, limit: 10 }, - }); - - // Assertions - const { users } = result.data.data.allUsersBasicData; - assert.isArray(users, 'Users should be an array'); - assert.isTrue(users.length > 0, 'Should return at least one user'); - - // If any users exist, ensure email and password is not part of the response - if (users.length > 0) { - assert.isUndefined( - users[0].email, - 'Email should not be included in the response', - ); - assert.isUndefined( - users[0].password, - 'Password should not be included in the response', - ); - } - }); - }); -} - function isValidEmailTestCases() { describe('isValidEmail() test cases', () => { it('should return true for valid email', async () => { diff --git a/src/resolvers/userResolver.ts b/src/resolvers/userResolver.ts index 94311de00..afe6b8af9 100644 --- a/src/resolvers/userResolver.ts +++ b/src/resolvers/userResolver.ts @@ -2,7 +2,6 @@ import { Arg, Ctx, Field, - Int, Mutation, ObjectType, Query, @@ -10,7 +9,7 @@ import { } from 'type-graphql'; import { Repository } from 'typeorm'; -import { User, UserPublicData } from '../entities/user'; +import { User } from '../entities/user'; import { AccountVerificationInput } from './types/accountVerificationInput'; import { ApolloContext } from '../types/ApolloContext'; import { i18n, translationErrorMessagesKeys } from '../utils/errorMessages'; @@ -45,15 +44,6 @@ class UserRelatedAddressResponse { hasDonated: boolean; } -@ObjectType() -class AllUsersPublicData { - @Field(_type => [UserPublicData]) - users: UserPublicData[]; - - @Field(_type => Number) - totalCount: number; -} - @Resolver(_of => User) export class UserResolver { constructor(private readonly userRepository: Repository) { @@ -438,31 +428,6 @@ export class UserResolver { return 'VERIFICATION_SUCCESS'; } - @Query(_returns => AllUsersPublicData) - async allUsersBasicData( - @Arg('limit', _type => Int, { nullable: true }) limit: number = 50, - @Arg('skip', _type => Int, { nullable: true }) skip: number = 0, - ): Promise { - const query = this.userRepository - .createQueryBuilder('user') - .select([ - 'user.firstName', - 'user.lastName', - 'user.name', - 'user.walletAddress', - ]) - .skip(skip) - .take(limit); - - // Execute the query and fetch results - const [users, totalCount] = await query.getManyAndCount(); - - return { - users, - totalCount, - }; - } - @Query(_returns => Boolean) async validateEmail(@Arg('email') email: string): Promise { return isValidEmail(email); diff --git a/test/graphqlQueries.ts b/test/graphqlQueries.ts index 84e87a6b8..6cff1bf09 100644 --- a/test/graphqlQueries.ts +++ b/test/graphqlQueries.ts @@ -2749,21 +2749,6 @@ export const fetchRecurringDonationsByDateQuery = ` } `; -// GraphQL query for fetching all users' basic data -export const allUsersBasicDataQuery = ` - query ($limit: Int, $skip: Int) { - allUsersBasicData(limit: $limit, skip: $skip) { - users { - firstName - lastName - name - walletAddress - } - totalCount - } - } -`; - export const getLastSitemapUrlQuery = ` query { getLastSitemap {