From 7eb5f21a1175d99c64924833400998757295ba8e Mon Sep 17 00:00:00 2001 From: "Marc J. Schmidt" Date: Fri, 8 Feb 2019 15:25:31 +0100 Subject: [PATCH] add non-convertable query also to field index fix invalid tslint.json and removed debugging info --- packages/mongo/src/mapping.ts | 2 +- packages/mongo/tests/mongo-query.spec.ts | 19 ++++++++++++++++--- tslint.json | 3 --- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/mongo/src/mapping.ts b/packages/mongo/src/mapping.ts index a2089443b..57c4a4911 100644 --- a/packages/mongo/src/mapping.ts +++ b/packages/mongo/src/mapping.ts @@ -479,7 +479,6 @@ export function convertClassQueryToMongo( fieldNamesMap: {[name: string]: boolean} = {}, ): { [path: string]: any } { return convertQueryToMongo(classType, target, (convertClassType: ClassType, path: string, value: any) => { - console.log('convert classtomongo', path, value, propertyClassToMongo(convertClassType, path, value)); return propertyClassToMongo(convertClassType, path, value); }, fieldNamesMap); } @@ -533,6 +532,7 @@ export function convertQueryToMongo( (fieldValue as any)[j] = (queryValue as any[]).map(v => converter(classType, i, v)); } else if (j === '$text' || j === '$exists' || j === '$mod' || j === '$size' || j === '$type' || j === '$regex' || j === '$where') { //don't transform + fieldNamesMap[i] = true; } else { fieldNamesMap[i] = true; (fieldValue as any)[j] = converter(classType, i, queryValue); diff --git a/packages/mongo/tests/mongo-query.spec.ts b/packages/mongo/tests/mongo-query.spec.ts index 6b14dd979..a966b657e 100644 --- a/packages/mongo/tests/mongo-query.spec.ts +++ b/packages/mongo/tests/mongo-query.spec.ts @@ -29,24 +29,28 @@ class Simple { } test('simple', () => { + const fieldNames = {}; const m = convertPlainQueryToMongo(Simple, { id: {$qt: '1'} - }); + }, fieldNames); expect(m['id']['$qt']).toBe(1); + expect(Object.keys(fieldNames)).toEqual(['id']); }); test('simple class', () => { const partial = propertyClassToMongo(Simple, 'config', new SimpleConfig(['a', 'b'])); expect(partial).toEqual(['a', 'b']); + const fieldNames = {}; const m = convertClassQueryToMongo(Simple, { id: {$qt: '1'}, config: new SimpleConfig(['a', 'b']) - }); + }, fieldNames); expect(m['id']['$qt']).toBe(1); expect(m['config']).toEqual(['a', 'b']); + expect(Object.keys(fieldNames)).toEqual(['id', 'config']); }); test('simple 2', () => { @@ -54,12 +58,21 @@ test('simple 2', () => { expect(m).toEqual({id: {dif: 1}}); }); +test('regex', () => { + const fieldNames = {}; + const m = convertPlainQueryToMongo(Simple, {id: {$regex: /0-9+/}}, fieldNames); + expect(m).toEqual({id: {$regex: /0-9+/}}); + expect(Object.keys(fieldNames)).toEqual(['id']); +}); + test('and', () => { - const m = convertPlainQueryToMongo(Simple, {$and: [{id: '1'}, {id: '2'}]}); + const fieldNames = {}; + const m = convertPlainQueryToMongo(Simple, {$and: [{id: '1'}, {id: '2'}]}, fieldNames); expect(m).toEqual({$and: [{id: 1}, {id: 2}]}); expect(m['$and'][0]['id']).toBe(1); expect(m['$and'][1]['id']).toBe(2); + expect(Object.keys(fieldNames)).toEqual(['id']); }); test('in', () => { diff --git a/tslint.json b/tslint.json index 128bb7293..4f0e98640 100644 --- a/tslint.json +++ b/tslint.json @@ -1,7 +1,4 @@ { -// "rulesDirectory": [ -// "node_modules/codelyzer" -// ], "rules": { "arrow-return-shorthand": true, "callable-types": true,