{"size": 885, "ext": "js", "max_stars_repo_path": "lib/daos/cabsDao.js", "max_stars_repo_name": "vivek-wednesday/nodejshapi", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/daos/cabsDao.js", "max_issues_repo_name": "vivek-wednesday/nodejshapi", "max_issues_repo_issues_event_min_datetime": "2021-09-21T11:33:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-24T12:02:22.000Z", "max_forks_repo_path": "lib/daos/cabsDao.js", "max_forks_repo_name": "vivek-wednesday/cab-booking-nodejs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 25.2857142857, "max_line_length": 79, "alphanum_fraction": 0.5875706215}
import { cabs } from 'models';
import { convertDbResponseToRawResponse } from 'utils/transformerUtils';

const attributes = ['id', 'driver_id', 'cab_type', 'cab_model', 'cab_license'];

export const findOneCab = async cabId =>
    cabs.findOne({
        attributes,
        where: {
            cabId
        },
        underscoredAll: false
    });

export const findAllCabs = async limit => {
    const where = {};
    const totalCount = await cabs.count({ where });
    const allCabs = await cabs.findAll({
        attributes,
        where,
        limit
    });
    return { allCabs, totalCount };
};

export const addCab = async (driverId, cabModel, cabType, cabLicense) =>
    await cabs
        .create({
            driverId,
            cabModel,
            cabType,
            cabLicense
        })
        .then(cabDetails => convertDbResponseToRawResponse(cabDetails));
