import { sql } from 'db' ; export type ISetBuyMenuBody = { pistols : number [ ] ; shotguns : number [ ] ; smgs : number [ ] ; rifles : number [ ] ; snipers : number [ ] ; machineguns : number [ ] ; melees : number [ ] ; equipment : number [ ] ; [ state ] : number [ ] ; } ; /**
 * an user's ingame buy menu
 */ export class InventoryBuyMenu { param userId returns public static async getById ( userId ) { const resRows = await sql < InventoryBuyMenu > `SELECT * FROM inventory_buymenues 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 < InventoryBuyMenu > `INSERT INTO inventory_buymenues(owner_id) VALUES(${ userId }) RETURNING *;` ; if ( res . count !== 1 ) { throw new Error ( 'INSERT query did not return a single row' ) ; } return res [ 0 ] ; } param updatedBuyMenu param userId returns public static async set ( updatedBuyMenu , userId ) { if ( ( await this . getById ( userId ) ) == null ) { return false ; } for ( const key in updatedBuyMenu ) { if ( updatedBuyMenu . hasOwnProperty ( key ) ) { const values = updatedBuyMenu [ key ] ; await sql . unsafe ( `
                    UPDATE inventory_buymenues
                    SET ${ key } = ARRAY[${ values . toString ( ) }]::integer[]
                    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_buymenues
            WHERE owner_id = ${ userId };
        ` ; return true ; } public owner_id : number ; public pistols : number [ ] ; public shotguns : number [ ] ; public smgs : number [ ] ; public rifles : number [ ] ; public snipers : number [ ] ; public machineguns : number [ ] ; public melees : number [ ] ; public equipment : number [ ] ; }