Skip to content

Commit

Permalink
feat: file upload 기초
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatoziyun committed Nov 7, 2023
1 parent 064eceb commit e3856b8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"@types/jest": "28.1.4",
"@types/multer": "^1.4.9",
"@types/node": "^16.0.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth-42.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Auth42Service {
email: response.data.email,
fortyTwoId: response.data.id,
};
this.logger.log(userData);
this.logger.log('user: ', userData);
return userData;
} catch (error) {
this.logger.error(error);
Expand Down
28 changes: 26 additions & 2 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { Controller, Get, Logger, Query, Res } from '@nestjs/common';
import {
Controller,
Get,
Logger,
Post,
Query,
Res,
UploadedFile,
UseInterceptors,
} from '@nestjs/common';
import { Auth42Service } from './auth-42.service';
import { AuthService } from './auth.service';
import { UserSigninResponseDto } from './dto/user-signin-response.dto';
import { FileInterceptor } from '@nestjs/platform-express';
import { diskStorage } from 'multer';

@Controller('auth')
export class AuthController {
Expand Down Expand Up @@ -37,10 +48,23 @@ export class AuthController {
});
const userSigninResponseDto: UserSigninResponseDto = {
userId: user.id,
isFirstLogin: user.avatar === null ? true : false,
isFirstLogin: user.avatar === null,
isMfaEnabled: user.isMfaEnabled,
mfaQRCode,
};
return res.send(userSigninResponseDto);
}

@Post('/login')
@UseInterceptors(
FileInterceptor('avatar', {
storage: diskStorage({
destination: './uploads',
}),
}),
)
async login(@UploadedFile() file: Express.Multer.File) {
console.log('file: ', file);
return `http://localhost:3000/auth/login/${file.filename}`;
}
}
6 changes: 6 additions & 0 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Auth42Service } from './auth-42.service';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { JwtModule } from '@nestjs/jwt';
import { MulterModule } from '@nestjs/platform-express';

@Module({
controllers: [AuthController],
Expand All @@ -20,6 +21,11 @@ import { JwtModule } from '@nestjs/jwt';
},
}),
}),
// MulterModule.registerAsync({
// useFactory: () => ({
// dest: './uploads',
// }),
// }),
],
})
export class AuthModule {}

0 comments on commit e3856b8

Please sign in to comment.