Add documentation to the helpers module.

This commit is contained in:
Spencer Ofwiti 2021-05-11 14:34:23 +03:00
parent c9f73899c3
commit e0c045cdfa
37 changed files with 1403 additions and 585 deletions

View File

@ -63,6 +63,13 @@
<code>src/app/_helpers/custom-error-state-matcher.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Custom provider that defines how form controls behave with regards to displaying error messages.</p>
</p>
<p class="comment">
@ -72,6 +79,11 @@
<code>ErrorStateMatcher</code>
</p>
<p class="comment">
<h3>Example</h3>
</p>
<div class="io-description">
</div>
<section>
<h3 id="index">Index</h3>
@ -130,14 +142,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="5"
class="link-to-prism">src/app/_helpers/custom-error-state-matcher.ts:5</a></div>
<div class="io-line">Defined in <a href="" data-line="18"
class="link-to-prism">src/app/_helpers/custom-error-state-matcher.ts:18</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Checks whether an invalid input has been made and an error should be made.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -147,6 +161,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -161,6 +176,12 @@
</td>
<td>
<ul>
<li>Tracks the value and validation status of an individual form control.</li>
</ul>
</td>
</tr>
<tr>
<td>form</td>
@ -173,6 +194,12 @@
</td>
<td>
<ul>
<li>Binding of an existing FormGroup to a DOM element.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -184,6 +211,7 @@
</div>
<div class="io-description">
<p>true - If an invalid input has been made to the form control.</p>
</div>
</td>
@ -200,10 +228,22 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {ErrorStateMatcher} from &#x27;@angular/material/core&#x27;;
import {FormControl, FormGroupDirective, NgForm} from &#x27;@angular/forms&#x27;;
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {FormControl, FormGroupDirective, NgForm} from &#x27;@angular/forms&#x27;;
import {ErrorStateMatcher} from &#x27;@angular/material/core&#x27;;
/**
* Custom provider that defines how form controls behave with regards to displaying error messages.
*
* @implements ErrorStateMatcher
*/
export class CustomErrorStateMatcher implements ErrorStateMatcher{
/**
* Checks whether an invalid input has been made and an error should be made.
*
* @param control - Tracks the value and validation status of an individual form control.
* @param form - Binding of an existing FormGroup to a DOM element.
* @returns true - If an invalid input has been made to the form control.
*/
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted: boolean &#x3D; form &amp;&amp; form.submitted;
return !!(control &amp;&amp; control.invalid &amp;&amp; (control.dirty || control.touched || isSubmitted));

View File

@ -63,6 +63,13 @@
<code>src/app/_helpers/custom.validator.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Provides methods to perform custom validation to form inputs.</p>
</p>
@ -131,14 +138,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="4"
class="link-to-prism">src/app/_helpers/custom.validator.ts:4</a></div>
<div class="io-line">Defined in <a href="" data-line="13"
class="link-to-prism">src/app/_helpers/custom.validator.ts:13</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Sets errors to the confirm password input field if it does not match with the value in the password input field.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -148,6 +157,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -162,6 +172,12 @@
</td>
<td>
<ul>
<li>The control object of the form being validated.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -203,14 +219,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="12"
class="link-to-prism">src/app/_helpers/custom.validator.ts:12</a></div>
<div class="io-line">Defined in <a href="" data-line="28"
class="link-to-prism">src/app/_helpers/custom.validator.ts:28</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Sets errors to a form field if it does not match with the regular expression given.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -220,6 +238,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -234,6 +253,12 @@
</td>
<td>
<ul>
<li>The regular expression to match with the form field.</li>
</ul>
</td>
</tr>
<tr>
<td>error</td>
@ -246,6 +271,12 @@
</td>
<td>
<ul>
<li>Defines the map of errors to return from failed validation checks.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -257,6 +288,7 @@
</div>
<div class="io-description">
<p>The map of errors returned from failed validation checks.</p>
</div>
</td>
@ -275,7 +307,15 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {AbstractControl, ValidationErrors} from &#x27;@angular/forms&#x27;;
/**
* Provides methods to perform custom validation to form inputs.
*/
export class CustomValidator {
/**
* Sets errors to the confirm password input field if it does not match with the value in the password input field.
*
* @param control - The control object of the form being validated.
*/
static passwordMatchValidator(control: AbstractControl): void {
const password: string &#x3D; control.get(&#x27;password&#x27;).value;
const confirmPassword: string &#x3D; control.get(&#x27;confirmPassword&#x27;).value;
@ -284,6 +324,13 @@ export class CustomValidator {
}
}
/**
* Sets errors to a form field if it does not match with the regular expression given.
*
* @param regex - The regular expression to match with the form field.
* @param error - Defines the map of errors to return from failed validation checks.
* @returns The map of errors returned from failed validation checks.
*/
static patternValidator(regex: RegExp, error: ValidationErrors): ValidationErrors | null {
return (control: AbstractControl): { [key: string]: any } &#x3D;&gt; {
if (!control.value) {

View File

@ -63,6 +63,13 @@
<code>src/app/_helpers/global-error-handler.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>A generalized http response error.</p>
</p>
<p class="comment">
<h3>Extends</h3>
@ -72,6 +79,11 @@
</p>
<p class="comment">
<h3>Example</h3>
</p>
<div class="io-description">
</div>
<section>
<h3 id="index">Index</h3>
@ -113,12 +125,14 @@
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="8" class="link-to-prism">src/app/_helpers/global-error-handler.ts:8</a></div>
<div class="io-line">Defined in <a href="" data-line="16" class="link-to-prism">src/app/_helpers/global-error-handler.ts:16</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Initialize the HttpError class.</p>
</div>
<div>
<b>Parameters :</b>
<table class="params">
@ -127,6 +141,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -141,6 +156,12 @@
No
</td>
<td>
<code><ul>
<li>The message given by the error.</li>
</ul>
</code>
</td>
</tr>
<tr>
<td>status</td>
@ -153,6 +174,12 @@
No
</td>
<td>
<code><ul>
<li>The status code given by the error.</li>
</ul>
</code>
</td>
</tr>
</tbody>
</table>
@ -189,10 +216,16 @@
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="8" class="link-to-prism">src/app/_helpers/global-error-handler.ts:8</a></div>
<div class="io-line">Defined in <a href="" data-line="16" class="link-to-prism">src/app/_helpers/global-error-handler.ts:16</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>The error&#39;s status code. </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -208,14 +241,28 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {ErrorHandler, Injectable} from &#x27;@angular/core&#x27;;
import {LoggingService} from &#x27;@app/_services/logging.service&#x27;;
import {HttpErrorResponse} from &#x27;@angular/common/http&#x27;;
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {HttpErrorResponse} from &#x27;@angular/common/http&#x27;;
import {ErrorHandler, Injectable} from &#x27;@angular/core&#x27;;
import {Router} from &#x27;@angular/router&#x27;;
// A generalized http response error
// Application imports
import {LoggingService} from &#x27;@app/_services/logging.service&#x27;;
/**
* A generalized http response error.
*
* @extends Error
*/
export class HttpError extends Error {
/** The error&#x27;s status code. */
public status: number;
/**
* Initialize the HttpError class.
*
* @param message - The message given by the error.
* @param status - The status code given by the error.
*/
constructor(message: string, status: number) {
super(message);
this.status &#x3D; status;
@ -223,10 +270,25 @@ export class HttpError extends Error {
}
}
/**
* Provides a hook for centralized exception handling.
*
* @extends ErrorHandler
*/
@Injectable()
export class GlobalErrorHandler extends ErrorHandler {
/**
* An array of sentence sections that denote warnings.
* @private
*/
private sentencesForWarningLogging: Array&lt;string&gt; &#x3D; [];
/**
* Initialization of the Global Error Handler.
*
* @param loggingService - A service that provides logging capabilities.
* @param router - A service that provides navigation among views and URL manipulation capabilities.
*/
constructor(
private loggingService: LoggingService,
private router: Router
@ -234,6 +296,11 @@ export class GlobalErrorHandler extends ErrorHandler {
super();
}
/**
* Handles different types of errors.
*
* @param error - An error objects thrown when a runtime errors occurs.
*/
handleError(error: Error): void {
this.logError(error);
const message: string &#x3D; error.message ? error.message : error.toString();
@ -254,24 +321,11 @@ export class GlobalErrorHandler extends ErrorHandler {
throw error;
}
logError(error: any): void {
const route: string &#x3D; this.router.url;
if (error instanceof HttpErrorResponse) {
this.loggingService.sendErrorLevelMessage(
&#x60;There was an HTTP error on route ${route}.\n${error.message}.\nStatus code: ${(error as HttpErrorResponse).status}&#x60;,
this, {error});
} else if (error instanceof TypeError) {
this.loggingService.sendErrorLevelMessage(&#x60;There was a Type error on route ${route}.\n${error.message}&#x60;, this, {error});
} else if (error instanceof Error) {
this.loggingService.sendErrorLevelMessage(&#x60;There was a general error on route ${route}.\n${error.message}&#x60;, this, {error});
} else {
this.loggingService.sendErrorLevelMessage(&#x60;Nobody threw an error but something happened on route ${route}!&#x60;, this, {error});
}
}
/**
* Checks if an error is of type warning.
*
* @param errorTraceString
* @param errorTraceString - A description of the error and it&#x27;s stack trace.
* @returns true - If the error is of type warning.
* @private
*/
private isWarning(errorTraceString: string): boolean {
@ -288,6 +342,26 @@ export class GlobalErrorHandler extends ErrorHandler {
return isWarning;
}
/**
* Write appropriate logs according to the type of error.
*
* @param error - An error objects thrown when a runtime errors occurs.
*/
logError(error: any): void {
const route: string &#x3D; this.router.url;
if (error instanceof HttpErrorResponse) {
this.loggingService.sendErrorLevelMessage(
&#x60;There was an HTTP error on route ${route}.\n${error.message}.\nStatus code: ${(error as HttpErrorResponse).status}&#x60;,
this, {error});
} else if (error instanceof TypeError) {
this.loggingService.sendErrorLevelMessage(&#x60;There was a Type error on route ${route}.\n${error.message}&#x60;, this, {error});
} else if (error instanceof Error) {
this.loggingService.sendErrorLevelMessage(&#x60;There was a general error on route ${route}.\n${error.message}&#x60;, this, {error});
} else {
this.loggingService.sendErrorLevelMessage(&#x60;Nobody threw an error but something happened on route ${route}!&#x60;, this, {error});
}
}
}
</code></pre>
</div>

View File

@ -160,292 +160,280 @@
<span class="coverage-count">(3/3)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#arraySum">src/app/_helpers/array-sum.ts</a>
</td>
<td>function</td>
<td>arraySum</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#copyToClipboard">src/app/_helpers/clipboard-copy.ts</a>
</td>
<td>function</td>
<td>copyToClipboard</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./classes/CustomErrorStateMatcher.html">src/app/_helpers/custom-error-state-matcher.ts</a>
</td>
<td>class</td>
<td>CustomErrorStateMatcher</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/2)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(2/2)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./classes/CustomValidator.html">src/app/_helpers/custom.validator.ts</a>
</td>
<td>class</td>
<td>CustomValidator</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/3)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(3/3)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#exportCsv">src/app/_helpers/export-csv.ts</a>
</td>
<td>function</td>
<td>exportCsv</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#removeSpecialChar">src/app/_helpers/export-csv.ts</a>
</td>
<td>function</td>
<td>removeSpecialChar</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./classes/HttpError.html">src/app/_helpers/global-error-handler.ts</a>
</td>
<td>class</td>
<td>HttpError</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/3)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(3/3)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./injectables/GlobalErrorHandler.html">src/app/_helpers/global-error-handler.ts</a>
</td>
<td>injectable</td>
<td>GlobalErrorHandler</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/6)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(6/6)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#HttpGetter">src/app/_helpers/http-getter.ts</a>
</td>
<td>function</td>
<td>HttpGetter</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./interceptors/MockBackendInterceptor.html">src/app/_helpers/mock-backend.ts</a>
</td>
<td>interceptor</td>
<td>MockBackendInterceptor</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/2)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(2/2)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#accountTypes">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>accountTypes</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#actions">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>actions</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#areaNames">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>areaNames</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#areaTypes">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>areaTypes</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#categories">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>categories</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#genders">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>genders</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#MockBackendProvider">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>MockBackendProvider</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#tokens">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>tokens</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#transactionTypes">src/app/_helpers/mock-backend.ts</a>
</td>
<td>variable</td>
<td>transactionTypes</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#parseData">src/app/_helpers/read-csv.ts</a>
</td>
<td>function</td>
<td>parseData</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#readCsv">src/app/_helpers/read-csv.ts</a>
</td>
<td>function</td>
<td>readCsv</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href="./miscellaneous/variables.html#objCsv">src/app/_helpers/read-csv.ts</a>
</td>
<td>variable</td>
<td>objCsv</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#personValidation">src/app/_helpers/schema-validation.ts</a>
</td>
<td>function</td>
<td>personValidation</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">
<tr class="very-good">
<td>
<!-- miscellaneous -->
<a href=".//functions.html#vcardValidation">src/app/_helpers/schema-validation.ts</a>
</td>
<td>function</td>
<td>vcardValidation</td>
<td align="right" data-sort="0">
<span class="coverage-percent">0 %</span>
<span class="coverage-count">(0/1)</span>
<td align="right" data-sort="100">
<span class="coverage-percent">100 %</span>
<span class="coverage-count">(1/1)</span>
</td>
</tr>
<tr class="low">

View File

@ -1,9 +1,9 @@
<svg width="135" height="20" xmlns="http://www.w3.org/2000/svg">
<g>
<rect id="svg_1" height="20" width="130" y="0" x="0" stroke-width="1.5" stroke="#5d5d5d" fill="#5d5d5d" rx="7" ry="7"/>
<rect id="svg_2" height="20" width="40" y="0" x="92" stroke-width="1.5" stroke="#d8604b" fill="#d8604b" rx="7" ry="7"/>
<rect id="svg_3" height="20" width="22" y="0" x="92" stroke-width="1.5" stroke="#d8604b" fill="#d8604b"/>
<rect id="svg_2" height="20" width="40" y="0" x="92" stroke-width="1.5" stroke="#dab226" fill="#dab226" rx="7" ry="7"/>
<rect id="svg_3" height="20" width="22" y="0" x="92" stroke-width="1.5" stroke="#dab226" fill="#dab226"/>
<text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="12" id="svg_4" y="14" x="6" stroke-width="0" stroke="#5d5d5d" fill="#ffffff">documentation</text>
<text xml:space="preserve" text-anchor="middle" font-family="Helvetica, Arial, sans-serif" font-size="12" id="svg_5" y="14" x="112" stroke-width="0" stroke="#5d5d5d" fill="#ffffff" style="text-anchor: middle">8%</text>
<text xml:space="preserve" text-anchor="middle" font-family="Helvetica, Arial, sans-serif" font-size="12" id="svg_5" y="14" x="112" stroke-width="0" stroke="#5d5d5d" fill="#ffffff" style="text-anchor: middle">30%</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 893 B

After

Width:  |  Height:  |  Size: 894 B

View File

@ -59,6 +59,13 @@
<code>src/app/_helpers/global-error-handler.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Provides a hook for centralized exception handling.</p>
</p>
<p class="comment">
<h3>Extends</h3>
@ -67,6 +74,11 @@
<code><a href="https://angular.io/api/core/ErrorHandler" target="_blank" >ErrorHandler</a></code>
</p>
<p class="comment">
<h3>Example</h3>
</p>
<div class="io-description">
</div>
<section>
<h3 id="index">Index</h3>
@ -129,12 +141,14 @@
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="18" class="link-to-prism">src/app/_helpers/global-error-handler.ts:18</a></div>
<div class="io-line">Defined in <a href="" data-line="42" class="link-to-prism">src/app/_helpers/global-error-handler.ts:42</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Initialization of the Global Error Handler.</p>
</div>
<div>
<b>Parameters :</b>
<table class="params">
@ -143,6 +157,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -157,6 +172,12 @@
No
</td>
<td>
<code><ul>
<li>A service that provides logging capabilities.</li>
</ul>
</code>
</td>
</tr>
<tr>
<td>router</td>
@ -169,6 +190,12 @@
No
</td>
<td>
<code><ul>
<li>A service that provides navigation among views and URL manipulation capabilities.</li>
</ul>
</code>
</td>
</tr>
</tbody>
</table>
@ -206,14 +233,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="27"
class="link-to-prism">src/app/_helpers/global-error-handler.ts:27</a></div>
<div class="io-line">Defined in <a href="" data-line="62"
class="link-to-prism">src/app/_helpers/global-error-handler.ts:62</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Handles different types of errors.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -223,6 +252,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -237,6 +267,12 @@
</td>
<td>
<ul>
<li>An error objects thrown when a runtime errors occurs.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -278,14 +314,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="67"
class="link-to-prism">src/app/_helpers/global-error-handler.ts:67</a></div>
<div class="io-line">Defined in <a href="" data-line="89"
class="link-to-prism">src/app/_helpers/global-error-handler.ts:89</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Checks if an error is of type warning.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -295,6 +333,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -309,6 +348,12 @@
</td>
<td>
<ul>
<li>A description of the error and it&#39;s stack trace.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -320,6 +365,7 @@
</div>
<div class="io-description">
<p>true - If the error is of type warning.</p>
</div>
</td>
@ -348,14 +394,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="47"
class="link-to-prism">src/app/_helpers/global-error-handler.ts:47</a></div>
<div class="io-line">Defined in <a href="" data-line="109"
class="link-to-prism">src/app/_helpers/global-error-handler.ts:109</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Write appropriate logs according to the type of error.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -365,6 +413,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -379,6 +428,12 @@
</td>
<td>
<ul>
<li>An error objects thrown when a runtime errors occurs.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -428,10 +483,16 @@
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="18" class="link-to-prism">src/app/_helpers/global-error-handler.ts:18</a></div>
<div class="io-line">Defined in <a href="" data-line="42" class="link-to-prism">src/app/_helpers/global-error-handler.ts:42</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>An array of sentence sections that denote warnings.</p>
</div>
</td>
</tr>
</tbody>
</table>
@ -441,14 +502,28 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {ErrorHandler, Injectable} from &#x27;@angular/core&#x27;;
import {LoggingService} from &#x27;@app/_services/logging.service&#x27;;
import {HttpErrorResponse} from &#x27;@angular/common/http&#x27;;
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {HttpErrorResponse} from &#x27;@angular/common/http&#x27;;
import {ErrorHandler, Injectable} from &#x27;@angular/core&#x27;;
import {Router} from &#x27;@angular/router&#x27;;
// A generalized http response error
// Application imports
import {LoggingService} from &#x27;@app/_services/logging.service&#x27;;
/**
* A generalized http response error.
*
* @extends Error
*/
export class HttpError extends Error {
/** The error&#x27;s status code. */
public status: number;
/**
* Initialize the HttpError class.
*
* @param message - The message given by the error.
* @param status - The status code given by the error.
*/
constructor(message: string, status: number) {
super(message);
this.status &#x3D; status;
@ -456,10 +531,25 @@ export class HttpError extends Error {
}
}
/**
* Provides a hook for centralized exception handling.
*
* @extends ErrorHandler
*/
@Injectable()
export class GlobalErrorHandler extends ErrorHandler {
/**
* An array of sentence sections that denote warnings.
* @private
*/
private sentencesForWarningLogging: Array&lt;string&gt; &#x3D; [];
/**
* Initialization of the Global Error Handler.
*
* @param loggingService - A service that provides logging capabilities.
* @param router - A service that provides navigation among views and URL manipulation capabilities.
*/
constructor(
private loggingService: LoggingService,
private router: Router
@ -467,6 +557,11 @@ export class GlobalErrorHandler extends ErrorHandler {
super();
}
/**
* Handles different types of errors.
*
* @param error - An error objects thrown when a runtime errors occurs.
*/
handleError(error: Error): void {
this.logError(error);
const message: string &#x3D; error.message ? error.message : error.toString();
@ -487,24 +582,11 @@ export class GlobalErrorHandler extends ErrorHandler {
throw error;
}
logError(error: any): void {
const route: string &#x3D; this.router.url;
if (error instanceof HttpErrorResponse) {
this.loggingService.sendErrorLevelMessage(
&#x60;There was an HTTP error on route ${route}.\n${error.message}.\nStatus code: ${(error as HttpErrorResponse).status}&#x60;,
this, {error});
} else if (error instanceof TypeError) {
this.loggingService.sendErrorLevelMessage(&#x60;There was a Type error on route ${route}.\n${error.message}&#x60;, this, {error});
} else if (error instanceof Error) {
this.loggingService.sendErrorLevelMessage(&#x60;There was a general error on route ${route}.\n${error.message}&#x60;, this, {error});
} else {
this.loggingService.sendErrorLevelMessage(&#x60;Nobody threw an error but something happened on route ${route}!&#x60;, this, {error});
}
}
/**
* Checks if an error is of type warning.
*
* @param errorTraceString
* @param errorTraceString - A description of the error and it&#x27;s stack trace.
* @returns true - If the error is of type warning.
* @private
*/
private isWarning(errorTraceString: string): boolean {
@ -521,6 +603,26 @@ export class GlobalErrorHandler extends ErrorHandler {
return isWarning;
}
/**
* Write appropriate logs according to the type of error.
*
* @param error - An error objects thrown when a runtime errors occurs.
*/
logError(error: any): void {
const route: string &#x3D; this.router.url;
if (error instanceof HttpErrorResponse) {
this.loggingService.sendErrorLevelMessage(
&#x60;There was an HTTP error on route ${route}.\n${error.message}.\nStatus code: ${(error as HttpErrorResponse).status}&#x60;,
this, {error});
} else if (error instanceof TypeError) {
this.loggingService.sendErrorLevelMessage(&#x60;There was a Type error on route ${route}.\n${error.message}&#x60;, this, {error});
} else if (error instanceof Error) {
this.loggingService.sendErrorLevelMessage(&#x60;There was a general error on route ${route}.\n${error.message}&#x60;, this, {error});
} else {
this.loggingService.sendErrorLevelMessage(&#x60;Nobody threw an error but something happened on route ${route}!&#x60;, this, {error});
}
}
}
</code></pre>
</div>

View File

@ -60,7 +60,20 @@
<code>src/app/_helpers/mock-backend.ts</code>
</p>
<p class="comment">
<h3>Description</h3>
</p>
<p class="comment">
<p>Intercepts HTTP requests and handles some specified requests internally.
Provides a backend that can handle requests for certain data items.</p>
</p>
<p class="comment">
<h3>Example</h3>
</p>
<div class="io-description">
</div>
<section>
<h3 id="index">Index</h3>
@ -118,14 +131,16 @@
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="240"
class="link-to-prism">src/app/_helpers/mock-backend.ts:240</a></div>
<div class="io-line">Defined in <a href="" data-line="268"
class="link-to-prism">src/app/_helpers/mock-backend.ts:268</a></div>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Intercepts HTTP requests.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -135,6 +150,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -149,6 +165,12 @@
</td>
<td>
<ul>
<li>An outgoing HTTP request with an optional typed body.</li>
</ul>
</td>
</tr>
<tr>
<td>next</td>
@ -161,6 +183,12 @@
</td>
<td>
<ul>
<li>The next HTTP handler or the outgoing request dispatcher.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -172,6 +200,7 @@
</div>
<div class="io-description">
<p>The response from the resolved request.</p>
</div>
</td>
@ -186,10 +215,18 @@
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import {HTTP_INTERCEPTORS, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from &#x27;@angular/common/http&#x27;;
import {Injectable} from &#x27;@angular/core&#x27;;
// Third party imports
import {Observable, of, throwError} from &#x27;rxjs&#x27;;
import {delay, dematerialize, materialize, mergeMap} from &#x27;rxjs/operators&#x27;;
// Application imports
import {Action, AreaName, AreaType, Category, Token} from &#x27;@app/_models&#x27;;
/** A mock of the curated account types. */
const accountTypes: Array&lt;string&gt; &#x3D; [&#x27;user&#x27;, &#x27;cashier&#x27;, &#x27;vendor&#x27;, &#x27;tokenagent&#x27;, &#x27;group&#x27;];
/** A mock of actions made by the admin staff. */
const actions: Array&lt;Action&gt; &#x3D; [
{ id: 1, user: &#x27;Tom&#x27;, role: &#x27;enroller&#x27;, action: &#x27;Disburse RSV 100&#x27;, approval: false },
{ id: 2, user: &#x27;Christine&#x27;, role: &#x27;admin&#x27;, action: &#x27;Change user phone number&#x27;, approval: true },
@ -199,38 +236,93 @@ const actions: Array&lt;Action&gt; &#x3D; [
{ id: 6, user: &#x27;Patience&#x27;, role: &#x27;enroller&#x27;, action: &#x27;Change user information&#x27;, approval: false }
];
const tokens: Array&lt;Token&gt; &#x3D; [
/** A mock of curated area names. */
const areaNames: Array&lt;AreaName&gt; &#x3D; [
{
name: &#x27;Giftable Reserve&#x27;, symbol: &#x27;GRZ&#x27;, address: &#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;, supply: &#x27;1000000001000000000000000000&#x27;,
decimals: &#x27;18&#x27;, reserves: {}
name: &#x27;Mukuru Nairobi&#x27;,
locations: [&#x27;kayaba&#x27;, &#x27;kayba&#x27;, &#x27;kambi&#x27;, &#x27;mukuru&#x27;, &#x27;masai&#x27;, &#x27;hazina&#x27;, &#x27;south&#x27;, &#x27;tetra&#x27;, &#x27;tetrapak&#x27;, &#x27;ruben&#x27;, &#x27;rueben&#x27;, &#x27;kingston&#x27;,
&#x27;korokocho&#x27;, &#x27;kingstone&#x27;, &#x27;kamongo&#x27;, &#x27;lungalunga&#x27;, &#x27;sinai&#x27;, &#x27;sigei&#x27;, &#x27;lungu&#x27;, &#x27;lunga lunga&#x27;, &#x27;owino road&#x27;, &#x27;seigei&#x27;]
},
{
name: &#x27;Demo Token&#x27;, symbol: &#x27;DEMO&#x27;, address: &#x27;0xc80D6aFF8194114c52AEcD84c9f15fd5c8abb187&#x27;, supply: &#x27;99999999999999998976&#x27;,
decimals: &#x27;18&#x27;, reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;99999999999999998976&#x27;}},
reserveRatio: &#x27;1000000&#x27;, owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
name: &#x27;Kinango Kwale&#x27;,
locations: [&#x27;amani&#x27;, &#x27;bofu&#x27;, &#x27;chibuga&#x27;, &#x27;chikomani&#x27;, &#x27;chilongoni&#x27;, &#x27;chigojoni&#x27;, &#x27;chinguluni&#x27;, &#x27;chigato&#x27;, &#x27;chigale&#x27;, &#x27;chikole&#x27;,
&#x27;chilongoni&#x27;, &#x27;chilumani&#x27;, &#x27;chigojoni&#x27;, &#x27;chikomani&#x27;, &#x27;chizini&#x27;, &#x27;chikomeni&#x27;, &#x27;chidzuvini&#x27;, &#x27;chidzivuni&#x27;, &#x27;chikuyu&#x27;, &#x27;chizingo&#x27;,
&#x27;doti&#x27;, &#x27;dzugwe&#x27;, &#x27;dzivani&#x27;, &#x27;dzovuni&#x27;, &#x27;hanje&#x27;, &#x27;kasemeni&#x27;, &#x27;katundani&#x27;, &#x27;kibandaogo&#x27;, &#x27;kibandaongo&#x27;, &#x27;kwale&#x27;, &#x27;kinango&#x27;,
&#x27;kidzuvini&#x27;, &#x27;kalalani&#x27;, &#x27;kafuduni&#x27;, &#x27;kaloleni&#x27;, &#x27;kilibole&#x27;, &#x27;lutsangani&#x27;, &#x27;peku&#x27;, &#x27;gona&#x27;, &#x27;guro&#x27;, &#x27;gandini&#x27;, &#x27;mkanyeni&#x27;, &#x27;myenzeni&#x27;,
&#x27;miyenzeni&#x27;, &#x27;miatsiani&#x27;, &#x27;mienzeni&#x27;, &#x27;mnyenzeni&#x27;, &#x27;minyenzeni&#x27;, &#x27;miyani&#x27;, &#x27;mioleni&#x27;, &#x27;makuluni&#x27;, &#x27;mariakani&#x27;, &#x27;makobeni&#x27;, &#x27;madewani&#x27;,
&#x27;mwangaraba&#x27;, &#x27;mwashanga&#x27;, &#x27;miloeni&#x27;, &#x27;mabesheni&#x27;, &#x27;mazeras&#x27;, &#x27;mazera&#x27;, &#x27;mlola&#x27;, &#x27;muugano&#x27;, &#x27;mulunguni&#x27;, &#x27;mabesheni&#x27;, &#x27;miatsani&#x27;,
&#x27;miatsiani&#x27;, &#x27;mwache&#x27;, &#x27;mwangani&#x27;, &#x27;mwehavikonje&#x27;, &#x27;miguneni&#x27;, &#x27;nzora&#x27;, &#x27;nzovuni&#x27;, &#x27;vikinduni&#x27;, &#x27;vikolani&#x27;, &#x27;vitangani&#x27;, &#x27;viogato&#x27;,
&#x27;vyogato&#x27;, &#x27;vistangani&#x27;, &#x27;yapha&#x27;, &#x27;yava&#x27;, &#x27;yowani&#x27;, &#x27;ziwani&#x27;, &#x27;majengo&#x27;, &#x27;matuga&#x27;, &#x27;vigungani&#x27;, &#x27;vidziweni&#x27;, &#x27;vinyunduni&#x27;, &#x27;ukunda&#x27;,
&#x27;kokotoni&#x27;, &#x27;mikindani&#x27;]
},
{
name: &#x27;Foo Token&#x27;, symbol: &#x27;FOO&#x27;, address: &#x27;0x9ceD86089f7aBB5A97B40eb0E7521e7aa308d354&#x27;, supply: &#x27;1000000000000000001014&#x27;,
decimals: &#x27;18&#x27;, reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;1000000000000000001014&#x27;}},
reserveRatio: &#x27;1000000&#x27;, owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
name: &#x27;Misc Nairobi&#x27;,
locations: [&#x27;nairobi&#x27;, &#x27;west&#x27;, &#x27;lindi&#x27;, &#x27;kibera&#x27;, &#x27;kibira&#x27;, &#x27;kibra&#x27;, &#x27;makina&#x27;, &#x27;soweto&#x27;, &#x27;olympic&#x27;, &#x27;kangemi&#x27;, &#x27;ruiru&#x27;, &#x27;congo&#x27;,
&#x27;kawangware&#x27;, &#x27;kwangware&#x27;, &#x27;donholm&#x27;, &#x27;dagoreti&#x27;, &#x27;dandora&#x27;, &#x27;kabete&#x27;, &#x27;sinai&#x27;, &#x27;donhom&#x27;, &#x27;donholm&#x27;, &#x27;huruma&#x27;, &#x27;kitengela&#x27;,
&#x27;makadara&#x27;, &#x27;,mlolongo&#x27;, &#x27;kenyatta&#x27;, &#x27;mlolongo&#x27;, &#x27;tassia&#x27;, &#x27;tasia&#x27;, &#x27;gatina&#x27;, &#x27;56&#x27;, &#x27;industrial&#x27;, &#x27;kariobangi&#x27;, &#x27;kasarani&#x27;, &#x27;kayole&#x27;,
&#x27;mathare&#x27;, &#x27;pipe&#x27;, &#x27;juja&#x27;, &#x27;uchumi&#x27;, &#x27;jogoo&#x27;, &#x27;umoja&#x27;, &#x27;thika&#x27;, &#x27;kikuyu&#x27;, &#x27;stadium&#x27;, &#x27;buru buru&#x27;, &#x27;ngong&#x27;, &#x27;starehe&#x27;, &#x27;mwiki&#x27;,
&#x27;fuata&#x27;, &#x27;kware&#x27;, &#x27;kabiro&#x27;, &#x27;embakassi&#x27;, &#x27;embakasi&#x27;, &#x27;kmoja&#x27;, &#x27;east&#x27;, &#x27;githurai&#x27;, &#x27;landi&#x27;, &#x27;langata&#x27;, &#x27;limuru&#x27;, &#x27;mathere&#x27;,
&#x27;dagoretti&#x27;, &#x27;kirembe&#x27;, &#x27;muugano&#x27;, &#x27;mwiki&#x27;, &#x27;toi market&#x27;]
},
{
name: &#x27;testb&#x27;, symbol: &#x27;tstb&#x27;, address: &#x27;0xC63cFA91A3BFf41cE31Ff436f67D3ACBC977DB95&#x27;, supply: &#x27;99000&#x27;, decimals: &#x27;18&#x27;,
reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;99000&#x27;}}, reserveRatio: &#x27;1000000&#x27;,
owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
name: &#x27;Misc Mombasa&#x27;,
locations: [&#x27;mombasa&#x27;, &#x27;likoni&#x27;, &#x27;bangla&#x27;, &#x27;bangladesh&#x27;, &#x27;kizingo&#x27;, &#x27;old town&#x27;, &#x27;makupa&#x27;, &#x27;mvita&#x27;, &#x27;ngombeni&#x27;, &#x27;ngómbeni&#x27;, &#x27;ombeni&#x27;,
&#x27;magongo&#x27;, &#x27;miritini&#x27;, &#x27;changamwe&#x27;, &#x27;jomvu&#x27;, &#x27;ohuru&#x27;, &#x27;tudor&#x27;, &#x27;diani&#x27;]
},
{
name: &#x27;testa&#x27;, symbol: &#x27;tsta&#x27;, address: &#x27;0x8fA4101ef19D0a078239d035659e92b278bD083C&#x27;, supply: &#x27;9981&#x27;, decimals: &#x27;18&#x27;,
reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;9981&#x27;}}, reserveRatio: &#x27;1000000&#x27;,
owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
name: &#x27;Kisauni&#x27;,
locations: [&#x27;bamburi&#x27;, &#x27;kisauni&#x27;, &#x27;mworoni&#x27;, &#x27;nyali&#x27;, &#x27;shanzu&#x27;, &#x27;bombolulu&#x27;, &#x27;mtopanga&#x27;, &#x27;mjambere&#x27;, &#x27;majaoni&#x27;, &#x27;manyani&#x27;, &#x27;magogoni&#x27;,
&#x27;junda&#x27;, &#x27;mwakirunge&#x27;, &#x27;mshomoroni&#x27;]
},
{
name: &#x27;testc&#x27;, symbol: &#x27;tstc&#x27;, address: &#x27;0x4A6fA6bc3BfE4C9661bC692D9798425350C9e3D4&#x27;, supply: &#x27;100990&#x27;, decimals: &#x27;18&#x27;,
reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;100990&#x27;}}, reserveRatio: &#x27;1000000&#x27;,
owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
name: &#x27;Kilifi&#x27;,
locations: [&#x27;kilfi&#x27;, &#x27;kilifi&#x27;, &#x27;mtwapa&#x27;, &#x27;takaungu&#x27;, &#x27;makongeni&#x27;, &#x27;mnarani&#x27;, &#x27;mnarani&#x27;, &#x27;office&#x27;, &#x27;g.e&#x27;, &#x27;ge&#x27;, &#x27;raibai&#x27;, &#x27;ribe&#x27;]
},
{
name: &#x27;Kakuma&#x27;,
locations: [&#x27;kakuma&#x27;]
},
{
name: &#x27;Kitui&#x27;,
locations: [&#x27;kitui&#x27;, &#x27;mwingi&#x27;]
},
{
name: &#x27;Nyanza&#x27;,
locations: [&#x27;busia&#x27;, &#x27;nyalgunga&#x27;, &#x27;mbita&#x27;, &#x27;siaya&#x27;, &#x27;kisumu&#x27;, &#x27;nyalenda&#x27;, &#x27;hawinga&#x27;, &#x27;rangala&#x27;, &#x27;uyoma&#x27;, &#x27;mumias&#x27;, &#x27;homabay&#x27;, &#x27;homaboy&#x27;,
&#x27;migori&#x27;, &#x27;kusumu&#x27;]
},
{
name: &#x27;Misc Rural Counties&#x27;,
locations: [&#x27;makueni&#x27;, &#x27;meru&#x27;, &#x27;kisii&#x27;, &#x27;bomet&#x27;, &#x27;machakos&#x27;, &#x27;bungoma&#x27;, &#x27;eldoret&#x27;, &#x27;kakamega&#x27;, &#x27;kericho&#x27;, &#x27;kajiado&#x27;, &#x27;nandi&#x27;, &#x27;nyeri&#x27;,
&#x27;wote&#x27;, &#x27;kiambu&#x27;, &#x27;mwea&#x27;, &#x27;nakuru&#x27;, &#x27;narok&#x27;]
},
{
name: &#x27;other&#x27;,
locations: [&#x27;other&#x27;, &#x27;none&#x27;, &#x27;unknown&#x27;]
}
];
/** A mock of curated area types. */
const areaTypes: Array&lt;AreaType&gt; &#x3D; [
{
name: &#x27;urban&#x27;,
area: [&#x27;urban&#x27;, &#x27;nairobi&#x27;, &#x27;mombasa&#x27;]
},
{
name: &#x27;rural&#x27;,
area: [&#x27;rural&#x27;, &#x27;kakuma&#x27;, &#x27;kwale&#x27;, &#x27;kinango&#x27;, &#x27;kitui&#x27;, &#x27;nyanza&#x27;]
},
{
name: &#x27;periurban&#x27;,
area: [&#x27;kilifi&#x27;, &#x27;periurban&#x27;]
},
{
name: &#x27;other&#x27;,
area: [&#x27;other&#x27;]
}
];
/** A mock of the user&#x27;s business categories */
const categories: Array&lt;Category&gt; &#x3D; [
{
name: &#x27;system&#x27;,
@ -333,96 +425,60 @@ const categories: Array&lt;Category&gt; &#x3D; [
}
];
const areaNames: Array&lt;AreaName&gt; &#x3D; [
{
name: &#x27;Mukuru Nairobi&#x27;,
locations: [&#x27;kayaba&#x27;, &#x27;kayba&#x27;, &#x27;kambi&#x27;, &#x27;mukuru&#x27;, &#x27;masai&#x27;, &#x27;hazina&#x27;, &#x27;south&#x27;, &#x27;tetra&#x27;, &#x27;tetrapak&#x27;, &#x27;ruben&#x27;, &#x27;rueben&#x27;, &#x27;kingston&#x27;,
&#x27;korokocho&#x27;, &#x27;kingstone&#x27;, &#x27;kamongo&#x27;, &#x27;lungalunga&#x27;, &#x27;sinai&#x27;, &#x27;sigei&#x27;, &#x27;lungu&#x27;, &#x27;lunga lunga&#x27;, &#x27;owino road&#x27;, &#x27;seigei&#x27;]
},
{
name: &#x27;Kinango Kwale&#x27;,
locations: [&#x27;amani&#x27;, &#x27;bofu&#x27;, &#x27;chibuga&#x27;, &#x27;chikomani&#x27;, &#x27;chilongoni&#x27;, &#x27;chigojoni&#x27;, &#x27;chinguluni&#x27;, &#x27;chigato&#x27;, &#x27;chigale&#x27;, &#x27;chikole&#x27;,
&#x27;chilongoni&#x27;, &#x27;chilumani&#x27;, &#x27;chigojoni&#x27;, &#x27;chikomani&#x27;, &#x27;chizini&#x27;, &#x27;chikomeni&#x27;, &#x27;chidzuvini&#x27;, &#x27;chidzivuni&#x27;, &#x27;chikuyu&#x27;, &#x27;chizingo&#x27;,
&#x27;doti&#x27;, &#x27;dzugwe&#x27;, &#x27;dzivani&#x27;, &#x27;dzovuni&#x27;, &#x27;hanje&#x27;, &#x27;kasemeni&#x27;, &#x27;katundani&#x27;, &#x27;kibandaogo&#x27;, &#x27;kibandaongo&#x27;, &#x27;kwale&#x27;, &#x27;kinango&#x27;,
&#x27;kidzuvini&#x27;, &#x27;kalalani&#x27;, &#x27;kafuduni&#x27;, &#x27;kaloleni&#x27;, &#x27;kilibole&#x27;, &#x27;lutsangani&#x27;, &#x27;peku&#x27;, &#x27;gona&#x27;, &#x27;guro&#x27;, &#x27;gandini&#x27;, &#x27;mkanyeni&#x27;, &#x27;myenzeni&#x27;,
&#x27;miyenzeni&#x27;, &#x27;miatsiani&#x27;, &#x27;mienzeni&#x27;, &#x27;mnyenzeni&#x27;, &#x27;minyenzeni&#x27;, &#x27;miyani&#x27;, &#x27;mioleni&#x27;, &#x27;makuluni&#x27;, &#x27;mariakani&#x27;, &#x27;makobeni&#x27;, &#x27;madewani&#x27;,
&#x27;mwangaraba&#x27;, &#x27;mwashanga&#x27;, &#x27;miloeni&#x27;, &#x27;mabesheni&#x27;, &#x27;mazeras&#x27;, &#x27;mazera&#x27;, &#x27;mlola&#x27;, &#x27;muugano&#x27;, &#x27;mulunguni&#x27;, &#x27;mabesheni&#x27;, &#x27;miatsani&#x27;,
&#x27;miatsiani&#x27;, &#x27;mwache&#x27;, &#x27;mwangani&#x27;, &#x27;mwehavikonje&#x27;, &#x27;miguneni&#x27;, &#x27;nzora&#x27;, &#x27;nzovuni&#x27;, &#x27;vikinduni&#x27;, &#x27;vikolani&#x27;, &#x27;vitangani&#x27;, &#x27;viogato&#x27;,
&#x27;vyogato&#x27;, &#x27;vistangani&#x27;, &#x27;yapha&#x27;, &#x27;yava&#x27;, &#x27;yowani&#x27;, &#x27;ziwani&#x27;, &#x27;majengo&#x27;, &#x27;matuga&#x27;, &#x27;vigungani&#x27;, &#x27;vidziweni&#x27;, &#x27;vinyunduni&#x27;, &#x27;ukunda&#x27;,
&#x27;kokotoni&#x27;, &#x27;mikindani&#x27;]
},
{
name: &#x27;Misc Nairobi&#x27;,
locations: [&#x27;nairobi&#x27;, &#x27;west&#x27;, &#x27;lindi&#x27;, &#x27;kibera&#x27;, &#x27;kibira&#x27;, &#x27;kibra&#x27;, &#x27;makina&#x27;, &#x27;soweto&#x27;, &#x27;olympic&#x27;, &#x27;kangemi&#x27;, &#x27;ruiru&#x27;, &#x27;congo&#x27;,
&#x27;kawangware&#x27;, &#x27;kwangware&#x27;, &#x27;donholm&#x27;, &#x27;dagoreti&#x27;, &#x27;dandora&#x27;, &#x27;kabete&#x27;, &#x27;sinai&#x27;, &#x27;donhom&#x27;, &#x27;donholm&#x27;, &#x27;huruma&#x27;, &#x27;kitengela&#x27;,
&#x27;makadara&#x27;, &#x27;,mlolongo&#x27;, &#x27;kenyatta&#x27;, &#x27;mlolongo&#x27;, &#x27;tassia&#x27;, &#x27;tasia&#x27;, &#x27;gatina&#x27;, &#x27;56&#x27;, &#x27;industrial&#x27;, &#x27;kariobangi&#x27;, &#x27;kasarani&#x27;, &#x27;kayole&#x27;,
&#x27;mathare&#x27;, &#x27;pipe&#x27;, &#x27;juja&#x27;, &#x27;uchumi&#x27;, &#x27;jogoo&#x27;, &#x27;umoja&#x27;, &#x27;thika&#x27;, &#x27;kikuyu&#x27;, &#x27;stadium&#x27;, &#x27;buru buru&#x27;, &#x27;ngong&#x27;, &#x27;starehe&#x27;, &#x27;mwiki&#x27;,
&#x27;fuata&#x27;, &#x27;kware&#x27;, &#x27;kabiro&#x27;, &#x27;embakassi&#x27;, &#x27;embakasi&#x27;, &#x27;kmoja&#x27;, &#x27;east&#x27;, &#x27;githurai&#x27;, &#x27;landi&#x27;, &#x27;langata&#x27;, &#x27;limuru&#x27;, &#x27;mathere&#x27;,
&#x27;dagoretti&#x27;, &#x27;kirembe&#x27;, &#x27;muugano&#x27;, &#x27;mwiki&#x27;, &#x27;toi market&#x27;]
},
{
name: &#x27;Misc Mombasa&#x27;,
locations: [&#x27;mombasa&#x27;, &#x27;likoni&#x27;, &#x27;bangla&#x27;, &#x27;bangladesh&#x27;, &#x27;kizingo&#x27;, &#x27;old town&#x27;, &#x27;makupa&#x27;, &#x27;mvita&#x27;, &#x27;ngombeni&#x27;, &#x27;ngómbeni&#x27;, &#x27;ombeni&#x27;,
&#x27;magongo&#x27;, &#x27;miritini&#x27;, &#x27;changamwe&#x27;, &#x27;jomvu&#x27;, &#x27;ohuru&#x27;, &#x27;tudor&#x27;, &#x27;diani&#x27;]
},
{
name: &#x27;Kisauni&#x27;,
locations: [&#x27;bamburi&#x27;, &#x27;kisauni&#x27;, &#x27;mworoni&#x27;, &#x27;nyali&#x27;, &#x27;shanzu&#x27;, &#x27;bombolulu&#x27;, &#x27;mtopanga&#x27;, &#x27;mjambere&#x27;, &#x27;majaoni&#x27;, &#x27;manyani&#x27;, &#x27;magogoni&#x27;,
&#x27;junda&#x27;, &#x27;mwakirunge&#x27;, &#x27;mshomoroni&#x27;]
},
{
name: &#x27;Kilifi&#x27;,
locations: [&#x27;kilfi&#x27;, &#x27;kilifi&#x27;, &#x27;mtwapa&#x27;, &#x27;takaungu&#x27;, &#x27;makongeni&#x27;, &#x27;mnarani&#x27;, &#x27;mnarani&#x27;, &#x27;office&#x27;, &#x27;g.e&#x27;, &#x27;ge&#x27;, &#x27;raibai&#x27;, &#x27;ribe&#x27;]
},
{
name: &#x27;Kakuma&#x27;,
locations: [&#x27;kakuma&#x27;]
},
{
name: &#x27;Kitui&#x27;,
locations: [&#x27;kitui&#x27;, &#x27;mwingi&#x27;]
},
{
name: &#x27;Nyanza&#x27;,
locations: [&#x27;busia&#x27;, &#x27;nyalgunga&#x27;, &#x27;mbita&#x27;, &#x27;siaya&#x27;, &#x27;kisumu&#x27;, &#x27;nyalenda&#x27;, &#x27;hawinga&#x27;, &#x27;rangala&#x27;, &#x27;uyoma&#x27;, &#x27;mumias&#x27;, &#x27;homabay&#x27;, &#x27;homaboy&#x27;,
&#x27;migori&#x27;, &#x27;kusumu&#x27;]
},
{
name: &#x27;Misc Rural Counties&#x27;,
locations: [&#x27;makueni&#x27;, &#x27;meru&#x27;, &#x27;kisii&#x27;, &#x27;bomet&#x27;, &#x27;machakos&#x27;, &#x27;bungoma&#x27;, &#x27;eldoret&#x27;, &#x27;kakamega&#x27;, &#x27;kericho&#x27;, &#x27;kajiado&#x27;, &#x27;nandi&#x27;, &#x27;nyeri&#x27;,
&#x27;wote&#x27;, &#x27;kiambu&#x27;, &#x27;mwea&#x27;, &#x27;nakuru&#x27;, &#x27;narok&#x27;]
},
{
name: &#x27;other&#x27;,
locations: [&#x27;other&#x27;, &#x27;none&#x27;, &#x27;unknown&#x27;]
}
];
const areaTypes: Array&lt;AreaType&gt; &#x3D; [
{
name: &#x27;urban&#x27;,
area: [&#x27;urban&#x27;, &#x27;nairobi&#x27;, &#x27;mombasa&#x27;]
},
{
name: &#x27;rural&#x27;,
area: [&#x27;rural&#x27;, &#x27;kakuma&#x27;, &#x27;kwale&#x27;, &#x27;kinango&#x27;, &#x27;kitui&#x27;, &#x27;nyanza&#x27;]
},
{
name: &#x27;periurban&#x27;,
area: [&#x27;kilifi&#x27;, &#x27;periurban&#x27;]
},
{
name: &#x27;other&#x27;,
area: [&#x27;other&#x27;]
}
];
const accountTypes: Array&lt;string&gt; &#x3D; [&#x27;user&#x27;, &#x27;cashier&#x27;, &#x27;vendor&#x27;, &#x27;tokenagent&#x27;, &#x27;group&#x27;];
const transactionTypes: Array&lt;string&gt; &#x3D; [&#x27;transactions&#x27;, &#x27;conversions&#x27;, &#x27;disbursements&#x27;, &#x27;rewards&#x27;, &#x27;reclamation&#x27;];
/** A mock of curated genders */
const genders: Array&lt;string&gt; &#x3D; [&#x27;male&#x27;, &#x27;female&#x27;, &#x27;other&#x27;];
/** A mock of the tokens in the system. */
const tokens: Array&lt;Token&gt; &#x3D; [
{
name: &#x27;Giftable Reserve&#x27;, symbol: &#x27;GRZ&#x27;, address: &#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;, supply: &#x27;1000000001000000000000000000&#x27;,
decimals: &#x27;18&#x27;, reserves: {}
},
{
name: &#x27;Demo Token&#x27;, symbol: &#x27;DEMO&#x27;, address: &#x27;0xc80D6aFF8194114c52AEcD84c9f15fd5c8abb187&#x27;, supply: &#x27;99999999999999998976&#x27;,
decimals: &#x27;18&#x27;, reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;99999999999999998976&#x27;}},
reserveRatio: &#x27;1000000&#x27;, owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
},
{
name: &#x27;Foo Token&#x27;, symbol: &#x27;FOO&#x27;, address: &#x27;0x9ceD86089f7aBB5A97B40eb0E7521e7aa308d354&#x27;, supply: &#x27;1000000000000000001014&#x27;,
decimals: &#x27;18&#x27;, reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;1000000000000000001014&#x27;}},
reserveRatio: &#x27;1000000&#x27;, owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
},
{
name: &#x27;testb&#x27;, symbol: &#x27;tstb&#x27;, address: &#x27;0xC63cFA91A3BFf41cE31Ff436f67D3ACBC977DB95&#x27;, supply: &#x27;99000&#x27;, decimals: &#x27;18&#x27;,
reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;99000&#x27;}}, reserveRatio: &#x27;1000000&#x27;,
owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
},
{
name: &#x27;testa&#x27;, symbol: &#x27;tsta&#x27;, address: &#x27;0x8fA4101ef19D0a078239d035659e92b278bD083C&#x27;, supply: &#x27;9981&#x27;, decimals: &#x27;18&#x27;,
reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;9981&#x27;}}, reserveRatio: &#x27;1000000&#x27;,
owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
},
{
name: &#x27;testc&#x27;, symbol: &#x27;tstc&#x27;, address: &#x27;0x4A6fA6bc3BfE4C9661bC692D9798425350C9e3D4&#x27;, supply: &#x27;100990&#x27;, decimals: &#x27;18&#x27;,
reserves: {&#x27;0xa686005CE37Dce7738436256982C3903f2E4ea8E&#x27;: {weight: &#x27;1000000&#x27;, balance: &#x27;100990&#x27;}}, reserveRatio: &#x27;1000000&#x27;,
owner: &#x27;0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a&#x27;
}
];
/** A mock of curated transaction types. */
const transactionTypes: Array&lt;string&gt; &#x3D; [&#x27;transactions&#x27;, &#x27;conversions&#x27;, &#x27;disbursements&#x27;, &#x27;rewards&#x27;, &#x27;reclamation&#x27;];
/**
* Intercepts HTTP requests and handles some specified requests internally.
* Provides a backend that can handle requests for certain data items.
*
* @implements HttpInterceptor
*/
@Injectable()
export class MockBackendInterceptor implements HttpInterceptor {
/**
* Intercepts HTTP requests.
*
* @param request - An outgoing HTTP request with an optional typed body.
* @param next - The next HTTP handler or the outgoing request dispatcher.
* @returns The response from the resolved request.
*/
intercept(request: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
const { url, method, headers, body } &#x3D; request;
@ -434,22 +490,17 @@ export class MockBackendInterceptor implements HttpInterceptor {
.pipe(delay(500))
.pipe(dematerialize());
/** Forward requests from select routes to their internal handlers. */
function handleRoute(): Observable&lt;any&gt; {
switch (true) {
case url.endsWith(&#x27;/accounttypes&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getAccountTypes();
case url.endsWith(&#x27;/actions&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getActions();
case url.match(/\/actions\/\d+$/) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getActionById();
case url.match(/\/actions\/\d+$/) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;POST&#x27;:
return approveAction();
case url.endsWith(&#x27;/tokens&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getTokens();
case url.match(/\/tokens\/\w+$/) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getTokenBySymbol();
case url.endsWith(&#x27;/categories&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getCategories();
case url.match(/\/categories\/\w+$/) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getCategoryByProduct();
case url.endsWith(&#x27;/areanames&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getAreaNames();
case url.match(/\/areanames\/\w+$/) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
@ -458,12 +509,18 @@ export class MockBackendInterceptor implements HttpInterceptor {
return getAreaTypes();
case url.match(/\/areatypes\/\w+$/) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getAreaTypeByArea();
case url.endsWith(&#x27;/accounttypes&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getAccountTypes();
case url.endsWith(&#x27;/transactiontypes&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getTransactionTypes();
case url.endsWith(&#x27;/categories&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getCategories();
case url.match(/\/categories\/\w+$/) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getCategoryByProduct();
case url.endsWith(&#x27;/genders&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getGenders();
case url.endsWith(&#x27;/tokens&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getTokens();
case url.match(/\/tokens\/\w+$/) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getTokenBySymbol();
case url.endsWith(&#x27;/transactiontypes&#x27;) &amp;&amp; method &#x3D;&#x3D;&#x3D; &#x27;GET&#x27;:
return getTransactionTypes();
default:
// pass through any requests not handled above
return next.handle(request);
@ -472,15 +529,6 @@ export class MockBackendInterceptor implements HttpInterceptor {
// route functions
function getActions(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(actions);
}
function getActionById(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const queriedAction: Action &#x3D; actions.find(action &#x3D;&gt; action.id &#x3D;&#x3D;&#x3D; idFromUrl());
return ok(queriedAction);
}
function approveAction(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const queriedAction: Action &#x3D; actions.find(action &#x3D;&gt; action.id &#x3D;&#x3D;&#x3D; idFromUrl());
queriedAction.approval &#x3D; body.approval;
@ -488,23 +536,17 @@ export class MockBackendInterceptor implements HttpInterceptor {
return ok(message);
}
function getTokens(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(tokens);
function getAccountTypes(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(accountTypes);
}
function getTokenBySymbol(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const queriedToken: Token &#x3D; tokens.find(token &#x3D;&gt; token.symbol &#x3D;&#x3D;&#x3D; stringFromUrl());
return ok(queriedToken);
function getActions(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(actions);
}
function getCategories(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const categoryList: Array&lt;string&gt; &#x3D; categories.map(category &#x3D;&gt; category.name);
return ok(categoryList);
}
function getCategoryByProduct(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const queriedCategory: Category &#x3D; categories.find(category &#x3D;&gt; category.products.includes(stringFromUrl()));
return ok(queriedCategory.name);
function getActionById(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const queriedAction: Action &#x3D; actions.find(action &#x3D;&gt; action.id &#x3D;&#x3D;&#x3D; idFromUrl());
return ok(queriedAction);
}
function getAreaNames(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
@ -527,24 +569,35 @@ export class MockBackendInterceptor implements HttpInterceptor {
return ok(queriedAreaType.name);
}
function getAccountTypes(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(accountTypes);
function getCategories(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const categoryList: Array&lt;string&gt; &#x3D; categories.map(category &#x3D;&gt; category.name);
return ok(categoryList);
}
function getTransactionTypes(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(transactionTypes);
function getCategoryByProduct(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const queriedCategory: Category &#x3D; categories.find(category &#x3D;&gt; category.products.includes(stringFromUrl()));
return ok(queriedCategory.name);
}
function getGenders(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(genders);
}
// helper functions
function ok(responseBody: any): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return of(new HttpResponse({ status: 200, body: responseBody }));
function getTokens(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(tokens);
}
function getTokenBySymbol(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
const queriedToken: Token &#x3D; tokens.find(token &#x3D;&gt; token.symbol &#x3D;&#x3D;&#x3D; stringFromUrl());
return ok(queriedToken);
}
function getTransactionTypes(): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return ok(transactionTypes);
}
// helper functions
function error(message): Observable&lt;any&gt; {
return throwError({ status: 400, error: { message } });
}
@ -554,6 +607,10 @@ export class MockBackendInterceptor implements HttpInterceptor {
return parseInt(urlParts[urlParts.length - 1], 10);
}
function ok(responseBody: any): Observable&lt;HttpResponse&lt;any&gt;&gt; {
return of(new HttpResponse({ status: 200, body: responseBody }));
}
function stringFromUrl(): string {
const urlParts: Array&lt;string&gt; &#x3D; url.split(&#x27;/&#x27;);
return urlParts[urlParts.length - 1];
@ -561,6 +618,11 @@ export class MockBackendInterceptor implements HttpInterceptor {
}
}
/**
* Exports the MockBackendInterceptor as an Angular provider.
*
* @exports
*/
export const MockBackendProvider &#x3D; {
provide: HTTP_INTERCEPTORS,
useClass: MockBackendInterceptor,

File diff suppressed because one or more lines are too long

View File

@ -78,9 +78,6 @@
<li>
<a href="#readCsv" title="src/app/_helpers/read-csv.ts"><b>readCsv</b>&nbsp;&nbsp;&nbsp;(src/.../read-csv.ts)</a>
</li>
<li>
<a href="#removeSpecialChar" title="src/app/_helpers/export-csv.ts"><b>removeSpecialChar</b>&nbsp;&nbsp;&nbsp;(src/.../export-csv.ts)</a>
</li>
<li>
<a href="#vcardValidation" title="src/app/_helpers/schema-validation.ts"><b>vcardValidation</b>&nbsp;&nbsp;&nbsp;(src/.../schema-validation.ts)</a>
</li>
@ -117,6 +114,8 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Returns the sum of all values in an array.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -125,6 +124,7 @@
<tr>
<td>Name</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -136,17 +136,33 @@
</td>
<td>
<ul>
<li>An array of numbers.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<b>Example :</b>
<div>
<pre class="line-numbers"><code class="language-html">Prints 6 for the array [1, 2, 3]:&lt;/p&gt;
&lt;p&gt;```typescript&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;console.log(arraySum([1, 2, 3]));&lt;/li&gt;
&lt;li&gt;```&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>
</div>
<div class="io-description">
<p>The sum of all values in the array.</p>
</div>
</td>
@ -179,6 +195,8 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Copies set text to clipboard.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -188,6 +206,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -202,17 +221,33 @@
</td>
<td>
<ul>
<li>The text to be copied to the clipboard.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<b>Example :</b>
<div>
<pre class="line-numbers"><code class="language-html">copies &amp;#39;Hello World!&amp;#39; to the clipboard and prints &amp;quot;true&amp;quot;:&lt;/p&gt;
&lt;p&gt;```typescript&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;console.log(copyToClipboard(&amp;#39;Hello World!&amp;#39;));&lt;/li&gt;
&lt;li&gt;```&lt;/li&gt;
&lt;/ul&gt;</code></pre>
</div>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/boolean" target="_blank" >boolean</a></code>
</div>
<div class="io-description">
<p>true - If the copy operation is successful.</p>
</div>
</td>
@ -245,6 +280,8 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Exports data to a CSV format and provides a download file.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -253,6 +290,7 @@
<tr>
<td>Name</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -264,6 +302,12 @@
</td>
<td>
<ul>
<li>An array of data to be converted to CSV format.</li>
</ul>
</td>
</tr>
<tr>
<td>filename</td>
@ -273,6 +317,12 @@
</td>
<td>
<ul>
<li>The name of the file to be downloaded.</li>
</ul>
</td>
</tr>
<tr>
<td>delimiter</td>
@ -282,6 +332,13 @@
</td>
<td>
<ul>
<li>The delimiter to be used when converting to CSV format.
Defaults to commas.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -294,66 +351,6 @@
</div>
<div class="io-description">
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-sm table-bordered">
<tbody>
<tr>
<td class="col-md-4">
<a name="removeSpecialChar"></a>
<span class="name">
<b>
removeSpecialChar
</b>
<a href="#removeSpecialChar"><span class="icon ion-ios-link"></span></a>
</span>
</td>
</tr>
<tr>
<td class="col-md-4">
<code>removeSpecialChar(str)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description">
<b>Parameters :</b>
<table class="params">
<thead>
<tr>
<td>Name</td>
<td>Optional</td>
</tr>
</thead>
<tbody>
<tr>
<td>str</td>
<td>
No
</td>
</tr>
</tbody>
</table>
</div>
<div>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
</div>
<div class="io-description">
</div>
</td>
</tr>
@ -385,6 +382,8 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Provides an avenue of fetching resources via HTTP calls. </p>
</div>
<div class="io-description">
<b>Returns : </b> <code><a href="https://www.typescriptlang.org/docs/handbook/basic-types.html" target="_blank" >void</a></code>
@ -420,6 +419,8 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Parses data to CSV format.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -429,6 +430,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -443,6 +445,12 @@
</td>
<td>
<ul>
<li>The data to be parsed.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -454,6 +462,7 @@
</div>
<div class="io-description">
<p>An array of the parsed data.</p>
</div>
</td>
@ -484,6 +493,8 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Reads a csv file and converts it to an array.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -493,6 +504,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -507,6 +519,12 @@
</td>
<td>
<ul>
<li>The file to be read.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -518,6 +536,7 @@
</div>
<div class="io-description">
<p>An array of the read data.</p>
</div>
</td>
@ -550,6 +569,8 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Validates a person object against the defined Person schema.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -559,6 +580,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -573,6 +595,12 @@
</td>
<td>
<ul>
<li>A person object to be validated.</li>
</ul>
</td>
</tr>
</tbody>
</table>
@ -614,6 +642,8 @@
<tr>
<td class="col-md-4">
<div class="io-description"><p>Validates a vcard object against the defined Vcard schema.</p>
</div>
<div class="io-description">
<b>Parameters :</b>
@ -623,6 +653,7 @@
<td>Name</td>
<td>Type</td>
<td>Optional</td>
<td>Description</td>
</tr>
</thead>
<tbody>
@ -637,6 +668,12 @@
</td>
<td>
<ul>
<li>A vcard object to be validated.</li>
</ul>
</td>
</tr>
</tbody>
</table>

View File

@ -294,6 +294,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>A mock of the curated account types. </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -328,6 +334,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>A mock of actions made by the admin staff. </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -418,6 +430,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>A mock of curated area names. </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -462,6 +480,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>A mock of curated area types. </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -589,6 +613,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>A mock of the user&#39;s business categories </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -616,6 +646,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>A mock of curated genders </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -647,6 +683,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>Exports the MockBackendInterceptor as an Angular provider.</p>
</div>
</td>
</tr>
</tbody>
</table>
@ -704,6 +746,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>A mock of the tokens in the system. </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -731,6 +779,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>A mock of curated transaction types. </p>
</div>
</td>
</tr>
</tbody>
</table>
@ -982,6 +1036,12 @@
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-description"><p>An object defining the properties of the data read. </p>
</div>
</td>
</tr>
</tbody>
</table>

File diff suppressed because one or more lines are too long

View File

@ -68,6 +68,18 @@
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Custom provider that defines how form controls behave with regards to displaying error messages.</p>
</div>
<dl class="tsd-comment-tags">
<dt>implements</dt>
<dd><p>ErrorStateMatcher</p>
</dd>
</dl>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
@ -131,19 +143,31 @@
<aside class="tsd-sources">
<p>Implementation of ErrorStateMatcher.isErrorState</p>
<ul>
<li>Defined in src/app/_helpers/custom-error-state-matcher.ts:5</li>
<li>Defined in src/app/_helpers/custom-error-state-matcher.ts:18</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Checks whether an invalid input has been made and an error should be made.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>control: <span class="tsd-signature-type">FormControl</span></h5>
<div class="tsd-comment tsd-typography">
<p>Tracks the value and validation status of an individual form control.</p>
</div>
</li>
<li>
<h5>form: <span class="tsd-signature-type">FormGroupDirective</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">NgForm</span></h5>
<div class="tsd-comment tsd-typography">
<p>Binding of an existing FormGroup to a DOM element.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
<p>true - If an invalid input has been made to the form control.</p>
</li>
</ul>
</section>

View File

@ -68,6 +68,13 @@
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Provides methods to perform custom validation to form inputs.</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
@ -125,13 +132,21 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/custom.validator.ts:4</li>
<li>Defined in src/app/_helpers/custom.validator.ts:13</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Sets errors to the confirm password input field if it does not match with the value in the password input field.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>control: <span class="tsd-signature-type">AbstractControl</span></h5>
<div class="tsd-comment tsd-typography">
<p>The control object of the form being validated.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
@ -148,19 +163,31 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/custom.validator.ts:12</li>
<li>Defined in src/app/_helpers/custom.validator.ts:28</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Sets errors to a form field if it does not match with the regular expression given.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>regex: <span class="tsd-signature-type">RegExp</span></h5>
<div class="tsd-comment tsd-typography">
<p>The regular expression to match with the form field.</p>
</div>
</li>
<li>
<h5>error: <span class="tsd-signature-type">ValidationErrors</span></h5>
<div class="tsd-comment tsd-typography">
<p>Defines the map of errors to return from failed validation checks.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">ValidationErrors</span></h4>
<p>The map of errors returned from failed validation checks.</p>
</li>
</ul>
</section>

View File

@ -68,6 +68,13 @@
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Provides a hook for centralized exception handling.</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
@ -121,16 +128,27 @@
<aside class="tsd-sources">
<p>Overrides ErrorHandler.constructor</p>
<ul>
<li>Defined in src/app/_helpers/global-error-handler.ts:18</li>
<li>Defined in src/app/_helpers/global-error-handler.ts:42</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Initialization of the Global Error Handler.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>loggingService: <a href="app__services_logging_service.loggingservice.html" class="tsd-signature-type" data-tsd-kind="Class">LoggingService</a></h5>
<div class="tsd-comment tsd-typography">
<p>A service that provides logging capabilities.</p>
</div>
</li>
<li>
<h5>router: <span class="tsd-signature-type">Router</span></h5>
<div class="tsd-comment tsd-typography">
<p>A service that provides navigation among views and URL manipulation capabilities.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <a href="app__helpers_global_error_handler.globalerrorhandler.html" class="tsd-signature-type" data-tsd-kind="Class">GlobalErrorHandler</a></h4>
@ -146,9 +164,14 @@
<div class="tsd-signature tsd-kind-icon">sentences<wbr>For<wbr>Warning<wbr>Logging<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol"> = []</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/global-error-handler.ts:18</li>
<li>Defined in src/app/_helpers/global-error-handler.ts:42</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>An array of sentence sections that denote warnings.</p>
</div>
</div>
</section>
</section>
<section class="tsd-panel-group tsd-member-group ">
@ -164,13 +187,21 @@
<aside class="tsd-sources">
<p>Overrides ErrorHandler.handleError</p>
<ul>
<li>Defined in src/app/_helpers/global-error-handler.ts:27</li>
<li>Defined in src/app/_helpers/global-error-handler.ts:62</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Handles different types of errors.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>error: <span class="tsd-signature-type">Error</span></h5>
<div class="tsd-comment tsd-typography">
<p>An error objects thrown when a runtime errors occurs.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
@ -187,16 +218,25 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/global-error-handler.ts:67</li>
<li>Defined in src/app/_helpers/global-error-handler.ts:89</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Checks if an error is of type warning.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>errorTraceString: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>A description of the error and it&#39;s stack trace.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
<p>true - If the error is of type warning.</p>
</li>
</ul>
</section>
@ -210,13 +250,21 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/global-error-handler.ts:47</li>
<li>Defined in src/app/_helpers/global-error-handler.ts:109</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Write appropriate logs according to the type of error.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>error: <span class="tsd-signature-type">any</span></h5>
<div class="tsd-comment tsd-typography">
<p>An error objects thrown when a runtime errors occurs.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>

View File

@ -68,6 +68,13 @@
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>A generalized http response error.</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
@ -124,16 +131,27 @@
<aside class="tsd-sources">
<p>Overrides Error.constructor</p>
<ul>
<li>Defined in src/app/_helpers/global-error-handler.ts:8</li>
<li>Defined in src/app/_helpers/global-error-handler.ts:16</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Initialize the HttpError class.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>message: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>The message given by the error.</p>
</div>
</li>
<li>
<h5>status: <span class="tsd-signature-type">number</span></h5>
<div class="tsd-comment tsd-typography">
<p>The status code given by the error.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <a href="app__helpers_global_error_handler.httperror.html" class="tsd-signature-type" data-tsd-kind="Class">HttpError</a></h4>
@ -182,9 +200,14 @@
<div class="tsd-signature tsd-kind-icon">status<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/global-error-handler.ts:8</li>
<li>Defined in src/app/_helpers/global-error-handler.ts:16</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>The error&#39;s status code.</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static tsd-is-external">
<a name="preparestacktrace" class="tsd-anchor"></a>

View File

@ -68,6 +68,19 @@
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Intercepts HTTP requests and handles some specified requests internally.
Provides a backend that can handle requests for certain data items.</p>
</div>
<dl class="tsd-comment-tags">
<dt>implements</dt>
<dd><p>HttpInterceptor</p>
</dd>
</dl>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
@ -131,19 +144,31 @@
<aside class="tsd-sources">
<p>Implementation of HttpInterceptor.intercept</p>
<ul>
<li>Defined in src/app/_helpers/mock-backend.ts:240</li>
<li>Defined in src/app/_helpers/mock-backend.ts:268</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Intercepts HTTP requests.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>request: <span class="tsd-signature-type">HttpRequest</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">&gt;</span></h5>
<div class="tsd-comment tsd-typography">
<p>An outgoing HTTP request with an optional typed body.</p>
</div>
</li>
<li>
<h5>next: <span class="tsd-signature-type">HttpHandler</span></h5>
<div class="tsd-comment tsd-typography">
<p>The next HTTP handler or the outgoing request dispatcher.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Observable</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">HttpEvent</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">&gt;</span></h4>
<p>The response from the resolved request.</p>
</li>
</ul>
</section>

View File

@ -90,16 +90,32 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/array-sum.ts:1</li>
<li>Defined in src/app/_helpers/array-sum.ts:13</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Returns the sum of all values in an array.</p>
</div>
<dl class="tsd-comment-tags">
<dt>example</dt>
<dd><p>Prints 6 for the array [1, 2, 3]:</p>
<pre><code class="language-typescript"><span style="color: #001080">console</span><span style="color: #000000">.</span><span style="color: #795E26">log</span><span style="color: #000000">(</span><span style="color: #795E26">arraySum</span><span style="color: #000000">([</span><span style="color: #098658">1</span><span style="color: #000000">, </span><span style="color: #098658">2</span><span style="color: #000000">, </span><span style="color: #098658">3</span><span style="color: #000000">]));</span>
</code></pre>
</dd>
</dl>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>arr: <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">[]</span></h5>
<div class="tsd-comment tsd-typography">
<p>An array of numbers.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4>
<p>The sum of all values in the array.</p>
</li>
</ul>
</section>

View File

@ -90,16 +90,32 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/clipboard-copy.ts:1</li>
<li>Defined in src/app/_helpers/clipboard-copy.ts:13</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Copies set text to clipboard.</p>
</div>
<dl class="tsd-comment-tags">
<dt>example</dt>
<dd><p>copies &#39;Hello World!&#39; to the clipboard and prints &quot;true&quot;:</p>
<pre><code class="language-typescript"><span style="color: #001080">console</span><span style="color: #000000">.</span><span style="color: #795E26">log</span><span style="color: #000000">(</span><span style="color: #795E26">copyToClipboard</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;Hello World!&#039;</span><span style="color: #000000">));</span>
</code></pre>
</dd>
</dl>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>text: <span class="tsd-signature-type">any</span></h5>
<div class="tsd-comment tsd-typography">
<p>The text to be copied to the clipboard.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
<p>true - If the copy operation is successful.</p>
</li>
</ul>
</section>

View File

@ -90,19 +90,34 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/export-csv.ts:1</li>
<li>Defined in src/app/_helpers/export-csv.ts:9</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Exports data to a CSV format and provides a download file.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>arrayData: <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5>
<div class="tsd-comment tsd-typography">
<p>An array of data to be converted to CSV format.</p>
</div>
</li>
<li>
<h5>filename: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>The name of the file to be downloaded.</p>
</div>
</li>
<li>
<h5>delimiter: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> = &#x27;,&#x27;</span></h5>
<div class="tsd-comment tsd-typography">
<p>The delimiter to be used when converting to CSV format.
Defaults to commas.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>

View File

@ -90,9 +90,14 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/http-getter.ts:1</li>
<li>Defined in src/app/_helpers/http-getter.ts:2</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Provides an avenue of fetching resources via HTTP calls.</p>
</div>
</div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
</li>
</ul>

View File

@ -92,9 +92,18 @@
<div class="tsd-signature tsd-kind-icon">Mock<wbr>Backend<wbr>Provider<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>multi<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">; </span>provide<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">InjectionToken</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">HttpInterceptor</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">; </span>useClass<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">typeof </span><a href="../classes/app__helpers_mock_backend.mockbackendinterceptor.html" class="tsd-signature-type" data-tsd-kind="Class">MockBackendInterceptor</a><span class="tsd-signature-symbol"> }</span><span class="tsd-signature-symbol"> = ...</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/mock-backend.ts:378</li>
<li>Defined in src/app/_helpers/mock-backend.ts:412</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Exports the MockBackendInterceptor as an Angular provider.</p>
</div>
<dl class="tsd-comment-tags">
<dt>exports</dt>
<dd></dd>
</dl>
</div>
<div class="tsd-type-declaration">
<h4>Type declaration</h4>
<ul class="tsd-parameters">

View File

@ -90,16 +90,25 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/read-csv.ts:6</li>
<li>Defined in src/app/_helpers/read-csv.ts:13</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Reads a csv file and converts it to an array.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>input: <span class="tsd-signature-type">any</span></h5>
<div class="tsd-comment tsd-typography">
<p>The file to be read.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">void</span></h4>
<p>An array of the read data.</p>
</li>
</ul>
</section>

View File

@ -91,13 +91,21 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/schema-validation.ts:3</li>
<li>Defined in src/app/_helpers/schema-validation.ts:9</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Validates a person object against the defined Person schema.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>person: <span class="tsd-signature-type">any</span></h5>
<div class="tsd-comment tsd-typography">
<p>A person object to be validated.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>
@ -114,13 +122,21 @@
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in src/app/_helpers/schema-validation.ts:11</li>
<li>Defined in src/app/_helpers/schema-validation.ts:22</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Validates a vcard object against the defined Vcard schema.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>vcard: <span class="tsd-signature-type">any</span></h5>
<div class="tsd-comment tsd-typography">
<p>A vcard object to be validated.</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>

View File

@ -1,7 +1,20 @@
/**
* Returns the sum of all values in an array.
*
* @example
* Prints 6 for the array [1, 2, 3]:
* ```typescript
* console.log(arraySum([1, 2, 3]));
* ```
*
* @param arr - An array of numbers.
* @return The sum of all values in the array.
*/
function arraySum(arr: Array<number>): number {
return arr.reduce((accumulator, current) => accumulator + current, 0);
}
/** @exports */
export {
arraySum
};

View File

@ -1,3 +1,15 @@
/**
* Copies set text to clipboard.
*
* @example
* copies 'Hello World!' to the clipboard and prints "true":
* ```typescript
* console.log(copyToClipboard('Hello World!'));
* ```
*
* @param text - The text to be copied to the clipboard.
* @returns true - If the copy operation is successful.
*/
function copyToClipboard(text: any): boolean {
// create our hidden div element
const hiddenCopy: HTMLDivElement = document.createElement('div');
@ -48,6 +60,7 @@ function copyToClipboard(text: any): boolean {
return true;
}
/** @exports */
export {
copyToClipboard
};

View File

@ -1,3 +1,4 @@
// Application imports
import { CustomErrorStateMatcher } from '@app/_helpers/custom-error-state-matcher';
describe('CustomErrorStateMatcher', () => {

View File

@ -1,7 +1,20 @@
import {ErrorStateMatcher} from '@angular/material/core';
// Core imports
import {FormControl, FormGroupDirective, NgForm} from '@angular/forms';
import {ErrorStateMatcher} from '@angular/material/core';
/**
* Custom provider that defines how form controls behave with regards to displaying error messages.
*
* @implements ErrorStateMatcher
*/
export class CustomErrorStateMatcher implements ErrorStateMatcher{
/**
* Checks whether an invalid input has been made and an error should be made.
*
* @param control - Tracks the value and validation status of an individual form control.
* @param form - Binding of an existing FormGroup to a DOM element.
* @returns true - If an invalid input has been made to the form control.
*/
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted: boolean = form && form.submitted;
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));

View File

@ -1,3 +1,4 @@
// Application imports
import { CustomValidator } from '@app/_helpers/custom.validator';
describe('Custom.Validator', () => {

View File

@ -1,6 +1,15 @@
// Core imports
import {AbstractControl, ValidationErrors} from '@angular/forms';
/**
* Provides methods to perform custom validation to form inputs.
*/
export class CustomValidator {
/**
* Sets errors to the confirm password input field if it does not match with the value in the password input field.
*
* @param control - The control object of the form being validated.
*/
static passwordMatchValidator(control: AbstractControl): void {
const password: string = control.get('password').value;
const confirmPassword: string = control.get('confirmPassword').value;
@ -9,6 +18,13 @@ export class CustomValidator {
}
}
/**
* Sets errors to a form field if it does not match with the regular expression given.
*
* @param regex - The regular expression to match with the form field.
* @param error - Defines the map of errors to return from failed validation checks.
* @returns The map of errors returned from failed validation checks.
*/
static patternValidator(regex: RegExp, error: ValidationErrors): ValidationErrors | null {
return (control: AbstractControl): { [key: string]: any } => {
if (!control.value) {

View File

@ -1,3 +1,11 @@
/**
* Exports data to a CSV format and provides a download file.
*
* @param arrayData - An array of data to be converted to CSV format.
* @param filename - The name of the file to be downloaded.
* @param delimiter - The delimiter to be used when converting to CSV format.
* Defaults to commas.
*/
function exportCsv(arrayData: Array<any>, filename: string, delimiter: string = ','): void {
if (arrayData === undefined || arrayData.length === 0) {
alert('No data to be exported!');
@ -26,13 +34,7 @@ function exportCsv(arrayData: Array<any>, filename: string, delimiter: string =
downloadLink.click();
}
function removeSpecialChar(str: string): string {
if (str === null || str === '') {
return '';
}
return str.replace(/[^a-zA-Z0-9 ]/g, '');
}
/** @exports */
export {
exportCsv
};

View File

@ -1,4 +1,5 @@
import { GlobalErrorHandler } from './global-error-handler';
// Application imports
import { GlobalErrorHandler } from '@app/_helpers/global-error-handler';
describe('GlobalErrorHandler', () => {
it('should create an instance', () => {

View File

@ -1,11 +1,26 @@
import {ErrorHandler, Injectable} from '@angular/core';
import {LoggingService} from '@app/_services/logging.service';
// Core imports
import {HttpErrorResponse} from '@angular/common/http';
import {ErrorHandler, Injectable} from '@angular/core';
import {Router} from '@angular/router';
// A generalized http response error
// Application imports
import {LoggingService} from '@app/_services/logging.service';
/**
* A generalized http response error.
*
* @extends Error
*/
export class HttpError extends Error {
/** The error's status code. */
public status: number;
/**
* Initialize the HttpError class.
*
* @param message - The message given by the error.
* @param status - The status code given by the error.
*/
constructor(message: string, status: number) {
super(message);
this.status = status;
@ -13,10 +28,25 @@ export class HttpError extends Error {
}
}
/**
* Provides a hook for centralized exception handling.
*
* @extends ErrorHandler
*/
@Injectable()
export class GlobalErrorHandler extends ErrorHandler {
/**
* An array of sentence sections that denote warnings.
* @private
*/
private sentencesForWarningLogging: Array<string> = [];
/**
* Initialization of the Global Error Handler.
*
* @param loggingService - A service that provides logging capabilities.
* @param router - A service that provides navigation among views and URL manipulation capabilities.
*/
constructor(
private loggingService: LoggingService,
private router: Router
@ -24,6 +54,11 @@ export class GlobalErrorHandler extends ErrorHandler {
super();
}
/**
* Handles different types of errors.
*
* @param error - An error objects thrown when a runtime errors occurs.
*/
handleError(error: Error): void {
this.logError(error);
const message: string = error.message ? error.message : error.toString();
@ -44,21 +79,13 @@ export class GlobalErrorHandler extends ErrorHandler {
throw error;
}
logError(error: any): void {
const route: string = this.router.url;
if (error instanceof HttpErrorResponse) {
this.loggingService.sendErrorLevelMessage(
`There was an HTTP error on route ${route}.\n${error.message}.\nStatus code: ${(error as HttpErrorResponse).status}`,
this, {error});
} else if (error instanceof TypeError) {
this.loggingService.sendErrorLevelMessage(`There was a Type error on route ${route}.\n${error.message}`, this, {error});
} else if (error instanceof Error) {
this.loggingService.sendErrorLevelMessage(`There was a general error on route ${route}.\n${error.message}`, this, {error});
} else {
this.loggingService.sendErrorLevelMessage(`Nobody threw an error but something happened on route ${route}!`, this, {error});
}
}
/**
* Checks if an error is of type warning.
*
* @param errorTraceString - A description of the error and it's stack trace.
* @returns true - If the error is of type warning.
* @private
*/
private isWarning(errorTraceString: string): boolean {
let isWarning: boolean = true;
if (errorTraceString.includes('/src/app/')) {
@ -73,4 +100,24 @@ export class GlobalErrorHandler extends ErrorHandler {
return isWarning;
}
/**
* Write appropriate logs according to the type of error.
*
* @param error - An error objects thrown when a runtime errors occurs.
*/
logError(error: any): void {
const route: string = this.router.url;
if (error instanceof HttpErrorResponse) {
this.loggingService.sendErrorLevelMessage(
`There was an HTTP error on route ${route}.\n${error.message}.\nStatus code: ${(error as HttpErrorResponse).status}`,
this, {error});
} else if (error instanceof TypeError) {
this.loggingService.sendErrorLevelMessage(`There was a Type error on route ${route}.\n${error.message}`, this, {error});
} else if (error instanceof Error) {
this.loggingService.sendErrorLevelMessage(`There was a general error on route ${route}.\n${error.message}`, this, {error});
} else {
this.loggingService.sendErrorLevelMessage(`Nobody threw an error but something happened on route ${route}!`, this, {error});
}
}
}

View File

@ -1,6 +1,13 @@
/** Provides an avenue of fetching resources via HTTP calls. */
function HttpGetter(): void {}
HttpGetter.prototype.get = filename => new Promise((resolve, reject) => {
/**
* Fetches files using HTTP get requests.
*
* @param filename - The filename to fetch.
* @returns The HTTP response text.
*/
HttpGetter.prototype.get = (filename: string) => new Promise((resolve, reject) => {
const xhr: XMLHttpRequest = new XMLHttpRequest();
xhr.addEventListener('load', (e) => {
if (xhr.status === 200) {
@ -13,6 +20,7 @@ HttpGetter.prototype.get = filename => new Promise((resolve, reject) => {
xhr.send();
});
/** @exports */
export {
HttpGetter
};

View File

@ -1,10 +1,10 @@
export * from '@app/_helpers/array-sum';
export * from '@app/_helpers/clipboard-copy';
export * from '@app/_helpers/custom.validator';
export * from '@app/_helpers/custom-error-state-matcher';
export * from '@app/_helpers/mock-backend';
export * from '@app/_helpers/array-sum';
export * from '@app/_helpers/http-getter';
export * from '@app/_helpers/global-error-handler';
export * from '@app/_helpers/export-csv';
export * from '@app/_helpers/global-error-handler';
export * from '@app/_helpers/http-getter';
export * from '@app/_helpers/mock-backend';
export * from '@app/_helpers/read-csv';
export * from '@app/_helpers/clipboard-copy';
export * from '@app/_helpers/schema-validation';

View File

@ -1,9 +1,18 @@
// Core imports
import {HTTP_INTERCEPTORS, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
import {Injectable} from '@angular/core';
// Third party imports
import {Observable, of, throwError} from 'rxjs';
import {delay, dematerialize, materialize, mergeMap} from 'rxjs/operators';
// Application imports
import {Action, AreaName, AreaType, Category, Token} from '@app/_models';
/** A mock of the curated account types. */
const accountTypes: Array<string> = ['user', 'cashier', 'vendor', 'tokenagent', 'group'];
/** A mock of actions made by the admin staff. */
const actions: Array<Action> = [
{ id: 1, user: 'Tom', role: 'enroller', action: 'Disburse RSV 100', approval: false },
{ id: 2, user: 'Christine', role: 'admin', action: 'Change user phone number', approval: true },
@ -13,38 +22,93 @@ const actions: Array<Action> = [
{ id: 6, user: 'Patience', role: 'enroller', action: 'Change user information', approval: false }
];
const tokens: Array<Token> = [
/** A mock of curated area names. */
const areaNames: Array<AreaName> = [
{
name: 'Giftable Reserve', symbol: 'GRZ', address: '0xa686005CE37Dce7738436256982C3903f2E4ea8E', supply: '1000000001000000000000000000',
decimals: '18', reserves: {}
name: 'Mukuru Nairobi',
locations: ['kayaba', 'kayba', 'kambi', 'mukuru', 'masai', 'hazina', 'south', 'tetra', 'tetrapak', 'ruben', 'rueben', 'kingston',
'korokocho', 'kingstone', 'kamongo', 'lungalunga', 'sinai', 'sigei', 'lungu', 'lunga lunga', 'owino road', 'seigei']
},
{
name: 'Demo Token', symbol: 'DEMO', address: '0xc80D6aFF8194114c52AEcD84c9f15fd5c8abb187', supply: '99999999999999998976',
decimals: '18', reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '99999999999999998976'}},
reserveRatio: '1000000', owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
name: 'Kinango Kwale',
locations: ['amani', 'bofu', 'chibuga', 'chikomani', 'chilongoni', 'chigojoni', 'chinguluni', 'chigato', 'chigale', 'chikole',
'chilongoni', 'chilumani', 'chigojoni', 'chikomani', 'chizini', 'chikomeni', 'chidzuvini', 'chidzivuni', 'chikuyu', 'chizingo',
'doti', 'dzugwe', 'dzivani', 'dzovuni', 'hanje', 'kasemeni', 'katundani', 'kibandaogo', 'kibandaongo', 'kwale', 'kinango',
'kidzuvini', 'kalalani', 'kafuduni', 'kaloleni', 'kilibole', 'lutsangani', 'peku', 'gona', 'guro', 'gandini', 'mkanyeni', 'myenzeni',
'miyenzeni', 'miatsiani', 'mienzeni', 'mnyenzeni', 'minyenzeni', 'miyani', 'mioleni', 'makuluni', 'mariakani', 'makobeni', 'madewani',
'mwangaraba', 'mwashanga', 'miloeni', 'mabesheni', 'mazeras', 'mazera', 'mlola', 'muugano', 'mulunguni', 'mabesheni', 'miatsani',
'miatsiani', 'mwache', 'mwangani', 'mwehavikonje', 'miguneni', 'nzora', 'nzovuni', 'vikinduni', 'vikolani', 'vitangani', 'viogato',
'vyogato', 'vistangani', 'yapha', 'yava', 'yowani', 'ziwani', 'majengo', 'matuga', 'vigungani', 'vidziweni', 'vinyunduni', 'ukunda',
'kokotoni', 'mikindani']
},
{
name: 'Foo Token', symbol: 'FOO', address: '0x9ceD86089f7aBB5A97B40eb0E7521e7aa308d354', supply: '1000000000000000001014',
decimals: '18', reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '1000000000000000001014'}},
reserveRatio: '1000000', owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
name: 'Misc Nairobi',
locations: ['nairobi', 'west', 'lindi', 'kibera', 'kibira', 'kibra', 'makina', 'soweto', 'olympic', 'kangemi', 'ruiru', 'congo',
'kawangware', 'kwangware', 'donholm', 'dagoreti', 'dandora', 'kabete', 'sinai', 'donhom', 'donholm', 'huruma', 'kitengela',
'makadara', ',mlolongo', 'kenyatta', 'mlolongo', 'tassia', 'tasia', 'gatina', '56', 'industrial', 'kariobangi', 'kasarani', 'kayole',
'mathare', 'pipe', 'juja', 'uchumi', 'jogoo', 'umoja', 'thika', 'kikuyu', 'stadium', 'buru buru', 'ngong', 'starehe', 'mwiki',
'fuata', 'kware', 'kabiro', 'embakassi', 'embakasi', 'kmoja', 'east', 'githurai', 'landi', 'langata', 'limuru', 'mathere',
'dagoretti', 'kirembe', 'muugano', 'mwiki', 'toi market']
},
{
name: 'testb', symbol: 'tstb', address: '0xC63cFA91A3BFf41cE31Ff436f67D3ACBC977DB95', supply: '99000', decimals: '18',
reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '99000'}}, reserveRatio: '1000000',
owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
name: 'Misc Mombasa',
locations: ['mombasa', 'likoni', 'bangla', 'bangladesh', 'kizingo', 'old town', 'makupa', 'mvita', 'ngombeni', 'ngómbeni', 'ombeni',
'magongo', 'miritini', 'changamwe', 'jomvu', 'ohuru', 'tudor', 'diani']
},
{
name: 'testa', symbol: 'tsta', address: '0x8fA4101ef19D0a078239d035659e92b278bD083C', supply: '9981', decimals: '18',
reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '9981'}}, reserveRatio: '1000000',
owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
name: 'Kisauni',
locations: ['bamburi', 'kisauni', 'mworoni', 'nyali', 'shanzu', 'bombolulu', 'mtopanga', 'mjambere', 'majaoni', 'manyani', 'magogoni',
'junda', 'mwakirunge', 'mshomoroni']
},
{
name: 'testc', symbol: 'tstc', address: '0x4A6fA6bc3BfE4C9661bC692D9798425350C9e3D4', supply: '100990', decimals: '18',
reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '100990'}}, reserveRatio: '1000000',
owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
name: 'Kilifi',
locations: ['kilfi', 'kilifi', 'mtwapa', 'takaungu', 'makongeni', 'mnarani', 'mnarani', 'office', 'g.e', 'ge', 'raibai', 'ribe']
},
{
name: 'Kakuma',
locations: ['kakuma']
},
{
name: 'Kitui',
locations: ['kitui', 'mwingi']
},
{
name: 'Nyanza',
locations: ['busia', 'nyalgunga', 'mbita', 'siaya', 'kisumu', 'nyalenda', 'hawinga', 'rangala', 'uyoma', 'mumias', 'homabay', 'homaboy',
'migori', 'kusumu']
},
{
name: 'Misc Rural Counties',
locations: ['makueni', 'meru', 'kisii', 'bomet', 'machakos', 'bungoma', 'eldoret', 'kakamega', 'kericho', 'kajiado', 'nandi', 'nyeri',
'wote', 'kiambu', 'mwea', 'nakuru', 'narok']
},
{
name: 'other',
locations: ['other', 'none', 'unknown']
}
];
/** A mock of curated area types. */
const areaTypes: Array<AreaType> = [
{
name: 'urban',
area: ['urban', 'nairobi', 'mombasa']
},
{
name: 'rural',
area: ['rural', 'kakuma', 'kwale', 'kinango', 'kitui', 'nyanza']
},
{
name: 'periurban',
area: ['kilifi', 'periurban']
},
{
name: 'other',
area: ['other']
}
];
/** A mock of the user's business categories */
const categories: Array<Category> = [
{
name: 'system',
@ -147,96 +211,60 @@ const categories: Array<Category> = [
}
];
const areaNames: Array<AreaName> = [
{
name: 'Mukuru Nairobi',
locations: ['kayaba', 'kayba', 'kambi', 'mukuru', 'masai', 'hazina', 'south', 'tetra', 'tetrapak', 'ruben', 'rueben', 'kingston',
'korokocho', 'kingstone', 'kamongo', 'lungalunga', 'sinai', 'sigei', 'lungu', 'lunga lunga', 'owino road', 'seigei']
},
{
name: 'Kinango Kwale',
locations: ['amani', 'bofu', 'chibuga', 'chikomani', 'chilongoni', 'chigojoni', 'chinguluni', 'chigato', 'chigale', 'chikole',
'chilongoni', 'chilumani', 'chigojoni', 'chikomani', 'chizini', 'chikomeni', 'chidzuvini', 'chidzivuni', 'chikuyu', 'chizingo',
'doti', 'dzugwe', 'dzivani', 'dzovuni', 'hanje', 'kasemeni', 'katundani', 'kibandaogo', 'kibandaongo', 'kwale', 'kinango',
'kidzuvini', 'kalalani', 'kafuduni', 'kaloleni', 'kilibole', 'lutsangani', 'peku', 'gona', 'guro', 'gandini', 'mkanyeni', 'myenzeni',
'miyenzeni', 'miatsiani', 'mienzeni', 'mnyenzeni', 'minyenzeni', 'miyani', 'mioleni', 'makuluni', 'mariakani', 'makobeni', 'madewani',
'mwangaraba', 'mwashanga', 'miloeni', 'mabesheni', 'mazeras', 'mazera', 'mlola', 'muugano', 'mulunguni', 'mabesheni', 'miatsani',
'miatsiani', 'mwache', 'mwangani', 'mwehavikonje', 'miguneni', 'nzora', 'nzovuni', 'vikinduni', 'vikolani', 'vitangani', 'viogato',
'vyogato', 'vistangani', 'yapha', 'yava', 'yowani', 'ziwani', 'majengo', 'matuga', 'vigungani', 'vidziweni', 'vinyunduni', 'ukunda',
'kokotoni', 'mikindani']
},
{
name: 'Misc Nairobi',
locations: ['nairobi', 'west', 'lindi', 'kibera', 'kibira', 'kibra', 'makina', 'soweto', 'olympic', 'kangemi', 'ruiru', 'congo',
'kawangware', 'kwangware', 'donholm', 'dagoreti', 'dandora', 'kabete', 'sinai', 'donhom', 'donholm', 'huruma', 'kitengela',
'makadara', ',mlolongo', 'kenyatta', 'mlolongo', 'tassia', 'tasia', 'gatina', '56', 'industrial', 'kariobangi', 'kasarani', 'kayole',
'mathare', 'pipe', 'juja', 'uchumi', 'jogoo', 'umoja', 'thika', 'kikuyu', 'stadium', 'buru buru', 'ngong', 'starehe', 'mwiki',
'fuata', 'kware', 'kabiro', 'embakassi', 'embakasi', 'kmoja', 'east', 'githurai', 'landi', 'langata', 'limuru', 'mathere',
'dagoretti', 'kirembe', 'muugano', 'mwiki', 'toi market']
},
{
name: 'Misc Mombasa',
locations: ['mombasa', 'likoni', 'bangla', 'bangladesh', 'kizingo', 'old town', 'makupa', 'mvita', 'ngombeni', 'ngómbeni', 'ombeni',
'magongo', 'miritini', 'changamwe', 'jomvu', 'ohuru', 'tudor', 'diani']
},
{
name: 'Kisauni',
locations: ['bamburi', 'kisauni', 'mworoni', 'nyali', 'shanzu', 'bombolulu', 'mtopanga', 'mjambere', 'majaoni', 'manyani', 'magogoni',
'junda', 'mwakirunge', 'mshomoroni']
},
{
name: 'Kilifi',
locations: ['kilfi', 'kilifi', 'mtwapa', 'takaungu', 'makongeni', 'mnarani', 'mnarani', 'office', 'g.e', 'ge', 'raibai', 'ribe']
},
{
name: 'Kakuma',
locations: ['kakuma']
},
{
name: 'Kitui',
locations: ['kitui', 'mwingi']
},
{
name: 'Nyanza',
locations: ['busia', 'nyalgunga', 'mbita', 'siaya', 'kisumu', 'nyalenda', 'hawinga', 'rangala', 'uyoma', 'mumias', 'homabay', 'homaboy',
'migori', 'kusumu']
},
{
name: 'Misc Rural Counties',
locations: ['makueni', 'meru', 'kisii', 'bomet', 'machakos', 'bungoma', 'eldoret', 'kakamega', 'kericho', 'kajiado', 'nandi', 'nyeri',
'wote', 'kiambu', 'mwea', 'nakuru', 'narok']
},
{
name: 'other',
locations: ['other', 'none', 'unknown']
}
];
const areaTypes: Array<AreaType> = [
{
name: 'urban',
area: ['urban', 'nairobi', 'mombasa']
},
{
name: 'rural',
area: ['rural', 'kakuma', 'kwale', 'kinango', 'kitui', 'nyanza']
},
{
name: 'periurban',
area: ['kilifi', 'periurban']
},
{
name: 'other',
area: ['other']
}
];
const accountTypes: Array<string> = ['user', 'cashier', 'vendor', 'tokenagent', 'group'];
const transactionTypes: Array<string> = ['transactions', 'conversions', 'disbursements', 'rewards', 'reclamation'];
/** A mock of curated genders */
const genders: Array<string> = ['male', 'female', 'other'];
/** A mock of the tokens in the system. */
const tokens: Array<Token> = [
{
name: 'Giftable Reserve', symbol: 'GRZ', address: '0xa686005CE37Dce7738436256982C3903f2E4ea8E', supply: '1000000001000000000000000000',
decimals: '18', reserves: {}
},
{
name: 'Demo Token', symbol: 'DEMO', address: '0xc80D6aFF8194114c52AEcD84c9f15fd5c8abb187', supply: '99999999999999998976',
decimals: '18', reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '99999999999999998976'}},
reserveRatio: '1000000', owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
},
{
name: 'Foo Token', symbol: 'FOO', address: '0x9ceD86089f7aBB5A97B40eb0E7521e7aa308d354', supply: '1000000000000000001014',
decimals: '18', reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '1000000000000000001014'}},
reserveRatio: '1000000', owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
},
{
name: 'testb', symbol: 'tstb', address: '0xC63cFA91A3BFf41cE31Ff436f67D3ACBC977DB95', supply: '99000', decimals: '18',
reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '99000'}}, reserveRatio: '1000000',
owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
},
{
name: 'testa', symbol: 'tsta', address: '0x8fA4101ef19D0a078239d035659e92b278bD083C', supply: '9981', decimals: '18',
reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '9981'}}, reserveRatio: '1000000',
owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
},
{
name: 'testc', symbol: 'tstc', address: '0x4A6fA6bc3BfE4C9661bC692D9798425350C9e3D4', supply: '100990', decimals: '18',
reserves: {'0xa686005CE37Dce7738436256982C3903f2E4ea8E': {weight: '1000000', balance: '100990'}}, reserveRatio: '1000000',
owner: '0x3Da99AAD2D9CA01D131eFc3B17444b832B31Ff4a'
}
];
/** A mock of curated transaction types. */
const transactionTypes: Array<string> = ['transactions', 'conversions', 'disbursements', 'rewards', 'reclamation'];
/**
* Intercepts HTTP requests and handles some specified requests internally.
* Provides a backend that can handle requests for certain data items.
*
* @implements HttpInterceptor
*/
@Injectable()
export class MockBackendInterceptor implements HttpInterceptor {
/**
* Intercepts HTTP requests.
*
* @param request - An outgoing HTTP request with an optional typed body.
* @param next - The next HTTP handler or the outgoing request dispatcher.
* @returns The response from the resolved request.
*/
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const { url, method, headers, body } = request;
@ -248,22 +276,17 @@ export class MockBackendInterceptor implements HttpInterceptor {
.pipe(delay(500))
.pipe(dematerialize());
/** Forward requests from select routes to their internal handlers. */
function handleRoute(): Observable<any> {
switch (true) {
case url.endsWith('/accounttypes') && method === 'GET':
return getAccountTypes();
case url.endsWith('/actions') && method === 'GET':
return getActions();
case url.match(/\/actions\/\d+$/) && method === 'GET':
return getActionById();
case url.match(/\/actions\/\d+$/) && method === 'POST':
return approveAction();
case url.endsWith('/tokens') && method === 'GET':
return getTokens();
case url.match(/\/tokens\/\w+$/) && method === 'GET':
return getTokenBySymbol();
case url.endsWith('/categories') && method === 'GET':
return getCategories();
case url.match(/\/categories\/\w+$/) && method === 'GET':
return getCategoryByProduct();
case url.endsWith('/areanames') && method === 'GET':
return getAreaNames();
case url.match(/\/areanames\/\w+$/) && method === 'GET':
@ -272,12 +295,18 @@ export class MockBackendInterceptor implements HttpInterceptor {
return getAreaTypes();
case url.match(/\/areatypes\/\w+$/) && method === 'GET':
return getAreaTypeByArea();
case url.endsWith('/accounttypes') && method === 'GET':
return getAccountTypes();
case url.endsWith('/transactiontypes') && method === 'GET':
return getTransactionTypes();
case url.endsWith('/categories') && method === 'GET':
return getCategories();
case url.match(/\/categories\/\w+$/) && method === 'GET':
return getCategoryByProduct();
case url.endsWith('/genders') && method === 'GET':
return getGenders();
case url.endsWith('/tokens') && method === 'GET':
return getTokens();
case url.match(/\/tokens\/\w+$/) && method === 'GET':
return getTokenBySymbol();
case url.endsWith('/transactiontypes') && method === 'GET':
return getTransactionTypes();
default:
// pass through any requests not handled above
return next.handle(request);
@ -286,15 +315,6 @@ export class MockBackendInterceptor implements HttpInterceptor {
// route functions
function getActions(): Observable<HttpResponse<any>> {
return ok(actions);
}
function getActionById(): Observable<HttpResponse<any>> {
const queriedAction: Action = actions.find(action => action.id === idFromUrl());
return ok(queriedAction);
}
function approveAction(): Observable<HttpResponse<any>> {
const queriedAction: Action = actions.find(action => action.id === idFromUrl());
queriedAction.approval = body.approval;
@ -302,23 +322,17 @@ export class MockBackendInterceptor implements HttpInterceptor {
return ok(message);
}
function getTokens(): Observable<HttpResponse<any>> {
return ok(tokens);
function getAccountTypes(): Observable<HttpResponse<any>> {
return ok(accountTypes);
}
function getTokenBySymbol(): Observable<HttpResponse<any>> {
const queriedToken: Token = tokens.find(token => token.symbol === stringFromUrl());
return ok(queriedToken);
function getActions(): Observable<HttpResponse<any>> {
return ok(actions);
}
function getCategories(): Observable<HttpResponse<any>> {
const categoryList: Array<string> = categories.map(category => category.name);
return ok(categoryList);
}
function getCategoryByProduct(): Observable<HttpResponse<any>> {
const queriedCategory: Category = categories.find(category => category.products.includes(stringFromUrl()));
return ok(queriedCategory.name);
function getActionById(): Observable<HttpResponse<any>> {
const queriedAction: Action = actions.find(action => action.id === idFromUrl());
return ok(queriedAction);
}
function getAreaNames(): Observable<HttpResponse<any>> {
@ -341,24 +355,35 @@ export class MockBackendInterceptor implements HttpInterceptor {
return ok(queriedAreaType.name);
}
function getAccountTypes(): Observable<HttpResponse<any>> {
return ok(accountTypes);
function getCategories(): Observable<HttpResponse<any>> {
const categoryList: Array<string> = categories.map(category => category.name);
return ok(categoryList);
}
function getTransactionTypes(): Observable<HttpResponse<any>> {
return ok(transactionTypes);
function getCategoryByProduct(): Observable<HttpResponse<any>> {
const queriedCategory: Category = categories.find(category => category.products.includes(stringFromUrl()));
return ok(queriedCategory.name);
}
function getGenders(): Observable<HttpResponse<any>> {
return ok(genders);
}
// helper functions
function ok(responseBody: any): Observable<HttpResponse<any>> {
return of(new HttpResponse({ status: 200, body: responseBody }));
function getTokens(): Observable<HttpResponse<any>> {
return ok(tokens);
}
function getTokenBySymbol(): Observable<HttpResponse<any>> {
const queriedToken: Token = tokens.find(token => token.symbol === stringFromUrl());
return ok(queriedToken);
}
function getTransactionTypes(): Observable<HttpResponse<any>> {
return ok(transactionTypes);
}
// helper functions
function error(message): Observable<any> {
return throwError({ status: 400, error: { message } });
}
@ -368,6 +393,10 @@ export class MockBackendInterceptor implements HttpInterceptor {
return parseInt(urlParts[urlParts.length - 1], 10);
}
function ok(responseBody: any): Observable<HttpResponse<any>> {
return of(new HttpResponse({ status: 200, body: responseBody }));
}
function stringFromUrl(): string {
const urlParts: Array<string> = url.split('/');
return urlParts[urlParts.length - 1];
@ -375,6 +404,11 @@ export class MockBackendInterceptor implements HttpInterceptor {
}
}
/**
* Exports the MockBackendInterceptor as an Angular provider.
*
* @exports
*/
export const MockBackendProvider = {
provide: HTTP_INTERCEPTORS,
useClass: MockBackendInterceptor,

View File

@ -1,8 +1,15 @@
/** An object defining the properties of the data read. */
const objCsv: { size: number, dataFile: any } = {
size: 0,
dataFile: []
};
/**
* Reads a csv file and converts it to an array.
*
* @param input - The file to be read.
* @returns An array of the read data.
*/
function readCsv(input: any): Array<any> | void {
if (input.files && input.files[0]) {
const reader: FileReader = new FileReader();
@ -15,6 +22,12 @@ function readCsv(input: any): Array<any> | void {
}
}
/**
* Parses data to CSV format.
*
* @param data - The data to be parsed.
* @returns An array of the parsed data.
*/
function parseData(data: any): Array<any> {
const csvData: Array<any> = [];
const lineBreak: Array<any> = data.split('\n');
@ -25,6 +38,7 @@ function parseData(data: any): Array<any> {
return csvData;
}
/** @exports */
export {
readCsv
};

View File

@ -1,5 +1,11 @@
// Third party imports
import { validatePerson, validateVcard } from 'cic-schemas-data-validator';
/**
* Validates a person object against the defined Person schema.
*
* @param person - A person object to be validated.
*/
async function personValidation(person: any): Promise<void> {
const personValidationErrors: any = await validatePerson(person);
@ -8,6 +14,11 @@ async function personValidation(person: any): Promise<void> {
}
}
/**
* Validates a vcard object against the defined Vcard schema.
*
* @param vcard - A vcard object to be validated.
*/
async function vcardValidation(vcard: any): Promise<void> {
const vcardValidationErrors: any = await validateVcard(vcard);
@ -16,6 +27,7 @@ async function vcardValidation(vcard: any): Promise<void> {
}
}
/** @exports */
export {
personValidation,
vcardValidation,