Skip to content

Commit 24bd657

Browse files
committed
removed unintended change
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent 0c7d04a commit 24bd657

File tree

2 files changed

+3
-57
lines changed

2 files changed

+3
-57
lines changed

lib/dao.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,10 @@ DataAccessObject._forDB = function(data) {
179179
const res = {};
180180
for (const propName in data) {
181181
const type = this.getPropertyType(propName);
182-
const value = data[propName];
183-
if (value !== null && (type === 'JSON' || type === 'Any' ||
184-
type === 'Object' || value instanceof Array)) {
185-
res[propName] = JSON.stringify(value);
182+
if (type === 'JSON' || type === 'Any' || type === 'Object' || data[propName] instanceof Array) {
183+
res[propName] = JSON.stringify(data[propName]);
186184
} else {
187-
res[propName] = value;
185+
res[propName] = data[propName];
188186
}
189187
}
190188
return res;

test/loopback-dl.test.js

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,58 +1363,6 @@ describe('Model define with scopes configuration', function() {
13631363
});
13641364
});
13651365

1366-
describe('DataAccessObject._forDB', function() {
1367-
const ds = new DataSource('memory');
1368-
const dao = ds.DataAccessObject;
1369-
1370-
it('should return input data if dataSource is not relational', function() {
1371-
const inputData = {testKey: 'testValue'};
1372-
dao.getDataSource = () => ({isRelational: () => false});
1373-
1374-
const outputData = dao._forDB(inputData);
1375-
1376-
assert.deepEqual(outputData, inputData);
1377-
});
1378-
1379-
it('should return JSON stringified values for appropriate types', function() {
1380-
const inputData = {
1381-
key1: [1, 2, 3],
1382-
key2: {subKey: 'value'},
1383-
key3: 'nonJSONvalue',
1384-
};
1385-
dao.getDataSource = () => ({isRelational: () => true});
1386-
dao.getPropertyType = (propName) => (propName !== 'key3' ? 'JSON' : 'String');
1387-
1388-
const outputData = dao._forDB(inputData);
1389-
1390-
assert.deepEqual(outputData, {
1391-
key1: JSON.stringify([1, 2, 3]),
1392-
key2: JSON.stringify({subKey: 'value'}),
1393-
key3: 'nonJSONvalue',
1394-
});
1395-
});
1396-
1397-
it('should return original value for non JSON, non Array types', function() {
1398-
const inputData = {key1: 'string', key2: 123, key3: true};
1399-
dao.getDataSource = () => ({isRelational: () => true});
1400-
dao.getPropertyType = () => 'String';
1401-
1402-
const outputData = dao._forDB(inputData);
1403-
1404-
assert.deepEqual(outputData, inputData);
1405-
});
1406-
1407-
it('should not process null values', function() {
1408-
const inputData = {key1: 'value', key2: null};
1409-
dao.getDataSource = () => ({isRelational: () => true});
1410-
dao.getPropertyType = (propName) => 'JSON';
1411-
1412-
const outputData = dao._forDB(inputData);
1413-
1414-
assert.deepEqual(outputData, {key1: JSON.stringify('value'), key2: null});
1415-
});
1416-
});
1417-
14181366
describe('DataAccessObject', function() {
14191367
let ds, model, where, error, filter;
14201368

0 commit comments

Comments
 (0)