Skip to content

Commit

Permalink
Merge pull request #31 from PBTP/feature/profile
Browse files Browse the repository at this point in the history
DMVM-174 feat: Modify update profile feature
  • Loading branch information
emibgo2 authored Sep 11, 2024
2 parents 58230c6 + e050f3a commit f2fcfde
Show file tree
Hide file tree
Showing 37 changed files with 696 additions and 399 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@types/socket.io": "^3.0.2",
"aws-sdk": "^2.1623.0",
"axios": "^1.7.2",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"ioredis": "^5.4.1",
Expand All @@ -54,6 +55,7 @@
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
Expand Down
21 changes: 11 additions & 10 deletions src/auth/application/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable } from '@nestjs/common';
import { JwtService, JwtSignOptions } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { CacheService } from '../../common/cache/cache.service';
import { UnauthorizedException } from '@nestjs/common/exceptions';
import { UserService } from './user.service';
import { UserDto } from '../presentation/user.dto';
import { AuthDto } from '../presentation/auth.dto';
import { Injectable } from "@nestjs/common";
import { JwtService, JwtSignOptions } from "@nestjs/jwt";
import { ConfigService } from "@nestjs/config";
import { CacheService } from "../../common/cache/cache.service";
import { UnauthorizedException } from "@nestjs/common/exceptions";
import { UserService } from "./user.service";
import { UserDto } from "../presentation/user.dto";
import { AuthDto } from "../presentation/auth.dto";

@Injectable()
export class AuthService {
Expand Down Expand Up @@ -62,7 +62,7 @@ export class AuthService {
);

await this.userService.update({
...user,
userId: user.userId,
userType: user.userType,
refreshToken: refreshToken,
});
Expand Down Expand Up @@ -110,7 +110,8 @@ export class AuthService {
await this.saveAccessToken(user, accessToken);

await this.userService.update({
...user,
userId: user.userId,
userType: user.userType,
refreshToken: refreshToken,
});

Expand Down
9 changes: 9 additions & 0 deletions src/auth/application/security.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { SecurityService } from './security.service';

@Global()
@Module({
providers: [SecurityService],
exports: [SecurityService],
})
export class SecurityModule {}
43 changes: 43 additions & 0 deletions src/auth/application/security.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Injectable } from "@nestjs/common";
import * as crypto from "crypto";
import { ConfigService } from "@nestjs/config";

@Injectable()
export class SecurityService {
private readonly algorithm: string;
private readonly secretKey: string;
private iv = crypto.randomBytes(16); // 초기화 벡터(IV)

constructor(private readonly configService: ConfigService) {
this.algorithm = this.configService.get('security/crypto/algorithm');
this.secretKey = this.configService.get('security/crypto/key');
}

encrypt(text: string): string {
if (!text) return null;

const cipher = crypto.createCipheriv(
this.algorithm,
this.secretKey,
this.iv,
);
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
return `${this.iv.toString('hex')}:${encrypted.toString('hex')}`; // IV와 암호화된 데이터를 함께 반환
}

decrypt(hash: string): string {
if (!hash) return null;

const [iv, encryptedText] = hash.split(':');
const decipher = crypto.createDecipheriv(
this.algorithm,
this.secretKey,
Buffer.from(iv, 'hex'),
);
const decrypted = Buffer.concat([
decipher.update(Buffer.from(encryptedText, 'hex')),
decipher.final(),
]);
return decrypted.toString();
}
}
14 changes: 7 additions & 7 deletions src/auth/decorator/auth.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
ForbiddenException,
HttpCode,
HttpStatus,
UseGuards,
} from '@nestjs/common';
import { Customer } from '../../schemas/customers.entity';
import { ApiBearerAuth, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { Business } from '../../schemas/business.entity';
import { Driver } from '../../schemas/drivers.entity';
UseGuards
} from "@nestjs/common";
import { Customer } from "../../schemas/customer.entity";
import { ApiBearerAuth, ApiUnauthorizedResponse } from "@nestjs/swagger";
import { AuthGuard } from "@nestjs/passport";
import { Business } from "../../schemas/business.entity";
import { Driver } from "../../schemas/drivers.entity";

