How to use the parse/node.Object function in parse

To help you get started, we’ve selected a few parse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github parse-community / parse-server / spec / ReadPreferenceOption.spec.js View on Github external
it('should change read preference in the beforeFind trigger even returning query', done => {
    const databaseAdapter = Config.get(Parse.applicationId).database.adapter;

    const obj0 = new Parse.Object('MyObject');
    obj0.set('boolKey', false);
    const obj1 = new Parse.Object('MyObject');
    obj1.set('boolKey', true);

    Parse.Object.saveAll([obj0, obj1]).then(() => {
      spyOn(databaseAdapter.database.serverConfig, 'cursor').and.callThrough();

      Parse.Cloud.beforeFind('MyObject', req => {
        req.readPreference = 'SECONDARY';

        const otherQuery = new Parse.Query('MyObject');
        otherQuery.equalTo('boolKey', true);
        return otherQuery;
      });

      const query = new Parse.Query('MyObject');
github parse-community / parse-server / spec / Uniqueness.spec.js View on Github external
it('unique indexing works on pointer fields', done => {
    const obj = new Parse.Object('UniquePointer');
    obj
      .save({ string: 'who cares' })
      .then(() => obj.save({ ptr: obj }))
      .then(() => {
        const config = Config.get('test');
        return config.database.adapter.ensureUniqueness(
          'UniquePointer',
          {
            fields: {
              string: { __type: 'String' },
              ptr: { __type: 'Pointer', targetClass: 'UniquePointer' },
            },
          },
          ['ptr']
        );
      })
github parse-community / parse-server / spec / ParseQuery.spec.js View on Github external
it('should match complex structure with dot notation when using doesNotMatchKeyInQuery', function(done) {
    const group1 = new Parse.Object('Group', {
      name: 'Group #1'
    });

    const group2 = new Parse.Object('Group', {
      name: 'Group #2'
    });

    Parse.Object.saveAll([group1, group2])
      .then(() => {
        const role1 = new Parse.Object('Role', {
          name: 'Role #1',
          type: 'x',
          belongsTo: group1
        });

        const role2 = new Parse.Object('Role', {
github parse-community / parse-server / spec / ParseQuery.spec.js View on Github external
it('containsAllStartingWith should match all strings that starts with string', (done) => {

    const object = new Parse.Object('Object');
    object.set('strings', ['the', 'brown', 'lazy', 'fox', 'jumps']);
    const object2 = new Parse.Object('Object');
    object2.set('strings', ['the', 'brown', 'fox', 'jumps']);
    const object3 = new Parse.Object('Object');
    object3.set('strings', ['over', 'the', 'lazy', 'dog']);

    const objectList = [object, object2, object3];

    Parse.Object.saveAll(objectList).then((results) => {
      equal(objectList.length, results.length);

      return require('request-promise').get({
        url: Parse.serverURL + "/classes/Object",
        json: {
          where: {
            strings: {
github parse-community / parse-server / spec / ParseQuery.spec.js View on Github external
it('objectId containedIn with multiple large array', done => {
    const obj = new Parse.Object('MyClass');
    obj.save().then(obj => {
      const longListOfStrings = [];
      for (let i = 0; i < 130; i++) {
        longListOfStrings.push(i.toString());
      }
      longListOfStrings.push(obj.id);
      const q = new Parse.Query('MyClass');
      q.containedIn('objectId', longListOfStrings);
      q.containedIn('objectId', longListOfStrings);
      return q.find();
    }).then(results => {
      expect(results.length).toEqual(1);
      done();
    });
  });
github parse-community / parse-server / spec / CloudCode.spec.js View on Github external
it('basic beforeDelete rejection via promise', function(done) {
    Parse.Cloud.beforeSave('BeforeDeleteFailWithPromise', function() {
      const query = new Parse.Query('Yolo');
      return query.find().then(() => {
        throw 'Nope';
      });
    });

    const obj = new Parse.Object('BeforeDeleteFailWithPromise');
    obj.set('foo', 'bar');
    obj.save().then(
      function() {
        fail('Should not have been able to save BeforeSaveFailure class.');
        done();
      },
      function(error) {
        expect(error.code).toEqual(Parse.Error.SCRIPT_FAILED);
        expect(error.message).toEqual('Nope');

        done();
      }
    );
  });
github parse-community / parse-server / spec / ParseAPI.spec.js View on Github external
it('doesnt convert interior keys of objects that use special names', done => {
    const obj = new Parse.Object('Obj');
    obj.set('val', { createdAt: 'a', updatedAt: 1 });
    obj.save()
      .then(obj => new Parse.Query('Obj').get(obj.id))
      .then(obj => {
        expect(obj.get('val').createdAt).toEqual('a');
        expect(obj.get('val').updatedAt).toEqual(1);
        done();
      });
  });
github parse-community / parse-server / spec / ParseQuery.spec.js View on Github external
it('containsAllStartingWith single invalid regex returns empty results', (done) => {

    const object = new Parse.Object('Object');
    object.set('strings', ['the', 'brown', 'lazy', 'fox', 'jumps']);

    object.save().then(() => {
      equal(object.isNew(), false);

      return require('request-promise').get({
        url: Parse.serverURL + "/classes/Object",
        json: {
          where: {
            strings: {
              $all: [ {$unknown: '\^\\Qlazy\\E'} ]
            }
          }
        },
        headers: {
          'X-Parse-Application-Id': Parse.applicationId,
github parse-community / parse-server / spec / ParseAPI.spec.js View on Github external
}, error => {
        expect(error.code).toEqual(Parse.Error.INVALID_NESTED_KEY);
        return new Parse.Object('Obj').save({innerObj: {'key with a .': 'fails'}});
      })
      .then(() => {
github parse-community / parse-server / spec / CloudCode.spec.js View on Github external
expect(catched).toBe(true);
    expect(called).toBe(7);

    catched = false;
    try {
      await triggerobject2.save(undefined, {
        sessionToken: triggeruser5.getSessionToken(),
      });
    } catch (e) {
      catched = true;
      expect(e.code).toBe(101);
    }
    expect(catched).toBe(true);
    expect(called).toBe(7);

    const triggerobject3 = new Parse.Object('triggerclass');
    triggerobject3.set('someField', 'someValue');
    triggerobject3.set('someField33', 'someValue');

    catched = false;
    try {
      await triggerobject3.save(undefined, {
        sessionToken: triggeruser4.getSessionToken(),
      });
    } catch (e) {
      catched = true;
      expect(e.code).toBe(119);
    }
    expect(catched).toBe(true);
    expect(called).toBe(7);

    catched = false;