add users point
This commit is contained in:
@ -25,6 +25,13 @@ export const GET_IMAGE_LIST_SUCCESS: ApiResponseOptions = {
|
|||||||
isArray: true
|
isArray: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const GET_USER_LIST_SUCCESS: ApiResponseOptions = {
|
||||||
|
status: 200,
|
||||||
|
description: 'Список всех пользователей',
|
||||||
|
type: String,
|
||||||
|
isArray: true
|
||||||
|
};
|
||||||
|
|
||||||
export const MANIPULATE_IMAGE_SUCCESS: ApiResponseOptions = {
|
export const MANIPULATE_IMAGE_SUCCESS: ApiResponseOptions = {
|
||||||
status: 200,
|
status: 200,
|
||||||
description: 'Картинка',
|
description: 'Картинка',
|
||||||
|
|||||||
@ -2,10 +2,10 @@ import {Controller, Delete, Get, Header, HttpCode, Options, Post, Put, Req} from
|
|||||||
import {AppService} from './app.service';
|
import {AppService} from './app.service';
|
||||||
import {AuthRequest, ImageCreateRequest} from './schemas';
|
import {AuthRequest, ImageCreateRequest} from './schemas';
|
||||||
import {Request} from 'express';
|
import {Request} from 'express';
|
||||||
import {ApiBody, ApiParam, ApiResponse, ApiSecurity, ApiTags} from '@nestjs/swagger';
|
import {ApiBody, ApiParam, ApiQuery, ApiResponse, ApiSecurity, ApiTags} from '@nestjs/swagger';
|
||||||
import {Image, ImageCreate} from './types';
|
import {Image, ImageCreate} from './types';
|
||||||
import {ALLOW_CREDENTIALS, ALLOW_HEADERS, ALLOW_METHOD, ALLOW_ORIGIN_ALL, CONTENT_LENGTH} from './consts';
|
import {ALLOW_CREDENTIALS, ALLOW_HEADERS, ALLOW_METHOD, ALLOW_ORIGIN_ALL, CONTENT_LENGTH} from './consts';
|
||||||
import {AUTH_ERROR, AUTH_SUCCESS, GET_IMAGE_LIST_SUCCESS, MANIPULATE_IMAGE_SUCCESS} from './api.responses';
|
import {AUTH_ERROR, AUTH_SUCCESS, GET_IMAGE_LIST_SUCCESS, GET_USER_LIST_SUCCESS, MANIPULATE_IMAGE_SUCCESS} from './api.responses';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@ApiTags('image-app')
|
@ApiTags('image-app')
|
||||||
@ -37,6 +37,23 @@ export class AppController {
|
|||||||
return this.appService.getImageList();
|
return this.appService.getImageList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/users')
|
||||||
|
@ApiSecurity('apiKey')
|
||||||
|
@Header(...ALLOW_ORIGIN_ALL)
|
||||||
|
@ApiQuery({
|
||||||
|
name: 'login',
|
||||||
|
description: 'Часть логина пользователя',
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
@ApiResponse(GET_USER_LIST_SUCCESS)
|
||||||
|
@ApiResponse(AUTH_ERROR)
|
||||||
|
async getUserList(
|
||||||
|
@Req() request: Request<null, null, null, {login?: string}>
|
||||||
|
): Promise<string[]> {
|
||||||
|
await this.appService.checkRequest(request.headers.authorization);
|
||||||
|
return this.appService.getUserList(request.query.login ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
@Get('/list/:id')
|
@Get('/list/:id')
|
||||||
@ApiSecurity('apiKey')
|
@ApiSecurity('apiKey')
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
|
|||||||
@ -34,6 +34,16 @@ export class AppService {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getUserList(searchLogin: string): Promise<string[]> {
|
||||||
|
const authorList = await this.authorModel.find().exec();
|
||||||
|
return authorList.reduce((acc, {login}) => {
|
||||||
|
if (login.includes(searchLogin)) {
|
||||||
|
acc.push(login);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
async authUser(login: string): Promise<string> {
|
async authUser(login: string): Promise<string> {
|
||||||
const authorList = await this.authorModel.find().exec();
|
const authorList = await this.authorModel.find().exec();
|
||||||
const searchAuthor = authorList.find((author) => author.login === login);
|
const searchAuthor = authorList.find((author) => author.login === login);
|
||||||
|
|||||||
Reference in New Issue
Block a user