Guest Book
  Save bill
  Update bill
  Show bill

Fix:
  Tax details was sending the rate multiplied by 100 but not dividing it on save/update

Feature:
  Updated the auth service to check local storage for the latest user token
This commit is contained in:
2020-09-24 07:39:46 +05:30
parent b19d8cc030
commit 6c06271315
12 changed files with 382 additions and 224 deletions

View File

@ -16,22 +16,39 @@ export class AuthService {
public currentUser: Observable<User>;
constructor(private http: HttpClient) {
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem(JWT_USER)));
this.checkStorage();
this.currentUser = this.currentUserSubject.asObservable();
}
checkStorage(): User {
const existingToken: User = JSON.parse(localStorage.getItem(JWT_USER));
if (existingToken === null || Date.now() > existingToken.exp * 1000) {
localStorage.removeItem(JWT_USER);
this.currentUserSubject = new BehaviorSubject<User>(null);
return null;
} else {
this.currentUserSubject = new BehaviorSubject<User>(existingToken);
return existingToken;
}
}
public get user(): User {
const val = this.currentUserSubject.value;
let val = this.currentUserSubject.value;
if (val == null) {
return val;
}
const expired = Date.now() > val.exp * 1000;
let expired = Date.now() > val.exp * 1000;
if (expired) {
val = this.checkStorage();
}
if (val == null) {
return null;
}
expired = Date.now() > val.exp * 1000;
if (expired) {
this.logout();
return null;
} else {
return this.currentUserSubject.value;
}
return this.currentUserSubject.value;
}
login(username: string, password: string, otp: string) {
@ -73,10 +90,6 @@ export class AuthService {
return Date.now() > (this.user.exp - (environment.ACCESS_TOKEN_REFRESH_MINUTES * 60)) * 1000;
}
expired(): boolean {
return Date.now() > this.user.exp * 1000;
}
logout() {
// remove user from local storage to log user out
localStorage.removeItem(JWT_USER);

View File

@ -10,9 +10,9 @@ const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/v1/vouchers';
const urlMoveTable = '/v1/move-table';
const urlMoveKot = '/v1/move-kot';
const url = '/api/voucher';
const urlMoveTable = '/api/move-table';
const urlMoveKot = '/api/move-kot';
const serviceName = 'VoucherService';
@Injectable({providedIn: 'root'})
@ -22,7 +22,7 @@ export class VoucherService {
}
get(id: string): Observable<Bill> {
return <Observable<Bill>>this.http.get<Bill>(`${url}/${id}`)
return <Observable<Bill>>this.http.get<Bill>(`${url}/from-id/${id}`)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
@ -30,9 +30,6 @@ export class VoucherService {
getFromTable(tableId: string, voucherId: string, guestId: string): Observable<Bill> {
let params = new HttpParams();
if (tableId !== null) {
params = params.set('t', tableId);
}
if (voucherId !== null) {
params = params.set('v', voucherId);
}
@ -40,7 +37,7 @@ export class VoucherService {
params = params.set('g', guestId);
}
return <Observable<Bill>>this.http.get<Bill>(`${url}/new`, {params: params})
return <Observable<Bill>>this.http.get<Bill>(`${url}/from-table/${tableId}`, {params: params})
.pipe(
catchError(this.log.handleError(
serviceName,
@ -54,7 +51,7 @@ export class VoucherService {
if (guest_book_id !== null) {
options.params = options.params.set('g', guest_book_id);
}
return <Observable<boolean>>this.http.post<boolean>(`${url}/new`, voucher, options)
return <Observable<boolean>>this.http.post<boolean>(`${url}/save`, voucher, options)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
@ -65,7 +62,7 @@ export class VoucherService {
if (guest_book_id !== null) {
options.params = options.params.set('g', guest_book_id);
}
return <Observable<boolean>>this.http.put<boolean>(`${url}/${voucher.id}`, voucher, options)
return <Observable<boolean>>this.http.put<boolean>(`${url}/update/${voucher.id}`, voucher, options)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);