Skip to content

Commit

Permalink
Merge branch 'main' into feat/logger
Browse files Browse the repository at this point in the history
  • Loading branch information
iaurg authored Nov 16, 2023
2 parents 470697d + 1b4960a commit 63a6743
Show file tree
Hide file tree
Showing 48 changed files with 648 additions and 396 deletions.
15 changes: 0 additions & 15 deletions .devcontainer/Dockerfile

This file was deleted.

29 changes: 0 additions & 29 deletions .devcontainer/devcontainer.json

This file was deleted.

44 changes: 0 additions & 44 deletions .devcontainer/docker-compose.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ postgres/

# Migrations
**/database/migrations/*

=======
# Local Uploads
/backend/uploads/*
data
4 changes: 3 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ lerna-debug.log*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json

uploads
25 changes: 7 additions & 18 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
###################
# BUILD FOR LOCAL DEVELOPMENT
###################
FROM node:18

# Base image
FROM node:18 AS development
WORKDIR /usr/src/app/server

# Set working directory
WORKDIR /usr/src/app
COPY . .

# Copy package.json and package-lock.json
COPY --chown=node:node package*.json ./
RUN npm install
RUN npm run build

# Install dependencies
RUN npm ci
RUN npm install -g @nestjs/cli
EXPOSE 3000

# Copy source code
COPY --chown=node:node . .
CMD [ "npm", "run", "start" ]

# Generate Prisma database client code
RUN npm run prisma:generate

ENTRYPOINT [ "npm", "run", "start:dev" ]
60 changes: 51 additions & 9 deletions backend/package-lock.json

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

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/platform-socket.io": "^9.0.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/websockets": "^9.0.0",
"@prisma/client": "^4.16.2",
"argon2": "^0.30.3",
Expand Down Expand Up @@ -60,6 +61,7 @@
"@types/express": "^4.17.13",
"@types/jest": "29.5.0",
"@types/ms": "^0.7.31",
"@types/multer": "^1.4.9",
"@types/node": "18.15.11",
"@types/passport-jwt": "^3.0.8",
"@types/passport-oauth2": "^1.4.12",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/bin/bash

# Install dependencies
cd backend/ && npm ci
cd backend/ && npm i

# Install NestJS CLI
npm install -g @nestjs/cli

# Generate Prisma Client
npm run prisma:generate
npx prisma generate

# Generate Prisma Migrations
npx prisma db push --force-reset && npx prisma db seed

# Docker daemon setup
sudo chown node:node /var/run/docker.sock
8 changes: 8 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { GameModule } from './game/game.module';
import { AuthModule } from './auth/auth.module';
import { FriendsModule } from './friends/friends.module';
import { LeaderboardModule } from './leaderboard/leaderboard.module';
import { AvatarUploadModule } from './avatar-upload/avatar-upload.module';
import { MatchHistoryModule } from './match-history/match-history.module';
import { LoggerModule } from 'nestjs-pino';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';

@Module({
imports: [
Expand Down Expand Up @@ -39,6 +42,11 @@ import { LoggerModule } from 'nestjs-pino';
FriendsModule,
LeaderboardModule,
MatchHistoryModule,
AvatarUploadModule,
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'uploads'),
serveRoot: '/avatars',
}),
],
providers: [PrismaService],
})
Expand Down
2 changes: 2 additions & 0 deletions backend/src/auth/jwt/jwt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export class JwtAuthService {

async generateJwt(user: User, mfaAuthenticated = false) {
const payload = this.generatePayload(user, mfaAuthenticated);

const accessToken = this.jwtService.sign(payload, {
expiresIn: this.accessTokenExpiration,
secret: this.configService.get('JWT_SECRET'),
});

const refreshToken = this.jwtService.sign(payload, {
expiresIn: this.refreshTokenExpiration,
secret: this.configService.get('JWT_SECRET'),
Expand Down
67 changes: 67 additions & 0 deletions backend/src/avatar-upload/avatar-upload.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
Controller,
Post,
Patch,
Delete,
UseInterceptors,
UploadedFile,
ParseFilePipe,
MaxFileSizeValidator,
UseGuards,
Req,
} from '@nestjs/common';
import { AvatarUploadService } from './avatar-upload.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { AccessTokenGuard } from 'src/auth/jwt/jwt.guard';
import { User } from '@prisma/client';

const fileValidators = [
new MaxFileSizeValidator({
// 1MB
maxSize: 1024 * 1024,
}),
];

@Controller('avatar-upload')
@UseGuards(AccessTokenGuard)
export class AvatarUploadController {
constructor(private readonly avatarUploadService: AvatarUploadService) {}

@Post()
@UseInterceptors(FileInterceptor('file'))
create(
@UploadedFile(
new ParseFilePipe({
validators: fileValidators,
}),
)
file: Express.Multer.File,
@Req() request: Request & { user: User },
) {
const { id } = request.user;

return this.avatarUploadService.create(id, file);
}

@Patch()
update(
@UploadedFile(
new ParseFilePipe({
validators: fileValidators,
}),
)
file: Express.Multer.File,
@Req() request: Request & { user: User },
) {
const { id } = request.user;

return this.avatarUploadService.update(id, file);
}

@Delete()
remove(@Req() request: Request & { user: User }) {
const { id } = request.user;

return this.avatarUploadService.remove(id);
}
}
Loading

0 comments on commit 63a6743

Please sign in to comment.