Skip to content

Commit

Permalink
ADD: get notifications (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
automerge-pingpong[bot] committed Oct 27, 2023
2 parents 7d3ae3e + 4c0dc11 commit 4784f70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions backend/code/src/profile/profile.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Param,
ParseFilePipe,
Post,
Query,
UploadedFile,
UseGuards,
UseInterceptors,
Expand All @@ -29,6 +30,7 @@ import {
ApiTags,
} from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { QueryOffsetDto } from 'src/friends/dto/query-ofsset-dto';

@ApiTags('profile')
@ApiCookieAuth('X-Acces-Token')
Expand Down Expand Up @@ -106,4 +108,13 @@ export class ProfileController {
getAvatar(@Param('id') recourseId: string) {
return this.profileService.getAvatar(recourseId);
}

@Get('notifications')
@UseGuards(AtGuard)
getNotifications(
@GetCurrentUser('userId') userId: string,
@Query() { offset, limit }: QueryOffsetDto,
) {
return this.profileService.getNotifications(userId, offset, limit);
}
}
16 changes: 15 additions & 1 deletion backend/code/src/profile/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { UsersService } from 'src/users/users.service';
import { ProfileDto } from './dto/profile.dto';
import { UpdateProfileDto } from './dto/update-profile.dto';
import { UploadApiResponse, v2 as cloudinary } from 'cloudinary';
import { PrismaService } from 'src/prisma/prisma.service';
import { Readable } from 'stream';

@Injectable()
export class ProfileService {
constructor(private usersService: UsersService) {}
constructor(
private usersService: UsersService,
private readonly prisma: PrismaService,
) {}

async getProfile(userId: string): Promise<ProfileDto> {
const user = await this.usersService.getUserById(userId);
Expand Down Expand Up @@ -98,4 +102,14 @@ export class ProfileService {
});
return result;
}

async getNotifications(userId: string, offset: number, limit: number) {
return await this.prisma.notification.findMany({
skip: offset,
take: limit,
where: {
recipientId: userId,
},
});
}
}

0 comments on commit 4784f70

Please sign in to comment.