2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +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) {
this.dbPath = dbPath;
}
return new Promise(resolve => {
this.conn = new sqlite3.Database(this.dbPath, () => {
return new Promise((resolve, reject) => {
this.conn = new sqlite3.Database(this.dbPath, (err) => {
if (err) {
console.log(err);
reject(err);
return;
}
if (debug) {
this.conn.on('trace', (trace) => console.log(trace));
}
@ -211,6 +216,7 @@ module.exports = class sqliteDatabase extends Database {
return new Promise((resolve, reject) => {
this.conn.run(query, params, (err) => {
if (err) {
console.error('Error in sql:', query);
reject(err);
} else {
resolve();
@ -220,8 +226,12 @@ module.exports = class sqliteDatabase extends Database {
}
sql(query, params) {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
this.conn.all(query, params, (err, rows) => {
if (err) {
console.error('Error in sql:', query);
reject(err)
}
resolve(rows);
});
});

View File

@ -52,10 +52,15 @@ module.exports = class BaseDocument extends Observable {
async applyChange(fieldname) {
if (await this.applyFormula()) {
// multiple changes
await this.trigger('change', { doc: this });
await this.trigger('change', {
doc: this
});
} else {
// 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;
if (field.fieldtype === 'Date') {
defaultValue = (new Date()).toISOString().substr(0, 10);
}
if (field.fieldtype === 'Table') {
defaultValue = [];
}
if (field.default) {
defaultValue = field.default;
}
@ -165,7 +165,9 @@ module.exports = class BaseDocument extends Observable {
this.clearValues();
Object.assign(this, data);
this._dirty = false;
this.trigger('change', {doc: this});
this.trigger('change', {
doc: this
});
}
clearValues() {

View File

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