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'})
|
||||
export class FullnodeService{
|
||||
beUrl = 'http://localhost:3000/';
|
||||
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 _memoUpdated: BehaviorSubject<string[]> = new BehaviorSubject(this.dataStore.memoList);
|
||||
|
@ -25,7 +26,7 @@ export class FullnodeService{
|
|||
}
|
||||
|
||||
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) => {
|
||||
this.dataStore.height = BlockData.height;
|
||||
this._heightUpdated.next(Object.assign({}, this.dataStore).height);
|
||||
|
@ -37,7 +38,7 @@ export class FullnodeService{
|
|||
getPrice(){
|
||||
var currency = 'usd';
|
||||
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) => {
|
||||
if (PriceData.status == 200) {
|
||||
this.dataStore.price = PriceData.body!.price.price;
|
||||
|
@ -62,7 +63,7 @@ export class FullnodeService{
|
|||
|
||||
|
||||
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) => {
|
||||
this.dataStore.addr = AddrData.addr;
|
||||
|
|
|
@ -6,6 +6,7 @@ import { HttpClient, HttpParams } from '@angular/common/http';
|
|||
@Injectable({providedIn: 'root'})
|
||||
|
||||
export class ItemService{
|
||||
beUrl = 'http://localhost:3000/';
|
||||
private dataStore: { items: Item[] } = { items: [] } ;
|
||||
private _itemsUpdated: BehaviorSubject<Item[]> = new BehaviorSubject(this.dataStore.items);
|
||||
public readonly itemsUpdated: Observable<Item[]> = this._itemsUpdated.asObservable();
|
||||
|
@ -17,7 +18,7 @@ export class ItemService{
|
|||
getItems(addr: string){
|
||||
this.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) => {
|
||||
if (ItemDataResponse.status == 200 ) {
|
||||
|
@ -33,7 +34,7 @@ export class ItemService{
|
|||
|
||||
addItem(item: 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) => {
|
||||
console.log('Item added');
|
||||
|
@ -44,7 +45,7 @@ export class ItemService{
|
|||
}
|
||||
|
||||
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) => {
|
||||
console.log('Item deleted');
|
||||
|
|
|
@ -10,6 +10,7 @@ import { LineItem} from '../items/lineitem.model';
|
|||
@Injectable({providedIn: 'root'})
|
||||
|
||||
export class OrderService {
|
||||
beUrl = 'http://localhost:3000/';
|
||||
private dataStore: {allOrders: Order[], user: User, order: Order } = {
|
||||
allOrders: [],
|
||||
user:{
|
||||
|
@ -58,7 +59,7 @@ export class OrderService {
|
|||
getOrder() {
|
||||
var session = this.dataStore.user.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) => {
|
||||
if (OrderDataResponse.status == 200) {
|
||||
|
@ -80,7 +81,7 @@ export class OrderService {
|
|||
getAllOrders(){
|
||||
var address = this.dataStore.user.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) => {
|
||||
if (OrdersData.status == 200 ){
|
||||
console.log('getAllOrder:', OrdersData.body);
|
||||
|
@ -96,7 +97,7 @@ export class OrderService {
|
|||
|
||||
addToOrder(lineItem: LineItem) {
|
||||
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) => {
|
||||
this.getOrder();
|
||||
});
|
||||
|
@ -115,7 +116,7 @@ export class OrderService {
|
|||
total: 0,
|
||||
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) => {
|
||||
console.log('Create order', orderData);
|
||||
this.dataStore.order = orderData.order;
|
||||
|
@ -127,7 +128,7 @@ export class OrderService {
|
|||
}
|
||||
|
||||
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) => {
|
||||
console.log('Order deleted');
|
||||
|
@ -159,7 +160,7 @@ export class OrderService {
|
|||
console.log('Price:', price);
|
||||
this.dataStore.order.closed = true;
|
||||
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) => {
|
||||
console.log('Closed order', orderData);
|
||||
this.dataStore.order = {
|
||||
|
|
|
@ -7,6 +7,7 @@ import {Owner} from './owner.model';
|
|||
@Injectable({providedIn: 'root'})
|
||||
|
||||
export class UserService{
|
||||
beUrl = 'http://localhost:3000/';
|
||||
private dataStore: { user: User, owner: Owner} = {
|
||||
user: {
|
||||
address: '',
|
||||
|
@ -41,7 +42,7 @@ export class UserService{
|
|||
this.session = localStorage.getItem('s4z_token');
|
||||
if (this.session != null) {
|
||||
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) => {
|
||||
console.log(UserDataResponse.status);
|
||||
|
@ -66,7 +67,7 @@ export class UserService{
|
|||
|
||||
addOwner(address: string) {
|
||||
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) => {
|
||||
console.log(responseData.message);
|
||||
|
@ -76,7 +77,7 @@ export class UserService{
|
|||
}
|
||||
|
||||
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) => {
|
||||
console.log(responseData.message);
|
||||
//this.dataStore.owner = responseData.owner;
|
||||
|
@ -88,7 +89,7 @@ export class UserService{
|
|||
getOwner(address: string) {
|
||||
console.log('getOwner', 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) => {
|
||||
console.log('api/getowner', OwnerDataResponse.status);
|
||||
|
|
Loading…
Reference in a new issue