-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
140 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const path = require('path'); | ||
|
||
const errors = require(path.resolve('./lib/helpers/errors')); | ||
const responses = require(path.resolve('./lib/helpers/responses')); | ||
|
||
const HistorysService = require('../services/historys.service'); | ||
|
||
/** | ||
* @desc Endpoint to ask the service to get the list of historys | ||
* @param {Object} req - Express request object | ||
* @param {Object} res - Express response object | ||
*/ | ||
exports.list = async (req, res) => { | ||
try { | ||
const historys = await HistorysService.list(req.user); | ||
responses.success(res, 'history list')(historys); | ||
} catch (err) { | ||
responses.error(res, 422, 'Unprocessable Entity', errors.getMessage(err))(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Module dependencies | ||
* */ | ||
const path = require('path'); | ||
|
||
const policy = require(path.resolve('./lib/middlewares/policy')); | ||
|
||
/** | ||
* Invoke Historys Permissions | ||
*/ | ||
exports.invokeRolesPolicies = () => { | ||
policy.Acl.allow([{ | ||
roles: ['user'], | ||
allows: [{ | ||
resources: '/api/historys', | ||
permissions: ['get'], | ||
}], | ||
}]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const mongoose = require('mongoose'); | ||
|
||
const History = mongoose.model('History'); | ||
const Api = mongoose.model('Api'); | ||
|
||
/** | ||
* @desc Function to get all history in db | ||
* @return {Array} All historys | ||
*/ | ||
exports.list = (user) => History.find({ user: user._id }).sort('-createdAt').limit(100).exec(); | ||
|
||
/** | ||
* @desc Function to create a scrap in db | ||
* @param {Object} scrap | ||
* @return {Object} scrap | ||
*/ | ||
exports.create = (history) => new History(history).save(); | ||
|
||
/** | ||
* @desc Function to update scrap history in db | ||
* @param {Object} scrap | ||
* @param {Object} history | ||
* @return {Object} scrap | ||
*/ | ||
exports.apiHistorize = (api, history) => Api.updateOne( | ||
{ _id: api._id }, | ||
{ | ||
$push: { history: history._id }, | ||
$set: { status: history.status }, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const passport = require('passport'); | ||
const path = require('path'); | ||
|
||
const model = require(path.resolve('./lib/middlewares/model')); | ||
const policy = require(path.resolve('./lib/middlewares/policy')); | ||
const historys = require('../controllers/historys.controller'); | ||
const historysSchema = require('../models/historys.schema'); | ||
|
||
/** | ||
* Routes | ||
*/ | ||
module.exports = (app) => { | ||
// list & post | ||
app.route('/api/historys').all(passport.authenticate('jwt'), policy.isAllowed) | ||
.get(historys.list); // list | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const path = require('path'); | ||
|
||
const montaineRequest = require(path.resolve('./lib/helpers/montaineRequest')); | ||
const HistorysRepository = require('../repositories/historys.repository'); | ||
|
||
/** | ||
* @desc Function to get all history in db | ||
* @return {Promise} All historys | ||
*/ | ||
exports.list = async (user) => { | ||
const result = await HistorysRepository.list(user); | ||
return Promise.resolve(result); | ||
}; | ||
|
||
/** | ||
* @desc Functio to ask repository to add an history | ||
* @param {Object} scrap - original scrap | ||
* @return {Promise} scrap | ||
*/ | ||
exports.historize = async (result, start, api, user) => { | ||
const history = await HistorysRepository.create(montaineRequest.setApiHistory(result, start, user)); | ||
await HistorysRepository.apiHistorize(api, history); | ||
api.history.push(history); | ||
return Promise.resolve(api); | ||
}; |