Fix update system schema

This commit is contained in:
Marco129
2016-03-04 03:06:53 +08:00
parent b301ea9a9c
commit 50735c4cbb
2 changed files with 24 additions and 0 deletions

View File

@@ -655,4 +655,21 @@ describe('Schema', () => {
});
done();
});
it('ignore default field when merge with system class', done => {
expect(Schema.buildMergedSchemaObject({
_id: '_User',
username: 'string',
password: 'string',
authData: 'object',
email: 'string',
emailVerified: 'boolean'
},{
authData: {type: 'string'},
customField: {type: 'string'},
})).toEqual({
customField: {type: 'string'}
});
done();
});
});

View File

@@ -308,8 +308,12 @@ function mongoFieldTypeToSchemaAPIType(type) {
// is done in mongoSchemaFromFieldsAndClassName.
function buildMergedSchemaObject(mongoObject, putRequest) {
var newSchema = {};
let sysSchemaField = Object.keys(defaultColumns).indexOf(mongoObject._id) === -1 ? [] : Object.keys(defaultColumns[mongoObject._id]);
for (var oldField in mongoObject) {
if (oldField !== '_id' && oldField !== 'ACL' && oldField !== 'updatedAt' && oldField !== 'createdAt' && oldField !== 'objectId') {
if (sysSchemaField.length > 0 && sysSchemaField.indexOf(oldField) !== -1) {
continue;
}
var fieldIsDeleted = putRequest[oldField] && putRequest[oldField].__op === 'Delete'
if (!fieldIsDeleted) {
newSchema[oldField] = mongoFieldTypeToSchemaAPIType(mongoObject[oldField]);
@@ -318,6 +322,9 @@ function buildMergedSchemaObject(mongoObject, putRequest) {
}
for (var newField in putRequest) {
if (newField !== 'objectId' && putRequest[newField].__op !== 'Delete') {
if (sysSchemaField.length > 0 && sysSchemaField.indexOf(newField) !== -1) {
continue;
}
newSchema[newField] = putRequest[newField];
}
}