2
0
mirror of https://github.com/frappe/books.git synced 2024-11-13 00:46:28 +00:00

Fix DateTime + error logs (#106)

This commit is contained in:
Nishchith K 2019-01-12 17:40:52 +05:30 committed by Faris Ansari
parent 8bdce07a00
commit 9053f4a710
3 changed files with 54 additions and 39 deletions

View File

@ -13,8 +13,13 @@ module.exports = class sqliteDatabase extends Database {
if (dbPath) { if (dbPath) {
this.dbPath = dbPath; this.dbPath = dbPath;
} }
return new Promise(resolve => { return new Promise((resolve, reject) => {
this.conn = new sqlite3.Database(this.dbPath, () => { this.conn = new sqlite3.Database(this.dbPath, (err) => {
if (err) {
console.log(err);
reject(err);
return;
}
if (debug) { if (debug) {
this.conn.on('trace', (trace) => console.log(trace)); this.conn.on('trace', (trace) => console.log(trace));
} }
@ -211,6 +216,7 @@ module.exports = class sqliteDatabase extends Database {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.conn.run(query, params, (err) => { this.conn.run(query, params, (err) => {
if (err) { if (err) {
console.error('Error in sql:', query);
reject(err); reject(err);
} else { } else {
resolve(); resolve();
@ -220,8 +226,12 @@ module.exports = class sqliteDatabase extends Database {
} }
sql(query, params) { sql(query, params) {
return new Promise((resolve) => { return new Promise((resolve, reject) => {
this.conn.all(query, params, (err, rows) => { this.conn.all(query, params, (err, rows) => {
if (err) {
console.error('Error in sql:', query);
reject(err)
}
resolve(rows); resolve(rows);
}); });
}); });

View File

@ -52,10 +52,15 @@ module.exports = class BaseDocument extends Observable {
async applyChange(fieldname) { async applyChange(fieldname) {
if (await this.applyFormula()) { if (await this.applyFormula()) {
// multiple changes // multiple changes
await this.trigger('change', { doc: this }); await this.trigger('change', {
doc: this
});
} else { } else {
// no other change, trigger control refresh // no other change, trigger control refresh
await this.trigger('change', { doc: this, fieldname: fieldname }); await this.trigger('change', {
doc: this,
fieldname: fieldname
});
} }
} }
@ -65,14 +70,9 @@ module.exports = class BaseDocument extends Observable {
let defaultValue = null; let defaultValue = null;
if (field.fieldtype === 'Date') {
defaultValue = (new Date()).toISOString().substr(0, 10);
}
if (field.fieldtype === 'Table') { if (field.fieldtype === 'Table') {
defaultValue = []; defaultValue = [];
} }
if (field.default) { if (field.default) {
defaultValue = field.default; defaultValue = field.default;
} }
@ -165,7 +165,9 @@ module.exports = class BaseDocument extends Observable {
this.clearValues(); this.clearValues();
Object.assign(this, data); Object.assign(this, data);
this._dirty = false; this._dirty = false;
this.trigger('change', {doc: this}); this.trigger('change', {
doc: this
});
} }
clearValues() { clearValues() {

View File

@ -15,7 +15,10 @@ module.exports = class Observable {
set(key, value) { set(key, value) {
this[key] = value; this[key] = value;
this.trigger('change', {doc: this, fieldname: key}); this.trigger('change', {
doc: this,
fieldname: key
});
} }
on(event, listener) { on(event, listener) {