fixed settings for real

This commit is contained in:
MasterGordon 2024-10-27 20:01:59 +01:00
parent 51fd7a4a23
commit 86163a61b0
2 changed files with 11 additions and 8 deletions

View File

@ -84,13 +84,16 @@ export const userController = createController({
const settings = await getUserSettings(db, user); const settings = await getUserSettings(db, user);
return settings; return settings;
}), }),
updateSettings: createEndpoint(userSettings, async (input, { db, user }) => { updateSettings: createEndpoint(
if (!user) throw new UnauthorizedError("Unauthorized"); userSettings.partial(),
const settings = await getUserSettings(db, user); async (input, { db, user }) => {
const newSettings = { ...settings, ...input }; if (!user) throw new UnauthorizedError("Unauthorized");
await upsertUserSettings(db, user, input); const settings = await getUserSettings(db, user);
return newSettings; const newSettings = { ...settings, ...input };
}), await upsertUserSettings(db, user, newSettings);
return newSettings;
},
),
getUserCount: createEndpoint(z.null(), async (_, { db }) => { getUserCount: createEndpoint(z.null(), async (_, { db }) => {
const count = await getUserCount(db); const count = await getUserCount(db);
return count; return count;

View File

@ -54,7 +54,7 @@ export const getUser = async (
export const getUserSettings = async ( export const getUserSettings = async (
db: BunSQLiteDatabase, db: BunSQLiteDatabase,
user: string, user: string,
): Promise<UserSettingsType | undefined> => { ): Promise<UserSettingsType> => {
const userSettings = await db const userSettings = await db
.select() .select()
.from(UserSettings) .from(UserSettings)