Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -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
Expand Down
17 changes: 2 additions & 15 deletions src/entities/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const publicSelectionFields = [
'user.ownedCausesCount',
'user.totalCausesRaised',
'user.totalCausesDistributed',
'user.causesTotalEarned',
'user.causesTotalEarnedUsdValue',
];

export enum UserRole {
Expand Down Expand Up @@ -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;
}
81 changes: 0 additions & 81 deletions src/resolvers/userResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
SEED_DATA,
} from '../../test/testUtils';
import {
allUsersBasicDataQuery,
refreshUserScores,
updateUser,
userByAddress,
Expand All @@ -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);
Expand Down Expand Up @@ -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 () => {
Expand Down
37 changes: 1 addition & 36 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import {
Arg,
Ctx,
Field,
Int,
Mutation,
ObjectType,
Query,
Resolver,
} 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';
Expand Down Expand Up @@ -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<User>) {
Expand Down Expand Up @@ -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<AllUsersPublicData> {
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<boolean> {
return isValidEmail(email);
Expand Down
15 changes: 0 additions & 15 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading