sendou.ink/app/features/sendouq-settings/QSettingsRepository.server.ts
Kalle 7dec8c572e
SendouQ Season 2 changes (#1542)
* Initial

* Saves preferences

* Include TW

* mapModePreferencesToModeList

* mapPoolFromPreferences initial

* Preference to map pool

* Adjust seed

* q.looking tests

* adds about created map preferences to memento in the correct spot (two preferrers)

* Failing test about modes

* Mode preferences to memento

* Remove old Plus Voting code

* Fix seeding

* find match by id via kysely

* View map memento

* Fix up map list generation logic

* Mode memento info

* Future match modes

* Add TODO

* Migration number

* Migrate test DB

* Remove old map pool code

* createGroupFromPrevious new

* Settings styling

* VC to settings

* Weapon pool

* Add TODOs

* Progress

* Adjust mode exclusion policy

* Progress

* Progress

* Progress

* Notes in progress

* Note feedback after submit

* Textarea styling

* Unskip tests

* Note sorting failing test

* Private note in Q

* Ownerpicksmaps later

* New bottom section

* Mobile layout initial

* Add basic match meta

* Tabs initial

* Sticky tab

* Unseen messages in match page

* Front page i18n

* Settings i18n

* Looking 18n

* Chat i18n

* Progress

* Tranfer weapon pools script

* Sticky on match page

* Match page translations

* i18n - tiers page

* Preparing page i18n

* Icon

* Show add note right after report
2023-11-30 20:57:06 +02:00

65 lines
1.5 KiB
TypeScript

import { db } from "~/db/sql";
import type { Tables, UserMapModePreferences } from "~/db/tables";
import type { MainWeaponId } from "~/modules/in-game-lists";
export async function settingsByUserId(userId: number) {
const preferences = await db
.selectFrom("User")
.select([
"User.mapModePreferences",
"User.vc",
"User.languages",
"User.qWeaponPool",
])
.where("id", "=", userId)
.executeTakeFirstOrThrow();
return {
...preferences,
languages: preferences.languages?.split(","),
};
}
export function updateUserMapModePreferences({
userId,
mapModePreferences,
}: {
userId: number;
mapModePreferences: UserMapModePreferences;
}) {
return db
.updateTable("User")
.set({ mapModePreferences: JSON.stringify(mapModePreferences) })
.where("id", "=", userId)
.execute();
}
export function updateVoiceChat(args: {
userId: number;
vc: Tables["User"]["vc"];
languages: string[];
}) {
return db
.updateTable("User")
.set({
vc: args.vc,
languages: args.languages.length > 0 ? args.languages.join(",") : null,
})
.where("User.id", "=", args.userId)
.execute();
}
export function updateSendouQWeaponPool(args: {
userId: number;
weaponPool: MainWeaponId[];
}) {
return db
.updateTable("User")
.set({
qWeaponPool:
args.weaponPool.length > 0 ? JSON.stringify(args.weaponPool) : null,
})
.where("User.id", "=", args.userId)
.execute();
}