Remove getRelationFields
This commit is contained in:
@@ -17,9 +17,6 @@ var dummySchema = {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
getRelationFields: function() {
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -39,7 +36,7 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
|||||||
createdAt: "2015-10-06T21:24:50.332Z",
|
createdAt: "2015-10-06T21:24:50.332Z",
|
||||||
updatedAt: "2015-10-06T21:24:50.332Z"
|
updatedAt: "2015-10-06T21:24:50.332Z"
|
||||||
};
|
};
|
||||||
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input);
|
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input, { fields: {} });
|
||||||
expect(output._created_at instanceof Date).toBe(true);
|
expect(output._created_at instanceof Date).toBe(true);
|
||||||
expect(output._updated_at instanceof Date).toBe(true);
|
expect(output._updated_at instanceof Date).toBe(true);
|
||||||
done();
|
done();
|
||||||
@@ -62,14 +59,14 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
|||||||
//have __op delete in a new object. Figure out what this should actually be testing.
|
//have __op delete in a new object. Figure out what this should actually be testing.
|
||||||
notWorking('a delete op', (done) => {
|
notWorking('a delete op', (done) => {
|
||||||
var input = {deleteMe: {__op: 'Delete'}};
|
var input = {deleteMe: {__op: 'Delete'}};
|
||||||
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input);
|
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input, { fields: {} });
|
||||||
jequal(output, {});
|
jequal(output, {});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('basic ACL', (done) => {
|
it('basic ACL', (done) => {
|
||||||
var input = {ACL: {'0123': {'read': true, 'write': true}}};
|
var input = {ACL: {'0123': {'read': true, 'write': true}}};
|
||||||
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input);
|
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input, { fields: {} });
|
||||||
// This just checks that it doesn't crash, but it should check format.
|
// This just checks that it doesn't crash, but it should check format.
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -124,7 +121,7 @@ describe('transformWhere', () => {
|
|||||||
describe('mongoObjectToParseObject', () => {
|
describe('mongoObjectToParseObject', () => {
|
||||||
it('built-in timestamps', (done) => {
|
it('built-in timestamps', (done) => {
|
||||||
var input = {createdAt: new Date(), updatedAt: new Date()};
|
var input = {createdAt: new Date(), updatedAt: new Date()};
|
||||||
var output = transform.mongoObjectToParseObject(dummySchema, null, input);
|
var output = transform.mongoObjectToParseObject(dummySchema, null, input, { fields: {} });
|
||||||
expect(typeof output.createdAt).toEqual('string');
|
expect(typeof output.createdAt).toEqual('string');
|
||||||
expect(typeof output.updatedAt).toEqual('string');
|
expect(typeof output.updatedAt).toEqual('string');
|
||||||
done();
|
done();
|
||||||
@@ -236,7 +233,7 @@ describe('transform schema key changes', () => {
|
|||||||
"Kevin": { "write": true }
|
"Kevin": { "write": true }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input);
|
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input, { fields: {} });
|
||||||
expect(typeof output._rperm).toEqual('object');
|
expect(typeof output._rperm).toEqual('object');
|
||||||
expect(typeof output._wperm).toEqual('object');
|
expect(typeof output._wperm).toEqual('object');
|
||||||
expect(output.ACL).toBeUndefined();
|
expect(output.ACL).toBeUndefined();
|
||||||
@@ -253,7 +250,7 @@ describe('transform schema key changes', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input);
|
var output = transform.parseObjectToMongoObjectForCreate(dummySchema, null, input, { fields: {} });
|
||||||
expect(typeof output._acl).toEqual('object');
|
expect(typeof output._acl).toEqual('object');
|
||||||
expect(output._acl["Kevin"].w).toBeTruthy();
|
expect(output._acl["Kevin"].w).toBeTruthy();
|
||||||
expect(output._acl["Kevin"].r).toBeUndefined();
|
expect(output._acl["Kevin"].r).toBeUndefined();
|
||||||
@@ -265,7 +262,7 @@ describe('transform schema key changes', () => {
|
|||||||
_rperm: ["*"],
|
_rperm: ["*"],
|
||||||
_wperm: ["Kevin"]
|
_wperm: ["Kevin"]
|
||||||
};
|
};
|
||||||
var output = transform.mongoObjectToParseObject(dummySchema, null, input);
|
var output = transform.mongoObjectToParseObject(dummySchema, null, input, { fields: {} });
|
||||||
expect(typeof output.ACL).toEqual('object');
|
expect(typeof output.ACL).toEqual('object');
|
||||||
expect(output._rperm).toBeUndefined();
|
expect(output._rperm).toBeUndefined();
|
||||||
expect(output._wperm).toBeUndefined();
|
expect(output._wperm).toBeUndefined();
|
||||||
|
|||||||
@@ -868,7 +868,16 @@ const mongoObjectToParseObject = (schemaController, className, mongoObject, sche
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...restObject, ...schemaController.getRelationFields(className) };
|
const relationFieldNames = Object.keys(schema.fields).filter(fieldName => schema.fields[fieldName].type === 'Relation');
|
||||||
|
let relationFields = {};
|
||||||
|
relationFieldNames.forEach(relationFieldName => {
|
||||||
|
relationFields[relationFieldName] = {
|
||||||
|
__type: 'Relation',
|
||||||
|
className: schema.fields[relationFieldName].targetClass,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return { ...restObject, ...relationFields };
|
||||||
default:
|
default:
|
||||||
throw 'unknown js type';
|
throw 'unknown js type';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -686,23 +686,6 @@ class SchemaController {
|
|||||||
hasClass(className) {
|
hasClass(className) {
|
||||||
return this.reloadData().then(() => !!(this.data[className]));
|
return this.reloadData().then(() => !!(this.data[className]));
|
||||||
}
|
}
|
||||||
|
|
||||||
getRelationFields(className) {
|
|
||||||
if (this.data && this.data[className]) {
|
|
||||||
let classData = this.data[className];
|
|
||||||
return Object.keys(classData).filter((field) => {
|
|
||||||
return classData[field].type === 'Relation';
|
|
||||||
}).reduce((memo, field) => {
|
|
||||||
let type = classData[field];
|
|
||||||
memo[field] = {
|
|
||||||
__type: 'Relation',
|
|
||||||
className: type.targetClass
|
|
||||||
};
|
|
||||||
return memo;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a promise for a new Schema.
|
// Returns a promise for a new Schema.
|
||||||
|
|||||||
Reference in New Issue
Block a user