Skip to content

Commit

Permalink
fix projectCount query
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Sep 19, 2023
1 parent 5fec931 commit 28c1299
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/repositories/userRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const isFirstTimeDonor = async (userId: number): Promise<boolean> => {
export const findUserByWalletAddress = async (
walletAddress: string,
includeSensitiveFields = true,
ownerUserId?: number,
): Promise<User | null> => {
const query = User.createQueryBuilder('user').where(
`LOWER("walletAddress") = :walletAddress`,
Expand All @@ -52,22 +51,22 @@ export const findUserByWalletAddress = async (

user.projectsCount = await fetchUserProjectsCount(
user!.id,
Number(user?.id) === Number(ownerUserId),
includeSensitiveFields,
);

return user;
};

export const fetchUserProjectsCount = async (
userId: number,
ownerViewing: boolean,
includeSensitiveFields: boolean,
) => {
const projectsCount = Project.createQueryBuilder('project').where(
'project."adminUserId" = :id',
{ id: userId },
);

if (!ownerViewing) {
if (!includeSensitiveFields) {
projectsCount.andWhere(
`project.statusId = ${ProjStatus.active} AND project.reviewStatus = :reviewStatus`,
{ reviewStatus: ReviewStatus.Listed },
Expand Down
2 changes: 0 additions & 2 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class UserResolver {
const foundUser = await findUserByWalletAddress(
address,
includeSensitiveFields,
user?.userId,
);
return {
isSignedIn: Boolean(user),
Expand All @@ -84,7 +83,6 @@ export class UserResolver {
const foundUser = await findUserByWalletAddress(
address,
includeSensitiveFields,
user?.userId,
);

if (!foundUser) return;
Expand Down

0 comments on commit 28c1299

Please sign in to comment.