export const CurrentCustomer = createParamDecorator(
(data: unknown, context: ExecutionContext) => {
Expand Down
6 changes: 3 additions & 3 deletions src/auth/presentation/auth.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsOptional } from 'class-validator';
import { UserDto } from './user.dto';
import { ApiProperty } from "@nestjs/swagger";
import { IsOptional } from "class-validator";
import { UserDto } from "./user.dto";

export class AuthDto extends UserDto {
@ApiProperty({
Expand Down
16 changes: 8 additions & 8 deletions src/chat/application/business-chat.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { BusinessChatRoom } from '../../schemas/business-chat-room.entity';
import { IChatService } from './chat.interface';
import { UserDto } from '../../auth/presentation/user.dto';
import { plainToInstance as toDto } from 'class-transformer';
import { ChatRoomDto } from '../presentation/chat.dto';
import { Injectable, Logger } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { BusinessChatRoom } from "../../schemas/business-chat-room.entity";
import { IChatService } from "./chat.interface";
import { UserDto } from "../../auth/presentation/user.dto";
import { ChatRoomDto } from "../presentation/chat.dto";
import { toDto } from "../../common/function/util.function";

@Injectable()
export class BusinessChatService implements IChatService {
Expand Down
36 changes: 18 additions & 18 deletions src/chat/application/chat.service.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { ForbiddenException, Injectable, Logger } from '@nestjs/common';
import { Repository } from 'typeorm';
import { ChatRoom } from '../../schemas/chat-room.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { ChatMessage } from '../../schemas/chat-message.entity';
import { CustomerChatService } from './customer-chat.service';
import { DriverChatService } from './driver-chat.service';
import { BusinessChatService } from './business-chat.service';
import { ChatMessageDto, ChatRoomDto } from '../presentation/chat.dto';
import { UserDto, UserType } from '../../auth/presentation/user.dto';
import { UserSocket } from '../presentation/chat.gateway';
import { CacheService } from '../../common/cache/cache.service';
import { Customer } from '../../schemas/customers.entity';
import { Driver } from '../../schemas/drivers.entity';
import { CursorDto } from '../../common/dto/cursor.dto';
import { Business } from '../../schemas/business.entity';
import { IChatService } from './chat.interface';
import { BadRequestException } from '@nestjs/common/exceptions';
import { ForbiddenException, Injectable, Logger } from "@nestjs/common";
import { Repository } from "typeorm";
import { ChatRoom } from "../../schemas/chat-room.entity";
import { InjectRepository } from "@nestjs/typeorm";
import { ChatMessage } from "../../schemas/chat-message.entity";
import { CustomerChatService } from "./customer-chat.service";
import { DriverChatService } from "./driver-chat.service";
import { BusinessChatService } from "./business-chat.service";
import { ChatMessageDto, ChatRoomDto } from "../presentation/chat.dto";
import { UserDto, UserType } from "../../auth/presentation/user.dto";
import { UserSocket } from "../presentation/chat.gateway";
import { CacheService } from "../../common/cache/cache.service";
import { Customer } from "../../schemas/customer.entity";
import { Driver } from "../../schemas/drivers.entity";
import { CursorDto } from "../../common/dto/cursor.dto";
import { Business } from "../../schemas/business.entity";
import { IChatService } from "./chat.interface";
import { BadRequestException } from "@nestjs/common/exceptions";

@Injectable()
export class ChatService {
Expand Down
24 changes: 12 additions & 12 deletions src/chat/application/customer-chat.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { CustomerChatRoom } from '../../schemas/customer-chat-room.entity';
import { Repository } from 'typeorm';
import { IChatService } from './chat.interface';
import { CustomerService } from '../../customer/application/customer.service';
import { UserDto } from '../../auth/presentation/user.dto';
import { plainToInstance as toDto } from 'class-transformer';
import { ChatRoomDto } from '../presentation/chat.dto';
import { ChatRoom } from '../../schemas/chat-room.entity';
import { ChatMessage } from '../../schemas/chat-message.entity';
import { Injectable, Logger, NotFoundException } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { CustomerChatRoom } from "../../schemas/customer-chat-room.entity";
import { Repository } from "typeorm";
import { IChatService } from "./chat.interface";
import { CustomerService } from "../../customer/application/customer.service";
import { UserDto } from "../../auth/presentation/user.dto";
import { ChatRoomDto } from "../presentation/chat.dto";
import { ChatRoom } from "../../schemas/chat-room.entity";
import { ChatMessage } from "../../schemas/chat-message.entity";
import { toDto } from "../../common/function/util.function";

@Injectable()
export class CustomerChatService implements IChatService {
Expand Down Expand Up @@ -77,7 +77,7 @@ export class CustomerChatService implements IChatService {

if (!customer) {
throw new NotFoundException(
`InvitUser(${dto.inviteUser.userId} not found `,
`InvitUser(${dto.inviteUser.userId} not found`,
);
}

Expand Down
18 changes: 9 additions & 9 deletions src/chat/application/driver-chat.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { DriverChatRoom } from '../../schemas/driver-chat-room.entity';
import { IChatService } from './chat.interface';
import { UserDto } from '../../auth/presentation/user.dto';
import { DriverService } from '../../driver/application/driver.service';
import { plainToInstance as toDto } from 'class-transformer';
import { ChatRoomDto } from '../presentation/chat.dto';
import { Injectable, Logger } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { DriverChatRoom } from "../../schemas/driver-chat-room.entity";
import { IChatService } from "./chat.interface";
import { UserDto } from "../../auth/presentation/user.dto";
import { DriverService } from "../../driver/application/driver.service";
import { ChatRoomDto } from "../presentation/chat.dto";
import { toDto } from "../../common/function/util.function";

@Injectable()
export class DriverChatService implements IChatService {
Expand Down
31 changes: 9 additions & 22 deletions src/chat/presentation/chat.controller.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import {
Body,
Controller,
Get,
HttpStatus,
Param,
Post,
Query,
} from '@nestjs/common';
import { ChatService } from '../application/chat.service';
import { Auth, CurrentCustomer } from '../../auth/decorator/auth.decorator';
import { Customer } from '../../schemas/customers.entity';
import { CrudGroup } from '../../common/validation/validation.data';
import { GroupValidation } from '../../common/validation/validation.decorator';
import { CursorDto } from '../../common/dto/cursor.dto';
import { ChatMessageDto, ChatRoomDto } from './chat.dto';
import {
ApiCreatedResponse,
ApiOkResponse,
ApiOperation,
ApiTags,
} from '@nestjs/swagger';
import { Body, Controller, Get, HttpStatus, Param, Post, Query } from "@nestjs/common";
import { ChatService } from "../application/chat.service";
import { Auth, CurrentCustomer } from "../../auth/decorator/auth.decorator";
import { Customer } from "../../schemas/customer.entity";
import { CrudGroup } from "../../common/validation/validation.data";
import { GroupValidation } from "../../common/validation/validation.decorator";
import { CursorDto } from "../../common/dto/cursor.dto";
import { ChatMessageDto, ChatRoomDto } from "./chat.dto";
import { ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiTags } from "@nestjs/swagger";

@ApiTags('채팅방 API')
@Controller('v1/chat/room')
Expand Down
34 changes: 22 additions & 12 deletions src/common/cloud/aws/s3/application/s3.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Injectable } from '@nestjs/common';
import { S3 } from 'aws-sdk';
import { ConfigService } from '@nestjs/config';
import { BadRequestException } from '@nestjs/common/exceptions';
import { CloudStorageInterface } from '../../../cloud.storage.interface';
import { MetaData } from '../../../../image/presentation/image.dto';
import { PresignedUrlDto } from '../presentation/presigned-url.dto';
import { Injectable } from "@nestjs/common";
import { S3 } from "aws-sdk";
import { ConfigService } from "@nestjs/config";
import { BadRequestException } from "@nestjs/common/exceptions";
import { ICloudStorage } from "../../../cloud-storage.interface";
import { ImageMetaDataDto } from "../../../../image/presentation/image.dto";
import { PresignedUrlDto } from "../presentation/presigned-url.dto";

@Injectable()
export class S3Service implements CloudStorageInterface {
export class S3Service implements ICloudStorage {
private readonly s3Client: S3;
private readonly bucketName: string =
this.configService.get('s3/bucket_name');
Expand All @@ -31,7 +31,7 @@ export class S3Service implements CloudStorageInterface {

async generatePreSignedUrl(
key: string,
metadata: MetaData,
metadata: ImageMetaDataDto,
expiredTime: number = 60,
): Promise<PresignedUrlDto> {
const split = metadata.fileName.split('.');
Expand All @@ -47,12 +47,17 @@ export class S3Service implements CloudStorageInterface {
Expires: expiredTime,
});

return { url, expiredTime };
return {
url,
expiredTime,
fileName: metadata.fileName,
fileSize: metadata.fileSize,
};
}

async generatePreSignedUrls(
key: string,
metadataArray: MetaData[],
metadataArray: ImageMetaDataDto[],
): Promise<PresignedUrlDto[]> {
const dtos: PresignedUrlDto[] = [];

Expand All @@ -72,7 +77,12 @@ export class S3Service implements CloudStorageInterface {
Expires: expiredTime,
});

dtos.push({ url, expiredTime });
dtos.push({
url,
expiredTime,
fileName: metadata.fileName,
fileSize: metadata.fileSize,
});
}

return dtos;
Expand Down
5 changes: 3 additions & 2 deletions src/common/cloud/aws/s3/presentation/presigned-url.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty } from "@nestjs/swagger";
import { ImageMetaDataDto } from "../../../../image/presentation/image.dto";

export class PresignedUrlDto {
export class PresignedUrlDto extends ImageMetaDataDto {
@ApiProperty({
description: 'presigned URL',
})
Expand Down
15 changes: 15 additions & 0 deletions src/common/cloud/cloud-storage.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ImageMetaDataDto } from "../image/presentation/image.dto";
import { PresignedUrlDto } from "./aws/s3/presentation/presigned-url.dto";

export interface ICloudStorage {
generatePreSignedUrl(
key: string,
metadata: ImageMetaDataDto,
expiredTime: number,
): Promise<PresignedUrlDto>;

generatePreSignedUrls(
key: string,
metadata: ImageMetaDataDto[],
): Promise<PresignedUrlDto[]>;
}
15 changes: 0 additions & 15 deletions src/common/cloud/cloud.storage.interface.ts

This file was deleted.

Loading

0 comments on commit f2fcfde

Please sign in to comment.