@magic.batua/account
Version:
The Account modules powers the user account management features of the Magic Batua platform.
1,559 lines (542 loc) • 23.5 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>Database - Postman Documentation</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/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Account.html">Account</a><ul class='methods'><li data-type='method'><a href="Account.html#AddPoints">AddPoints</a></li><li data-type='method'><a href="Account.html#AddReferral">AddReferral</a></li><li data-type='method'><a href="Account.html#CanAuthenticateUsing">CanAuthenticateUsing</a></li><li data-type='method'><a href="Account.html#Delete">Delete</a></li><li data-type='method'><a href="Account.html#Export">Export</a></li><li data-type='method'><a href="Account.html#RedeemPoints">RedeemPoints</a></li><li data-type='method'><a href="Account.html#RemoveReferral">RemoveReferral</a></li><li data-type='method'><a href="Account.html#ResetPassword">ResetPassword</a></li><li data-type='method'><a href="Account.html#SetOTP">SetOTP</a></li><li data-type='method'><a href="Account.html#SetReferrer">SetReferrer</a></li><li data-type='method'><a href="Account.html#Undelete">Undelete</a></li><li data-type='method'><a href="Account.html#UnsetOTP">UnsetOTP</a></li></ul></li><li><a href="Registry.html">Registry</a><ul class='methods'><li data-type='method'><a href="Registry.html#Create">Create</a></li><li data-type='method'><a href="Registry.html#DidResetPassword">DidResetPassword</a></li><li data-type='method'><a href="Registry.html#DidSendOTP">DidSendOTP</a></li><li data-type='method'><a href="Registry.html#HasVerified">HasVerified</a></li><li data-type='method'><a href="Registry.html#IsDuplicate">IsDuplicate</a></li><li data-type='method'><a href="Registry.html#Modify">Modify</a></li><li data-type='method'><a href="Registry.html#Remove">Remove</a></li><li data-type='method'><a href="Registry.html#Retrieve">Retrieve</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-Database.html">Database</a><ul class='methods'><li data-type='method'><a href="module-Database.html#~Find">Find</a></li><li data-type='method'><a href="module-Database.html#~FindAndReplace">FindAndReplace</a></li><li data-type='method'><a href="module-Database.html#~GetAccountByID">GetAccountByID</a></li><li data-type='method'><a href="module-Database.html#~GetReferrer">GetReferrer</a></li><li data-type='method'><a href="module-Database.html#~Insert">Insert</a></li><li data-type='method'><a href="module-Database.html#~IsDuplicate">IsDuplicate</a></li><li data-type='method'><a href="module-Database.html#~UpdateInPlace">UpdateInPlace</a></li></ul></li><li><a href="module-Source.html">Source</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">Database</h1>
<section>
<header>
</header>
<article>
<div class="container-overview">
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="~Find"><span class="type-signature">(async, inner) </span>Find<span class="signature">(phone, db)</span><span class="type-signature"> → {Promise.<(<a href="Account.html">Account</a>|null)>}</span></h4>
<div class="description">
<p>Looks up the <code>phone</code> number in the user account registry.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>phone</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>Phone number to be searched</p></td>
</tr>
<tr>
<td class="name"><code>db</code></td>
<td class="type">
<span class="param-type">Mongo.Db</span>
</td>
<td class="description last"><p>Database to be scoured</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Source_Database.js.html">Source/Database.js</a>, <a href="Source_Database.js.html#line36">line 36</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>If the search operation fails, a <code>424 Failed Dependency</code>
error is thrown.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ExternalError</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>An <code>Account</code> object if a match is found. If a
match is found but the referrer account has been soft-deleted, returns <code>null</code>. If
no match is found, returns <code>null</code>.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(<a href="Account.html">Account</a>|null)></span>
</dd>
</dl>
<h4 class="name" id="~FindAndReplace"><span class="type-signature">(async, inner) </span>FindAndReplace<span class="signature">(account, db)</span><span class="type-signature"> → {Promise.<<a href="Account.html">Account</a>>}</span></h4>
<div class="description">
<p>Finds a user account registry entry that matches the given account information and
replaces that document with the <code>account</code> document provided.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>account</code></td>
<td class="type">
<span class="param-type"><a href="Account.html">Account</a></span>
</td>
<td class="description last"><p>Phone number to be searched</p></td>
</tr>
<tr>
<td class="name"><code>db</code></td>
<td class="type">
<span class="param-type">Mongo.Db</span>
</td>
<td class="description last"><p>Database to be scoured</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Source_Database.js.html">Source/Database.js</a>, <a href="Source_Database.js.html#line68">line 68</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>If the operation fails, a <code>424 Failed Dependency</code> error is thrown.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ExternalError</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>The updated <code>Account</code> object if a match is found and
successfully replaced by the document provided.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<<a href="Account.html">Account</a>></span>
</dd>
</dl>
<h4 class="name" id="~GetAccountByID"><span class="type-signature">(async, inner) </span>GetAccountByID<span class="signature">(id, db)</span><span class="type-signature"> → {Promise.<(<a href="Account.html">Account</a>|null)>}</span></h4>
<div class="description">
<p>Given a user <code>id</code>, retrieves the full account information stored against that <code>id</code> in
the database.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>Magic Batua user ID</p></td>
</tr>
<tr>
<td class="name"><code>db</code></td>
<td class="type">
<span class="param-type">Mongo.Db</span>
</td>
<td class="description last"><p>Database to be searched</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Source_Database.js.html">Source/Database.js</a>, <a href="Source_Database.js.html#line99">line 99</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>If the search operation fails, a <code>424 Failed Dependency</code>
error is thrown.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ExternalError</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>An <code>Account</code> object if a match is found. If a
match is found but the referrer account has been soft-deleted, returns <code>null</code>. If
no match is found, returns <code>null</code>.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(<a href="Account.html">Account</a>|null)></span>
</dd>
</dl>
<h4 class="name" id="~GetReferrer"><span class="type-signature">(async, inner) </span>GetReferrer<span class="signature">(inviteCode, db)</span><span class="type-signature"> → {Promise.<(<a href="Account.html">Account</a>|null)>}</span></h4>
<div class="description">
<p>When a user is referred to Magic Batua by their friends and family, their signup
request contains an <code>inviteCode</code> that helps us identify the referrer in our systems.
This is the method that does that heavy lifting.</p>
<p> This method searches the database to find the <code>Account</code> having the same <code>referralCode</code>
property as the given <code>inviteCode</code>. If a match is found, it is deemed the rightful
referrer and returned to the calling scope.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>inviteCode</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>Referral code used at signup</p></td>
</tr>
<tr>
<td class="name"><code>db</code></td>
<td class="type">
<span class="param-type">Mongo.Db</span>
</td>
<td class="description last"><p>Database to be scoured</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Source_Database.js.html">Source/Database.js</a>, <a href="Source_Database.js.html#line138">line 138</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>If the search operation fails, a <code>424 Failed Dependency</code>
error is thrown.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ExternalError</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>An <code>Account</code> object if a referrer is found. If
a match is found but the referrer account has been soft-deleted, returns <code>null</code>. If
no match is found, returns <code>null</code>.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(<a href="Account.html">Account</a>|null)></span>
</dd>
</dl>
<h4 class="name" id="~Insert"><span class="type-signature">(async, inner) </span>Insert<span class="signature">(account, db)</span><span class="type-signature"> → {Promise.<<a href="Account.html">Account</a>>}</span></h4>
<div class="description">
<p>Inserts the given <code>account</code> document into the MongoDB database instance
held by <code>db</code>. No validation checks are run before writing the object to
database.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>account</code></td>
<td class="type">
<span class="param-type"><a href="Account.html">Account</a></span>
</td>
<td class="description last"><p><code>Account</code> object to be written to database</p></td>
</tr>
<tr>
<td class="name"><code>db</code></td>
<td class="type">
<span class="param-type">Mongo.Db</span>
</td>
<td class="description last"><p>The recipient MongoDB database</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Source_Database.js.html">Source/Database.js</a>, <a href="Source_Database.js.html#line170">line 170</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>If the write operation fails, a <code>424 Failed Dependency</code>
error is thrown.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ExternalError</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>A fully instantiated <code>Account</code> object</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<<a href="Account.html">Account</a>></span>
</dd>
</dl>
<h4 class="name" id="~IsDuplicate"><span class="type-signature">(async, inner) </span>IsDuplicate<span class="signature">(account, db)</span><span class="type-signature"> → {Promise.<boolean>}</span></h4>
<div class="description">
<p>Checks whether the given <code>account</code> information is already registered with us.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>account</code></td>
<td class="type">
<span class="param-type"><a href="Account.html">Account</a></span>
</td>
<td class="description last"><p>Account information</p></td>
</tr>
<tr>
<td class="name"><code>db</code></td>
<td class="type">
<span class="param-type">Mongo.Db</span>
</td>
<td class="description last"><p>Database to be scoured</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Source_Database.js.html">Source/Database.js</a>, <a href="Source_Database.js.html#line196">line 196</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>If the search operation fails, a <code>424 Failed Dependency</code>
error is thrown.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ExternalError</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p><code>true</code> if a matching account is found. If a match is found
but the account has been soft-deleted, returns <code>false</code>. If no match is found,
returns <code>false</code>.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<boolean></span>
</dd>
</dl>
<h4 class="name" id="~UpdateInPlace"><span class="type-signature">(async, inner) </span>UpdateInPlace<span class="signature">(id, query, db)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Updates the database object corresponding to the given <code>_id</code> in place. Doesn't run data
validation checks, so use very carefully and sparsely. Most of the update operations in the
software are done through the <code>Database.FindAndReplace()</code> method. Use that.</p>
<p> <strong>Only allows updates for <code>name</code>, <code>email</code> or <code>phone</code>.</strong></p>
<p> If the <code>query</code> parameter contains a Magic Points transaction entry, then the entry is
pushed to the <code>pointsLedger.transactions</code> array.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>Magic Batua user <code>_id</code></p></td>
</tr>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type">any</span>
</td>
<td class="description last"><p>A JSON containing key-value pairs that should be updated.</p></td>
</tr>
<tr>
<td class="name"><code>db</code></td>
<td class="type">
<span class="param-type">Mongo.Db</span>
</td>
<td class="description last"><p>MongoDB database instance</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Source_Database.js.html">Source/Database.js</a>, <a href="Source_Database.js.html#line236">line 236</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>If the operation fails, a <code>424 Failed Dependency</code> error is thrown.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">ExternalError</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated at Mon Mar 19 2018 22:39:23 GMT+0530 (IST)
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>