groupcore-utils 3.0.0 → 3.0.1
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.
- package/database/crud.js +3 -1
- package/database/crud.spec.js +20 -0
- package/package.json +1 -1
package/database/crud.js
CHANGED
@@ -55,8 +55,10 @@ module.exports = class {
|
|
55
55
|
where.fields.forEach((field, i) => {
|
56
56
|
if (_.last(where.fields) === field) {
|
57
57
|
whereClause += `${field.field} = '${field.value}'`;
|
58
|
-
} else {
|
58
|
+
} else if (where.conditions) {
|
59
59
|
whereClause += `${field.field} = '${field.value}' ${where.conditions[i]} `;
|
60
|
+
} else {
|
61
|
+
whereClause += `${field.field} = '${field.value}' ${where.condition} `;
|
60
62
|
}
|
61
63
|
});
|
62
64
|
}
|
package/database/crud.spec.js
CHANGED
@@ -96,6 +96,26 @@ describe('read()', () => {
|
|
96
96
|
expect(querySpy).toHaveBeenCalledWith("select * from test where id = '10' or tag = 'test' and slug = 'testslug'");
|
97
97
|
});
|
98
98
|
|
99
|
+
it('should work when "where" is an array of objects with one condition', async () => {
|
100
|
+
expect.hasAssertions();
|
101
|
+
|
102
|
+
const querySpy = jest.spyOn(Init.prototype, 'query').mockImplementation(() => {
|
103
|
+
console.log('query called');
|
104
|
+
});
|
105
|
+
await new Crud({ dbTable: 'test', db }).read({
|
106
|
+
where: {
|
107
|
+
condition: 'and',
|
108
|
+
fields: [
|
109
|
+
{ field: 'id', value: '10' },
|
110
|
+
{ field: 'tag', value: 'test' },
|
111
|
+
{ field: 'slug', value: 'testslug' },
|
112
|
+
],
|
113
|
+
},
|
114
|
+
orderBy: null,
|
115
|
+
});
|
116
|
+
expect(querySpy).toHaveBeenCalledWith("select * from test where id = '10' and tag = 'test' and slug = 'testslug'");
|
117
|
+
});
|
118
|
+
|
99
119
|
it('should work without any conditions', async () => {
|
100
120
|
expect.hasAssertions();
|
101
121
|
|