fix(serverless): add condition on query
This commit is contained in:
@@ -14,6 +14,7 @@ import { Auth } from '~/common/decorator/auth.decorator'
|
||||
import { HTTPDecorators } from '~/common/decorator/http.decorator'
|
||||
import { ApiName } from '~/common/decorator/openapi.decorator'
|
||||
import { IsMaster } from '~/common/decorator/role.decorator'
|
||||
import { SnippetType } from '../snippet/snippet.model'
|
||||
import { createMockedContextResponse } from './mock-response.util'
|
||||
import { ServerlessReferenceDto } from './serverless.dto'
|
||||
import { ServerlessService } from './serverless.service'
|
||||
@@ -66,6 +67,7 @@ export class ServerlessController {
|
||||
const snippet = await this.serverlessService.model.findOne({
|
||||
name,
|
||||
reference,
|
||||
type: SnippetType.Function,
|
||||
})
|
||||
|
||||
if (!snippet) {
|
||||
@@ -75,6 +77,7 @@ export class ServerlessController {
|
||||
if (snippet.private && !isMaster) {
|
||||
throw new ForbiddenException('no permission to run this function')
|
||||
}
|
||||
|
||||
const result =
|
||||
await this.serverlessService.injectContextIntoServerlessFunctionAndCall(
|
||||
snippet,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
@@ -89,12 +88,6 @@ export class SnippetController {
|
||||
if (snippet.type !== SnippetType.Function) {
|
||||
return this.snippetService.attachSnippet(snippet).then((res) => res.data)
|
||||
}
|
||||
|
||||
if (snippet.type === SnippetType.Function) {
|
||||
throw new BadRequestException(
|
||||
'this snippet should run in serverless function scope',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
|
||||
@@ -98,7 +98,9 @@ export class SnippetService {
|
||||
* @returns
|
||||
*/
|
||||
async getSnippetByName(name: string, reference: string) {
|
||||
const doc = await this.model.findOne({ name, reference }).lean()
|
||||
const doc = await this.model
|
||||
.findOne({ name, reference, type: { $ne: SnippetType.Function } })
|
||||
.lean()
|
||||
if (!doc) {
|
||||
throw new NotFoundException('snippet is not found')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user