Skip to content

Commit 8dcae3d

Browse files
committed
Merge pull request parse-community#357 from ParsePlatform/nlutsenko.router.installations
Cleanup duplicate logic and refactor installations.js into InstallationsRouter.
2 parents 7de31fd + 6a12744 commit 8dcae3d

File tree

3 files changed

+66
-81
lines changed

3 files changed

+66
-81
lines changed

src/Routers/InstallationsRouter.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// InstallationsRouter.js
2+
3+
import ClassesRouter from './ClassesRouter';
4+
import PromiseRouter from '../PromiseRouter';
5+
import rest from '../rest';
6+
7+
export class InstallationsRouter extends ClassesRouter {
8+
handleFind(req) {
9+
var options = {};
10+
if (req.body.skip) {
11+
options.skip = Number(req.body.skip);
12+
}
13+
if (req.body.limit) {
14+
options.limit = Number(req.body.limit);
15+
}
16+
if (req.body.order) {
17+
options.order = String(req.body.order);
18+
}
19+
if (req.body.count) {
20+
options.count = true;
21+
}
22+
if (req.body.include) {
23+
options.include = String(req.body.include);
24+
}
25+
26+
return rest.find(req.config, req.auth,
27+
'_Installation', req.body.where, options)
28+
.then((response) => {
29+
return {response: response};
30+
});
31+
}
32+
33+
handleGet(req) {
34+
req.params.className = '_Installation';
35+
return super.handleGet(req);
36+
}
37+
38+
handleCreate(req) {
39+
req.params.className = '_Installation';
40+
return super.handleCreate(req);
41+
}
42+
43+
handleUpdate(req) {
44+
req.params.className = '_Installation';
45+
return super.handleUpdate(req);
46+
}
47+
48+
handleDelete(req) {
49+
req.params.className = '_Installation';
50+
return super.handleDelete(req);
51+
}
52+
53+
getExpressRouter() {
54+
var router = new PromiseRouter();
55+
router.route('GET','/installations', (req) => { return this.handleFind(req); });
56+
router.route('GET','/installations/:objectId', (req) => { return this.handleGet(req); });
57+
router.route('POST','/installations', (req) => { return this.handleCreate(req); });
58+
router.route('PUT','/installations/:objectId', (req) => { return this.handleUpdate(req); });
59+
router.route('DELETE','/installations/:objectId', (req) => { return this.handleDelete(req); });
60+
return router;
61+
}
62+
}
63+
64+
export default InstallationsRouter;

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ParsePushAdapter from './Adapters/Push/ParsePushAdapter';
1919
import { PushController } from './Controllers/PushController';
2020

2121
import { ClassesRouter } from './Routers/ClassesRouter';
22+
import { InstallationsRouter } from './Routers/InstallationsRouter';
2223

2324
// Mutate the Parse object to add the Cloud Code handlers
2425
addParseCloud();
@@ -132,7 +133,7 @@ function ParseServer(args) {
132133
require('./sessions'),
133134
require('./roles'),
134135
require('./analytics'),
135-
require('./installations'),
136+
new InstallationsRouter().getExpressRouter(),
136137
require('./functions'),
137138
require('./schemas'),
138139
new PushController(pushAdapter).getExpressRouter()

src/installations.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)