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

[EN-7483] Referer - Dashboard - Allow to filter profiles by refererId #236

Merged
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
15 changes: 15 additions & 0 deletions src/user-profiles/user-profiles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ export class UserProfilesController {
});
}

@UserPermissions(Permissions.REFERER)
@Get('refered')
async findReferedCandidates(
@UserPayload('id', new ParseUUIDPipe()) userId: string,
@Query('limit', new ParseIntPipe())
limit: number,
@Query('offset', new ParseIntPipe())
offset: number
) {
return this.userProfilesService.findAllReferedCandidates(userId, {
offset,
limit,
});
}

@Self('params.userId')
@UseGuards(SelfGuard)
@UseInterceptors(FileInterceptor('profileImage', { dest: 'uploads/' }))
Expand Down
49 changes: 49 additions & 0 deletions src/user-profiles/user-profiles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,55 @@ export class UserProfilesService {
);
}

async findAllReferedCandidates(
userId: string,
query: {
offset: number;
limit: number;
}
): Promise<PublicProfile[]> {
const { offset, limit } = query;

const profiles = await this.userProfileModel.findAll({
attributes: UserProfilesAttributes,
order: sequelize.literal('"user.createdAt" DESC'),
include: [
...getUserProfileInclude(),
{
model: User,
as: 'user',
attributes: UserProfilesUserAttributes,
where: {
refererId: userId,
},
},
],
limit,
offset,
});

return Promise.all(
profiles.map(async (profile): Promise<PublicProfile> => {
const lastSentMessage = await this.getLastContact(
userId,
profile.user.id
);
const lastReceivedMessage = await this.getLastContact(
profile.user.id,
userId
);

const { user, ...restProfile }: UserProfile = profile.toJSON();
return {
...user,
...restProfile,
lastSentMessage: lastSentMessage?.createdAt || null,
lastReceivedMessage: lastReceivedMessage?.createdAt || null,
};
Comment on lines +241 to +257
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas sur que ce soit opti si y a beaucoup de referredUsers mais on verra en temps voulu.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, j'ai simplement utilisé la même logique de construction que dans le réseau d'entraide mais c'est clairement perfectible.

})
);
}

async findRecommendationsByUserId(
userId: string
): Promise<UserProfileRecommendation[]> {
Expand Down