anote-server-libs 0.6.9 → 0.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -68,10 +68,10 @@ class Dao {
|
|
|
68
68
|
}
|
|
69
69
|
return Object.getOwnPropertyNames(storage).map(k => storage[k]);
|
|
70
70
|
}
|
|
71
|
-
update(instance, client) {
|
|
71
|
+
update(instance, client, on) {
|
|
72
72
|
if (instance.archivedOn)
|
|
73
73
|
return Promise.reject('Record archived!');
|
|
74
|
-
instance.updatedOn = new Date();
|
|
74
|
+
instance.updatedOn = on || new Date();
|
|
75
75
|
if (this.pool) {
|
|
76
76
|
const props = this.serialize(instance);
|
|
77
77
|
props.push(instance.id);
|
|
@@ -84,8 +84,8 @@ class Dao {
|
|
|
84
84
|
return request.query('UPDATE ' + this.table + ' SET ' + this.updateDefinition + ' WHERE id=@' + (this.nFields + 1)).then(() => instance.id);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
create(instance, client) {
|
|
88
|
-
instance.createdOn = instance.updatedOn = new Date();
|
|
87
|
+
create(instance, client, on) {
|
|
88
|
+
instance.createdOn = instance.updatedOn = on || new Date();
|
|
89
89
|
if (this.pool) {
|
|
90
90
|
const props = this.serialize(instance);
|
|
91
91
|
return (client || this.pool).query('INSERT INTO ' + this.table + '(' + this.updateDefinition.replace(/=\$\d+/g, '').replace(/=[^)]+\)/g, '') + ')'
|
|
@@ -105,10 +105,10 @@ class Dao {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
createSeveral(instances, client) {
|
|
108
|
+
createSeveral(instances, client, on) {
|
|
109
109
|
if (!instances.length)
|
|
110
110
|
return Promise.resolve([]);
|
|
111
|
-
const now = new Date();
|
|
111
|
+
const now = on || new Date();
|
|
112
112
|
instances.forEach(instance => instance.updatedOn = now);
|
|
113
113
|
const props = [].concat.apply([], instances.map(instance => this.serialize(instance)));
|
|
114
114
|
return (client || this.pool).query('INSERT INTO ' + this.table + '(' + this.updateDefinition.replace(/=\$\d+/g, '').replace(/=[^)]+\)/g, '') + ')'
|
|
@@ -90,9 +90,9 @@ export abstract class Dao<R, T extends Model<R>> implements ModelRepr {
|
|
|
90
90
|
return Object.getOwnPropertyNames(storage).map(k => storage[k]);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
update(instance: T, client: ClientBase | ConnectionPool | Transaction): Promise<R> {
|
|
93
|
+
update(instance: T, client: ClientBase | ConnectionPool | Transaction, on?: Date): Promise<R> {
|
|
94
94
|
if((<any>instance).archivedOn) return Promise.reject('Record archived!');
|
|
95
|
-
instance.updatedOn = new Date();
|
|
95
|
+
instance.updatedOn = on || new Date();
|
|
96
96
|
if(this.pool) {
|
|
97
97
|
const props = this.serialize(instance);
|
|
98
98
|
props.push(instance.id);
|
|
@@ -105,8 +105,8 @@ export abstract class Dao<R, T extends Model<R>> implements ModelRepr {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
create(instance: T, client?: ClientBase | Transaction): Promise<R> {
|
|
109
|
-
(<any>instance).createdOn = instance.updatedOn = new Date();
|
|
108
|
+
create(instance: T, client?: ClientBase | Transaction, on?: Date): Promise<R> {
|
|
109
|
+
(<any>instance).createdOn = instance.updatedOn = on || new Date();
|
|
110
110
|
if(this.pool) {
|
|
111
111
|
const props = this.serialize(instance);
|
|
112
112
|
return (<ClientBase | Pool>(client || this.pool)).query('INSERT INTO ' + this.table + '(' + this.updateDefinition.replace(/=\$\d+/g, '').replace(/=[^)]+\)/g, '') + ')'
|
|
@@ -126,9 +126,9 @@ export abstract class Dao<R, T extends Model<R>> implements ModelRepr {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
createSeveral(instances: T[], client?: ClientBase): Promise<R[]> {
|
|
129
|
+
createSeveral(instances: T[], client?: ClientBase, on?: Date): Promise<R[]> {
|
|
130
130
|
if(!instances.length) return Promise.resolve([]);
|
|
131
|
-
const now = new Date();
|
|
131
|
+
const now = on || new Date();
|
|
132
132
|
instances.forEach(instance => instance.updatedOn = now);
|
|
133
133
|
const props = [].concat.apply([], instances.map(instance => this.serialize(instance)));
|
|
134
134
|
return (client || this.pool).query('INSERT INTO ' + this.table + '(' + this.updateDefinition.replace(/=\$\d+/g, '').replace(/=[^)]+\)/g, '') + ')'
|
package/package.json
CHANGED
package/.vscode/settings.json
DELETED