D-Klimishen
3 years ago
13 changed files with 106 additions and 120 deletions
@ -1,75 +1,52 @@
@@ -1,75 +1,52 @@
|
||||
<p align="center"> |
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a> |
||||
</p> |
||||
# 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 |
||||
Version: 2.0 Beta |
||||
|
||||
<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 |
||||
### Requires |
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. |
||||
The following software must be installed on the system to run the project |
||||
|
||||
## Installation |
||||
- Docker 20.10.2 + |
||||
- Docker-compose 1.28.0 + |
||||
- Node.js 14.0.0 + |
||||
- npm 8.0.0 + |
||||
|
||||
```bash |
||||
$ npm install |
||||
``` |
||||
--- |
||||
|
||||
## Running the app |
||||
### Setting project |
||||
|
||||
```bash |
||||
# development |
||||
$ npm run start |
||||
Create .env file from .env.example |
||||
|
||||
# watch mode |
||||
$ npm run start:dev |
||||
`cp .env .env.example` |
||||
|
||||
# production mode |
||||
$ npm run start:prod |
||||
``` |
||||
Change configuration params |
||||
|
||||
## Test |
||||
`nano .env` |
||||
|
||||
```bash |
||||
# unit tests |
||||
$ npm run test |
||||
Install dependencies |
||||
|
||||
# e2e tests |
||||
$ npm run test:e2e |
||||
`npm install` |
||||
|
||||
# test coverage |
||||
$ npm run test:cov |
||||
``` |
||||
--- |
||||
|
||||
## Support |
||||
### Start project local |
||||
|
||||
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). |
||||
Build `npm run start` |
||||
|
||||
## Stay in touch |
||||
Start `docker-compose up` |
||||
|
||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) |
||||
- Website - [https://nestjs.com](https://nestjs.com/) |
||||
- Twitter - [@nestframework](https://twitter.com/nestframework) |
||||
### Run project stage/dev |
||||
|
||||
## License |
||||
Build |
||||
`npm run build` |
||||
|
||||
Nest is [MIT licensed](LICENSE). |
||||
Start |
||||
`docker-compose -f docker-compose.stage up -d` |
||||
|
||||
Restart |
||||
`docker-compose restart` |
||||
|
||||
Stop |
||||
`docker-compose stop` |
||||
|
@ -1,21 +1,32 @@
@@ -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) {} |
||||
|
||||
@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) |
||||
} |
||||
} |
||||
|
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
import { DtoProperty } from 'src/shared' |
||||
|
||||
export class GetUserSessionsParamsDto { |
||||
@DtoProperty() |
||||
userId: number |
||||
} |
@ -1 +1,3 @@
@@ -1 +1,3 @@
|
||||
export * from './get-user-sessions.dto' |
||||
export * from './stop-sessions-params.dto' |
||||
export * from './get-user-sessions-params.dto' |
||||
|
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
import { DtoProperty } from 'src/shared' |
||||
|
||||
export class StopSessionsParamsDto { |
||||
@DtoProperty() |
||||
userId: number |
||||
} |
@ -1,17 +1,19 @@
@@ -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) |
||||
} |
||||
} |
||||
|
@ -1,17 +0,0 @@
@@ -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