Feature: add resource to list all accounts

This commit is contained in:
2015-09-29 13:16:14 +00:00
parent 9acd8af035
commit a28ed5d302
8 changed files with 255 additions and 3 deletions

View File

@@ -117,6 +117,18 @@ module.exports = {
});
},
retrieve_accounts : function(request, response) {
Account
.find({user_id: request.user.id})
.sort({name: 1})
.exec(function(errors, accounts) {
if( errors ) {
Handler.errorHandler(errors, 400, response);
}
return response.json(accounts);
});
},
modify : function(request, response) {
return check_account(request, response, function(error, account) {
account.name = request.body.name;

View File

@@ -10,7 +10,7 @@ module.exports = function(app) {
}
})
app.get('*', function(req, res) {
app.get('*', function(req, res, next) {
res.sendfile('./public/index.html');
});
};

View File

@@ -2,6 +2,57 @@ var passport = require('../security/passport'),
AccountController = require('../controllers/accounts');
module.exports = function(app) {
/**
* @api {get} /accounts List accounts
* @apiVersion 1.0.0
* @apiName Retrieve accounts
* @apiGroup Accounts
*
* @apiHeader {String} Content-Type application/json
*
* @apiHeader {String} Authorization The valid JWT token provided by the {post} /users/login resource
* @apiHeaderExample {string} Authorization header example:
* "Authorization": "JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTVlNmU0ZTAwNTIzMGY0OTI3MWM3MDc4IiwiaWF0IjoxNDQxMTk1MjMyfQ.eWh9nuXVVSVDKKCmTMDoc9FBU55-KgkiOJH1hrdQRTQ"
* @apiError (401) {json} AuthenticationFailed The user can't be found.
* @apiErrorExample AuthenticationFailed:
* HTTP/1.1 401 Not Found
* {
* "message": "Authentication failed"
* }
*
* @apiSuccess (200) {json} accounts List of all accounts and their (sub)categories.
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* [{
* "name": "Home",
* "reference": "1234567890",
* "user_id": "55e6e4e005230f49271c7078",
* "_id": "55e8218912c65a1730c34858",
* "created_at": "2015-09-03T10:31:37.889Z",
* "categories": [
* {
* "key": "alimony_payments",
* "label": "Alimony Payments",
* "_id": "55e8218912c65a1730c34859",
* "sub_categories": []
* },
* {
* "key": "automobile_expenses",
* "label": "Automobile Expenses",
* "_id": "55e8218912c65a1730c3485a",
* "sub_categories": [
* {
* "label": "Car Payment",
* "key": "car_payment",
* "_id": "55e8218912c65a1730c3485d"
* }
* ]
* }
* ]
* }]
*/
app.get('/api/accounts', passport.jwt, AccountController.retrieve_accounts);
/**
* @api {post} /accounts Create account
* @apiVersion 1.0.0