From 292b64c1e051844502e651753385446a9c209b5a Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 28 Apr 2021 15:53:25 +0300 Subject: [PATCH] Add querying of location mappings and categories from API endpoint. - Implement stub in mock backend for testing purposes. --- src/app/_helpers/mock-backend.ts | 364 ++++++++++++------ src/app/_services/location.service.ts | 21 +- src/app/_services/user.service.ts | 27 +- .../account-details.component.html | 33 +- .../account-details.component.ts | 16 +- .../create-account.component.html | 25 +- .../create-account.component.ts | 19 +- 7 files changed, 304 insertions(+), 201 deletions(-) diff --git a/src/app/_helpers/mock-backend.ts b/src/app/_helpers/mock-backend.ts index 55f2d85..470e91b 100644 --- a/src/app/_helpers/mock-backend.ts +++ b/src/app/_helpers/mock-backend.ts @@ -3,14 +3,6 @@ import {Injectable} from '@angular/core'; import {Observable, of, throwError} from 'rxjs'; import {delay, dematerialize, materialize, mergeMap} from 'rxjs/operators'; -const accounts = [ - {id: 1, name: 'John Doe', phone: '+25412345678', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', age: 43, created: '08/16/2020', balance: '12987', failedPinAttempts: 1, status: 'active', bio: 'Bodaboda', category: 'transport', gender: 'male', location: 'Bofu', locationType: 'Rural', token: 'RSV', referrer: '+25412341234'}, - {id: 2, name: 'Jane Buck', phone: '+25412341234', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9866', type: 'vendor', age: 25, created: '04/02/2020', balance: '56281', failedPinAttempts: 0, status: 'active', bio: 'Groceries', category: 'food/water', gender: 'female', location: 'Lindi', locationType: 'Urban', token: 'ERN', referrer: ''}, - {id: 3, name: 'Mc Donald', phone: '+25498765432', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9867', type: 'group', age: 31, created: '11/16/2020', balance: '450', failedPinAttempts: 2, status: 'blocked', bio: 'Food', category: 'food/water', gender: 'male', location: 'Miyani', locationType: 'Rural', token: 'RSV', referrer: '+25498769876'}, - {id: 4, name: 'Hera Cles', phone: '+25498769876', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9868', type: 'user', age: 38, created: '05/28/2020', balance: '5621', failedPinAttempts: 3, status: 'active', bio: 'Shop', category: 'shop', gender: 'female', location: 'Kayaba', locationType: 'Urban', token: 'BRT', referrer: '+25412341234'}, - {id: 5, name: 'Silver Fia', phone: '+25462518374', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9869', type: 'tokenAgent', age: 19, created: '10/10/2020', balance: '817', failedPinAttempts: 0, status: 'blocked', bio: 'Electronics', category: 'shop', gender: 'male', location: 'Mkanyeni', locationType: 'Rural', token: 'RSV', referrer: '+25412345678'}, -]; - const actions = [ { 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 }, @@ -20,59 +12,222 @@ const actions = [ { id: 6, user: 'Patience', role: 'enroller', action: 'Change user information', approval: false } ]; -const histories = [ - { id: 1, userId: 3, userName: 'Mc Donald', action: 'Receive RSV 100', staff: 'Tom', timestamp: Date.now() }, - { id: 2, userId: 5, userName: 'Silver Fia', action: 'Change phone number from +25412345678 to +25498765432', staff: 'Christine', timestamp: Date.now()}, - { id: 3, userId: 4, userName: 'Hera Cles', action: 'Completed user profile', staff: 'Vivian', timestamp: Date.now() }, -]; - -const locations: any = [ - { name: 'Kwale', - districts: [ - { name: 'Kinango', - locations: [ - { name: 'Bofu', villages: ['Bofu', 'Chidzuvini', 'Mkanyeni']}, - { name: 'Mnyenzeni', villages: ['Miloeni', 'Miyani', 'Mnyenzeni', 'Vikolani', 'Vitangani']} - ] - } - ] +const tokens = [ + { + name: 'Giftable Reserve', symbol: 'GRZ', address: '0xa686005CE37Dce7738436256982C3903f2E4ea8E', supply: '1000000001000000000000000000', + decimals: '18', reserves: {} }, - { name: 'Nairobi', - districts: [ - { name: 'Dagorreti', - locations: [ - { name: 'Kawangware', villages: ['Congo']}, - ] - }, - { name: 'Ngong', - locations: [ - { name: 'Kibera', villages: ['Kibera', 'Lindi']}, - ] - }, - { name: 'South B', - locations: [ - { name: 'Mukuru', villages: ['Kayaba']}, - { name: 'South B', villages: ['South B']}, - ] - }, - ] + { + 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' } ]; -const staffMembers = [ - { id: 1, name: 'admin@acme.org', accountType: 'Admin', created: '17/11/2020', status: 'activated'}, - { id: 2, name: 'will@grassecon.org', accountType: 'SuperAdmin', created: '17/11/2020', status: 'activated'}, - { id: 3, name: 'spence@grassecon.org', accountType: 'Enroller', created: '17/11/2020', status: 'activated'}, - { id: 4, name: 'admin@redcross.org', accountType: 'View', created: '17/11/2020', status: 'activated'} +const categories = [ + { + name: 'system', + products: ['system', 'office main', 'office main phone'] + }, + { + name: 'education', + products: ['book', 'coach', 'teacher', 'sch', 'school', 'pry', 'education', 'student', 'mwalimu', 'maalim', 'consultant', 'consult', + 'college', 'university', 'lecturer', 'primary', 'secondary', 'daycare', 'babycare', 'baby care', 'elim', 'eimu', 'nursery', + 'red cross', 'volunteer', 'instructor', 'journalist', 'lesson', 'academy', 'headmistress', 'headteacher', 'cyber', 'researcher', + 'professor', 'demo', 'expert', 'tution', 'tuition', 'children', 'headmaster', 'educator', 'Marital counsellor', 'counsellor', + 'trainer', 'vijana', 'youth', 'intern', 'redcross', 'KRCS', 'danish', 'science', 'data', 'facilitator', 'vitabu', 'kitabu'] + }, + { + name: 'faith', + products: ['pastor', 'imam', 'madrasa', 'religous', 'religious', 'ustadh', 'ustadhi', 'Marital counsellor', 'counsellor', 'church', + 'kanisa', 'mksiti', 'donor'] + }, + { + name: 'government', + products: ['elder', 'chief', 'police', 'government', 'country', 'county', 'soldier', 'village admin', 'ward', 'leader', 'kra', + 'mailman', 'immagration', 'immigration'] + }, + { + name: 'environment', + products: ['conservation', 'toilet', 'choo', 'garbage', 'fagio', 'waste', 'tree', 'taka', 'scrap', 'cleaning', 'gardener', 'rubbish', + 'usafi', 'mazingira', 'miti', 'trash', 'cleaner', 'plastic', 'collection', 'seedling', 'seedlings', 'recycling'] + }, + { + name: 'farming', + products: ['farm', 'farmer', 'farming', 'mkulima', 'kulima', 'ukulima', 'wakulima', 'jembe', 'shamba'] + }, + { + name: 'labour', + products: ['artist', 'agent', 'guard', 'askari', 'accountant', 'baker', 'beadwork', 'beauty', 'business', 'barber', 'casual', + 'electrian', 'caretaker', 'car wash', 'capenter', 'construction', 'chef', 'catering', 'cobler', 'cobbler', 'carwash', 'dhobi', + 'landlord', 'design', 'carpenter', 'fundi', 'hawking', 'hawker', 'househelp', 'hsehelp', 'house help', 'help', 'housegirl', 'kushona', + 'juakali', 'jualikali', 'juacali', 'jua kali', 'shepherd', 'makuti', 'kujenga', 'kinyozi', 'kazi', 'knitting', 'kufua', 'fua', + 'hustler', 'biashara', 'labour', 'labor', 'laundry', 'repair', 'hair', 'posho', 'mill', 'mtambo', 'uvuvi', 'engineer', 'manager', + 'tailor', 'nguo', 'mason', 'mtumba', 'garage', 'mechanic', 'mjenzi', 'mfugaji', 'painter', 'receptionist', 'printing', 'programming', + 'plumb', 'charging', 'salon', 'mpishi', 'msusi', 'mgema', 'footballer', 'photocopy', 'peddler', 'staff', 'sales', 'service', 'saloon', + 'seremala', 'security', 'insurance', 'secretary', 'shoe', 'shepard', 'shephard', 'tout', 'tv', 'mvuvi', 'mawe', 'majani', 'maembe', + 'freelance', 'mjengo', 'electronics', 'photographer', 'programmer', 'electrician', 'washing', 'bricks', 'welder', 'welding', + 'working', 'worker', 'watchman', 'waiter', 'waitress', 'viatu', 'yoga', 'guitarist', 'house', 'artisan', 'musician', 'trade', + 'makonge', 'ujenzi', 'vendor', 'watchlady', 'marketing', 'beautician', 'photo', 'metal work', 'supplier', 'law firm', 'brewer'] + }, + { + name: 'food', + products: ['avocado', 'bhajia', 'bajia', 'mbonga', 'bofu', 'beans', 'biscuits', 'biringanya', 'banana', 'bananas', 'crisps', 'chakula', + 'coconut', 'chapati', 'cereal', 'chipo', 'chapo', 'chai', 'chips', 'cassava', 'cake', 'cereals', 'cook', 'corn', 'coffee', 'chicken', + 'dagaa', 'donut', 'dough', 'groundnuts', 'hotel', 'holel', 'hoteli', 'butcher', 'butchery', 'fruit', 'food', 'fruits', 'fish', + 'githeri', 'grocery', 'grocer', 'pojo', 'papa', 'goats', 'mabenda', 'mbenda', 'poultry', 'soda', 'peanuts', 'potatoes', 'samosa', + 'soko', 'samaki', 'tomato', 'tomatoes', 'mchele', 'matunda', 'mango', 'melon', 'mellon', 'nyanya', 'nyama', 'omena', 'umena', 'ndizi', + 'njugu', 'kamba kamba', 'khaimati', 'kaimati', 'kunde', 'kuku', 'kahawa', 'keki', 'muguka', 'miraa', 'milk', 'choma', 'maziwa', + 'mboga', 'mbog', 'busaa', 'chumvi', 'cabbages', 'mabuyu', 'machungwa', 'mbuzi', 'mnazi', 'mchicha', 'ngombe', 'ngano', 'nazi', + 'oranges', 'peanuts', 'mkate', 'bread', 'mikate', 'vitungu', 'sausages', 'maize', 'mbata', 'mchuzi', 'mchuuzi', 'mandazi', 'mbaazi', + 'mahindi', 'maandazi', 'mogoka', 'meat', 'mhogo', 'mihogo', 'muhogo', 'maharagwe', 'miwa', 'mahamri', 'mitumba', 'simsim', 'porridge', + 'pilau', 'vegetable', 'egg', 'mayai', 'mifugo', 'unga', 'good', 'sima', 'sweet', 'sweats', 'sambusa', 'snacks', 'sugar', 'suger', + 'ugoro', 'sukari', 'soup', 'spinach', 'smokie', 'smokies', 'sukuma', 'tea', 'uji', 'ugali', 'uchuzi', 'uchuuzi', 'viazi', 'yoghurt', + 'yogurt', 'wine', 'marondo', 'maandzi', 'matoke', 'omeno', 'onions', 'nzugu', 'korosho', 'barafu', 'juice'] + }, + { + name: 'water', + products: ['maji', 'water'] + }, + { + name: 'health', + products: ['agrovet', 'dispensary', 'barakoa', 'chemist', 'Chemicals', 'chv', 'doctor', 'daktari', 'dawa', 'hospital', 'herbalist', + 'mganga', 'sabuni', 'soap', 'nurse', 'heath', 'community health worker', 'clinic', 'clinical', 'mask', 'medicine', 'lab technician', + 'pharmacy', 'cosmetics', 'veterinary', 'vet', 'sickly', 'emergency response', 'emergency'] + }, + { + name: 'savings', + products: ['chama', 'group', 'savings', 'loan', 'silc', 'vsla', 'credit', 'finance'] + }, + { + name: 'shop', + products: ['bag', 'bead', 'belt', 'bedding', 'jik', 'bed', 'cement', 'botique', 'boutique', 'lines', 'kibanda', 'kiosk', 'spareparts', + 'candy', 'cloth', 'electricals', 'mutumba', 'cafe', 'leso', 'lesso', 'duka', 'spare parts', 'socks', 'malimali', 'mitungi', + 'mali mali', 'hardware', 'detergent', 'detergents', 'dera', 'retail', 'kamba', 'pombe', 'pampers', 'pool', 'phone', 'simu', 'mangwe', + 'mikeka', 'movie', 'shop', 'acces', 'mchanga', 'uto', 'airtime', 'matress', 'mattress', 'mattresses', 'mpsea', 'mpesa', 'shirt', + 'wholesaler', 'perfume', 'playstation', 'tissue', 'vikapu', 'uniform', 'flowers', 'vitenge', 'utencils', 'utensils', 'station', + 'jewel', 'pool table', 'club', 'pub', 'bar', 'furniture', 'm-pesa', 'vyombo'] + }, + { + name: 'transport', + products: ['kebeba', 'beba', 'bebabeba', 'bike', 'bicycle', 'matatu', 'boda', 'bodaboda', 'cart', 'carrier', 'tour', 'travel', 'driver', + 'dereva', 'tout', 'conductor', 'kubeba', 'tuktuk', 'taxi', 'piki', 'pikipiki', 'manamba', 'trasportion', 'mkokoteni', 'mover', + 'motorist', 'motorbike', 'transport', 'transpoter', 'gari', 'magari', 'makanga', 'car'] + }, + { + name: 'fuel/energy', + products: ['timber', 'timberyard', 'biogas', 'charcol', 'charcoal', 'kuni', 'mbao', 'fuel', 'makaa', 'mafuta', 'moto', 'solar', 'stima', + 'fire', 'firewood', 'wood', 'oil', 'taa', 'gas', 'paraffin', 'parrafin', 'parafin', 'petrol', 'petro', 'kerosine', 'kerosene', + 'diesel'] + }, + { + name: 'other', + products: ['other', 'none', 'unknown', 'none'] + } ]; -const tokens = [ - {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'} +const areaNames = [ + { + 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 = [ + { + name: 'urban', + area: ['urban', 'nairobi', 'mombasa'] + }, + { + name: 'rural', + area: ['rural', 'kakuma', 'kwale', 'kinango', 'kitui', 'nyanza'] + }, + { + name: 'periurban', + area: ['kilifi', 'periurban'] + }, + { + name: 'other', + area: ['other'] + } ]; @Injectable() @@ -90,32 +245,28 @@ export class MockBackendInterceptor implements HttpInterceptor { function handleRoute(): Observable { switch (true) { - case url.endsWith('/accounts') && method === 'GET': - return getAccounts(); - case url.match(/\/accounts\/\d+$/) && method === 'GET': - return getAccountById(); 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.match(/\/history\/\d+$/) && method === 'GET': - return getHistoryByUser(); - case url.endsWith('/locations') && method === 'GET': - return getLocations(); - case url.endsWith('/staff') && method === 'GET': - return getStaff(); - case url.match(/\/staff\/\d+$/) && method === 'GET': - return getStaffById(); - case url.match(/\/staff\/\d+$/) && method === 'POST' && body.status !== undefined: - return changeStaffStatus(); - case url.match(/\/staff\/\d+$/) && method === 'POST' && body.accountType !== undefined: - return changeStaffType(); 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': + return getAreaNameByLocation(); + case url.endsWith('/areatypes') && method === 'GET': + return getAreaTypes(); + case url.match(/\/areatypes\/\w+$/) && method === 'GET': + return getAreaTypeByArea(); default: // pass through any requests not handled above return next.handle(request); @@ -124,15 +275,6 @@ export class MockBackendInterceptor implements HttpInterceptor { // route functions - function getAccounts(): Observable { - return ok(accounts); - } - - function getAccountById(): Observable { - const queriedAccount = accounts.find(account => account.id === idFromUrl()); - return ok(queriedAccount); - } - function getActions(): Observable { return ok(actions); } @@ -149,38 +291,6 @@ export class MockBackendInterceptor implements HttpInterceptor { return ok(message); } - function getHistoryByUser(): Observable { - const queriedUserHistory = histories.filter(history => history.userId === idFromUrl()); - return ok(queriedUserHistory); - } - - function getLocations(): Observable { - return ok(locations); - } - - function getStaff(): Observable { - return ok(staffMembers); - } - - function getStaffById(): Observable { - const queriedStaff = staffMembers.find(staff => staff.id === idFromUrl()); - return ok(queriedStaff); - } - - function changeStaffStatus(): Observable { - const queriedStaff = staffMembers.find(staff => staff.id === idFromUrl()); - queriedStaff.status = body.status; - const message = `Staff account status changed to ${body.status} successfully!`; - return ok(message); - } - - function changeStaffType(): Observable { - const queriedStaff = staffMembers.find(staff => staff.id === idFromUrl()); - queriedStaff.accountType = body.accountType; - const message = `Staff account type changed to ${body.accountType} successfully!`; - return ok(message); - } - function getTokens(): Observable { return ok(tokens); } @@ -190,6 +300,36 @@ export class MockBackendInterceptor implements HttpInterceptor { return ok(queriedToken); } + function getCategories(): Observable { + const categoryList = categories.map(category => category.name); + return ok(categoryList); + } + + function getCategoryByProduct(): Observable { + const queriedCategory = categories.find(category => category.products.includes(stringFromUrl())); + return ok(queriedCategory.name); + } + + function getAreaNames(): Observable { + const areaNameList = areaNames.map(areaName => areaName.name); + return ok(areaNameList); + } + + function getAreaNameByLocation(): Observable { + const queriedAreaName = areaNames.find(areaName => areaName.locations.includes(stringFromUrl())); + return ok(queriedAreaName.name); + } + + function getAreaTypes(): Observable { + const areaTypeList = areaTypes.map(areaType => areaType.name); + return ok(areaTypeList); + } + + function getAreaTypeByArea(): Observable { + const queriedAreaType = areaTypes.find(areaType => areaType.area.includes(stringFromUrl())); + return ok(queriedAreaType.name); + } + // helper functions function ok(body): Observable { diff --git a/src/app/_services/location.service.ts b/src/app/_services/location.service.ts index 834d02a..2916c53 100644 --- a/src/app/_services/location.service.ts +++ b/src/app/_services/location.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import {BehaviorSubject} from 'rxjs'; +import {Observable} from 'rxjs'; import {environment} from '@src/environments/environment'; import {first} from 'rxjs/operators'; import {HttpClient} from '@angular/common/http'; @@ -8,15 +8,24 @@ import {HttpClient} from '@angular/common/http'; providedIn: 'root' }) export class LocationService { - locations: any = ''; - private locationsList = new BehaviorSubject(this.locations); - locationsSubject = this.locationsList.asObservable(); constructor( private httpClient: HttpClient, ) { } - getLocations(): void { - this.httpClient.get(`${environment.cicCacheUrl}/locations`).pipe(first()).subscribe(res => this.locationsList.next(res)); + getAreaNames(): Observable { + return this.httpClient.get(`${environment.cicCacheUrl}/areanames`); + } + + getAreaNameByLocation(location: string): Observable { + return this.httpClient.get(`${environment.cicCacheUrl}/areanames/${location.toLowerCase()}`); + } + + getAreaTypes(): Observable { + return this.httpClient.get(`${environment.cicCacheUrl}/areatypes`).pipe(first()); + } + + getAreaTypeByArea(area: string): Observable { + return this.httpClient.get(`${environment.cicCacheUrl}/areatypes/${area.toLowerCase()}`).pipe(first()); } } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index f064776..b02e8d3 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -117,14 +117,6 @@ export class UserService { }); } - getAccounts(): void { - this.httpClient.get(`${environment.cicCacheUrl}/accounts`).pipe(first()).subscribe(res => this.accountsList.next(res)); - } - - getAccountById(id: number): Observable { - return this.httpClient.get(`${environment.cicCacheUrl}/accounts/${id}`); - } - getActions(): void { this.httpClient.get(`${environment.cicCacheUrl}/actions`).pipe(first()).subscribe(res => this.actionsList.next(res)); } @@ -141,21 +133,10 @@ export class UserService { return this.httpClient.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: false }); } - getHistoryByUser(id: string): Observable { - return this.httpClient.get(`${environment.cicCacheUrl}/history/${id}`); - } - getAccountDetailsFromMeta(userKey: string): Observable { return this.httpClient.get(`${environment.cicMetaUrl}/${userKey}`, { headers: this.headers }); } - getUser(userKey: string): any { - return this.httpClient.get(`${environment.cicMetaUrl}/${userKey}`, { headers: this.headers }) - .pipe(first()).subscribe(async res => { - return Envelope.fromJSON(JSON.stringify(res)).unwrap(); - }); - } - wrap(syncable: Syncable, signer: Signer): Promise { return new Promise(async (whohoo, doh) => { syncable.setSigner(signer); @@ -220,4 +201,12 @@ export class UserService { } searchAccountByName(name: string): any { return; } + + getCategories(): Observable { + return this.httpClient.get(`${environment.cicCacheUrl}/categories`); + } + + getCategoryByProduct(product: string): Observable { + return this.httpClient.get(`${environment.cicCacheUrl}/categories/${product.toLowerCase()}`); + } } diff --git a/src/app/pages/accounts/account-details/account-details.component.html b/src/app/pages/accounts/account-details/account-details.component.html index 11a87ea..8df9812 100644 --- a/src/app/pages/accounts/account-details/account-details.component.html +++ b/src/app/pages/accounts/account-details/account-details.component.html @@ -115,16 +115,9 @@ BUSINESS CATEGORY: - Food/Water - Fuel/Energy - Education - Health - Shop - Environment - Transport - Farming/Labour - Savings Group - Savings Group + + {{category | titlecase}} + Category is required. @@ -149,16 +142,9 @@ LOCATION: -
-
- - - {{village}} - - -
-
+ + {{area | uppercase}} +
Location is required. @@ -169,10 +155,9 @@ LOCATION TYPE: - URBAN - PERIURBAN - RURAL - OTHER + + {{type | uppercase}} + Location Type is required. diff --git a/src/app/pages/accounts/account-details/account-details.component.ts b/src/app/pages/accounts/account-details/account-details.component.ts index 8f39912..80d544f 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -37,7 +37,9 @@ export class AccountDetailsComponent implements OnInit { accountStatus: any; accounts: any[] = []; accountsType = 'all'; - locations: any; + categories: any[]; + areaNames: any[]; + areaTypes: any[]; transaction: any; transactions: any[]; transactionsType = 'all'; @@ -97,11 +99,9 @@ export class AccountDetailsComponent implements OnInit { }); this.blockSyncService.blockSync(this.accountAddress); }); - this.userService.getAccounts(); - this.locationService.getLocations(); - this.locationService.locationsSubject.subscribe(locations => { - this.locations = locations; - }); + this.userService.getCategories().pipe(first()).subscribe(res => this.categories = res); + this.locationService.getAreaNames().pipe(first()).subscribe(res => this.areaNames = res); + this.locationService.getAreaTypes().pipe(first()).subscribe(res => this.areaTypes = res); } ngOnInit(): void { @@ -186,10 +186,6 @@ export class AccountDetailsComponent implements OnInit { }); } - public trackByName(index, item): string { - return item.name; - } - downloadCsv(data: any, filename: string): void { exportCsv(data, filename); } diff --git a/src/app/pages/accounts/create-account/create-account.component.html b/src/app/pages/accounts/create-account/create-account.component.html index ca75dec..a7a00d6 100644 --- a/src/app/pages/accounts/create-account/create-account.component.html +++ b/src/app/pages/accounts/create-account/create-account.component.html @@ -81,15 +81,9 @@ Location: -
-
- - - {{village}} - - -
-
+ + {{area | uppercase}} +
Location is required.

