8000 Rename internal route id property by daffl · Pull Request #74 · feathersjs-ecosystem/feathers-rest · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 6, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading 8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function rest(handler = formatter) {
app.providers.push(function (path, service, options) {
const uri = path.indexOf('/') === 0 ? path : `/${path}`;
const baseRoute = app.route(uri);
const idRoute = app.route(`${uri}/:id`);
const idRoute = app.route(`${uri}/:__feathersId`);

let middleware = (options || {}).middleware || {};
let before = middleware.before || [];
Expand Down
6 changes: 3 additions & 3 deletions src/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getHandler (method, getArgs, service) {
}

let params = Object.assign({}, req.params || {});
delete params.id;
delete params.__feathersId;

// Grab the service parameters. Use req.feathers and set the query to req.query
params = Object.assign({ query: req.query || {} }, params, req.feathers);
Expand Down Expand Up @@ -79,12 +79,12 @@ function reqNone () {

// Returns the leading parameters for a `get` or `remove` request (the id)
function reqId (req) {
return [ req.params.id || null ];
return [ req.params.__feathersId || null ];
}

// Returns the leading parameters for an `update` or `patch` request (id, data)
function reqUpdate (req) {
return [ req.params.id || null, req.body ];
return [ req.params.__feathersId || null, req.body ];
}

// Returns the leading parameters for a `create` request (data)
Expand Down
30 changes: 30 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,34 @@ describe('REST provider', function () {
server.close(done);
});
});

it('Extend params with route params and allows id property (#76, #407)', done => {
const todoService = {
get(id, params) {
return Promise.resolve({
id,
appId: params.appId,
paramsId: params.id
});
}
};

const app = feathers()
.configure(rest())
.use('/:appId/:id/todo', todoService);

const expected = {
id: 'dishes',
appId: 'theApp',
paramsId: 'myId'
};

const server = app.listen(6880).on('listening', function () {
request('http://localhost:6880/theApp/myId/todo/' + expected.id, (error, response, body) => {
assert.ok(response.statusCode === 200, 'Got OK status code');
assert.deepEqual(expected, JSON.parse(body));
server.close(done);
});
});
});
});
0