D-Klimishen
3 years ago
13 changed files with 106 additions and 120 deletions
@ -1,75 +1,52 @@ |
|||||||
<p align="center"> |
# Task Me Api |
||||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a> |
|
||||||
</p> |
|
||||||
|
|
||||||
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master |
Version: 2.0 Beta |
||||||
[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 |
|
||||||
|
|
||||||
<p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p> |
|
||||||
<p align="center"> |
|
||||||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> |
|
||||||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> |
|
||||||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a> |
|
||||||
<a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a> |
|
||||||
<a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a> |
|
||||||
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a> |
|
||||||
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a> |
|
||||||
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> |
|
||||||
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> |
|
||||||
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a> |
|
||||||
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a> |
|
||||||
</p> |
|
||||||
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer) |
|
||||||
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)--> |
|
||||||
|
|
||||||
## 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 |
- Docker 20.10.2 + |
||||||
$ npm install |
- Docker-compose 1.28.0 + |
||||||
``` |
- Node.js 14.0.0 + |
||||||
|
- npm 8.0.0 + |
||||||
|
|
||||||
## Running the app |
--- |
||||||
|
|
||||||
```bash |
### Setting project |
||||||
# development |
|
||||||
$ npm run start |
|
||||||
|
|
||||||
# watch mode |
Create .env file from .env.example |
||||||
$ npm run start:dev |
|
||||||
|
|
||||||
# production mode |
`cp .env .env.example` |
||||||
$ npm run start:prod |
|
||||||
``` |
|
||||||
|
|
||||||
## Test |
Change configuration params |
||||||
|
|
||||||
```bash |
`nano .env` |
||||||
# unit tests |
|
||||||
$ npm run test |
|
||||||
|
|
||||||
# e2e tests |
Install dependencies |
||||||
$ npm run test:e2e |
|
||||||
|
|
||||||
# test coverage |
`npm install` |
||||||
$ 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). |
### Start project local |
||||||
|
|
||||||
## Stay in touch |
Build `npm run start` |
||||||
|
|
||||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) |
Start `docker-compose up` |
||||||
- Website - [https://nestjs.com](https://nestjs.com/) |
|
||||||
- Twitter - [@nestframework](https://twitter.com/nestframework) |
|
||||||
|
|
||||||
## 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` |
||||||
|
@ -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 { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger' |
||||||
import { Users } from "src/core" |
import { Users } from 'src/core' |
||||||
import { RoleGuard } from "src/domain/sessions/decorators" |
import { RoleGuard } from 'src/domain/sessions/decorators' |
||||||
import { GetUserSessionsResDto } from "../dto" |
import { PermissionsTabsGuard } from 'src/shared' |
||||||
|
import { GetUserSessionsParamsDto, GetUserSessionsResDto, StopSessionsParamsDto } from '../dto' |
||||||
import { AdminSessionsService } from '../services' |
import { AdminSessionsService } from '../services' |
||||||
|
|
||||||
|
|
||||||
@ApiTags('Admin | Sessions') |
@ApiTags('Admin | Sessions') |
||||||
@Controller('admin/sessions') |
@Controller('admin/sessions') |
||||||
export class AdminSessionsController { |
export class AdminSessionsController { |
||||||
constructor(private readonly adminSessionsService: AdminSessionsService) { } |
constructor(private readonly adminSessionsService: AdminSessionsService) {} |
||||||
|
|
||||||
@ApiOperation({ summary: 'Список активних сесій користувача' }) |
@ApiOperation({ summary: 'Список активних сесій користувача' }) |
||||||
@ApiResponse({ status: 200, description: 'Список активних сесій', type: [GetUserSessionsResDto] }) |
@ApiResponse({ |
||||||
|
status: 200, |
||||||
|
description: 'Список активних сесій', |
||||||
|
type: [GetUserSessionsResDto], |
||||||
|
}) |
||||||
@RoleGuard(Users.Role.Admin) |
@RoleGuard(Users.Role.Admin) |
||||||
@Get('/:userId') |
@Get('/') |
||||||
public async getUserSessions(@Param('userId') userId: number) { |
public async getUserSessions(@Query() dto: GetUserSessionsParamsDto) { |
||||||
return await this.adminSessionsService.getUserSessionsList(userId) |
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) |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -0,0 +1,6 @@ |
|||||||
|
import { DtoProperty } from 'src/shared' |
||||||
|
|
||||||
|
export class GetUserSessionsParamsDto { |
||||||
|
@DtoProperty() |
||||||
|
userId: number |
||||||
|
} |
@ -1 +1,3 @@ |
|||||||
export * from './get-user-sessions.dto' |
export * from './get-user-sessions.dto' |
||||||
|
export * from './stop-sessions-params.dto' |
||||||
|
export * from './get-user-sessions-params.dto' |
||||||
|
@ -0,0 +1,6 @@ |
|||||||
|
import { DtoProperty } from 'src/shared' |
||||||
|
|
||||||
|
export class StopSessionsParamsDto { |
||||||
|
@DtoProperty() |
||||||
|
userId: number |
||||||
|
} |
@ -1,17 +1,19 @@ |
|||||||
import { BadRequestException } from "@nestjs/common" |
|
||||||
import { Inject, Injectable } from '@nestjs/common' |
import { Inject, Injectable } from '@nestjs/common' |
||||||
import { throwError } from "rxjs" |
|
||||||
import { Sessions } from 'src/core' |
import { Sessions } from 'src/core' |
||||||
import { SESSIONS_SERVICE } from 'src/core/consts' |
import { SESSIONS_SERVICE } from 'src/core/consts' |
||||||
|
import { GetUserSessionsParamsDto } from '../dto' |
||||||
|
|
||||||
@Injectable() |
@Injectable() |
||||||
export class AdminSessionsService { |
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) { |
public async getUserSessions(dto: GetUserSessionsParamsDto) { |
||||||
if (!userId) throw new BadRequestException('userId is required') |
return await this.sessionsService.getByUserId(dto.userId) |
||||||
const res = await this.sessionsService.getByUserId(userId) |
} |
||||||
if (!res[0]) throw new BadRequestException('Not found sessions by id') |
|
||||||
return res |
public async stopUsersSessions(userId: number) { |
||||||
|
await this.sessionsService.closeAllUserSessions(userId) |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -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) |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue