Skip to content

Commit

Permalink
fix: filter notification list
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed Jan 21, 2024
1 parent 8c93bdb commit 3877354
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/blurting/blurting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
BlurtingQuestionEntity,
LikeEntity,
UserEntity,
NotificationEntity,
} from 'src/entities';
import { UserService } from 'src/user/user.service';
import { In, Repository } from 'typeorm';
Expand All @@ -41,6 +42,8 @@ export class BlurtingService {
private readonly questionRepository: Repository<BlurtingQuestionEntity>,
@InjectRepository(BlurtingAnswerEntity)
private readonly answerRepository: Repository<BlurtingAnswerEntity>,
@InjectRepository(NotificationEntity)
private readonly notificationRepository: Repository<NotificationEntity>,
@Inject(CACHE_MANAGER) private cacheManager: Cache,
@InjectQueue('blurtingQuestions') private readonly queue: Queue,
private readonly fcmService: FcmService,
Expand All @@ -61,9 +64,14 @@ export class BlurtingService {
await this.userService.updateUser(id, 'group', group);
await this.fcmService.sendPush(
id,
'그룹 매칭이 완료되었습니다.',
'그룹 매칭이 완료되었습니다!',
'blurting',
);
const newEntity = this.notificationRepository.create({
user: { id: id },
body: '그룹 매칭이 완료되었습니다!',
});
await this.notificationRepository.insert(newEntity);
}),
);

Expand Down Expand Up @@ -499,6 +507,11 @@ export class BlurtingService {
`${user.userNickname}님이 당신에게 화살표를 보냈습니다!`,
'blurting',
);
const newEntity = this.notificationRepository.create({
user: { id: userId },
body: `${user.userNickname}님이 당신에게 화살표를 보냈습니다!`,
});
await this.notificationRepository.insert(newEntity);
}

async getArrows(userId: number): Promise<ArrowInfoResponseDto> {
Expand Down
12 changes: 11 additions & 1 deletion src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose/dist/common';
import { Room, Chatting, SocketUser } from './models';
import { Model } from 'mongoose';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { UnauthorizedException } from '@nestjs/common/exceptions';
import { Socket } from 'socket.io';
import * as jwt from 'jsonwebtoken';
Expand All @@ -13,6 +15,7 @@ import {
} from 'src/dtos/chat.dto';
import { UserService } from 'src/user/user.service';
import { FcmService } from 'src/firebase/fcm.service';
import { NotificationEntity } from 'src/entities';

@Injectable()
export class ChatService {
Expand All @@ -22,6 +25,8 @@ export class ChatService {
private readonly roomModel: Model<Room>,
@InjectModel(SocketUser.name)
private readonly socketUserModel: Model<SocketUser>,
@InjectRepository(NotificationEntity)
private readonly notificationRepository: Repository<NotificationEntity>,
private readonly userService: UserService,
private readonly fcmService: FcmService,
) {}
Expand Down Expand Up @@ -352,8 +357,13 @@ export class ChatService {
return room.users[index].blur;
}

pushCreateRoom(userId: number) {
async pushCreateRoom(userId: number) {
this.fcmService.sendPush(userId, '지금 귓속말을 시작해보세요!', 'whisper');
const newEntity = this.notificationRepository.create({
user: { id: userId },
body: '새로운 귓속말이 시작되었습니다!',
});
await this.notificationRepository.insert(newEntity);
}

async pushNewChat(roomId: string, userId: number) {
Expand Down
5 changes: 0 additions & 5 deletions src/firebase/fcm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ export class FcmService {
this.disableNotification(userId);
}
});
const newEntity = this.notificationRepository.create({
user: { id: userId },
body: body,
});
await this.notificationRepository.insert(newEntity);
}
} catch (error) {
return error;
Expand Down

0 comments on commit 3877354

Please sign in to comment.