Endpoints for audiences CRUD (#3861)
This commit is contained in:
committed by
Natan Rolnik
parent
e94991b368
commit
4509d25471
287
spec/AudienceRouter.spec.js
Normal file
287
spec/AudienceRouter.spec.js
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
var auth = require('../src/Auth');
|
||||||
|
var Config = require('../src/Config');
|
||||||
|
var rest = require('../src/rest');
|
||||||
|
var AudiencesRouter = require('../src/Routers/AudiencesRouter').AudiencesRouter;
|
||||||
|
|
||||||
|
describe('AudiencesRouter', () => {
|
||||||
|
it('uses find condition from request.body', (done) => {
|
||||||
|
var config = new Config('test');
|
||||||
|
var androidAudienceRequest = {
|
||||||
|
'name': 'Android Users',
|
||||||
|
'query': '{ "test": "android" }'
|
||||||
|
};
|
||||||
|
var iosAudienceRequest = {
|
||||||
|
'name': 'Iphone Users',
|
||||||
|
'query': '{ "test": "ios" }'
|
||||||
|
};
|
||||||
|
var request = {
|
||||||
|
config: config,
|
||||||
|
auth: auth.master(config),
|
||||||
|
body: {
|
||||||
|
where: {
|
||||||
|
query: '{ "test": "android" }'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
query: {},
|
||||||
|
info: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
var router = new AudiencesRouter();
|
||||||
|
rest.create(config, auth.nobody(config), '_Audience', androidAudienceRequest)
|
||||||
|
.then(() => {
|
||||||
|
return rest.create(config, auth.nobody(config), '_Audience', iosAudienceRequest);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return router.handleFind(request);
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
var results = res.response.results;
|
||||||
|
expect(results.length).toEqual(1);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
fail(JSON.stringify(err));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses find condition from request.query', (done) => {
|
||||||
|
var config = new Config('test');
|
||||||
|
var androidAudienceRequest = {
|
||||||
|
'name': 'Android Users',
|
||||||
|
'query': '{ "test": "android" }'
|
||||||
|
};
|
||||||
|
var iosAudienceRequest = {
|
||||||
|
'name': 'Iphone Users',
|
||||||
|
'query': '{ "test": "ios" }'
|
||||||
|
};
|
||||||
|
var request = {
|
||||||
|
config: config,
|
||||||
|
auth: auth.master(config),
|
||||||
|
body: {},
|
||||||
|
query: {
|
||||||
|
where: {
|
||||||
|
'query': '{ "test": "android" }'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
info: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
var router = new AudiencesRouter();
|
||||||
|
rest.create(config, auth.nobody(config), '_Audience', androidAudienceRequest)
|
||||||
|
.then(() => {
|
||||||
|
return rest.create(config, auth.nobody(config), '_Audience', iosAudienceRequest);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return router.handleFind(request);
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
var results = res.response.results;
|
||||||
|
expect(results.length).toEqual(1);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
fail(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('query installations with limit = 0', (done) => {
|
||||||
|
var config = new Config('test');
|
||||||
|
var androidAudienceRequest = {
|
||||||
|
'name': 'Android Users',
|
||||||
|
'query': '{ "test": "android" }'
|
||||||
|
};
|
||||||
|
var iosAudienceRequest = {
|
||||||
|
'name': 'Iphone Users',
|
||||||
|
'query': '{ "test": "ios" }'
|
||||||
|
};
|
||||||
|
var request = {
|
||||||
|
config: config,
|
||||||
|
auth: auth.master(config),
|
||||||
|
body: {},
|
||||||
|
query: {
|
||||||
|
limit: 0
|
||||||
|
},
|
||||||
|
info: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
new Config('test');
|
||||||
|
var router = new AudiencesRouter();
|
||||||
|
rest.create(config, auth.nobody(config), '_Audience', androidAudienceRequest)
|
||||||
|
.then(() => {
|
||||||
|
return rest.create(config, auth.nobody(config), '_Audience', iosAudienceRequest);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return router.handleFind(request);
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
var response = res.response;
|
||||||
|
expect(response.results.length).toEqual(0);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
fail(JSON.stringify(err));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('query installations with count = 1', done => {
|
||||||
|
var config = new Config('test');
|
||||||
|
var androidAudienceRequest = {
|
||||||
|
'name': 'Android Users',
|
||||||
|
'query': '{ "test": "android" }'
|
||||||
|
};
|
||||||
|
var iosAudienceRequest = {
|
||||||
|
'name': 'Iphone Users',
|
||||||
|
'query': '{ "test": "ios" }'
|
||||||
|
};
|
||||||
|
var request = {
|
||||||
|
config: config,
|
||||||
|
auth: auth.master(config),
|
||||||
|
body: {},
|
||||||
|
query: {
|
||||||
|
count: 1
|
||||||
|
},
|
||||||
|
info: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
var router = new AudiencesRouter();
|
||||||
|
rest.create(config, auth.nobody(config), '_Audience', androidAudienceRequest)
|
||||||
|
.then(() => rest.create(config, auth.nobody(config), '_Audience', iosAudienceRequest))
|
||||||
|
.then(() => router.handleFind(request))
|
||||||
|
.then((res) => {
|
||||||
|
var response = res.response;
|
||||||
|
expect(response.results.length).toEqual(2);
|
||||||
|
expect(response.count).toEqual(2);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
fail(JSON.stringify(error));
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
it('query installations with limit = 0 and count = 1', (done) => {
|
||||||
|
var config = new Config('test');
|
||||||
|
var androidAudienceRequest = {
|
||||||
|
'name': 'Android Users',
|
||||||
|
'query': '{ "test": "android" }'
|
||||||
|
};
|
||||||
|
var iosAudienceRequest = {
|
||||||
|
'name': 'Iphone Users',
|
||||||
|
'query': '{ "test": "ios" }'
|
||||||
|
};
|
||||||
|
var request = {
|
||||||
|
config: config,
|
||||||
|
auth: auth.master(config),
|
||||||
|
body: {},
|
||||||
|
query: {
|
||||||
|
limit: 0,
|
||||||
|
count: 1
|
||||||
|
},
|
||||||
|
info: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
var router = new AudiencesRouter();
|
||||||
|
rest.create(config, auth.nobody(config), '_Audience', androidAudienceRequest)
|
||||||
|
.then(() => {
|
||||||
|
return rest.create(config, auth.nobody(config), '_Audience', iosAudienceRequest);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return router.handleFind(request);
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
var response = res.response;
|
||||||
|
expect(response.results.length).toEqual(0);
|
||||||
|
expect(response.count).toEqual(2);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
fail(JSON.stringify(err));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create, read, update and delete audiences throw api', (done) => {
|
||||||
|
Parse._request('POST', 'push_audiences', { name: 'My Audience', query: JSON.stringify({ deviceType: 'ios' })}, { useMasterKey: true })
|
||||||
|
.then(() => {
|
||||||
|
Parse._request('GET', 'push_audiences', {}, { useMasterKey: true }).then((results) => {
|
||||||
|
expect(results.results.length).toEqual(1);
|
||||||
|
expect(results.results[0].name).toEqual('My Audience');
|
||||||
|
expect(results.results[0].query.deviceType).toEqual('ios');
|
||||||
|
Parse._request('GET', `push_audiences/${results.results[0].objectId}`, {}, { useMasterKey: true }).then((results) => {
|
||||||
|
expect(results.name).toEqual('My Audience');
|
||||||
|
expect(results.query.deviceType).toEqual('ios');
|
||||||
|
Parse._request('PUT', `push_audiences/${results.objectId}`, { name: 'My Audience 2' }, { useMasterKey: true }).then(() => {
|
||||||
|
Parse._request('GET', `push_audiences/${results.objectId}`, {}, { useMasterKey: true }).then((results) => {
|
||||||
|
expect(results.name).toEqual('My Audience 2');
|
||||||
|
expect(results.query.deviceType).toEqual('ios');
|
||||||
|
Parse._request('DELETE', `push_audiences/${results.objectId}`, {}, { useMasterKey: true }).then(() => {
|
||||||
|
Parse._request('GET', 'push_audiences', {}, { useMasterKey: true }).then((results) => {
|
||||||
|
expect(results.results.length).toEqual(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should only create with master key', (done) => {
|
||||||
|
Parse._request('POST', 'push_audiences', { name: 'My Audience', query: JSON.stringify({ deviceType: 'ios' })})
|
||||||
|
.then(
|
||||||
|
() => {},
|
||||||
|
(error) => {
|
||||||
|
expect(error.message).toEqual('unauthorized: master key is required');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should only find with master key', (done) => {
|
||||||
|
Parse._request('GET', 'push_audiences', {})
|
||||||
|
.then(
|
||||||
|
() => {},
|
||||||
|
(error) => {
|
||||||
|
expect(error.message).toEqual('unauthorized: master key is required');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should only get with master key', (done) => {
|
||||||
|
Parse._request('GET', `push_audiences/someId`, {})
|
||||||
|
.then(
|
||||||
|
() => {},
|
||||||
|
(error) => {
|
||||||
|
expect(error.message).toEqual('unauthorized: master key is required');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should only update with master key', (done) => {
|
||||||
|
Parse._request('PUT', `push_audiences/someId`, { name: 'My Audience 2' })
|
||||||
|
.then(
|
||||||
|
() => {},
|
||||||
|
(error) => {
|
||||||
|
expect(error.message).toEqual('unauthorized: master key is required');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should only delete with master key', (done) => {
|
||||||
|
Parse._request('DELETE', `push_audiences/someId`, {})
|
||||||
|
.then(
|
||||||
|
() => {},
|
||||||
|
(error) => {
|
||||||
|
expect(error.message).toEqual('unauthorized: master key is required');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -936,7 +936,8 @@ describe('Parse.Query testing', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}, (err) => {
|
},
|
||||||
|
(err) => {
|
||||||
jfail(err);
|
jfail(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -175,12 +175,12 @@ describe('rest query', () => {
|
|||||||
|
|
||||||
const p0 = rp.get({
|
const p0 = rp.get({
|
||||||
headers: headers,
|
headers: headers,
|
||||||
url: 'http://localhost:8378/1/classes/TestParameterEncode?'
|
url: 'http://localhost:8378/1/classes/TestParameterEncode?' + querystring.stringify({
|
||||||
+ querystring.stringify({
|
|
||||||
where: '{"foo":{"$ne": "baz"}}',
|
where: '{"foo":{"$ne": "baz"}}',
|
||||||
limit: 1
|
limit: 1
|
||||||
}).replace('=', '%3D'),
|
}).replace('=', '%3D'),
|
||||||
}).then(fail, (response) => {
|
})
|
||||||
|
.then(fail, (response) => {
|
||||||
const error = response.error;
|
const error = response.error;
|
||||||
var b = JSON.parse(error);
|
var b = JSON.parse(error);
|
||||||
expect(b.code).toEqual(Parse.Error.INVALID_QUERY);
|
expect(b.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||||
@@ -188,11 +188,11 @@ describe('rest query', () => {
|
|||||||
|
|
||||||
const p1 = rp.get({
|
const p1 = rp.get({
|
||||||
headers: headers,
|
headers: headers,
|
||||||
url: 'http://localhost:8378/1/classes/TestParameterEncode?'
|
url: 'http://localhost:8378/1/classes/TestParameterEncode?' + querystring.stringify({
|
||||||
+ querystring.stringify({
|
|
||||||
limit: 1
|
limit: 1
|
||||||
}).replace('=', '%3D'),
|
}).replace('=', '%3D'),
|
||||||
}).then(fail, (response) => {
|
})
|
||||||
|
.then(fail, (response) => {
|
||||||
const error = response.error;
|
const error = response.error;
|
||||||
var b = JSON.parse(error);
|
var b = JSON.parse(error);
|
||||||
expect(b.code).toEqual(Parse.Error.INVALID_QUERY);
|
expect(b.code).toEqual(Parse.Error.INVALID_QUERY);
|
||||||
|
|||||||
@@ -667,7 +667,7 @@ export class PostgresStorageAdapter {
|
|||||||
const joins = results.reduce((list, schema) => {
|
const joins = results.reduce((list, schema) => {
|
||||||
return list.concat(joinTablesForSchema(schema.schema));
|
return list.concat(joinTablesForSchema(schema.schema));
|
||||||
}, []);
|
}, []);
|
||||||
const classes = ['_SCHEMA','_PushStatus','_JobStatus','_JobSchedule','_Hooks','_GlobalConfig', ...results.map(result => result.className), ...joins];
|
const classes = ['_SCHEMA', '_PushStatus', '_JobStatus', '_JobSchedule', '_Hooks', '_GlobalConfig', '_Audience', ...results.map(result => result.className), ...joins];
|
||||||
return this._client.tx(t=>t.batch(classes.map(className=>t.none('DROP TABLE IF EXISTS $<className:name>', {className}))));
|
return this._client.tx(t=>t.batch(classes.map(className=>t.none('DROP TABLE IF EXISTS $<className:name>', {className}))));
|
||||||
}, error => {
|
}, error => {
|
||||||
if (error.code === PostgresRelationDoesNotExistError) {
|
if (error.code === PostgresRelationDoesNotExistError) {
|
||||||
|
|||||||
@@ -690,7 +690,8 @@ DatabaseController.prototype.reduceRelationKeys = function(className, query) {
|
|||||||
return this.relatedIds(
|
return this.relatedIds(
|
||||||
relatedTo.object.className,
|
relatedTo.object.className,
|
||||||
relatedTo.key,
|
relatedTo.key,
|
||||||
relatedTo.object.objectId).then((ids) => {
|
relatedTo.object.objectId)
|
||||||
|
.then((ids) => {
|
||||||
delete query['$relatedTo'];
|
delete query['$relatedTo'];
|
||||||
this.addInObjectIdsIds(ids, query);
|
this.addInObjectIdsIds(ids, query);
|
||||||
return this.reduceRelationKeys(className, query);
|
return this.reduceRelationKeys(className, query);
|
||||||
|
|||||||
@@ -114,6 +114,11 @@ const defaultColumns = Object.freeze({
|
|||||||
_GlobalConfig: {
|
_GlobalConfig: {
|
||||||
"objectId": {type: 'String'},
|
"objectId": {type: 'String'},
|
||||||
"params": {type: 'Object'}
|
"params": {type: 'Object'}
|
||||||
|
},
|
||||||
|
_Audience: {
|
||||||
|
"objectId": {type:'String'},
|
||||||
|
"name": {type:'String'},
|
||||||
|
"query": {type:'String'} //storing query as JSON string to prevent "Nested keys should not contain the '$' or '.' characters" error
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,9 +127,9 @@ const requiredColumns = Object.freeze({
|
|||||||
_Role: ["name", "ACL"]
|
_Role: ["name", "ACL"]
|
||||||
});
|
});
|
||||||
|
|
||||||
const systemClasses = Object.freeze(['_User', '_Installation', '_Role', '_Session', '_Product', '_PushStatus', '_JobStatus', '_JobSchedule']);
|
const systemClasses = Object.freeze(['_User', '_Installation', '_Role', '_Session', '_Product', '_PushStatus', '_JobStatus', '_JobSchedule', '_Audience']);
|
||||||
|
|
||||||
const volatileClasses = Object.freeze(['_JobStatus', '_PushStatus', '_Hooks', '_GlobalConfig', '_JobSchedule']);
|
const volatileClasses = Object.freeze(['_JobStatus', '_PushStatus', '_Hooks', '_GlobalConfig', '_JobSchedule', '_Audience']);
|
||||||
|
|
||||||
// 10 alpha numberic chars + uppercase
|
// 10 alpha numberic chars + uppercase
|
||||||
const userIdRegex = /^[a-zA-Z0-9]{10}$/;
|
const userIdRegex = /^[a-zA-Z0-9]{10}$/;
|
||||||
@@ -306,7 +311,11 @@ const _JobScheduleSchema = convertSchemaToAdapterSchema(injectDefaultSchema({
|
|||||||
fields: {},
|
fields: {},
|
||||||
classLevelPermissions: {}
|
classLevelPermissions: {}
|
||||||
}));
|
}));
|
||||||
const VolatileClassesSchemas = [_HooksSchema, _JobStatusSchema, _JobScheduleSchema, _PushStatusSchema, _GlobalConfigSchema];
|
const _AudienceSchema = convertSchemaToAdapterSchema(injectDefaultSchema({
|
||||||
|
className: "_Audience",
|
||||||
|
fields: defaultColumns._Audience
|
||||||
|
}));
|
||||||
|
const VolatileClassesSchemas = [_HooksSchema, _JobStatusSchema, _JobScheduleSchema, _PushStatusSchema, _GlobalConfigSchema, _AudienceSchema];
|
||||||
|
|
||||||
const dbTypeMatchesObjectType = (dbType, objectType) => {
|
const dbTypeMatchesObjectType = (dbType, objectType) => {
|
||||||
if (dbType.type !== objectType.type) return false;
|
if (dbType.type !== objectType.type) return false;
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import { SessionsRouter } from './Routers/SessionsRouter';
|
|||||||
import { UserController } from './Controllers/UserController';
|
import { UserController } from './Controllers/UserController';
|
||||||
import { UsersRouter } from './Routers/UsersRouter';
|
import { UsersRouter } from './Routers/UsersRouter';
|
||||||
import { PurgeRouter } from './Routers/PurgeRouter';
|
import { PurgeRouter } from './Routers/PurgeRouter';
|
||||||
|
import { AudiencesRouter } from './Routers/AudiencesRouter';
|
||||||
|
|
||||||
import DatabaseController from './Controllers/DatabaseController';
|
import DatabaseController from './Controllers/DatabaseController';
|
||||||
import SchemaCache from './Controllers/SchemaCache';
|
import SchemaCache from './Controllers/SchemaCache';
|
||||||
@@ -379,7 +380,8 @@ class ParseServer {
|
|||||||
new GlobalConfigRouter(),
|
new GlobalConfigRouter(),
|
||||||
new PurgeRouter(),
|
new PurgeRouter(),
|
||||||
new HooksRouter(),
|
new HooksRouter(),
|
||||||
new CloudCodeRouter()
|
new CloudCodeRouter(),
|
||||||
|
new AudiencesRouter()
|
||||||
];
|
];
|
||||||
|
|
||||||
const routes = routers.reduce((memo, router) => {
|
const routes = routers.reduce((memo, router) => {
|
||||||
|
|||||||
@@ -197,8 +197,8 @@ RestQuery.prototype.redirectClassNameForKey = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We need to change the class name based on the schema
|
// We need to change the class name based on the schema
|
||||||
return this.config.database.redirectClassNameForKey(
|
return this.config.database.redirectClassNameForKey(this.className, this.redirectKey)
|
||||||
this.className, this.redirectKey).then((newClassName) => {
|
.then((newClassName) => {
|
||||||
this.className = newClassName;
|
this.className = newClassName;
|
||||||
this.redirectClassName = newClassName;
|
this.redirectClassName = newClassName;
|
||||||
});
|
});
|
||||||
@@ -491,8 +491,8 @@ RestQuery.prototype.runFind = function(options = {}) {
|
|||||||
if (options.op) {
|
if (options.op) {
|
||||||
findOptions.op = options.op;
|
findOptions.op = options.op;
|
||||||
}
|
}
|
||||||
return this.config.database.find(
|
return this.config.database.find(this.className, this.restWhere, findOptions)
|
||||||
this.className, this.restWhere, findOptions).then((results) => {
|
.then((results) => {
|
||||||
if (this.className === '_User') {
|
if (this.className === '_User') {
|
||||||
for (var result of results) {
|
for (var result of results) {
|
||||||
cleanResultOfSensitiveUserInfo(result, this.auth, this.config);
|
cleanResultOfSensitiveUserInfo(result, this.auth, this.config);
|
||||||
@@ -520,8 +520,8 @@ RestQuery.prototype.runCount = function() {
|
|||||||
this.findOptions.count = true;
|
this.findOptions.count = true;
|
||||||
delete this.findOptions.skip;
|
delete this.findOptions.skip;
|
||||||
delete this.findOptions.limit;
|
delete this.findOptions.limit;
|
||||||
return this.config.database.find(
|
return this.config.database.find(this.className, this.restWhere, this.findOptions)
|
||||||
this.className, this.restWhere, this.findOptions).then((c) => {
|
.then((c) => {
|
||||||
this.response.count = c;
|
this.response.count = c;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
71
src/Routers/AudiencesRouter.js
Normal file
71
src/Routers/AudiencesRouter.js
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import ClassesRouter from './ClassesRouter';
|
||||||
|
import rest from '../rest';
|
||||||
|
import * as middleware from '../middlewares';
|
||||||
|
|
||||||
|
export class AudiencesRouter extends ClassesRouter {
|
||||||
|
handleFind(req) {
|
||||||
|
const body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
|
||||||
|
var options = {};
|
||||||
|
|
||||||
|
if (body.skip) {
|
||||||
|
options.skip = Number(body.skip);
|
||||||
|
}
|
||||||
|
if (body.limit || body.limit === 0) {
|
||||||
|
options.limit = Number(body.limit);
|
||||||
|
}
|
||||||
|
if (body.order) {
|
||||||
|
options.order = String(body.order);
|
||||||
|
}
|
||||||
|
if (body.count) {
|
||||||
|
options.count = true;
|
||||||
|
}
|
||||||
|
if (body.include) {
|
||||||
|
options.include = String(body.include);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rest.find(req.config, req.auth, '_Audience', body.where, options, req.info.clientSDK)
|
||||||
|
.then((response) => {
|
||||||
|
|
||||||
|
response.results.forEach((item) => {
|
||||||
|
item.query = JSON.parse(item.query);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {response: response};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGet(req) {
|
||||||
|
req.params.className = '_Audience';
|
||||||
|
return super.handleGet(req)
|
||||||
|
.then((data) => {
|
||||||
|
data.response.query = JSON.parse(data.response.query);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleCreate(req) {
|
||||||
|
req.params.className = '_Audience';
|
||||||
|
return super.handleCreate(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUpdate(req) {
|
||||||
|
req.params.className = '_Audience';
|
||||||
|
return super.handleUpdate(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDelete(req) {
|
||||||
|
req.params.className = '_Audience';
|
||||||
|
return super.handleDelete(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
mountRoutes() {
|
||||||
|
this.route('GET','/push_audiences', middleware.promiseEnforceMasterKeyAccess, req => { return this.handleFind(req); });
|
||||||
|
this.route('GET','/push_audiences/:objectId', middleware.promiseEnforceMasterKeyAccess, req => { return this.handleGet(req); });
|
||||||
|
this.route('POST','/push_audiences', middleware.promiseEnforceMasterKeyAccess, req => { return this.handleCreate(req); });
|
||||||
|
this.route('PUT','/push_audiences/:objectId', middleware.promiseEnforceMasterKeyAccess, req => { return this.handleUpdate(req); });
|
||||||
|
this.route('DELETE','/push_audiences/:objectId', middleware.promiseEnforceMasterKeyAccess, req => { return this.handleDelete(req); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AudiencesRouter;
|
||||||
@@ -32,7 +32,7 @@ export class FeaturesRouter extends PromiseRouter {
|
|||||||
immediatePush: req.config.hasPushSupport,
|
immediatePush: req.config.hasPushSupport,
|
||||||
scheduledPush: req.config.hasPushScheduledSupport,
|
scheduledPush: req.config.hasPushScheduledSupport,
|
||||||
storedPushData: req.config.hasPushSupport,
|
storedPushData: req.config.hasPushSupport,
|
||||||
pushAudiences: false,
|
pushAudiences: true,
|
||||||
},
|
},
|
||||||
schemas: {
|
schemas: {
|
||||||
addField: true,
|
addField: true,
|
||||||
|
|||||||
@@ -128,26 +128,29 @@ export class FunctionsRouter extends PromiseRouter {
|
|||||||
var response = FunctionsRouter.createResponseObject((result) => {
|
var response = FunctionsRouter.createResponseObject((result) => {
|
||||||
try {
|
try {
|
||||||
const cleanResult = logger.truncateLogMessage(JSON.stringify(result.response.result));
|
const cleanResult = logger.truncateLogMessage(JSON.stringify(result.response.result));
|
||||||
logger.info(`Ran cloud function ${functionName} for user ${userString} `
|
logger.info(
|
||||||
+ `with:\n Input: ${cleanInput }\n Result: ${cleanResult }`, {
|
`Ran cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput }\n Result: ${cleanResult }`,
|
||||||
|
{
|
||||||
functionName,
|
functionName,
|
||||||
params,
|
params,
|
||||||
user: userString,
|
user: userString,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
resolve(result);
|
resolve(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e);
|
reject(e);
|
||||||
}
|
}
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
try {
|
try {
|
||||||
logger.error(`Failed running cloud function ${functionName} for `
|
logger.error(
|
||||||
+ `user ${userString} with:\n Input: ${cleanInput}\n Error: `
|
`Failed running cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput}\n Error: ` + JSON.stringify(error),
|
||||||
+ JSON.stringify(error), {
|
{
|
||||||
functionName,
|
functionName,
|
||||||
error,
|
error,
|
||||||
params,
|
params,
|
||||||
user: userString
|
user: userString
|
||||||
});
|
}
|
||||||
|
);
|
||||||
reject(error);
|
reject(error);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e);
|
reject(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user