use null for unsetting instead of empty string
This commit is contained in:
1 parent
6404a06999
commit
48e71d4345
5 files changed
+20
-16
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import mongoose from "mongoose";
|
||||
import { ISettingsRepository } from "@/repositories/settings/ISettingsRepository.js";
|
||||
import type { Settings } from "@/types/index.js";
|
||||
import type { Settings, SettingsUpdate } from "@/types/index.js";
|
||||
import { AppSettingsModel, type AppSettingsDocument } from "@/db/models/index.js";
|
||||
|
||||
class MongoSettingsRepository implements ISettingsRepository {
|
||||
@@ -59,12 +59,12 @@ class MongoSettingsRepository implements ISettingsRepository {
|
||||
return this.toEntity(settings);
|
||||
};
|
||||
|
||||
update = async (settings: Partial<Settings>) => {
|
||||
update = async (settings: SettingsUpdate) => {
|
||||
const update: Record<string, any> = { $set: {}, $unset: {} };
|
||||
|
||||
// Iterate through settings and separate into $set and $unset
|
||||
Object.entries(settings).forEach(([key, value]) => {
|
||||
if (value === undefined || value === "") {
|
||||
if (value === undefined || value === null) {
|
||||
// Unset undefined or empty string values
|
||||
update.$unset[key] = "";
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user