Merge in json representation of settings protos
This commit is contained in:
parent
72ba6e02b1
commit
b62fc8aca8
@ -27,6 +27,7 @@ import {
|
|||||||
UserSettingsProtos,
|
UserSettingsProtos,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { PreloadedUserSettings } from "discord-protos";
|
import { PreloadedUserSettings } from "discord-protos";
|
||||||
|
import { JsonValue } from "@protobuf-ts/runtime";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -167,12 +168,25 @@ async function patchUserSettings(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Updating user settings for user ${userId} with atomic=${atomic}:`, updatedSettings);
|
console.log(
|
||||||
|
`Updating user settings for user ${userId} with atomic=${atomic}:`,
|
||||||
|
updatedSettings,
|
||||||
|
);
|
||||||
|
|
||||||
if (!atomic) {
|
if (!atomic) {
|
||||||
settings = Object.assign(settings, updatedSettings);
|
settings = PreloadedUserSettings.fromJson(
|
||||||
|
Object.assign(
|
||||||
|
PreloadedUserSettings.toJson(settings) as object,
|
||||||
|
PreloadedUserSettings.toJson(updatedSettings) as object,
|
||||||
|
) as JsonValue,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
settings = OrmUtils.mergeDeep(settings, updatedSettings);
|
settings = PreloadedUserSettings.fromJson(
|
||||||
|
OrmUtils.mergeDeep(
|
||||||
|
PreloadedUserSettings.toJson(settings) as object,
|
||||||
|
PreloadedUserSettings.toJson(updatedSettings) as object,
|
||||||
|
) as JsonValue,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
userSettings.userSettings = settings;
|
userSettings.userSettings = settings;
|
||||||
|
|||||||
@ -26,7 +26,8 @@ import {
|
|||||||
SettingsProtoUpdateSchema,
|
SettingsProtoUpdateSchema,
|
||||||
UserSettingsProtos,
|
UserSettingsProtos,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { FrecencyUserSettings } from "discord-protos";
|
import { FrecencyUserSettings, PreloadedUserSettings } from "discord-protos";
|
||||||
|
import { JsonValue } from "@protobuf-ts/runtime";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -103,7 +104,9 @@ router.get(
|
|||||||
const userSettings = await UserSettingsProtos.getOrCreate(req.user_id);
|
const userSettings = await UserSettingsProtos.getOrCreate(req.user_id);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
settings: FrecencyUserSettings.toJson(userSettings.frecencySettings!),
|
settings: FrecencyUserSettings.toJson(
|
||||||
|
userSettings.frecencySettings!,
|
||||||
|
),
|
||||||
} as SettingsProtoJsonResponse);
|
} as SettingsProtoJsonResponse);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -167,12 +170,25 @@ async function patchUserSettings(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Updating frecency settings for user ${userId} with atomic=${atomic}:`, updatedSettings);
|
console.log(
|
||||||
|
`Updating frecency settings for user ${userId} with atomic=${atomic}:`,
|
||||||
|
updatedSettings,
|
||||||
|
);
|
||||||
|
|
||||||
if (!atomic) {
|
if (!atomic) {
|
||||||
settings = Object.assign(settings, updatedSettings);
|
settings = FrecencyUserSettings.fromJson(
|
||||||
|
Object.assign(
|
||||||
|
FrecencyUserSettings.toJson(settings) as object,
|
||||||
|
FrecencyUserSettings.toJson(updatedSettings) as object,
|
||||||
|
) as JsonValue,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
settings = OrmUtils.mergeDeep(settings, updatedSettings);
|
settings = FrecencyUserSettings.fromJson(
|
||||||
|
OrmUtils.mergeDeep(
|
||||||
|
FrecencyUserSettings.toJson(settings) as object,
|
||||||
|
FrecencyUserSettings.toJson(updatedSettings) as object,
|
||||||
|
) as JsonValue,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
userSettings.frecencySettings = settings;
|
userSettings.frecencySettings = settings;
|
||||||
|
|||||||
Reference in New Issue
Block a user