All files / src/apis/v2/minis list.ts

100% Statements 4/4
100% Branches 4/4
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                                            3x       3x 1x     2x    
import { Params, Schema, Minis, Mini } from '@/types/v2';
import type { V2 } from '../';
import { MiniUtils } from './utils/map';
 
export type Options<V extends Schema, Ids extends Params.Ids<Mini<V>['id']>> = V2.Options<V, true> & {
  /**
   * The mini ids.
   */
  ids?: 'all' | Ids;
};
 
export type Response<V extends Schema, Ids extends Params.Ids<Mini<V>['id']>> = Ids extends undefined
  ? Minis<V>
  : Mini<V>[];
 
/**
 * Returns a list of minis available in the game.
 */
export async function list<V extends Schema, O extends Schema = V, Ids extends Params.Ids<Mini<O>['id']> = undefined>(
  this: V2.API<V>,
  options?: Options<O, Ids>
) {
  const minis = await this.fetch<Response<V, Ids>>('/v2/minis', {
    params: options,
  });
 
  if (this.config.apply_corrections && MiniUtils.is(minis)) {
    return MiniUtils.correctAll(minis) as Response<V, Ids>;
  }
 
  return minis;
}