on auth token

This commit is contained in:
vigdorov
2020-08-04 22:46:33 +03:00
parent 5919ba92f1
commit cb67c430cd
4 changed files with 51 additions and 9 deletions

View File

@ -18,6 +18,7 @@ import {
REMOVE_SUCCESS,
REMOVE_NOT_FOUND,
} from './store.responses';
import {AuthService} from 'src/services/auth.service';
const prepareStoreToStoreRequest = ({
key, value, description, service_name, author
@ -35,13 +36,17 @@ const makeApiHeader = (request: Request): string => {
@ApiTags(COLLECTION_STORE)
export class StoreController {
constructor(
private readonly storeService: StoreService
private readonly storeService: StoreService,
private readonly authService: AuthService,
) {}
@Get()
@Header(...ALLOW_ORIGIN_ALL)
@ApiResponse(FIND_ALL_SUCCESS)
async findAll(@Req() request: Request): Promise<StoreRequest[]> {
await this.authService.checkRequest(request);
const api = makeApiHeader(request);
const storeList = await this.storeService.findAll(api);
return storeList.map(prepareStoreToStoreRequest);
@ -56,6 +61,8 @@ export class StoreController {
description: 'Ключ для поиска хранилища',
})
async findOne(@Req() request: Request<{key: string}>): Promise<StoreRequest> {
await this.authService.checkRequest(request);
const {key} = request.params;
const api = makeApiHeader(request);
const store = await this.storeService.findOne(api, key);