BuildRepository
app/features/builds/BuildRepository.server.ts- Tables
- BuildBuildAbilitySumBuildWeaponBuildWeaponAbilityPlusTierSplatoonPlayerUserUserSubmittedImageXRankPlacement
- Calls
- no other repositories
- Imports
- no other modules
- Used by
- 5 loaders2 actions1 repository2 scripts6 other
Functions & values
export async function findAllByUserId( userId: number, options: { showPrivate?: boolean; sortAbilities?: boolean; limit?: number; } = {}, )
export async function insert(args: CreateArgs)
export async function update(args: CreateArgs & { id: number })
export async function findOwnerIdById(buildId: number)
Ability point sums of every public build updated after the date (YYYY-MM-DD, all when null), a build counted once however many weapons it lists.
export async function findAllAbilityPointSums(updatedSince: string | null)
Unit tests (2)
For each of the weapons (alt skins folded), how many public builds updated after the date (YYYY-MM-DD, all when null) run each amount of AP of each ability, plus their build counts.
export async function findAbilityPointCountsByWeaponIds({ weaponIds, updatedSince, }: { weaponIds: MainWeaponId[]; updatedSince: string | null; })
Unit tests (2)
The newest public build of each owner listing the weapon (alt skins folded), if updated after the date (YYYY-MM-DD, any time when null).
export async function findNewestBuildPerOwnerByWeaponId({ weaponId, updatedSince, }: { weaponId: MainWeaponId; updatedSince: string | null; })
Unit tests (4)
A page of the authors of public builds listing the weapon (alt skins folded) that match the filters, with all of their matching builds. Authors rank by their best ranked build and their builds come together, best first. buildCount counts every matching build but only while filtering (null otherwise, as it would cost an extra read).
export async function findPageByWeaponId({ weaponId, filters, page, sortAbilities: shouldSortAbilities, }: { weaponId: MainWeaponId; filters: BuildListFilters; page: number; sortAbilities: boolean; })
Unit tests (8)
A page of the user's builds matching the filters, in their chosen sort order.
export async function findPageByUserId({ userId, showPrivate, filters, sorting, page, sortAbilities: shouldSortAbilities, }: { userId: number; showPrivate: boolean; filters: BuildListFilters & { /** Exact weapon id, alt skins and kits not folded. */ weaponId: MainWeaponId | null; visibility: "PUBLIC" | "PRIVATE" | null; }; sorting: { buildSorting: BuildSort[] | null; weaponPool: MainWeaponId[]; }; page: number; sortAbilities: boolean; })
Unit tests (17)
- hides private builds unless asked to show them
- filters
- returns a page of builds and the total count
- grants the owner edit permission
- sorting › sorts
- by UPDATED_AT, newest first
- by ALPHABETICAL_TITLE ignoring case
- by WEAPON_POOL, kits of a pool weapon counting as it and builds without pool weapons last
- by WEAPON_IN_GAME_ORDER using the build's lowest weapon id
- by MODE in mode order, builds without modes last
- by TOP_500
- by HEADGEAR_ID, builds without one last
- by $sort× 2
- by weapon pool, then newest first, when the user hasn't chosen
- sorting › breaks ties with the next sort
How many builds the user has, how many of them are private and the count per (exact) weapon id.
export async function countsByUserId( userId: number, { showPrivate }: { showPrivate: boolean }, )
Unit tests (2)
Public build count per canonical weapon id (alt skins folded), weapons without builds omitted.
export async function countAllPublicByWeaponId()
Recomputes BuildWeapon.sortValue (plus tier + per-weapon top500), for one user's builds if given.
export async function recalculateAllSortValues( userId?: number, trx?: Transaction<DB>, )
Unit tests not about one export (16)
- BuildRepository.insert — computeBuildData › abilitiesSignature
- & ability sums › writes the serialized abilitiesSignature sorted by AP desc
- & ability sums › inserts one BuildAbilitySum row per distinct ability with summed AP
- & ability sums › agrees with the analyzer's AP calculation for Ability Doubler builds
- & ability sums › does not insert BuildAbilitySum rows for private builds
- & ability sums › still writes abilitiesSignature for private builds
- BuildRepository.insert — computeBuildData › BuildWeaponAbility
- BuildRepository.insert — computeBuildData › BuildWeapon.canonicalWeaponSplId › stores the canonical id alongside the original weaponSplId
- BuildRepository.insert — computeBuildData › sortValue
- BuildRepository.insert — computeBuildData › findPageByWeaponId.weapons[].isTop500 matches the sortValue formula
- BuildRepository.insert — computeBuildData › a multi-weapon build is returned by findPageByWeaponId for each of its weapons
Not shown, only used by tests: BuildListFilters