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