From 829fd8a0169702e0c4f9491bf2241b8327582579 Mon Sep 17 00:00:00 2001 From: 0fatal <72899968+0fatal@users.noreply.github.com> Date: Tue, 9 Jan 2024 11:30:31 +0800 Subject: [PATCH] feat(server): support function history changelog (#1756) * feat(server): support function history changelog --- server/src/function/dto/update-function.dto.ts | 4 ++++ server/src/function/entities/cloud-function-history.ts | 3 +++ server/src/function/function.service.ts | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/function/dto/update-function.dto.ts b/server/src/function/dto/update-function.dto.ts index b90a4f4339..32313c293a 100644 --- a/server/src/function/dto/update-function.dto.ts +++ b/server/src/function/dto/update-function.dto.ts @@ -40,6 +40,10 @@ export class UpdateFunctionDto { @IsNotEmpty({ each: true }) tags: string[] + @ApiPropertyOptional() + @MaxLength(256) + changelog?: string + validate() { return null } diff --git a/server/src/function/entities/cloud-function-history.ts b/server/src/function/entities/cloud-function-history.ts index 715622213f..f186183d0b 100644 --- a/server/src/function/entities/cloud-function-history.ts +++ b/server/src/function/entities/cloud-function-history.ts @@ -19,6 +19,9 @@ export class CloudFunctionHistory { @ApiProperty({ type: CloudFunctionHistorySource }) source: CloudFunctionHistorySource + @ApiProperty({ type: String }) + changelog?: string + @ApiProperty() createdAt: Date } diff --git a/server/src/function/function.service.ts b/server/src/function/function.service.ts index 5213416bbc..2cd2cc9588 100644 --- a/server/src/function/function.service.ts +++ b/server/src/function/function.service.ts @@ -59,7 +59,7 @@ export class FunctionService { const fn = await this.findOne(appid, dto.name) - await this.addOneHistoryRecord(fn) + await this.addOneHistoryRecord(fn, 'created') await this.publish(fn) return fn } @@ -175,7 +175,7 @@ export class FunctionService { ) const fn = await this.findOne(func.appid, func.name) - await this.addOneHistoryRecord(fn) + await this.addOneHistoryRecord(fn, dto.changelog) await this.publish(fn) return fn @@ -414,7 +414,7 @@ export class FunctionService { return history } - async addOneHistoryRecord(func: CloudFunction) { + async addOneHistoryRecord(func: CloudFunction, changelog = '') { await this.db .collection('CloudFunctionHistory') .insertOne({ @@ -424,6 +424,7 @@ export class FunctionService { code: func.source.code, }, createdAt: new Date(), + changelog, }) }