Skip to content

Commit

Permalink
Merge pull request #94 from depromeet/dev
Browse files Browse the repository at this point in the history
공지사항, 탈퇴작업 추가 배포
  • Loading branch information
ImNM authored Jun 16, 2022
2 parents 1420ea4 + 92f23ea commit 1f8fe89
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/apis/letter/letter.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { BadRequestException, Injectable, Type } from '@nestjs/common';
import { ObjectId, Types } from 'mongoose';
import { CATEGORY_TYPE, FIND_ROOM_FILTER_TYPE } from 'src/common/consts/enum';
import {
CATEGORY_TYPE,
FIND_ROOM_FILTER_TYPE,
STATUS_TYPE,
} from 'src/common/consts/enum';
import { BlockedUserDto } from 'src/common/dtos/BlockedUserList.dto';
import { LetterRoomIdDto } from 'src/common/dtos/LetterRoomId.dto';
import { MongoId } from 'src/common/dtos/MongoId.dto';
Expand Down Expand Up @@ -52,6 +56,10 @@ export class LetterService {
throw new BadRequestException('수신자가 존재하지 않음');
}

if (receiverExist.status === STATUS_TYPE.SIGNOUT) {
throw new BadRequestException('탈퇴한 유저');
}

//TODO : 400 번대
// 보낼 수 없는 사용자 추가

Expand Down
12 changes: 12 additions & 0 deletions src/apis/users/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 4 additions & 0 deletions src/apis/users/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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),
Expand All @@ -29,6 +32,7 @@ import { UserService } from './user.service';
UserService,
ReportRepository,
LightningRepository,
OfficialNotiRepository,
],
exports: [UserService, ReportRepository, UserRepository],
})
Expand Down
7 changes: 7 additions & 0 deletions src/apis/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/auth/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
);
}
} else if (user.status === STATUS_TYPE.SIGNOUT) {
throw new UnauthorizedException('탈퇴한 유저');
throw new ForbiddenException('탈퇴한 유저');
}
return user;
} else {
Expand Down
71 changes: 71 additions & 0 deletions src/models/officialNoti.ts
Original file line number Diff line number Diff line change
@@ -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);
// 한달 간격 사라짐
1 change: 0 additions & 1 deletion src/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class User {
})
@Prop({
required: true,
unique: true,
})
@IsPhoneNumber('KR')
@IsNotEmpty()
Expand Down
24 changes: 24 additions & 0 deletions src/repositories/officialNoti.repository.ts
Original file line number Diff line number Diff line change
@@ -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<Alarm>,
) {}

async getOfficialNotis(): Promise<OfficialNoti[]> {
const notis = await this.officialNotiModel
.find()
.sort({ _id: -1 })
.lean<OfficialNoti[]>();
return notis;
}
}

0 comments on commit 1f8fe89

Please sign in to comment.