Improves Controller and Adapter relationship

- Controllers that have adapters are AdaptableControllers
- AdaptableController is responsible to instantiate the proper adapter if needed (string, function or BaseAdapter)
- BaseAdapter is the base class for adapters, allows skipping when passed directly to the controller
This commit is contained in:
Florent Vilmart
2016-02-21 12:02:18 -05:00
parent bd548786ea
commit d504681589
11 changed files with 403 additions and 319 deletions

View File

@@ -1,12 +1,9 @@
import { Parse } from 'parse/node';
import PromiseRouter from '../PromiseRouter';
import rest from '../rest';
import AdaptableController from './AdaptableController';
export class PushController {
constructor(pushAdapter) {
this._pushAdapter = pushAdapter;
};
export class PushController extends AdaptableController {
/**
* Check whether the deviceType parameter in qury condition is valid or not.
@@ -42,13 +39,12 @@ export class PushController {
}
sendPush(body = {}, where = {}, config, auth) {
var pushAdapter = this._pushAdapter;
var pushAdapter = this.adapter;
if (!pushAdapter) {
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
'Push adapter is not available');
}
PushController.validateMasterKey(auth);
PushController.validatePushType(where, pushAdapter.getValidPushTypes());
// Replace the expiration_time with a valid Unix epoch milliseconds time
body['expiration_time'] = PushController.getExpirationTime(body);