Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:Giveth/impact-graph into add_bas…
Browse files Browse the repository at this point in the history
…e_chain
  • Loading branch information
Meriem-B committed May 27, 2024
2 parents 8c24411 + bba8206 commit 34bc965
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/resolvers/projectResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ describe(
'addRecipientAddressToProject test cases --->',
addRecipientAddressToProjectTestCases,
);

describe('projectsByUserId test cases --->', projectsByUserIdTestCases);

describe('deactivateProject test cases --->', deactivateProjectTestCases);
Expand Down
74 changes: 58 additions & 16 deletions src/resolvers/projectResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,27 +827,65 @@ export class ProjectResolver {
@Arg('connectedWalletUserId', _type => Int, { nullable: true })
connectedWalletUserId: number,
@Ctx() { req: { user } }: ApolloContext,
@Info() info: any,
) {
const fields = graphqlFields(info);

let query = this.projectRepository
.createQueryBuilder('project')
.where(`project.id=:id`, {
id,
})
.leftJoinAndSelect('project.status', 'status')
.leftJoinAndSelect(
'project.categories',
'categories',
'categories.isActive = :isActive',
{ isActive: true },
)
.leftJoinAndSelect('categories.mainCategory', 'mainCategory')
.leftJoinAndSelect('project.addresses', 'addresses')
.leftJoinAndSelect('project.socialMedia', 'socialMedia')
.leftJoinAndSelect('project.anchorContracts', 'anchor_contract_address')
.leftJoinAndSelect('project.organization', 'organization')
.leftJoin('project.adminUser', 'user')
.addSelect(publicSelectionFields); // aliased selection
query = ProjectResolver.addUserReaction(query, connectedWalletUserId, user);
.leftJoinAndSelect('project.status', 'status');

if (fields.categories) {
query = query
.leftJoinAndSelect(
'project.categories',
'categories',
'categories.isActive = :isActive',
{ isActive: true },
)
.leftJoinAndSelect('categories.mainCategory', 'mainCategory');
}
if (fields.organization) {
query = query.leftJoinAndSelect('project.organization', 'organization');
}
if (fields.addresses) {
query = query.leftJoinAndSelect('project.addresses', 'addresses');
}
if (fields.socialMedia) {
query = query.leftJoinAndSelect('project.socialMedia', 'socialMedia');
}
if (fields.anchorContracts) {
query = query.leftJoinAndSelect(
'project.anchorContracts',
'anchor_contract_address',
);
}
if (fields.adminUser) {
const adminUserFields = Object.keys(fields.adminUser).map(
field => `user.${field}`,
);
const filterByPublicFields = publicSelectionFields.filter(field =>
adminUserFields.includes(field),
);
query = query
.leftJoin('project.adminUser', 'user')
.addSelect(
filterByPublicFields.length > 0
? filterByPublicFields
: publicSelectionFields,
); // aliased selection
}
if (fields.reaction) {
query = ProjectResolver.addUserReaction(
query,
connectedWalletUserId,
user,
);
}

const project = await query.getOne();

canUserVisitProject(project, user?.userId);
Expand Down Expand Up @@ -966,7 +1004,11 @@ export class ProjectResolver {
);
query = query
.leftJoin('project.adminUser', 'user')
.addSelect(filterByPublicFields); // aliased selection
.addSelect(
filterByPublicFields.length > 0
? filterByPublicFields
: publicSelectionFields,
); // aliased selection
}
if (fields.reaction) {
query = ProjectResolver.addUserReaction(
Expand Down

0 comments on commit 34bc965

Please sign in to comment.