Исправлена ошибка изза которой не было доступа по хуку
This commit is contained in:
@ -2,14 +2,12 @@
|
||||
GET http://localhost:4001/store HTTP/1.1
|
||||
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpbiI6InZpZ2Rvcm92IiwiYWdlbnQiOiJ2c2NvZGUtcmVzdGNsaWVudCIsImlhdCI6MTU5OTQ5OTYyMSwiZXhwIjoxNTk5NDk5OTIxfQ.Ym4xOpoe8UvO626Vxp-XqxspoJSL7JpjZ1rlSW0vIWs
|
||||
|
||||
|
||||
###
|
||||
GET http://localhost:4001/store/rgfdfff HTTP/1.1
|
||||
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpbiI6InZpZ2Rvcm92IiwiYWdlbnQiOiJ2c2NvZGUtcmVzdGNsaWVudCIsImlhdCI6MTU5OTQ5OTYyMSwiZXhwIjoxNTk5NDk5OTIxfQ.Ym4xOpoe8UvO626Vxp-XqxspoJSL7JpjZ1rlSW0vIWs
|
||||
|
||||
|
||||
###
|
||||
GET http://localhost:4001/store/rgfdfff?hook=sdf6sdfhs99-sdf HTTP/1.1
|
||||
GET http://localhost:4001/store/testAp2?hook=c8d5f28b-4460-47b9-9369-01caf4951846 HTTP/1.1
|
||||
|
||||
###
|
||||
POST http://localhost:4001/store HTTP/1.1
|
||||
@ -28,14 +26,15 @@ Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpbiI6InZpZ2Rvcm92Iiwi
|
||||
}
|
||||
|
||||
### Update Request
|
||||
PUT http://localhost:4001/store HTTP/1.1
|
||||
PUT http://localhost:4001/store?hook=c8d5f28b-4460-47b9-9369-01caf4951846 HTTP/1.1
|
||||
content-type: application/json
|
||||
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpbiI6ImFkbWluIiwiYWdlbnQiOiJ2c2NvZGUtcmVzdGNsaWVudCIsImlhdCI6MTU5OTQ5OTAxNCwiZXhwIjoxNTk5NDk5MzE0fQ.kpW1KPVGQvI7iZ1-EhyeO5MAGbo4clpQ0J-ategIf2w
|
||||
|
||||
{
|
||||
"key": "testAp",
|
||||
"key": "testAp2",
|
||||
"value": {
|
||||
|
||||
"test": 45,
|
||||
"test2": 33,
|
||||
"test3": 13
|
||||
},
|
||||
"description": "тестовое апи22",
|
||||
"service_name": "test-api",
|
||||
|
||||
@ -71,7 +71,7 @@ export class StoreController {
|
||||
await this.authService.checkRequest(request);
|
||||
}
|
||||
|
||||
const store = await this.storeService.findOneStore(api, key, request.headers.authorization);
|
||||
const store = await this.storeService.findOneStore(api, key, isActualHook, request.headers.authorization);
|
||||
return prepareStoreToStoreRequest(store);
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ export class StoreController {
|
||||
await this.authService.checkRequest(request);
|
||||
}
|
||||
|
||||
const store = await this.storeService.update(api, request.body, request.headers.authorization);
|
||||
const store = await this.storeService.update(api, request.body, isActualHook, request.headers.authorization);
|
||||
return prepareStoreToStoreRequest(store);
|
||||
}
|
||||
|
||||
|
||||
@ -134,15 +134,17 @@ export class StoreService {
|
||||
|
||||
}
|
||||
|
||||
async update(api: string, {author, ...omitProps}: StoreRequest, access_token: string): Promise<Store> {
|
||||
async update(api: string, {author, ...omitProps}: StoreRequest, isActualHook: boolean, access_token: string): Promise<Store> {
|
||||
const searchStore = await this.findOne(api, omitProps.key);
|
||||
|
||||
if (searchStore) {
|
||||
if (!isActualHook) {
|
||||
const user = await this.loadUserByToken(access_token);
|
||||
|
||||
if (!user.is_admin && user.login !== searchStore.author) {
|
||||
throw new NotFoundException(`Not found api key "${omitProps.key}"`);
|
||||
}
|
||||
}
|
||||
|
||||
const store = {
|
||||
...omitProps,
|
||||
@ -177,8 +179,11 @@ export class StoreService {
|
||||
return searchStore;
|
||||
}
|
||||
|
||||
async findOneStore(api: string, key: string, access_token: string): Promise<Store> {
|
||||
async findOneStore(api: string, key: string, isActualHook: boolean, access_token: string): Promise<Store> {
|
||||
const store = await this.findOne(api, key);
|
||||
if (isActualHook) {
|
||||
return store;
|
||||
}
|
||||
const user = await this.loadUserByToken(access_token);
|
||||
if (user.is_admin || user.login === store.author || !store.hide) {
|
||||
return store;
|
||||
|
||||
Reference in New Issue
Block a user