Add new createTransaction method
This commit is contained in:
parent
c5e66b4720
commit
9de1258f7f
@ -11,12 +11,25 @@ const httpOptions = {
|
|||||||
})
|
})
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} email
|
||||||
|
* @param {string} password
|
||||||
|
* @returns Observable
|
||||||
|
*/
|
||||||
login(email: string, password: string): Observable<any> {
|
login(email: string, password: string): Observable<any> {
|
||||||
return this.http.post(AUTH_API + '/login', {
|
return this.http.post(AUTH_API + '/login', {
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} email
|
||||||
|
* @param {string} username
|
||||||
|
* @param {string} password
|
||||||
|
* @returns Observable
|
||||||
|
*/
|
||||||
register(email: string, username: string, password: string): Observable<any> {
|
register(email: string, username: string, password: string): Observable<any> {
|
||||||
return this.http.post(
|
return this.http.post(
|
||||||
AUTH_API + '/register',
|
AUTH_API + '/register',
|
||||||
|
@ -51,8 +51,8 @@ export class DataService {
|
|||||||
*/
|
*/
|
||||||
public createTransaction(
|
public createTransaction(
|
||||||
symbol: string,
|
symbol: string,
|
||||||
time: Date,
|
time: string,
|
||||||
count: number,
|
count: BigInt,
|
||||||
price: number
|
price: number
|
||||||
): Observable<any> {
|
): Observable<any> {
|
||||||
return this.http.post(API_URL + 'transactions', {
|
return this.http.post(API_URL + 'transactions', {
|
||||||
@ -60,10 +60,11 @@ export class DataService {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
||||||
}),
|
}),
|
||||||
symbol,
|
responseType: 'text',
|
||||||
time,
|
|
||||||
count,
|
count,
|
||||||
price,
|
price,
|
||||||
|
symbol,
|
||||||
|
time,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,20 +6,42 @@ const USER_KEY = 'auth-user';
|
|||||||
})
|
})
|
||||||
export class TokenStorageService {
|
export class TokenStorageService {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
signOut(): void {
|
signOut(): void {
|
||||||
window.sessionStorage.clear();
|
window.sessionStorage.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} token
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
public saveToken(token: string): void {
|
public saveToken(token: string): void {
|
||||||
window.sessionStorage.removeItem(TOKEN_KEY);
|
window.sessionStorage.removeItem(TOKEN_KEY);
|
||||||
window.sessionStorage.setItem(TOKEN_KEY, token);
|
window.sessionStorage.setItem(TOKEN_KEY, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
public getToken(): string | null {
|
public getToken(): string | null {
|
||||||
return window.sessionStorage.getItem(TOKEN_KEY);
|
return window.sessionStorage.getItem(TOKEN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {any} user
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
public saveUser(user: any): void {
|
public saveUser(user: any): void {
|
||||||
window.sessionStorage.removeItem(USER_KEY);
|
window.sessionStorage.removeItem(USER_KEY);
|
||||||
window.sessionStorage.setItem(USER_KEY, JSON.stringify(user));
|
window.sessionStorage.setItem(USER_KEY, JSON.stringify(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns any
|
||||||
|
*/
|
||||||
public getUser(): any {
|
public getUser(): any {
|
||||||
const user = window.sessionStorage.getItem(USER_KEY);
|
const user = window.sessionStorage.getItem(USER_KEY);
|
||||||
if (user) {
|
if (user) {
|
||||||
|
@ -45,8 +45,8 @@ const ELEMENT_DATA: PeriodicElement[] = [
|
|||||||
|
|
||||||
export interface TransactionData {
|
export interface TransactionData {
|
||||||
symbol: string;
|
symbol: string;
|
||||||
time: Date;
|
time: string;
|
||||||
count: number;
|
count: BigInt;
|
||||||
price: number;
|
price: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,11 +25,17 @@ export class UserDialogComponent implements OnInit {
|
|||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
console.log(this.data);
|
console.log(this.data);
|
||||||
this.dataService.createTransaction(
|
console.log(
|
||||||
|
this.dataService
|
||||||
|
.createTransaction(
|
||||||
this.data.symbol,
|
this.data.symbol,
|
||||||
this.data.time,
|
this.data.time,
|
||||||
this.data.count,
|
this.data.count,
|
||||||
this.data.price
|
this.data.price
|
||||||
|
)
|
||||||
|
.subscribe((data) => {
|
||||||
|
console.log(data);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
this.dialog.closeAll();
|
this.dialog.closeAll();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user