diff --git a/README.md b/README.md index a59ef92..8c6df83 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,52 @@ -

- Nest Logo -

+# Task Me Api -[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master -[travis-url]: https://travis-ci.org/nestjs/nest -[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux -[linux-url]: https://travis-ci.org/nestjs/nest - -

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

-

-NPM Version -Package License -NPM Downloads -Travis -Linux -Coverage -Gitter -Backers on Open Collective -Sponsors on Open Collective - - -

- +Version: 2.0 Beta -## Description +--- -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. +### Requires -## Installation +The following software must be installed on the system to run the project -```bash -$ npm install -``` +- Docker 20.10.2 + +- Docker-compose 1.28.0 + +- Node.js 14.0.0 + +- npm 8.0.0 + -## Running the app +--- -```bash -# development -$ npm run start +### Setting project -# watch mode -$ npm run start:dev +Create .env file from .env.example -# production mode -$ npm run start:prod -``` +`cp .env .env.example` -## Test +Change configuration params -```bash -# unit tests -$ npm run test +`nano .env` -# e2e tests -$ npm run test:e2e +Install dependencies -# test coverage -$ npm run test:cov -``` +`npm install` -## 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). +### Start project local -## Stay in touch +Build `npm run start` -- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) -- Website - [https://nestjs.com](https://nestjs.com/) -- Twitter - [@nestframework](https://twitter.com/nestframework) +Start `docker-compose up` -## License +### Run project stage/dev - Nest is [MIT licensed](LICENSE). +Build +`npm run build` + +Start +`docker-compose -f docker-compose.stage up -d` + +Restart +`docker-compose restart` + +Stop +`docker-compose stop` diff --git a/package-lock.json b/package-lock.json index bb4f0f6..28548bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8811,6 +8811,7 @@ "version": "4.7.7", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==", + "devOptional": true, "dependencies": { "minimist": "^1.2.5", "neo-async": "^2.6.0", @@ -8831,6 +8832,7 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "devOptional": true, "engines": { "node": ">=0.10.0" } @@ -13193,7 +13195,8 @@ "node_modules/neo-async": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", - "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", + "devOptional": true }, "node_modules/netmask": { "version": "2.0.2", @@ -18197,6 +18200,7 @@ "version": "3.14.1", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.14.1.tgz", "integrity": "sha512-JhS3hmcVaXlp/xSo3PKY5R0JqKs5M3IV+exdLHW99qKvKivPO4Z8qbej6mte17SOPqAOVMjt/XGgWacnFSzM3g==", + "dev": true, "optional": true, "bin": { "uglifyjs": "bin/uglifyjs" @@ -18809,7 +18813,8 @@ "node_modules/wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", - "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=" + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", + "devOptional": true }, "node_modules/wrap-ansi": { "version": "6.2.0", @@ -25962,6 +25967,7 @@ "version": "4.7.7", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==", + "devOptional": true, "requires": { "minimist": "^1.2.5", "neo-async": "^2.6.0", @@ -25973,7 +25979,8 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "devOptional": true } } }, @@ -29488,7 +29495,8 @@ "neo-async": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", - "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", + "devOptional": true }, "netmask": { "version": "2.0.2", @@ -33385,6 +33393,7 @@ "version": "3.14.1", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.14.1.tgz", "integrity": "sha512-JhS3hmcVaXlp/xSo3PKY5R0JqKs5M3IV+exdLHW99qKvKivPO4Z8qbej6mte17SOPqAOVMjt/XGgWacnFSzM3g==", + "dev": true, "optional": true }, "uid2": { @@ -33863,7 +33872,8 @@ "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", - "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=" + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", + "devOptional": true }, "wrap-ansi": { "version": "6.2.0", diff --git a/src/domain/mailer/mailer.module.ts b/src/domain/mailer/mailer.module.ts index c85d906..5a8c4f7 100644 --- a/src/domain/mailer/mailer.module.ts +++ b/src/domain/mailer/mailer.module.ts @@ -15,7 +15,6 @@ export class MailerModule { static getImports() { const { options } = MailerModule - console.log(options) if (options.test) return [] return [ @@ -30,7 +29,7 @@ export class MailerModule { }, }, defaults: { - from: '"nest-modules" ', + from: options.login, }, }), ] diff --git a/src/rest/admin/sessions/admin-sessions.module.ts b/src/rest/admin/sessions/admin-sessions.module.ts index 46fd97d..9450b09 100644 --- a/src/rest/admin/sessions/admin-sessions.module.ts +++ b/src/rest/admin/sessions/admin-sessions.module.ts @@ -1,7 +1,7 @@ import { DynamicModule, Module } from '@nestjs/common' -import { SessionsModule } from 'src/domain' -import { JwtModule } from "src/libs" +import { PermissionsModule, SessionsModule } from 'src/domain' +import { JwtModule } from 'src/libs' import { AdminSessionsController } from './controllers' import { AdminSessionsService } from './services' @@ -10,7 +10,11 @@ export class AdminSessionsModule { static forRoot(): DynamicModule { return { module: AdminSessionsModule, - imports: [SessionsModule.forFeature(), JwtModule.forFeature()], + imports: [ + SessionsModule.forFeature(), + JwtModule.forFeature(), + PermissionsModule.forFeature(), + ], providers: [AdminSessionsService], controllers: [AdminSessionsController], } diff --git a/src/rest/admin/sessions/controllers/admin-sessions.controller.ts b/src/rest/admin/sessions/controllers/admin-sessions.controller.ts index 69c1066..d4c2ae3 100644 --- a/src/rest/admin/sessions/controllers/admin-sessions.controller.ts +++ b/src/rest/admin/sessions/controllers/admin-sessions.controller.ts @@ -1,21 +1,32 @@ -import { Controller, Get, Param } from '@nestjs/common' +import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common' import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger' -import { Users } from "src/core" -import { RoleGuard } from "src/domain/sessions/decorators" -import { GetUserSessionsResDto } from "../dto" +import { Users } from 'src/core' +import { RoleGuard } from 'src/domain/sessions/decorators' +import { PermissionsTabsGuard } from 'src/shared' +import { GetUserSessionsParamsDto, GetUserSessionsResDto, StopSessionsParamsDto } from '../dto' import { AdminSessionsService } from '../services' - @ApiTags('Admin | Sessions') @Controller('admin/sessions') export class AdminSessionsController { - constructor(private readonly adminSessionsService: AdminSessionsService) { } + constructor(private readonly adminSessionsService: AdminSessionsService) {} @ApiOperation({ summary: 'Список активних сесій користувача' }) - @ApiResponse({ status: 200, description: 'Список активних сесій', type: [GetUserSessionsResDto] }) + @ApiResponse({ + status: 200, + description: 'Список активних сесій', + type: [GetUserSessionsResDto], + }) @RoleGuard(Users.Role.Admin) - @Get('/:userId') - public async getUserSessions(@Param('userId') userId: number) { - return await this.adminSessionsService.getUserSessionsList(userId) + @Get('/') + public async getUserSessions(@Query() dto: GetUserSessionsParamsDto) { + return await this.adminSessionsService.getUserSessions(dto) + } + + @ApiOperation({ summary: 'Зупинка сесії' }) + @PermissionsTabsGuard('user', 'logout') + @Post('/stop') + public async stopUsersSessions(@Body() dto: StopSessionsParamsDto) { + return await this.adminSessionsService.stopUsersSessions(dto.userId) } } diff --git a/src/rest/admin/sessions/dto/get-user-sessions-params.dto.ts b/src/rest/admin/sessions/dto/get-user-sessions-params.dto.ts new file mode 100644 index 0000000..f0ab1a5 --- /dev/null +++ b/src/rest/admin/sessions/dto/get-user-sessions-params.dto.ts @@ -0,0 +1,6 @@ +import { DtoProperty } from 'src/shared' + +export class GetUserSessionsParamsDto { + @DtoProperty() + userId: number +} diff --git a/src/rest/admin/sessions/dto/index.ts b/src/rest/admin/sessions/dto/index.ts index a9b5ad6..bc1355f 100644 --- a/src/rest/admin/sessions/dto/index.ts +++ b/src/rest/admin/sessions/dto/index.ts @@ -1 +1,3 @@ -export * from './get-user-sessions.dto' \ No newline at end of file +export * from './get-user-sessions.dto' +export * from './stop-sessions-params.dto' +export * from './get-user-sessions-params.dto' diff --git a/src/rest/admin/sessions/dto/stop-sessions-params.dto.ts b/src/rest/admin/sessions/dto/stop-sessions-params.dto.ts new file mode 100644 index 0000000..bbd2671 --- /dev/null +++ b/src/rest/admin/sessions/dto/stop-sessions-params.dto.ts @@ -0,0 +1,6 @@ +import { DtoProperty } from 'src/shared' + +export class StopSessionsParamsDto { + @DtoProperty() + userId: number +} diff --git a/src/rest/admin/sessions/services/admin-sessions.service.ts b/src/rest/admin/sessions/services/admin-sessions.service.ts index bdb68ae..a3b92eb 100644 --- a/src/rest/admin/sessions/services/admin-sessions.service.ts +++ b/src/rest/admin/sessions/services/admin-sessions.service.ts @@ -1,17 +1,19 @@ -import { BadRequestException } from "@nestjs/common" import { Inject, Injectable } from '@nestjs/common' -import { throwError } from "rxjs" import { Sessions } from 'src/core' import { SESSIONS_SERVICE } from 'src/core/consts' +import { GetUserSessionsParamsDto } from '../dto' @Injectable() export class AdminSessionsService { - constructor(@Inject(SESSIONS_SERVICE) private readonly sessionsService: Sessions.ISessionsService) { } + constructor( + @Inject(SESSIONS_SERVICE) private readonly sessionsService: Sessions.ISessionsService, + ) {} - public async getUserSessionsList(userId: number) { - if (!userId) throw new BadRequestException('userId is required') - const res = await this.sessionsService.getByUserId(userId) - if (!res[0]) throw new BadRequestException('Not found sessions by id') - return res + public async getUserSessions(dto: GetUserSessionsParamsDto) { + return await this.sessionsService.getByUserId(dto.userId) + } + + public async stopUsersSessions(userId: number) { + await this.sessionsService.closeAllUserSessions(userId) } } diff --git a/src/rest/admin/users/admin-users.module.ts b/src/rest/admin/users/admin-users.module.ts index 71122d6..046deee 100644 --- a/src/rest/admin/users/admin-users.module.ts +++ b/src/rest/admin/users/admin-users.module.ts @@ -4,16 +4,8 @@ import { PermissionsModule, SessionsModule } from 'src/domain' /** IMPORTANT FULL PART */ import { UsersModule } from 'src/domain/users/users.module' import { JwtModule } from 'src/libs' -import { - AdminUsersController, - AdminUsersFactoriesController, - AdminUsersSessionsController, -} from './controllers' -import { - AdminUsersService, - AdminUsersFactoriesService, - AdminUsersSessionsService, -} from './services' +import { AdminUsersController, AdminUsersFactoriesController } from './controllers' +import { AdminUsersService, AdminUsersFactoriesService } from './services' @Module({}) export class AdminUsersModule { @@ -26,12 +18,8 @@ export class AdminUsersModule { JwtModule.forFeature(), PermissionsModule.forFeature(), ], - providers: [AdminUsersService, AdminUsersFactoriesService, AdminUsersSessionsService], - controllers: [ - AdminUsersController, - AdminUsersFactoriesController, - AdminUsersSessionsController, - ], + providers: [AdminUsersService, AdminUsersFactoriesService], + controllers: [AdminUsersController, AdminUsersFactoriesController], } } } diff --git a/src/rest/admin/users/controllers/admin-users-sessions.controller.ts b/src/rest/admin/users/controllers/admin-users-sessions.controller.ts deleted file mode 100644 index 63804f0..0000000 --- a/src/rest/admin/users/controllers/admin-users-sessions.controller.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Controller, Param, Post } from '@nestjs/common' -import { ApiOperation, ApiTags } from '@nestjs/swagger' -import { PermissionsTabsGuard, ReqUser } from 'src/shared' -import { AdminUsersSessionsService } from '../services' - -@ApiTags('Admin | Users Sessions') -@Controller('admin/users/sessions') -export class AdminUsersSessionsController { - constructor(private readonly adminUsersSessionsService: AdminUsersSessionsService) {} - - @ApiOperation({ summary: 'Розлогінення користувача' }) - @PermissionsTabsGuard('user', 'logout') - @Post('stop/:id') - public async stopUsersSessions(@Param('id') id: number) { - return await this.adminUsersSessionsService.stopUsersSessions(id) - } -} diff --git a/src/rest/admin/users/controllers/index.ts b/src/rest/admin/users/controllers/index.ts index 5ebc230..9277311 100644 --- a/src/rest/admin/users/controllers/index.ts +++ b/src/rest/admin/users/controllers/index.ts @@ -1,3 +1,2 @@ export * from './admin-users.controller' export * from './admin-users-factories.controllers' -export * from './admin-users-sessions.controller' diff --git a/src/rest/app/account/controllers/app-accounts.controller.ts b/src/rest/app/account/controllers/app-accounts.controller.ts index f8c9572..bb69bc2 100644 --- a/src/rest/app/account/controllers/app-accounts.controller.ts +++ b/src/rest/app/account/controllers/app-accounts.controller.ts @@ -54,7 +54,6 @@ export class AppAccountsController { @Patch() public async update(@ReqUser() id: number, @Body() dto: UpdateAccountDto) { const user = await this.accountsService.update(id, dto) - console.log(user, plainToClass(GetAccountDto, user)) return plainToClass(GetAccountDto, user) }