{"size": 699, "ext": "js", "max_stars_repo_path": "src/models/authorModel.js", "max_stars_repo_name": "Fercho191/express-graphql-firebase", "max_stars_repo_stars_event_min_datetime": "2018-01-09T22:04:03.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-09T15:34:35.000Z", "max_issues_repo_path": "src/models/authorModel.js", "max_issues_repo_name": "Fercho191/express-graphql-firebase", "max_issues_repo_issues_event_min_datetime": "2018-01-08T14:51:57.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-08T15:47:37.000Z", "max_forks_repo_path": "src/models/authorModel.js", "max_forks_repo_name": "Fercho191/express-graphql-firebase", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 20.5588235294, "max_line_length": 51, "alphanum_fraction": 0.6223175966}
const BaseModel = require("./baseModel");

class AuthorModel extends BaseModel {
  constructor() {
    super("authors", "Author");
  }

  createAuthor(author) {
    let newPushRef = this.ref.push({
      firstName: author.firstName,
      lastName: author.lastName,
      twitterHandle: author.twitterHandle
    });
    return author;
  }

  deleteAuthor(id) {
    this.ref.child(id).set(null, e => {
      if (e) return false;
      else return true;
    });
    return true;
  }

  updateAuthor(author, id) {
    const authorRef = this.ref.child(id);
    return authorRef.once("value", snapshot => {
      if (snapshot.val()) authorRef.update(author);
    });
  }
}

module.exports = AuthorModel;