@@ -119,16 +113,9 @@ Business Category: - Food/Water - Fuel/Energy - Education - Health - Shop - Environment - Transport - Farming/Labour - Savings Group - Other + + {{category | titlecase}} + Business Category is required. diff --git a/src/app/pages/accounts/create-account/create-account.component.ts b/src/app/pages/accounts/create-account/create-account.component.ts index 81b5ff8..1d4e87e 100644 --- a/src/app/pages/accounts/create-account/create-account.component.ts +++ b/src/app/pages/accounts/create-account/create-account.component.ts @@ -1,7 +1,8 @@ import {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {LocationService} from '@app/_services'; +import {LocationService, UserService} from '@app/_services'; import {CustomErrorStateMatcher} from '@app/_helpers'; +import {first} from 'rxjs/operators'; @Component({ selector: 'app-create-account', @@ -13,11 +14,13 @@ export class CreateAccountComponent implements OnInit { createForm: FormGroup; matcher = new CustomErrorStateMatcher(); submitted: boolean = false; - locations: any; + categories: any[]; + areaNames: any[]; constructor( private formBuilder: FormBuilder, - private locationService: LocationService + private locationService: LocationService, + private userService: UserService ) { } ngOnInit(): void { @@ -33,10 +36,8 @@ export class CreateAccountComponent implements OnInit { referrer: ['', Validators.required], businessCategory: ['', Validators.required] }); - this.locationService.getLocations(); - this.locationService.locationsSubject.subscribe(locations => { - this.locations = locations; - }); + this.userService.getCategories().pipe(first()).subscribe(res => this.categories = res); + this.locationService.getAreaNames().pipe(first()).subscribe(res => this.areaNames = res); } get createFormStub(): any { return this.createForm.controls; } @@ -46,8 +47,4 @@ export class CreateAccountComponent implements OnInit { if (this.createForm.invalid || !confirm('Create account?')) { return; } this.submitted = false; } - - public trackByName(index, item): string { - return item.name; - } }