{"size": 870, "ext": "js", "max_stars_repo_path": "back/models/Adventure.js", "max_stars_repo_name": "UIC-CS484/assignment-2---final-project-repository-team-2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "back/models/Adventure.js", "max_issues_repo_name": "UIC-CS484/assignment-2---final-project-repository-team-2", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "back/models/Adventure.js", "max_forks_repo_name": "UIC-CS484/assignment-2---final-project-repository-team-2", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.1666666667, "max_line_length": 64, "alphanum_fraction": 0.7114942529}
const crypto = require("crypto");
const { DBConfig, runQ, fatherQ, getQ } = require("../DB");

const Adventure = {
    assignAdventure,
    getAdventureByHero,
    deleteAdventureByHero
}


// Auth Model
async function assignAdventure(hero_id, timestamp) {
    // get insert from queries
    const { insert } = DBConfig.adventures.queries;

    // create adventure for a given hero_id
    const res = fatherQ(await runQ(insert(hero_id, timestamp)));

    return res.success;
}

async function getAdventureByHero(hero_id) {
    const { getByHeroId } = DBConfig.adventures.queries;
    const qRes = await getQ(getByHeroId(hero_id));

    return qRes;
}

async function deleteAdventureByHero(hero_id) {
    const { deleteByHeroId } = DBConfig.adventures.queries;
    const qRes = await runQ(deleteByHeroId(hero_id));

    return qRes.success;
}

module.exports = Adventure;