fix: config merge

This commit is contained in:
Innei
2021-11-20 17:05:08 +08:00
parent 397bf853f1
commit cf0b3aae18
2 changed files with 4 additions and 2 deletions

View File

@@ -60,8 +60,10 @@ export class UrlDto {
class MailOption {
@IsInt()
@Transform(({ value: val }) => parseInt(val))
@IsOptional()
port: number
@IsUrl({ require_protocol: false })
@IsOptional()
host: string
}
export class MailOptionsDto {

View File

@@ -5,7 +5,7 @@ import {
} from '@nestjs/common'
import { DocumentType, ReturnModelType } from '@typegoose/typegoose'
import { BeAnObject } from '@typegoose/typegoose/lib/types'
import { cloneDeep } from 'lodash'
import { cloneDeep, merge } from 'lodash'
import { LeanDocument } from 'mongoose'
import { InjectModel } from 'nestjs-typegoose'
import { API_VERSION } from '~/app.config'
@@ -121,7 +121,7 @@ export class ConfigsService {
public async patch<T extends keyof IConfig>(key: T, data: IConfig[T]) {
await this.optionModel.updateOne(
{ name: key as string },
{ value: { ...this.config[key], ...data } },
{ value: merge(this.config[key], data) },
{ upsert: true, omitUndefined: true },
)
const newData = (await this.optionModel.findOne({ name: key as string }))