Parametrize backend url
This commit is contained in:
parent
f33666bd0e
commit
dacb8dbafb
4 changed files with 20 additions and 16 deletions
|
@ -7,6 +7,7 @@ import {UserService} from './user.service';
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class FullnodeService{
|
export class FullnodeService{
|
||||||
|
beUrl = 'http://localhost:3000/';
|
||||||
private dataStore: { height: number, memoList: string[], addr: string, price: number } = { height: 0, memoList: [], addr: '', price:0 };
|
private dataStore: { height: number, memoList: string[], addr: string, price: number } = { height: 0, memoList: [], addr: '', price:0 };
|
||||||
private _heightUpdated: BehaviorSubject<number> = new BehaviorSubject(this.dataStore.height);
|
private _heightUpdated: BehaviorSubject<number> = new BehaviorSubject(this.dataStore.height);
|
||||||
private _memoUpdated: BehaviorSubject<string[]> = new BehaviorSubject(this.dataStore.memoList);
|
private _memoUpdated: BehaviorSubject<string[]> = new BehaviorSubject(this.dataStore.memoList);
|
||||||
|
@ -25,7 +26,7 @@ export class FullnodeService{
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeight(){
|
getHeight(){
|
||||||
let obs = this.http.get<{message: string, height: number}>('http://localhost:3000/api/blockheight');
|
let obs = this.http.get<{message: string, height: number}>(this.beUrl+'api/blockheight');
|
||||||
obs.subscribe((BlockData) => {
|
obs.subscribe((BlockData) => {
|
||||||
this.dataStore.height = BlockData.height;
|
this.dataStore.height = BlockData.height;
|
||||||
this._heightUpdated.next(Object.assign({}, this.dataStore).height);
|
this._heightUpdated.next(Object.assign({}, this.dataStore).height);
|
||||||
|
@ -37,7 +38,7 @@ export class FullnodeService{
|
||||||
getPrice(){
|
getPrice(){
|
||||||
var currency = 'usd';
|
var currency = 'usd';
|
||||||
const params = new HttpParams().append('currency', currency);
|
const params = new HttpParams().append('currency', currency);
|
||||||
let obs = this.http.get<{message: string, price: any}>('http://localhost:3000/api/price', { headers:{}, params: params, observe: 'response'});
|
let obs = this.http.get<{message: string, price: any}>(this.beUrl+'api/price', { headers:{}, params: params, observe: 'response'});
|
||||||
obs.subscribe((PriceData) => {
|
obs.subscribe((PriceData) => {
|
||||||
if (PriceData.status == 200) {
|
if (PriceData.status == 200) {
|
||||||
this.dataStore.price = PriceData.body!.price.price;
|
this.dataStore.price = PriceData.body!.price.price;
|
||||||
|
@ -62,7 +63,7 @@ export class FullnodeService{
|
||||||
|
|
||||||
|
|
||||||
getAddr() {
|
getAddr() {
|
||||||
let obs = this.http.get<{message: string, addr: string}>('http://localhost:3000/api/getaddr');
|
let obs = this.http.get<{message: string, addr: string}>(this.beUrl+'api/getaddr');
|
||||||
|
|
||||||
obs.subscribe((AddrData) => {
|
obs.subscribe((AddrData) => {
|
||||||
this.dataStore.addr = AddrData.addr;
|
this.dataStore.addr = AddrData.addr;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { HttpClient, HttpParams } from '@angular/common/http';
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
|
|
||||||
export class ItemService{
|
export class ItemService{
|
||||||
|
beUrl = 'http://localhost:3000/';
|
||||||
private dataStore: { items: Item[] } = { items: [] } ;
|
private dataStore: { items: Item[] } = { items: [] } ;
|
||||||
private _itemsUpdated: BehaviorSubject<Item[]> = new BehaviorSubject(this.dataStore.items);
|
private _itemsUpdated: BehaviorSubject<Item[]> = new BehaviorSubject(this.dataStore.items);
|
||||||
public readonly itemsUpdated: Observable<Item[]> = this._itemsUpdated.asObservable();
|
public readonly itemsUpdated: Observable<Item[]> = this._itemsUpdated.asObservable();
|
||||||
|
@ -17,7 +18,7 @@ export class ItemService{
|
||||||
getItems(addr: string){
|
getItems(addr: string){
|
||||||
this.address = addr;
|
this.address = addr;
|
||||||
const params = new HttpParams().append('address', addr);
|
const params = new HttpParams().append('address', addr);
|
||||||
let obs = this.http.get<{message: string, items: any}>('http://localhost:3000/api/getitems', { headers:{}, params: params, observe: 'response'});
|
let obs = this.http.get<{message: string, items: any}>(this.beUrl+'api/getitems', { headers:{}, params: params, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((ItemDataResponse) => {
|
obs.subscribe((ItemDataResponse) => {
|
||||||
if (ItemDataResponse.status == 200 ) {
|
if (ItemDataResponse.status == 200 ) {
|
||||||
|
@ -33,7 +34,7 @@ export class ItemService{
|
||||||
|
|
||||||
addItem(item: Item) {
|
addItem(item: Item) {
|
||||||
//const params = new HttpParams().append('item', JSON.stringify(item));
|
//const params = new HttpParams().append('item', JSON.stringify(item));
|
||||||
let obs = this.http.post<{message: string}>('http://localhost:3000/api/item', { item: item });
|
let obs = this.http.post<{message: string}>(this.beUrl+'api/item', { item: item });
|
||||||
|
|
||||||
obs.subscribe((ItemResponse) => {
|
obs.subscribe((ItemResponse) => {
|
||||||
console.log('Item added');
|
console.log('Item added');
|
||||||
|
@ -44,7 +45,7 @@ export class ItemService{
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteItem(id: string) {
|
deleteItem(id: string) {
|
||||||
let obs = this.http.delete<{message: string}>('http://localhost:3000/api/item/'+id);
|
let obs = this.http.delete<{message: string}>(this.beUrl+'api/item/'+id);
|
||||||
|
|
||||||
obs.subscribe((ItemResponse) => {
|
obs.subscribe((ItemResponse) => {
|
||||||
console.log('Item deleted');
|
console.log('Item deleted');
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { LineItem} from '../items/lineitem.model';
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
|
|
||||||
export class OrderService {
|
export class OrderService {
|
||||||
|
beUrl = 'http://localhost:3000/';
|
||||||
private dataStore: {allOrders: Order[], user: User, order: Order } = {
|
private dataStore: {allOrders: Order[], user: User, order: Order } = {
|
||||||
allOrders: [],
|
allOrders: [],
|
||||||
user:{
|
user:{
|
||||||
|
@ -58,7 +59,7 @@ export class OrderService {
|
||||||
getOrder() {
|
getOrder() {
|
||||||
var session = this.dataStore.user.session;
|
var session = this.dataStore.user.session;
|
||||||
const params = new HttpParams().append('session', session);
|
const params = new HttpParams().append('session', session);
|
||||||
let obs = this.http.get<{message: string, order: any}>('http://localhost:3000/api/order', { headers:{}, params:params, observe: 'response'});
|
let obs = this.http.get<{message: string, order: any}>(this.beUrl+'api/order', { headers:{}, params:params, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((OrderDataResponse) => {
|
obs.subscribe((OrderDataResponse) => {
|
||||||
if (OrderDataResponse.status == 200) {
|
if (OrderDataResponse.status == 200) {
|
||||||
|
@ -80,7 +81,7 @@ export class OrderService {
|
||||||
getAllOrders(){
|
getAllOrders(){
|
||||||
var address = this.dataStore.user.address;
|
var address = this.dataStore.user.address;
|
||||||
const params = new HttpParams().append('address', address);
|
const params = new HttpParams().append('address', address);
|
||||||
let obs = this.http.get<{message: string, orders: any}>('http://localhost:3000/api/allorders', { headers:{}, params:params, observe: 'response'});
|
let obs = this.http.get<{message: string, orders: any}>(this.beUrl+'api/allorders', { headers:{}, params:params, observe: 'response'});
|
||||||
obs.subscribe((OrdersData) => {
|
obs.subscribe((OrdersData) => {
|
||||||
if (OrdersData.status == 200 ){
|
if (OrdersData.status == 200 ){
|
||||||
console.log('getAllOrder:', OrdersData.body);
|
console.log('getAllOrder:', OrdersData.body);
|
||||||
|
@ -96,7 +97,7 @@ export class OrderService {
|
||||||
|
|
||||||
addToOrder(lineItem: LineItem) {
|
addToOrder(lineItem: LineItem) {
|
||||||
if(this.dataStore.order._id != null) {
|
if(this.dataStore.order._id != null) {
|
||||||
let obs = this.http.post<{message: string}>('http://localhost:3000/api/lineitem', { order_id: this.dataStore.order._id, line: lineItem });
|
let obs = this.http.post<{message: string}>(this.beUrl+'api/lineitem', { order_id: this.dataStore.order._id, line: lineItem });
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
this.getOrder();
|
this.getOrder();
|
||||||
});
|
});
|
||||||
|
@ -115,7 +116,7 @@ export class OrderService {
|
||||||
total: 0,
|
total: 0,
|
||||||
lines: []
|
lines: []
|
||||||
};
|
};
|
||||||
let obs = this.http.post<{message: string, order: Order}>('http://localhost:3000/api/order', {order: order});
|
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {order: order});
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
console.log('Create order', orderData);
|
console.log('Create order', orderData);
|
||||||
this.dataStore.order = orderData.order;
|
this.dataStore.order = orderData.order;
|
||||||
|
@ -127,7 +128,7 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelOrder(id: string) {
|
cancelOrder(id: string) {
|
||||||
let obs = this.http.delete<{message: string}>('http://localhost:3000/api/order/'+id);
|
let obs = this.http.delete<{message: string}>(this.beUrl+'api/order/'+id);
|
||||||
|
|
||||||
obs.subscribe((OrderResponse) => {
|
obs.subscribe((OrderResponse) => {
|
||||||
console.log('Order deleted');
|
console.log('Order deleted');
|
||||||
|
@ -159,7 +160,7 @@ export class OrderService {
|
||||||
console.log('Price:', price);
|
console.log('Price:', price);
|
||||||
this.dataStore.order.closed = true;
|
this.dataStore.order.closed = true;
|
||||||
this.dataStore.order.price = price;
|
this.dataStore.order.price = price;
|
||||||
let obs = this.http.post<{message: string, order: Order}>('http://localhost:3000/api/order', {order: this.dataStore.order});
|
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {order: this.dataStore.order});
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
console.log('Closed order', orderData);
|
console.log('Closed order', orderData);
|
||||||
this.dataStore.order = {
|
this.dataStore.order = {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {Owner} from './owner.model';
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
|
|
||||||
export class UserService{
|
export class UserService{
|
||||||
|
beUrl = 'http://localhost:3000/';
|
||||||
private dataStore: { user: User, owner: Owner} = {
|
private dataStore: { user: User, owner: Owner} = {
|
||||||
user: {
|
user: {
|
||||||
address: '',
|
address: '',
|
||||||
|
@ -41,7 +42,7 @@ export class UserService{
|
||||||
this.session = localStorage.getItem('s4z_token');
|
this.session = localStorage.getItem('s4z_token');
|
||||||
if (this.session != null) {
|
if (this.session != null) {
|
||||||
const params = new HttpParams().append('session', this.session!);
|
const params = new HttpParams().append('session', this.session!);
|
||||||
let obs = this.http.get<{message: string, user: any}>('http://localhost:3000/api/getuser', { headers:{}, params: params, observe: 'response'});
|
let obs = this.http.get<{message: string, user: any}>(this.beUrl+'api/getuser', { headers:{}, params: params, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((UserDataResponse) => {
|
obs.subscribe((UserDataResponse) => {
|
||||||
console.log(UserDataResponse.status);
|
console.log(UserDataResponse.status);
|
||||||
|
@ -66,7 +67,7 @@ export class UserService{
|
||||||
|
|
||||||
addOwner(address: string) {
|
addOwner(address: string) {
|
||||||
const owner: Owner={_id: '', address: address, name: 'Zgo-'.concat(address.substring(0,5))};
|
const owner: Owner={_id: '', address: address, name: 'Zgo-'.concat(address.substring(0,5))};
|
||||||
let obs = this.http.post<{message: string}>('http://localhost:3000/api/addowner', {address: owner.address, name: owner.name});
|
let obs = this.http.post<{message: string}>(this.beUrl+'api/addowner', {address: owner.address, name: owner.name});
|
||||||
|
|
||||||
obs.subscribe((responseData) => {
|
obs.subscribe((responseData) => {
|
||||||
console.log(responseData.message);
|
console.log(responseData.message);
|
||||||
|
@ -76,7 +77,7 @@ export class UserService{
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOwner(owner: Owner) {
|
updateOwner(owner: Owner) {
|
||||||
this.http.post<{message: string, owner: Owner}>('http://localhost:3000/api/updateowner', {owner: owner}).
|
this.http.post<{message: string, owner: Owner}>(this.beUrl+'api/updateowner', {owner: owner}).
|
||||||
subscribe((responseData) => {
|
subscribe((responseData) => {
|
||||||
console.log(responseData.message);
|
console.log(responseData.message);
|
||||||
//this.dataStore.owner = responseData.owner;
|
//this.dataStore.owner = responseData.owner;
|
||||||
|
@ -88,7 +89,7 @@ export class UserService{
|
||||||
getOwner(address: string) {
|
getOwner(address: string) {
|
||||||
console.log('getOwner', address);
|
console.log('getOwner', address);
|
||||||
const ownParams = new HttpParams().append('address', address);
|
const ownParams = new HttpParams().append('address', address);
|
||||||
let obs = this.http.get<{message:string, owner: any}>('http://localhost:3000/api/getowner', {params: ownParams, observe: 'response'});
|
let obs = this.http.get<{message:string, owner: any}>(this.beUrl+'api/getowner', {params: ownParams, observe: 'response'});
|
||||||
|
|
||||||
obs.subscribe((OwnerDataResponse) => {
|
obs.subscribe((OwnerDataResponse) => {
|
||||||
console.log('api/getowner', OwnerDataResponse.status);
|
console.log('api/getowner', OwnerDataResponse.status);
|
||||||
|
|
Loading…
Reference in a new issue