Add new fields for Owner

This commit is contained in:
Rene Vergara 2022-01-17 14:49:08 -06:00
parent c9f84f1a28
commit c40ac0fd44
10 changed files with 84 additions and 23 deletions

View file

@ -127,7 +127,7 @@ var blockInterval = setInterval( function() {
if (txData.confirmations >= 6 ) { if (txData.confirmations >= 6 ) {
usermodel.findOne({address: address, session: session, blocktime: blocktime}).then(function(doc){ usermodel.findOne({address: address, session: session, blocktime: blocktime}).then(function(doc){
if (doc == null){ if (doc == null){
console.log('User not found', session, blocktime, amount); console.log('User not found', session, blocktime);
const n = crypto.randomInt(0, 10000000); const n = crypto.randomInt(0, 10000000);
const pin = n.toString().padStart(6, '0'); const pin = n.toString().padStart(6, '0');
sendPin(pin, address); sendPin(pin, address);
@ -333,6 +333,7 @@ app.get('/api/getowner', (req, res, next) => {
}); });
app.post('/api/addowner', (req, res, next) => { app.post('/api/addowner', (req, res, next) => {
// TODO: confirm passing owner works
console.log('Post: /api/addowner'); console.log('Post: /api/addowner');
const owner = new ownermodel(req.body); const owner = new ownermodel(req.body);
owner.save(); owner.save();

View file

@ -13,7 +13,8 @@ const ownerSchema = mongoose.Schema({
city: {type: String, required: true}, city: {type: String, required: true},
state: {type: String, required: true}, state: {type: String, required: true},
postal: {type: String, required: true}, postal: {type: String, required: true},
phone: {type: String, required: true} phone: {type: String, required: true},
paid: {type: Boolean, required: true, default: false}
}); });
module.exports = mongoose.model('Owner', ownerSchema); module.exports = mongoose.model('Owner', ownerSchema);

View file

@ -30,7 +30,15 @@ export class FullnodeService{
tax: false, tax: false,
taxValue: 0, taxValue: 0,
vat: false, vat: false,
vatValue: 0 vatValue: 0,
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
paid: false
}; };
constructor(private http: HttpClient, public userService: UserService){ constructor(private http: HttpClient, public userService: UserService){

View file

@ -23,7 +23,15 @@ export class HeaderComponent implements OnInit, OnDestroy {
tax: false, tax: false,
taxValue: 0, taxValue: 0,
vat: false, vat: false,
vatValue: 0 vatValue: 0,
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
paid: false
}; };
private session: string | null = ''; private session: string | null = '';
public heightUpdate: Observable<number>; public heightUpdate: Observable<number>;

View file

@ -28,7 +28,15 @@ export class ItemListComponent implements OnInit{
tax: false, tax: false,
taxValue: 0, taxValue: 0,
vat: false, vat: false,
vatValue: 0 vatValue: 0,
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
paid: false
}; };
public price: number = 1; public price: number = 1;
public ownerUpdate: Observable<Owner>; public ownerUpdate: Observable<Owner>;

View file

@ -9,6 +9,7 @@ import { FullnodeService } from '../fullnode.service';
import { ScanComponent} from '../scan/scan.component'; import { ScanComponent} from '../scan/scan.component';
import { Tx } from '../tx.model'; import { Tx } from '../tx.model';
import {User} from '../user.model'; import {User} from '../user.model';
import { Owner } from '../owner.model';
import { Subscription, Observable } from 'rxjs'; import { Subscription, Observable } from 'rxjs';
import { take } from 'rxjs/operators'; import { take } from 'rxjs/operators';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
@ -38,11 +39,28 @@ export class LoginComponent implements OnInit, AfterViewInit {
pin: '', pin: '',
validated: false validated: false
}; };
public owner:Owner = {
address: '',
name: '',
currency: '',
tax: false,
taxValue:0,
vat: false,
vatValue: 0,
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
paid: false
};
private FullnodeSub: Subscription = new Subscription(); private FullnodeSub: Subscription = new Subscription();
private UserSub: Subscription = new Subscription(); private UserSub: Subscription = new Subscription();
public heightUpdate: Observable<number>; public heightUpdate: Observable<number>;
public uZaddrUpdate: Observable<string>; public uZaddrUpdate: Observable<string>;
public userUpdate:Observable<User>; public userUpdate:Observable<User>;
public ownerUpdate:Observable<Owner>;
public txsUpdate: Observable<Tx[]>; public txsUpdate: Observable<Tx[]>;
tickets = [ tickets = [
{ {
@ -87,9 +105,13 @@ export class LoginComponent implements OnInit, AfterViewInit {
this.heightUpdate = fullnodeService.heightUpdate; this.heightUpdate = fullnodeService.heightUpdate;
this.uZaddrUpdate = userService.uZaddrUpdate; this.uZaddrUpdate = userService.uZaddrUpdate;
this.userUpdate = userService.userUpdate; this.userUpdate = userService.userUpdate;
this.ownerUpdate = userService.ownerUpdate;
this.userUpdate.subscribe((user) => { this.userUpdate.subscribe((user) => {
this.user = user; this.user = user;
}); });
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
});
this.txsUpdate = userService.txUpdate; this.txsUpdate = userService.txUpdate;
this.txsUpdate.subscribe((txs) => { this.txsUpdate.subscribe((txs) => {
this.txs = txs; this.txs = txs;

View file

@ -30,7 +30,14 @@ export class OrderService {
tax: false, tax: false,
taxValue: 0, taxValue: 0,
vat: false, vat: false,
vatValue: 0 vatValue: 0,
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
paid: false
}, },
order: { order: {
address: '', address: '',

View file

@ -13,4 +13,5 @@ export interface Owner {
state: string; state: string;
postal: string; postal: string;
phone: string; phone: string;
paid: boolean;
} }

View file

@ -25,7 +25,15 @@ export class UserService{
tax: false, tax: false,
taxValue: 0, taxValue: 0,
vat: false, vat: false,
vatValue: 0 vatValue: 0,
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
paid: false
}, },
txs : [] txs : []
}; };
@ -38,10 +46,12 @@ export class UserService{
private uNameUpdated = new Subject<string>(); private uNameUpdated = new Subject<string>();
private _ownerUpdated: BehaviorSubject<Owner> = new BehaviorSubject(this.dataStore.owner); private _ownerUpdated: BehaviorSubject<Owner> = new BehaviorSubject(this.dataStore.owner);
private _txsUpdated: BehaviorSubject<Tx[]> = new BehaviorSubject(this.dataStore.txs); private _txsUpdated: BehaviorSubject<Tx[]> = new BehaviorSubject(this.dataStore.txs);
private _paidUpdated: BehaviorSubject<boolean> = new BehaviorSubject(this.dataStore.owner.paid);
public readonly uZaddrUpdate: Observable<string> = this._uZaddrUpdated.asObservable(); public readonly uZaddrUpdate: Observable<string> = this._uZaddrUpdated.asObservable();
public readonly ownerUpdate: Observable<Owner> = this._ownerUpdated.asObservable(); public readonly ownerUpdate: Observable<Owner> = this._ownerUpdated.asObservable();
public readonly userUpdate: Observable<User> = this._userUpdated.asObservable(); public readonly userUpdate: Observable<User> = this._userUpdated.asObservable();
public readonly txUpdate: Observable<Tx[]> = this._txsUpdated.asObservable(); public readonly txUpdate: Observable<Tx[]> = this._txsUpdated.asObservable();
public readonly paidUpdate: Observable<boolean> = this._paidUpdated.asObservable();
private reqHeaders: HttpHeaders; private reqHeaders: HttpHeaders;
private apiKey = 'Le2adeic8Thah4Aeng4daem6i'; private apiKey = 'Le2adeic8Thah4Aeng4daem6i';
@ -116,18 +126,8 @@ export class UserService{
}); });
} }
addOwner(address: string) { addOwner(owner: Owner) {
const owner: Owner={ let obs = this.http.post<{message: string}>(this.beUrl+'api/addowner', {owner: owner}, {headers: this.reqHeaders});
_id: '',
address: address,
name: 'Zgo-'.concat(address.substring(0,5)),
currency: 'usd',
tax: false,
taxValue: 0,
vat: false,
vatValue: 0
};
let obs = this.http.post<{message: string}>(this.beUrl+'api/addowner', {address: owner.address, name: owner.name}, {headers: this.reqHeaders});
obs.subscribe((responseData) => { obs.subscribe((responseData) => {
console.log(responseData.message); console.log(responseData.message);
@ -157,9 +157,7 @@ export class UserService{
this.dataStore.owner = OwnerDataResponse.body!.owner[0]; this.dataStore.owner = OwnerDataResponse.body!.owner[0];
//console.log('getOwner object', this.dataStore.owner); //console.log('getOwner object', this.dataStore.owner);
this._ownerUpdated.next(Object.assign({},this.dataStore).owner); this._ownerUpdated.next(Object.assign({},this.dataStore).owner);
} else { this._paidUpdated.next(Object.assign({}, this.dataStore).owner.paid);
console.log("No owner found, adding");
this.addOwner(address);
} }
}); });

View file

@ -36,7 +36,14 @@ export class ViewerComponent implements OnInit {
tax: false, tax: false,
taxValue: 0, taxValue: 0,
vat: false, vat: false,
vatValue: 0 vatValue: 0,
email: '',
street: '',
city: '',
state: '',
postal: '',
phone: '',
paid: false
}; };
public addrUpdate: Observable<string>; public addrUpdate: Observable<string>;
public ownerUpdate: Observable<Owner>; public ownerUpdate: Observable<Owner>;