Skip to content

Commit 737c31b

Browse files
committed
first version
1 parent 7402ec4 commit 737c31b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const JSONAPISerializer = require('jsonapi-serializer').Serializer;
3+
4+
function jsonapify(data, model, selfUrl) {
5+
return new JSONAPISerializer(model.name, data, {
6+
topLevelLinks: {
7+
self: selfUrl
8+
},
9+
attributes: Object.keys(model.attributes).filter(function(attribute) {
10+
return !model.attributes[attribute].primaryKey;
11+
})
12+
});
13+
}
14+
15+
module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
16+
return function (hook) {
17+
hook.result = jsonapify(hook.result.data, hook.service.Model, hook.path);
18+
return Promise.resolve(hook);
19+
};
20+
};

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "feathers-hooks-jsonapify",
3+
"version": "0.0.0",
4+
"description": "Feathers hook for outputting data in a JSON-API-compliant way. Edit",
5+
"main": "index.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/joelalejandro/feathers-hooks-jsonapify.git"
9+
},
10+
"keywords": [
11+
"feathers",
12+
"hook",
13+
"json-api"
14+
],
15+
"author": "Joel A. Villarreal Bertoldi <joel.a.villarreal@gmail.com>",
16+
"license": "MIT",
17+
"bugs": {
18+
"url": "https://github.com/joelalejandro/feathers-hooks-jsonapify/issues"
19+
},
20+
"homepage": "https://github.com/joelalejandro/feathers-hooks-jsonapify#readme",
21+
"dependencies": {
22+
"jsonapi-serializer": "^3.5.2"
23+
}
24+
}

0 commit comments

Comments
 (0)