From 0043e923d3619236e140d1e0a74aa113756f2beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Thu, 16 Jun 2022 19:04:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:rocket:=20feat(officialnoti)=20:=20?= =?UTF-8?q?=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/users/user.controller.ts | 12 ++++ src/apis/users/user.module.ts | 4 ++ src/apis/users/user.service.ts | 7 ++ src/models/officialNoti.ts | 71 +++++++++++++++++++++ src/repositories/officialNoti.repository.ts | 21 ++++++ 5 files changed, 115 insertions(+) create mode 100644 src/models/officialNoti.ts create mode 100644 src/repositories/officialNoti.repository.ts diff --git a/src/apis/users/user.controller.ts b/src/apis/users/user.controller.ts index 7107c0d..6d92dbf 100644 --- a/src/apis/users/user.controller.ts +++ b/src/apis/users/user.controller.ts @@ -31,6 +31,7 @@ import { SendLightningSuccessDtoResDto } from './dto/sendLigningSuccessDto.res.d import { AlarmService } from '../alarm/alarm.service'; import { FCMUpdateDto } from './dto/fcmUpdate.dto'; import { UserProfileClickDto } from './dto/UserProfileClick.dto'; +import { OfficialNoti } from 'src/models/officialNoti'; @ApiTags('user') @Controller('user') @@ -111,6 +112,17 @@ export class UserController { return this.userService.getMyBlockUser(user.userIdDto); } + @ApiOperation({ summary: '공지사항 불러옴' }) + @Get('/officialNoti') + @ApiResponse({ + status: 200, + description: '요청 성공시', + type: [OfficialNoti], + }) + getOfficialNoti() { + return this.userService.getOfficialNoti(); + } + // @ApiOperation({ summary: '상대방 유저정보를 가져온다.' }) @ApiResponse({ diff --git a/src/apis/users/user.module.ts b/src/apis/users/user.module.ts index 6ac26e0..2d71cca 100644 --- a/src/apis/users/user.module.ts +++ b/src/apis/users/user.module.ts @@ -2,9 +2,11 @@ import { forwardRef, Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; import { AuthModule } from 'src/auth/auth.module'; import { Lightning, LightningSchema } from 'src/models/lightning.model'; +import { OfficialNoti, OfficialNotiSchema } from 'src/models/officialNoti'; import { Report, ReportSchema } from 'src/models/report.model'; import { User, UserSchema } from 'src/models/user.model'; import { LightningRepository } from 'src/repositories/lightning.repository'; +import { OfficialNotiRepository } from 'src/repositories/officialNoti.repository'; import { ReportRepository } from 'src/repositories/report.repository'; import { UserRepository } from 'src/repositories/user.repository'; import { AlarmModule } from '../alarm/alarm.module'; @@ -18,6 +20,7 @@ import { UserService } from './user.service'; { name: User.name, schema: UserSchema }, { name: Report.name, schema: ReportSchema }, { name: Lightning.name, schema: LightningSchema }, + { name: OfficialNoti.name, schema: OfficialNotiSchema }, ]), forwardRef(() => AuthModule), forwardRef(() => AlarmModule), @@ -29,6 +32,7 @@ import { UserService } from './user.service'; UserService, ReportRepository, LightningRepository, + OfficialNotiRepository, ], exports: [UserService, ReportRepository, UserRepository], }) diff --git a/src/apis/users/user.service.ts b/src/apis/users/user.service.ts index 32ff1cd..fdd2ff1 100644 --- a/src/apis/users/user.service.ts +++ b/src/apis/users/user.service.ts @@ -30,6 +30,8 @@ import { FCMUpdateDto } from './dto/fcmUpdate.dto'; import { RoomsService } from '../rooms/rooms.service'; import { RoomIdDto } from 'src/common/dtos/RoomId.dto'; import { UserProfileClickDto } from './dto/UserProfileClick.dto'; +import { OfficialNotiRepository } from 'src/repositories/officialNoti.repository'; +import { OfficialNoti } from 'src/models/officialNoti'; @Injectable() export class UserService { @@ -41,6 +43,7 @@ export class UserService { private lightnignRepository: LightningRepository, private alarmService: AlarmService, private roomService: RoomsService, + private OfficialNotiRepository: OfficialNotiRepository, ) {} private checkBlocked(userIdDto: UserIdDto, blockedUserDto: BlockedUserDto) { @@ -91,6 +94,10 @@ export class UserService { await this.userRepository.signOutUser(user.userIdDto, user); return user; } + @returnValueToDto(OfficialNoti) + async getOfficialNoti() { + return await this.OfficialNotiRepository.getOfficialNotis(); + } @returnValueToDto(User) async updateProfile( diff --git a/src/models/officialNoti.ts b/src/models/officialNoti.ts new file mode 100644 index 0000000..29858f5 --- /dev/null +++ b/src/models/officialNoti.ts @@ -0,0 +1,71 @@ +import { IsBoolean } from 'class-validator'; +import { Prop, Schema, SchemaFactory, SchemaOptions } from '@nestjs/mongoose'; +import { Types } from 'mongoose'; + +import { TransformObjectIdToString } from 'src/common/decorators/Expose.decorator'; +import { Expose, Transform, Type } from 'class-transformer'; +import { ApiProperty } from '@nestjs/swagger'; +import { toKRTimeZone } from 'src/common/funcs/toKRTimezone'; + +const options: SchemaOptions = { + collection: 'officialNoti', + timestamps: true, +}; + +@Schema(options) +export class OfficialNoti { + @ApiProperty({ + description: '개별 공지사항의 고유 아이디', + type: String, + }) + // 시리얼 라이제이션 할때 사용 + @TransformObjectIdToString({ toClassOnly: true }) + @Type(() => Types.ObjectId) + @Expose() + _id: Types.ObjectId; + + @ApiProperty({ + type: String, + description: '작성자', + }) + @Prop({ + default: '', + type: String, + }) + @Expose() + nickname: string; + + @ApiProperty({ + type: String, + description: '글내용', + }) + @Prop({ + type: String, + }) + @Expose() + content: string; + + @ApiProperty({ + type: String, + nullable: true, + default: null, + description: '뎁스 넘어갈수있는 링크', + }) + @Prop({ + default: null, + type: String, + }) + @Expose() + link: string; + + @ApiProperty({ + type: String, + description: '한국시간으로 보정된 시간값', + }) + @Transform(({ value }) => toKRTimeZone(value), { toClassOnly: true }) + @Expose() + createdAt: Date; +} + +export const OfficialNotiSchema = SchemaFactory.createForClass(OfficialNoti); +// 한달 간격 사라짐 diff --git a/src/repositories/officialNoti.repository.ts b/src/repositories/officialNoti.repository.ts new file mode 100644 index 0000000..29584fb --- /dev/null +++ b/src/repositories/officialNoti.repository.ts @@ -0,0 +1,21 @@ +import { InjectModel } from '@nestjs/mongoose'; +import { Injectable } from '@nestjs/common'; +import { Model } from 'mongoose'; + +import { Alarm } from 'src/models/alarm.model'; +import { SaveAlarmDto } from 'src/apis/alarm/dto/saveAlarm.dto'; + +import { OfficialNoti } from 'src/models/officialNoti'; + +@Injectable() +export class OfficialNotiRepository { + constructor( + @InjectModel(OfficialNoti.name) + private readonly officialNotiModel: Model, + ) {} + + async getOfficialNotis(): Promise { + const notis = await this.officialNotiModel.find().lean(); + return notis; + } +} From 6d5f62f53aa9bf7643496585029f82d1f5cc934a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Thu, 16 Jun 2022 19:06:09 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:hammer:=20fix(noti)=20:=20=EA=B3=B5?= =?UTF-8?q?=EC=A7=80=EC=82=AC=ED=95=AD=20=EC=A0=95=EB=A0=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/repositories/officialNoti.repository.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/repositories/officialNoti.repository.ts b/src/repositories/officialNoti.repository.ts index 29584fb..eccfdfd 100644 --- a/src/repositories/officialNoti.repository.ts +++ b/src/repositories/officialNoti.repository.ts @@ -15,7 +15,10 @@ export class OfficialNotiRepository { ) {} async getOfficialNotis(): Promise { - const notis = await this.officialNotiModel.find().lean(); + const notis = await this.officialNotiModel + .find() + .sort({ _id: -1 }) + .lean(); return notis; } }