diff --git a/backend/app.js b/backend/app.js
index 2c0693a..dd00a65 100644
--- a/backend/app.js
+++ b/backend/app.js
@@ -12,6 +12,7 @@ const pricemodel = require('./models/price');
const txmodel = require('./models/tx');
const paymentmodel = require('./models/payment');
const zecTxModel = require('./models/zectxs.js');
+const countryModel = require('./models/country.js');
const mongoose = require('mongoose');
const stdrpc = require('stdrpc');
const CoinGecko = require('coingecko-api');
@@ -225,6 +226,22 @@ app.get('/api/test', (req, res, next) => {
res.status(200).send('Endpoint triggered');
});
+app.get('/api/countries', (req, res, next) => {
+ console.log('Get: /api/countries');
+ countryModel.find({}).then((documents) => {
+ if (documents != null) {
+ res.status(200).json({
+ message: 'Country data found',
+ countries: documents
+ });
+ } else {
+ res.status(204).json({
+ message: 'No country data available'
+ });
+ }
+ });
+});
+
app.get('/api/users', (req, res, next) => {
console.log('Get: /api/users');
usermodel.find({'address': req.query.address, 'session': req.query.session}).
diff --git a/backend/models/country.js b/backend/models/country.js
new file mode 100644
index 0000000..520cead
--- /dev/null
+++ b/backend/models/country.js
@@ -0,0 +1,9 @@
+const mongoose = require('mongoose');
+
+const countrySchema = mongoose.Schema({
+ name: {type: String, required: true},
+ code: {type: Number, required: true}
+});
+
+
+module.exports = mongoose.model('Country', countrySchema);
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 7633a41..9b564aa 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
+import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatCardModule } from '@angular/material/card';
import { MatButtonModule } from '@angular/material/button';
import { MatToolbarModule } from '@angular/material/toolbar';
@@ -32,6 +33,7 @@ import { ListOrdersComponent } from './listorders/listorders.component';
import { ScanComponent } from './scan/scan.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BusinessComponent } from './business/business.component';
+import { SearchOptionsPipe } from './searchoptions.pipe';
@NgModule({
declarations: [
@@ -49,7 +51,8 @@ import { BusinessComponent } from './business/business.component';
SettingsComponent,
ScanComponent,
ListOrdersComponent,
- BusinessComponent
+ BusinessComponent,
+ SearchOptionsPipe
],
imports: [
BrowserModule,
@@ -69,6 +72,7 @@ import { BusinessComponent } from './business/business.component';
MatSelectModule,
MatProgressBarModule,
MatStepperModule,
+ MatAutocompleteModule,
BrowserAnimationsModule
],
exports: [
diff --git a/src/app/business/business.component.html b/src/app/business/business.component.html
index 3d82482..6159d13 100644
--- a/src/app/business/business.component.html
+++ b/src/app/business/business.component.html
@@ -1,11 +1,43 @@
-
business works!
diff --git a/src/app/business/business.component.ts b/src/app/business/business.component.ts
index a734372..724c4fb 100644
--- a/src/app/business/business.component.ts
+++ b/src/app/business/business.component.ts
@@ -1,7 +1,11 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators, FormGroup, FormControl } from '@angular/forms';
+import { Observable } from 'rxjs';
+import { filter, startWith, map, switchMap } from 'rxjs/operators';
+import { Country } from '../country.model';
import { Owner } from '../owner.model';
import { UserService } from '../user.service';
+import { SearchOptionsPipe } from '../searchoptions.pipe';
@Component({
selector: 'app-business',
@@ -11,12 +15,28 @@ import { UserService } from '../user.service';
export class BusinessComponent implements OnInit {
bizForm: FormGroup;
+ countries: Country[] = [];
+ public countriesUpdate: Observable;
+ testSearch = 'uni';
constructor(
- private fb: FormBuilder
+ private fb: FormBuilder,
+ private userService: UserService
) {
+ this.countriesUpdate = userService.countriesUpdate;
this.bizForm = fb.group({
- name: ['', Validators.required]
+ name: ['', Validators.required],
+ street: ['', Validators.required],
+ city: ['', Validators.required],
+ state: ['', Validators.required],
+ postal: ['', Validators.required],
+ country: ['', Validators.required],
+ email: ['', Validators.required],
+ website: ['', Validators.required]
+ });
+ this.userService.getCountries();
+ this.countriesUpdate.subscribe((countries) => {
+ this.countries = countries;
});
}
diff --git a/src/app/country.model.ts b/src/app/country.model.ts
new file mode 100644
index 0000000..5865976
--- /dev/null
+++ b/src/app/country.model.ts
@@ -0,0 +1,5 @@
+export interface Country {
+ _id?: string;
+ name: string;
+ code: string;
+}
diff --git a/src/app/searchoptions.pipe.ts b/src/app/searchoptions.pipe.ts
new file mode 100644
index 0000000..7cd4cf6
--- /dev/null
+++ b/src/app/searchoptions.pipe.ts
@@ -0,0 +1,15 @@
+import { Pipe, PipeTransform } from '@angular/core';
+
+@Pipe({
+ name: 'searchOptions'
+})
+export class SearchOptionsPipe implements PipeTransform {
+ transform(items: any[], filter: string): any {
+ if (!items || !filter) {
+ return items;
+ }
+
+ // This will search and match any option.value that contains the search term
+ return items.filter(item => item.name.toLowerCase().indexOf(filter.toLowerCase()) !== -1);
+ }
+}
diff --git a/src/app/user.service.ts b/src/app/user.service.ts
index 4b091fb..e3e529d 100644
--- a/src/app/user.service.ts
+++ b/src/app/user.service.ts
@@ -3,13 +3,14 @@ import {Subject, BehaviorSubject, Observable} from 'rxjs';
import {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http';
import {User} from './user.model';
import {Owner} from './owner.model';
+import { Country } from './country.model';
import {Tx} from './tx.model';
@Injectable({providedIn: 'root'})
export class UserService{
beUrl = 'http://localhost:3000/';
- private dataStore: { user: User, owner: Owner, txs: Tx[]} = {
+ private dataStore: { user: User, owner: Owner, txs: Tx[], countries: Country[]} = {
user: {
address: '',
session: '',
@@ -36,7 +37,8 @@ export class UserService{
website: '',
country: ''
},
- txs : []
+ txs : [],
+ countries: []
};
private uZaddr = '';
private oZaddr = '';
@@ -48,11 +50,13 @@ export class UserService{
private _ownerUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.owner);
private _txsUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.txs);
private _paidUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.owner.paid);
+ private _countriesUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.countries);
public readonly uZaddrUpdate: Observable = this._uZaddrUpdated.asObservable();
public readonly ownerUpdate: Observable = this._ownerUpdated.asObservable();
public readonly userUpdate: Observable = this._userUpdated.asObservable();
public readonly txUpdate: Observable = this._txsUpdated.asObservable();
public readonly paidUpdate: Observable = this._paidUpdated.asObservable();
+ public readonly countriesUpdate: Observable = this._countriesUpdated.asObservable();
private reqHeaders: HttpHeaders;
private apiKey = 'Le2adeic8Thah4Aeng4daem6i';
@@ -66,6 +70,17 @@ export class UserService{
}
}
+ getCountries() {
+ let obs = this.http.get<{message: string, countries: any}>(this.beUrl+'api/countries', { headers: this.reqHeaders, observe: 'response'});
+
+ obs.subscribe((CountryResponse) => {
+ if (CountryResponse.status == 200) {
+ this.dataStore.countries = CountryResponse.body!.countries;
+ this._countriesUpdated.next(Object.assign({}, this.dataStore).countries);
+ }
+ });
+ }
+
findUser() {
this.session = localStorage.getItem('s4z_token');
if (this.session != null) {