fix(serverless): delete stale built-in function

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2023-05-25 22:12:20 +08:00
parent 96604b6e70
commit 83d8eed681
2 changed files with 11 additions and 7 deletions

View File

@@ -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)

View File

@@ -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