Add documentation to the helpers module.
This commit is contained in:
@@ -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,7 +200,8 @@
|
||||
|
||||
</div>
|
||||
<div class="io-description">
|
||||
|
||||
<p>The response from the resolved request.</p>
|
||||
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -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 '@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 },
|
||||
@@ -199,38 +236,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',
|
||||
@@ -333,96 +425,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;
|
||||
|
||||
@@ -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<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':
|
||||
@@ -458,12 +509,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);
|
||||
@@ -472,15 +529,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;
|
||||
@@ -488,23 +536,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>> {
|
||||
@@ -527,24 +569,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 } });
|
||||
}
|
||||
@@ -554,6 +607,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];
|
||||
@@ -561,6 +618,11 @@ export class MockBackendInterceptor implements HttpInterceptor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the MockBackendInterceptor as an Angular provider.
|
||||
*
|
||||
* @exports
|
||||
*/
|
||||
export const MockBackendProvider = {
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
useClass: MockBackendInterceptor,
|
||||
|
||||
Reference in New Issue
Block a user