A progressive Node.js framework for building efficient and scalable server-side applications.
- - - -## Description - -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. - -## Installation - -```bash -$ npm install -``` - -## Running the app - -```bash -# development -$ npm run start - -# watch mode -$ npm run start:dev - -# production mode -$ npm run start:prod -``` - -## Test - -```bash -# unit tests -$ npm run test - -# e2e tests -$ npm run test:e2e - -# test coverage -$ npm run test:cov -``` - -## Support - -Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). - -## Stay in touch - -- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) -- Website - [https://nestjs.com](https://nestjs.com/) -- Twitter - [@nestframework](https://twitter.com/nestframework) - -## License - -Nest is [MIT licensed](LICENSE). diff --git a/api/nest-cli.json b/api/nest-cli.json deleted file mode 100644 index 56167b36..00000000 --- a/api/nest-cli.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "collection": "@nestjs/schematics", - "sourceRoot": "src" -} diff --git a/api/package.json b/api/package.json deleted file mode 100644 index 5108ae29..00000000 --- a/api/package.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "name": "api", - "version": "0.0.1", - "description": "", - "author": "", - "private": true, - "license": "UNLICENSED", - "scripts": { - "prebuild": "rimraf dist", - "build": "nest build", - "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "start": "nest start", - "start:dev": "nest start --watch", - "start:debug": "nest start --debug --watch", - "start:prod": "node dist/main", - "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", - "test": "jest", - "test:watch": "jest --watch", - "test:cov": "jest --coverage", - "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./test/jest-e2e.json" - }, - "dependencies": { - "@nestjs/common": "^8.0.0", - "@nestjs/core": "^8.0.0", - "@nestjs/jwt": "^9.0.0", - "@nestjs/mapped-types": "*", - "@nestjs/mongoose": "^9.2.1", - "@nestjs/passport": "^9.0.0", - "@nestjs/platform-express": "^8.4.7", - "axios": "^1.2.0", - "jsdom": "^20.0.3", - "jwt-decode": "^3.1.2", - "mongoose": "^6.8.0", - "passport": "^0.6.0", - "passport-jwt": "^4.0.0", - "passport-local": "^1.0.0", - "rand-token": "^1.0.1", - "reflect-metadata": "^0.1.13", - "rimraf": "^3.0.2", - "rxjs": "^7.5.7", - "schema-dts": "^1.1.0" - }, - "devDependencies": { - "@nestjs/cli": "^9.1.5", - "@nestjs/schematics": "^9.0.3", - "@nestjs/testing": "^8.0.0", - "@types/express": "^4.17.14", - "@types/jest": "27.4.1", - "@types/node": "^18.11.10", - "@types/passport-jwt": "^3.0.7", - "@types/passport-local": "^1.0.34", - "@types/supertest": "^2.0.11", - "@typescript-eslint/eslint-plugin": "^5.45.1", - "@typescript-eslint/parser": "^5.45.1", - "eslint": "^8.28.0", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-prettier": "^4.2.1", - "jest": "^27.2.5", - "prettier": "^2.7.1", - "source-map-support": "^0.5.20", - "supertest": "^6.3.2", - "ts-jest": "^27.0.3", - "ts-loader": "^9.4.2", - "ts-node": "^10.9.1", - "tsconfig-paths": "^4.1.1", - "typescript": "^4.9.3", - "@types/multer": "^1.4.7" - }, - "jest": { - "moduleFileExtensions": [ - "js", - "json", - "ts" - ], - "rootDir": "src", - "testRegex": ".*\\.spec\\.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - }, - "collectCoverageFrom": [ - "**/*.(t|j)s" - ], - "coverageDirectory": "../coverage", - "testEnvironment": "node" - } -} diff --git a/api/src/app.controller.ts b/api/src/app.controller.ts deleted file mode 100644 index 025c358d..00000000 --- a/api/src/app.controller.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Controller, Get, Request } from '@nestjs/common'; -import { AuthService } from './auth/auth.service'; - -@Controller() -export class AppController { - constructor(private authService: AuthService) {} - - @Get('profile') - getProfile(@Request() req) { - return req.user; - } -} diff --git a/api/src/app.module.ts b/api/src/app.module.ts deleted file mode 100644 index 4ec53a6d..00000000 --- a/api/src/app.module.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Module } from '@nestjs/common'; -import { AppService } from './app.service'; -import { MongooseModule } from '@nestjs/mongoose'; -import { AuthModule } from './auth/auth.module'; -import { UsersService } from './users/users.service'; -import { UsersModule } from './users/users.module'; -import { APP_GUARD } from '@nestjs/core'; -import { JwtAuthGuard } from './auth/jwt-auth.guard'; -import { RolesGuard } from './auth/roles.guard'; -import { RecipesModule } from './recipes/recipes.module'; -import { GrocyModule } from './grocy/grocy.module'; -import { ImportModule } from './import/import.module'; - -@Module({ - imports: [ - MongooseModule.forRoot('mongodb://root:root@mongo:27017/'), - AuthModule, - UsersModule, - RecipesModule, - GrocyModule, - ImportModule, - ], - providers: [ - AppService, - UsersService, - { provide: APP_GUARD, useClass: JwtAuthGuard }, - { provide: APP_GUARD, useClass: RolesGuard }, - ], -}) -export class AppModule {} diff --git a/api/src/app.service.ts b/api/src/app.service.ts deleted file mode 100644 index 7263d33a..00000000 --- a/api/src/app.service.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AppService {} diff --git a/api/src/auth/auth.controller.ts b/api/src/auth/auth.controller.ts deleted file mode 100644 index 703a0573..00000000 --- a/api/src/auth/auth.controller.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Controller, Delete, Post, Request, UseGuards } from '@nestjs/common'; -import { Public, Roles } from './decorators'; -import { LocalAuthGuard } from './local-auth.guard'; -import { Role } from '../users/role.enum'; -import jwtDecode from 'jwt-decode'; -import { AuthService } from './auth.service'; - -@Controller('auth') -export class AuthController { - constructor(private authService: AuthService) {} - @Public() - @UseGuards(LocalAuthGuard) - @Post('/login') - async login(@Request() req) { - return this.authService.login(req.user); - } - - @Delete('/login') - async logout(@Request() req) { - return this.authService.logout(req.body.username); - } - - @Roles(Role.User) - @Post('/token') - async token(@Request() req) { - const { body, headers } = req; - // @ts-ignore - const username = jwtDecode(headers.authorization).username; - return this.authService.refreshToken(body.refresh_token, username); - } -} diff --git a/api/src/auth/auth.module.ts b/api/src/auth/auth.module.ts deleted file mode 100644 index ee532678..00000000 --- a/api/src/auth/auth.module.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Module } from '@nestjs/common'; -import { AuthService } from './auth.service'; -import { UsersModule } from '../users/users.module'; -import { PassportModule } from '@nestjs/passport'; -import { LocalStrategy } from './local.strategy'; -import { JwtModule } from '@nestjs/jwt'; -import { jwtConstants } from './constants'; -import { JwtStrategy } from './jwt.strategy'; -import { AuthController } from './auth.controller'; - -@Module({ - providers: [AuthService, LocalStrategy, JwtStrategy], - imports: [ - UsersModule, - PassportModule, - JwtModule.register({ - secret: jwtConstants.secret, - signOptions: { expiresIn: '5m' }, - }), - ], - exports: [AuthService], - controllers: [AuthController], -}) -export class AuthModule {} diff --git a/api/src/auth/auth.service.ts b/api/src/auth/auth.service.ts deleted file mode 100644 index 289304d7..00000000 --- a/api/src/auth/auth.service.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { Injectable, UnauthorizedException, Logger } from '@nestjs/common'; -import { UsersService } from '../users/users.service'; -import { JwtService } from '@nestjs/jwt'; -import { uid } from 'rand-token'; -import { refreshTokenSize } from './constants'; - -@Injectable() -export class AuthService { - private readonly logger = new Logger(UsersService.name); - constructor( - private usersService: UsersService, - private jwtService: JwtService, - ) {} - - generateRefreshToken(): string { - return uid(refreshTokenSize); - } - - async validateUser(username: string, password: string): Promise