From e5b35273f992f2e61dc31b8568c0220257e03444 Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 11 Jan 2025 17:14:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/env.ts | 2 +- back/schedule/api.ts | 10 ++++++++-- back/services/env.ts | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/back/data/env.ts b/back/data/env.ts index 965c826a..f6a9094e 100644 --- a/back/data/env.ts +++ b/back/data/env.ts @@ -20,7 +20,7 @@ export class Env { this.timestamp = new Date().toString(); this.position = options.position; this.name = options.name; - this.remarks = options.remarks; + this.remarks = options.remarks || ''; } } diff --git a/back/schedule/api.ts b/back/schedule/api.ts index a586ee27..9402359a 100644 --- a/back/schedule/api.ts +++ b/back/schedule/api.ts @@ -21,6 +21,7 @@ import { } from '../protos/api'; import LoggerInstance from '../loaders/logger'; import NotificationService from '../services/notify'; +import pick from 'lodash/pick'; Container.set('logger', LoggerInstance); @@ -63,7 +64,9 @@ export const updateEnv = async ( ) => { try { const envService = Container.get(EnvService); - const data = await envService.update(call.request.env as EnvItem); + const data = await envService.update( + pick(call.request.env, ['id', 'name', 'value', 'remark']) as EnvItem, + ); callback(null, { code: 200, data }); } catch (e: any) { callback(e); @@ -148,7 +151,10 @@ export const getEnvById = async ( try { const envService = Container.get(EnvService); const data = await envService.getDb({ id: call.request.id }); - callback(null, { code: 200, data }); + callback(null, { + code: 200, + data: { ...data, remarks: data.remarks || '' }, + }); } catch (e: any) { callback(e); } diff --git a/back/services/env.ts b/back/services/env.ts index bb38e559..be89cc86 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -41,7 +41,7 @@ export default class EnvService { } public async insert(payloads: Env[]): Promise { - const result = []; + const result: Env[] = []; for (const env of payloads) { const doc = await EnvModel.create(env, { returning: true }); result.push(doc);