diff options
| author | Fuwn <[email protected]> | 2026-03-01 16:20:51 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-01 16:21:02 -0800 |
| commit | eae5d24d9e79e59a19d4721caaeaa0ca650ecb33 (patch) | |
| tree | 1b685bb248e051dfa26d2bfdebe6689402dd93c5 /src/lib/Database/SB/User/configuration.ts | |
| parent | chore(tooling): remove legacy eslint and prettier (diff) | |
| download | due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.tar.xz due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.zip | |
chore(biome): drop formatter style overrides
Diffstat (limited to 'src/lib/Database/SB/User/configuration.ts')
| -rw-r--r-- | src/lib/Database/SB/User/configuration.ts | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/src/lib/Database/SB/User/configuration.ts b/src/lib/Database/SB/User/configuration.ts index ab1373da..6007e41b 100644 --- a/src/lib/Database/SB/User/configuration.ts +++ b/src/lib/Database/SB/User/configuration.ts @@ -1,47 +1,56 @@ -import sb from '../../sb'; +import sb from "../../sb"; interface UserConfiguration { - user_id: number; - configuration: object; - created_at: string; - updated_at: string; + user_id: number; + configuration: object; + created_at: string; + updated_at: string; } interface NewUserConfiguration { - configuration: object; - updated_at?: string; + configuration: object; + updated_at?: string; } export const getUserConfiguration = async (userId: number) => { - const { data, error } = await sb.from('user_configuration').select('*').eq('user_id', userId); + const { data, error } = await sb + .from("user_configuration") + .select("*") + .eq("user_id", userId); - if (error || data.length === 0 || data[0].user_id !== userId) return null; + if (error || data.length === 0 || data[0].user_id !== userId) return null; - return data[0] as UserConfiguration; + return data[0] as UserConfiguration; }; -export const setUserConfiguration = async (userId: number, configuration: NewUserConfiguration) => { - const { data, error } = await sb - .from('user_configuration') - .upsert( - { - user_id: userId, - configuration: configuration.configuration, - updated_at: configuration.updated_at || new Date().toISOString() - }, - { onConflict: 'user_id' } - ) - .select(); - - if (error || !data || (data as []).length === 0) return null; - - return data[0].configuration as UserConfiguration; +export const setUserConfiguration = async ( + userId: number, + configuration: NewUserConfiguration, +) => { + const { data, error } = await sb + .from("user_configuration") + .upsert( + { + user_id: userId, + configuration: configuration.configuration, + updated_at: configuration.updated_at || new Date().toISOString(), + }, + { onConflict: "user_id" }, + ) + .select(); + + if (error || !data || (data as []).length === 0) return null; + + return data[0].configuration as UserConfiguration; }; export const deleteUserConfiguration = async (userId: number) => { - const { data, error } = await sb.from('user_configuration').delete().eq('user_id', userId); + const { data, error } = await sb + .from("user_configuration") + .delete() + .eq("user_id", userId); - if (error || !data) return null; + if (error || !data) return null; - return data; + return data; }; |