Skip to content

Commit 37c049c

Browse files
authored
fix(server): fix compile function api params schema error (#540)
1 parent 3a2669e commit 37c049c

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApiProperty } from '@nestjs/swagger'
2+
import { IsNotEmpty } from 'class-validator'
3+
4+
export class CompileFunctionDto {
5+
@ApiProperty({
6+
description: 'The source code of the function',
7+
})
8+
@IsNotEmpty()
9+
code: string
10+
}

server/src/function/function.controller.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { JwtAuthGuard } from '../auth/jwt.auth.guard'
2424
import { ApplicationAuthGuard } from '../auth/application.auth.guard'
2525
import { FunctionService } from './function.service'
2626
import { IRequest } from '../utils/types'
27+
import { CompileFunctionDto } from './dto/compile-function.dto.ts'
2728

2829
@ApiTags('Function')
2930
@ApiBearerAuth('Authorization')
@@ -154,13 +155,21 @@ export class FunctionController {
154155
@ApiOperation({ summary: 'Compile a function ' })
155156
@UseGuards(JwtAuthGuard, ApplicationAuthGuard)
156157
@Post(':name/compile')
157-
async compile(@Param('appid') appid: string, @Param('name') name: string) {
158+
async compile(
159+
@Param('appid') appid: string,
160+
@Param('name') name: string,
161+
@Body() dto: CompileFunctionDto,
162+
) {
163+
if (!dto.code) {
164+
return ResponseUtil.error('code is required')
165+
}
166+
158167
const func = await this.functionsService.findOne(appid, name)
159168
if (!func) {
160169
throw new HttpException('function not found', HttpStatus.NOT_FOUND)
161170
}
162171

163-
const res = this.functionsService.compile(func)
172+
const res = await this.functionsService.compile(func, dto)
164173
return res
165174
}
166175
}

server/src/function/function.service.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { CreateFunctionDto } from './dto/create-function.dto'
1212
import { UpdateFunctionDto } from './dto/update-function.dto'
1313
import * as assert from 'node:assert'
1414
import { JwtService } from '@nestjs/jwt'
15+
import { CompileFunctionDto } from './dto/compile-function.dto.ts'
1516

1617
@Injectable()
1718
export class FunctionService {
@@ -108,10 +109,18 @@ export class FunctionService {
108109
}
109110
}
110111

111-
compile(func: CloudFunction) {
112-
const code = func.source.code
113-
func.source.compiled = compileTs2js(code)
114-
return func
112+
async compile(func: CloudFunction, dto: CompileFunctionDto) {
113+
const data: CloudFunction = {
114+
...func,
115+
source: {
116+
...func.source,
117+
code: dto.code,
118+
compiled: compileTs2js(dto.code),
119+
version: func.source.version + 1,
120+
},
121+
updatedAt: new Date(),
122+
}
123+
return data
115124
}
116125

117126
async getDebugFunctionToken(appid: string) {
@@ -135,7 +144,7 @@ export class FunctionService {
135144
return token
136145
}
137146

138-
async findLogs(
147+
async getLogs(
139148
appid: string,
140149
params: {
141150
page: number
@@ -151,7 +160,7 @@ export class FunctionService {
151160
const coll = db.collection(CN_FUNCTION_LOGS)
152161
const query: any = {}
153162
if (requestId) {
154-
query.requestId = requestId
163+
query.request_id = requestId
155164
}
156165
if (functionName) {
157166
query.func = functionName

server/src/log/log.controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class LogController {
7070
page = page || 1
7171
limit = limit || 10
7272

73-
const res = await this.funcService.findLogs(appid, {
73+
const res = await this.funcService.getLogs(appid, {
7474
requestId,
7575
functionName,
7676
limit,

0 commit comments

Comments
 (0)