Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit c73f407

Browse files
Robb Sadleretsuo
authored andcommitted
work in progress
1 parent d9f27b5 commit c73f407

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

src/core/@model/model-operators/from-db.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ describe('@Model.fromDb', () => {
471471
expect(result.leads.length).toBe(0);
472472
});
473473

474-
fit('maps an array of sub documents from the DB to a resulting array of type model', () => {
474+
it('maps an array of sub documents from the DB to a resulting array of type model', () => {
475475

476476
const leadSubDocs = [
477477
{

src/core/@model/model-operators/from-db.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
5454
return source;
5555
}
5656

57-
console.log('=================='.zebra.green, JSON.stringify(target, null, 2).green);
5857
const dbOptionsByFieldName: Map<string, IDbOptions>
5958
= Reflect.getMetadata(dbSymbols.dbByFieldName, target) || new Map<string, IDbOptions>();
6059

@@ -64,7 +63,6 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
6463

6564
// convert the DB key name to the Model key name
6665
const mapper = map(key, source[key], dbOptionsByFieldName);
67-
if (key === 'tag') console.log('================== mapper'.cyan, JSON.stringify(mapper, null, 2).cyan);
6866
const model = mapper.model;
6967

7068
let nextTarget;
@@ -77,8 +75,6 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
7775
+ ` cannot be constructed`);
7876
}
7977

80-
console.log('================== 111111'.zebra.green, JSON.stringify(target, null, 2).green);
81-
8278
if (model || shouldRecurse(source[key])) {
8379

8480
// if the key should be included
@@ -91,9 +87,10 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
9187
const values = [];
9288

9389
for (const src of source[key]) {
94-
console.log('==================src'.cyan, src);
95-
nextTarget = (model);
9690
values.push(Object.assign(new model(), mapDbToModel(src, nextTarget, map)));
91+
nextTarget = (model)
92+
? Object.assign(new model(), target[mapper.newKey])
93+
: target[mapper.newKey];
9794
}
9895
value = values;
9996

@@ -108,23 +105,19 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
108105
}
109106
}
110107
}
111-
console.log('================== >>>>>>>'.cyan, mapper.newKey);
112108
target[mapper.newKey] = value;
113109
}
114110

115111
} else {
116112
// otherwise, map a property that has a primitive value or an ObjectID value
117-
if (mapper.newKey !== undefined) {
118-
console.log('================== %%%%%%'.cyan, `assigning ${source[key]} to ${mapper.newKey}`);
113+
if (mapper.newKey !== undefined) {
119114
target[mapper.newKey] = (source[key] !== undefined && source[key] !== null)
120115
? source[key]
121116
: nextTarget; // resolves issue #94
122117
}
123118
}
124-
console.log('================== 222222'.zebra.green, JSON.stringify(target, null, 2).green);
125119
}
126120

127-
if (!!target.order) console.log('=================='.zebra.red, JSON.stringify(target, null, 2).red);
128121
return target;
129122
}
130123

0 commit comments

Comments
 (0)