Skip to content

Commit 8814e1f

Browse files
committed
Fix add field to system schema
1 parent e3d26e2 commit 8814e1f

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

spec/schemas.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,63 @@ describe('schemas', () => {
561561
})
562562
});
563563

564+
it('lets you add fields to system schema', done => {
565+
request.post({
566+
url: 'http://localhost:8378/1/schemas/_User',
567+
headers: masterKeyHeaders,
568+
json: true
569+
}, (error, response, body) => {
570+
request.put({
571+
url: 'http://localhost:8378/1/schemas/_User',
572+
headers: masterKeyHeaders,
573+
json: true,
574+
body: {
575+
fields: {
576+
newField: {type: 'String'}
577+
}
578+
}
579+
}, (error, response, body) => {
580+
expect(body).toEqual({
581+
className: '_User',
582+
fields: {
583+
objectId: {type: 'String'},
584+
updatedAt: {type: 'Date'},
585+
createdAt: {type: 'Date'},
586+
username: {type: 'String'},
587+
password: {type: 'String'},
588+
authData: {type: 'Object'},
589+
email: {type: 'String'},
590+
emailVerified: {type: 'Boolean'},
591+
newField: {type: 'String'},
592+
ACL: {type: 'ACL'}
593+
}
594+
});
595+
request.get({
596+
url: 'http://localhost:8378/1/schemas/_User',
597+
headers: masterKeyHeaders,
598+
json: true
599+
}, (error, response, body) => {
600+
expect(body).toEqual({
601+
className: '_User',
602+
fields: {
603+
objectId: {type: 'String'},
604+
updatedAt: {type: 'Date'},
605+
createdAt: {type: 'Date'},
606+
username: {type: 'String'},
607+
password: {type: 'String'},
608+
authData: {type: 'Object'},
609+
email: {type: 'String'},
610+
emailVerified: {type: 'Boolean'},
611+
newField: {type: 'String'},
612+
ACL: {type: 'ACL'}
613+
}
614+
});
615+
done();
616+
});
617+
});
618+
})
619+
});
620+
564621
it('lets you delete multiple fields and add fields', done => {
565622
var obj1 = hasAllPODobject();
566623
obj1.save()

src/Routers/SchemasRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function modifySchema(req) {
8585
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${req.params.className} does not exist.`);
8686
}
8787

88-
let existingFields = schema.data[className];
88+
let existingFields = Object.assign(schema.data[className], {_id: className});
8989
Object.keys(submittedFields).forEach(name => {
9090
let field = submittedFields[name];
9191
if (existingFields[name] && field.__op !== 'Delete') {

0 commit comments

Comments
 (0)