noobling/anglicare-sprint-week

View on GitHub
app_server/out/controllers_authentication.js.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: controllers/authentication.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: controllers/authentication.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>const mongoose = require('mongoose');

const User = mongoose.model('User');
// This builds a json response
// Generally you should call `return` after this
// function
function sendJSONresponse(res, status, content) {
  res.status(status);
  res.json(content);
}

/**
 * Adds a new user to the database.
 * @param  {Object} req Express request object.
 * @param  {Object} res Express response object.
 */
module.exports.register = (req, res) => {
  if (!req.body.name || !req.body.email || !req.body.password) {
    sendJSONresponse(res, 400, {
      message: 'All fields required',
    });
    return;
  }

  const user = new User();

  user.name = req.body.name;
  user.email = req.body.email;

  user.setPassword(req.body.password);

  user.save((err) => {
    if (err) {
      sendJSONresponse(res, 404, err);
    } else {
      sendJSONresponse(res, 200, { message: 'successs' });
    }
  });
};
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#about">about</a></li><li><a href="global.html#addPhoneToRequest">addPhoneToRequest</a></li><li><a href="global.html#addRequest">addRequest</a></li><li><a href="global.html#addressSchema">addressSchema</a></li><li><a href="global.html#addService">addService</a></li><li><a href="global.html#ageSchema">ageSchema</a></li><li><a href="global.html#bedSchema">bedSchema</a></li><li><a href="global.html#dashboard">dashboard</a></li><li><a href="global.html#email">email</a></li><li><a href="global.html#findService">findService</a></li><li><a href="global.html#findServiceOfAvailability">findServiceOfAvailability</a></li><li><a href="global.html#gracefulShutdown">gracefulShutdown</a></li><li><a href="global.html#hoursSchema">hoursSchema</a></li><li><a href="global.html#index">index</a></li><li><a href="global.html#nexmo">nexmo</a></li><li><a href="global.html#notification">notification</a></li><li><a href="global.html#openCloseSchema">openCloseSchema</a></li><li><a href="global.html#profile">profile</a></li><li><a href="global.html#register">register</a></li><li><a href="global.html#requestSchema">requestSchema</a></li><li><a href="global.html#sendEmail">sendEmail</a></li><li><a href="global.html#sendSMS">sendSMS</a></li><li><a href="global.html#service">service</a></li><li><a href="global.html#serviceSchema">serviceSchema</a></li><li><a href="global.html#showLocation">showLocation</a></li><li><a href="global.html#showLocations">showLocations</a></li><li><a href="global.html#sms">sms</a></li><li><a href="global.html#tagSchema">tagSchema</a></li><li><a href="global.html#transporter">transporter</a></li><li><a href="global.html#userSchema">userSchema</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat Jan 27 2018 15:27:38 GMT+0800 (AWST)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>