fix(serverless): delete stale built-in function
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -113,14 +113,22 @@ export class ServerlessController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置内建函数
|
||||
* 重置内建函数,过期的内建函数会被删除
|
||||
*/
|
||||
@Delete('/reset/:id')
|
||||
@Auth()
|
||||
async resetBuiltInFunction(@Param('id') id: string) {
|
||||
const builtIn = await this.serverlessService.isBuiltInFunction(id)
|
||||
if (!builtIn) {
|
||||
throw new BadRequestException('can not reset a non-builtin function')
|
||||
// throw new BadRequestException('can not reset a non-builtin function')
|
||||
const snippet = await this.serverlessService.model.findById(id)
|
||||
if (!snippet) {
|
||||
throw new BadRequestException('function not found')
|
||||
}
|
||||
await this.serverlessService.model.deleteOne({
|
||||
_id: id,
|
||||
})
|
||||
return
|
||||
}
|
||||
await this.serverlessService.resetBuiltInFunction(builtIn)
|
||||
|
||||
|
||||
@@ -728,11 +728,7 @@ export class ServerlessService implements OnModuleInit {
|
||||
}
|
||||
|
||||
async isBuiltInFunction(id: string) {
|
||||
const document = await this.model
|
||||
.findOne({
|
||||
_id: id,
|
||||
})
|
||||
.lean()
|
||||
const document = await this.model.findById(id).lean()
|
||||
if (!document) return false
|
||||
const isBuiltin = document.type == SnippetType.Function && document.builtIn
|
||||
return isBuiltin
|
||||
|
||||
Reference in New Issue
Block a user