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

Feat/user sitemap list #1887

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions src/entities/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,18 @@ export class User extends BaseEntity {
return `givethId-${this.id}`;
}
}

@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;
}
37 changes: 36 additions & 1 deletion src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import {
Arg,
Ctx,
Field,
Int,
Mutation,
ObjectType,
Query,
Resolver,
} from 'type-graphql';
import { Repository } from 'typeorm';

import { User } from '../entities/user';
import { User, UserPublicData } from '../entities/user';
import { AccountVerificationInput } from './types/accountVerificationInput';
import { ApolloContext } from '../types/ApolloContext';
import { i18n, translationErrorMessagesKeys } from '../utils/errorMessages';
Expand Down Expand Up @@ -43,6 +44,15 @@ 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 @@ -422,4 +432,29 @@ 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> {
kkatusic marked this conversation as resolved.
Show resolved Hide resolved
const query = this.userRepository
.createQueryBuilder('user')
.select([
'user.firstName',
'user.lastName',
'user.name',
'user.walletAddress',
])
.skip(skip)
.take(limit);
kkatusic marked this conversation as resolved.
Show resolved Hide resolved

// Execute the query and fetch results
const [users, totalCount] = await query.getManyAndCount();

return {
users,
totalCount,
};
}
kkatusic marked this conversation as resolved.
Show resolved Hide resolved
}
Loading