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 5fdc88b..452452f 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); 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..eccfdfd --- /dev/null +++ b/src/repositories/officialNoti.repository.ts @@ -0,0 +1,24 @@ +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() + .sort({ _id: -1 }) + .lean(); + return notis; + } +}