1
import WebSql from '../WebSql';
2
import axios from 'axios';
4
export default class Currency {
9
this.dataProvider = {};
11
this.tableName = 'currency';
13
this.db = new WebSql(this.tableName, '1.0', 'currency information table', 20000000);
40
this.db.createTable(this.tableName, columns);
46
const columns = ['num_code', 'char_code', 'nominal', 'name', 'value'];
48
this.dataProvider = '';
50
this.getCurrenciesFromServer();
52
let interval = setInterval(() => {
54
if(this.dataProvider !== '') {
56
clearInterval(interval);
58
for (let key in this.dataProvider) {
60
this.dataProvider[key].num_code,
61
this.dataProvider[key].char_code,
62
this.dataProvider[key].nominal,
63
this.dataProvider[key].name,
64
this.dataProvider[key].value
67
this.db.insertRecordToTable(this.tableName, columns, values);
76
return new Promise((resolve, reject) => {
77
this.db.db.transaction((tx) => {
78
tx.executeSql("SELECT * FROM " + this.tableName, [], (trans, result) => {
87
getCurrency(currencyCode)
89
let query = "SELECT * FROM " + this.tableName + " WHERE num_code=?";
91
return new Promise((resolve, reject) => {
92
this.db.db.transaction((tx) => {
93
tx.executeSql(query, [currencyCode], (trans, result) => {
94
resolve(result.rows[0]);
102
getCurrenciesFromServer()
104
axios.get('/pa/get-currencies')
106
this.dataProvider = response.data.data;