Skip to content

Commit

Permalink
fixing handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancisZamora committed Jul 25, 2018
1 parent 7666dac commit bf9b616
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
17 changes: 12 additions & 5 deletions server/anchor/anchor-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ const register = function (server,serverOptions) {
},
handler: async function (request,h) {

console.log(request.pre.model.routes.create);

return await request.pre.model.routes.create.handler(request,h);
}

Expand Down Expand Up @@ -82,7 +80,7 @@ const register = function (server,serverOptions) {
},
handler: async function (request,h) {

return await request.pre.model.routes.getid.handler(request,h);
return await request.pre.model.routes.getId.handler(request,h);
}
});

Expand Down Expand Up @@ -202,9 +200,18 @@ const register = function (server,serverOptions) {
}]

},
handler: async function (request,h) {
handler: async function (request,reply) {

const model = request.pre.model;

const query = {};
const limit = request.query.limit;
const page = request.query.page;
const options = {
sort: model.sortAdapter(request.query.sort)
};

return await request.pre.model.routes.get.handler(request,h);
return await model.pagedFind(query, page, limit, options);
}
});
};
Expand Down
13 changes: 6 additions & 7 deletions server/anchor/anchor-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,19 +926,20 @@ AnchorModel.routes = {
},
get: {
disabled: false,
payload: null,
query: null,
handler: async (request,h) => {


const model = request.pre.model;

const query = {};
const limit = request.query.limit;
const page = request.query.page;
const options = {
sort: model.sortAdapter(request.query.sort)
};

return await model.pagedFind(query,page,limit,options);
return await model.pagedFind(query, page, limit, options);
},
auth: true
},
Expand All @@ -948,14 +949,13 @@ AnchorModel.routes = {
handler: async (request,h) => {

const model = request.pre.model;
const id = request.id;
const payload = request.payload;
const id = request.params.id;
const update = {
$set: payload
$set: request.payload

};

return await model.findByIdAndUpdate(update,id);
return await model.findByIdAndUpdate(id,update);
},
query: null
},
Expand All @@ -973,7 +973,6 @@ AnchorModel.routes = {
},
getId: {
disabled: false,
payload: null,
handler: async (request,h) => {

const model = request.pre.model;
Expand Down
2 changes: 1 addition & 1 deletion server/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const register = function (server, options) {
}
});

server.auth.default('session');
//server.auth.default('session');
};


Expand Down
8 changes: 7 additions & 1 deletion server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,17 @@ User.payload = Joi.object({

User.routes = Hoek.applyToDefaults(AnchorModel.routes, {
create: {
disabled: true
disabled: false,
payload: User.payload
},
update: {
disabled: false,
payload: User.payload
},
get: {
disabled: false
}

});

User.indexes = [
Expand Down

0 comments on commit bf9b616

Please sign in to comment.