import { sql } from 'db' ; import { SetupSetParams } from 'utilitites' ; export type ISetCosmeticsBody = { ct_item ? : number ; ter_item ? : number ; head_item ? : number ; glove_item ? : number ; back_item ? : number ; steps_item ? : number ; card_item ? : number ; spray_item ? : number ; } ; /**
 * stores an user's equipped cosmetic items
 */ export class InventoryCosmetics { param userId returns public static async getById ( userId ) { const resRows = await sql < InventoryCosmetics > `SELECT * FROM inventory_cosmetics WHERE owner_id = ${ userId };` ; if ( resRows . count === 0 ) { return null ; } else if ( resRows . count === 1 ) { return resRows [ 0 ] ; } else { throw new Error ( 'getById: got more than one row for an inventory' ) ; } } param userId returns public static async create ( userId ) { const res = await sql < InventoryCosmetics > `
            INSERT INTO inventory_cosmetics(owner_id) VALUES(${ userId }) RETURNING *;` ; if ( res . count !== 1 ) { throw new Error ( 'INSERT query did not return a single row' ) ; } return res [ 0 ] ; } param updatedCosmetics param userId returns public static async set ( updatedCosmetics , userId ) { if ( ( await this . getById ( userId ) ) == null ) { return false ; } await sql `
            UPDATE inventory_cosmetics
            SET ${ sql ( updatedCosmetics , ... SetupSetParams ( updatedCosmetics ) ) }
            WHERE owner_id = ${ userId };
        ` ; return true ; } param userId returns public static async remove ( userId ) { if ( ( await this . getById ( userId ) ) == null ) { return false ; } await sql `
            DELETE FROM inventory_cosmetics
            WHERE owner_id = ${ userId };
        ` ; return true ; } public owner_id : number ; public ct_item : number ; public ter_item : number ; public head_item : number ; public glove_item : number ; public back_item : number ; public steps_item : number ; public card_item : number ; public spray_item : number ; }