Skip to content

Commit

Permalink
0.2.1 #54
Browse files Browse the repository at this point in the history
0.2.1
  • Loading branch information
raymondanythings authored Dec 29, 2023
2 parents 2efbb74 + 8963f96 commit 2ba924d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shinnyang",
"version": "0.2.0",
"version": "0.2.1",
"description": "",
"author": {
"name": "Medici",
Expand Down
11 changes: 10 additions & 1 deletion src/mails/dtos/mails.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export class LetterFromMailResponseDTO {
@IsUUID('all')
id: string;

@ApiProperty()
@IsUUID('all')
mailId: string;

@ApiProperty()
@IsDate()
createdAt: Date;
Expand Down Expand Up @@ -44,9 +48,14 @@ export class LetterFromMailResponseDTO {
isRespond: boolean;

constructor(
letter: Mail['letter'] & { replyLetterId: string | null; isRead: boolean },
letter: Mail['letter'] & {
replyLetterId: string | null;
isRead: boolean;
mailId: string;
},
) {
this.id = letter.id;
this.mailId = letter.mailId;
this.createdAt = letter.createdAt;
this.updatedAt = letter.updatedAt;
this.senderId = letter.senderId;
Expand Down
21 changes: 20 additions & 1 deletion src/mails/mails.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { AccessGuard } from 'src/auth/guards/acess.guard';
import { MailsService } from './mails.service';
import { Body, Controller, Get, Post, Put, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
Get,
Param,
ParseUUIDPipe,
Post,
Put,
UseGuards,
} from '@nestjs/common';
import { AuthUser } from 'src/auth/decorators/auth-user.decorator';
import {
ApiBearerAuth,
Expand Down Expand Up @@ -29,6 +38,16 @@ export class MailsController {
async getMyMails(@AuthUser() { id }) {
return await this.mailsService.getMyMails(id);
}
@Get(':mailId')
@ApiOkResponse({
type: [LetterFromMailResponseDTO],
})
async getMyMailById(
@AuthUser() { id },
@Param('mailId', ParseUUIDPipe) mailId: string,
) {
return await this.mailsService.getMyMailById(id, mailId);
}

@ApiOperation({
summary: '편지 보관하기',
Expand Down
22 changes: 22 additions & 0 deletions src/mails/mails.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ import { Letter } from 'src/letters/entities/letter.entity';
export class MailsService {
constructor(@InjectDataSource() private readonly dataSource: DataSource) {}

async getMyMailById(userId: string, mailId: string) {
const mail = await this.dataSource.getRepository(Mail).findOne({
where: {
id: mailId,
userId,
},
relations: {
letter: true,
},
});
if (!mail) {
throw new BadRequestException();
}
return new LetterFromMailResponseDTO({
...mail.letter,
mailId,
isRead: mail.isRead,
replyLetterId: mail.replyLetterId,
});
}

async getMyMails(userId: string) {
const myMails = await this.dataSource.getRepository(Mail).find({
where: {
Expand All @@ -27,6 +48,7 @@ export class MailsService {
(mail) =>
new LetterFromMailResponseDTO({
...mail.letter,
mailId: mail.id,
isRead: mail.isRead,
replyLetterId: mail.replyLetterId,
}),
Expand Down

0 comments on commit 2ba924d

Please sign in to comment.