修复更新环境变量

This commit is contained in:
whyour 2025-01-11 17:14:30 +08:00
parent 647ed3b66c
commit e5b35273f9
3 changed files with 10 additions and 4 deletions

View File

@ -20,7 +20,7 @@ export class Env {
this.timestamp = new Date().toString(); this.timestamp = new Date().toString();
this.position = options.position; this.position = options.position;
this.name = options.name; this.name = options.name;
this.remarks = options.remarks; this.remarks = options.remarks || '';
} }
} }

View File

@ -21,6 +21,7 @@ import {
} from '../protos/api'; } from '../protos/api';
import LoggerInstance from '../loaders/logger'; import LoggerInstance from '../loaders/logger';
import NotificationService from '../services/notify'; import NotificationService from '../services/notify';
import pick from 'lodash/pick';
Container.set('logger', LoggerInstance); Container.set('logger', LoggerInstance);
@ -63,7 +64,9 @@ export const updateEnv = async (
) => { ) => {
try { try {
const envService = Container.get(EnvService); 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 }); callback(null, { code: 200, data });
} catch (e: any) { } catch (e: any) {
callback(e); callback(e);
@ -148,7 +151,10 @@ export const getEnvById = async (
try { try {
const envService = Container.get(EnvService); const envService = Container.get(EnvService);
const data = await envService.getDb({ id: call.request.id }); 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) { } catch (e: any) {
callback(e); callback(e);
} }

View File

@ -41,7 +41,7 @@ export default class EnvService {
} }
public async insert(payloads: Env[]): Promise<Env[]> { public async insert(payloads: Env[]): Promise<Env[]> {
const result = []; const result: Env[] = [];
for (const env of payloads) { for (const env of payloads) {
const doc = await EnvModel.create(env, { returning: true }); const doc = await EnvModel.create(env, { returning: true });
result.push(doc); result.push(doc);