mirror of
https://github.com/Febbweiss/CloudBudget.git
synced 2026-03-05 06:45:39 +00:00
Feature: add resource to list all accounts
This commit is contained in:
@@ -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) {
|
modify : function(request, response) {
|
||||||
return check_account(request, response, function(error, account) {
|
return check_account(request, response, function(error, account) {
|
||||||
account.name = request.body.name;
|
account.name = request.body.name;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ module.exports = function(app) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('*', function(req, res) {
|
app.get('*', function(req, res, next) {
|
||||||
res.sendfile('./public/index.html');
|
res.sendfile('./public/index.html');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -2,6 +2,57 @@ var passport = require('../security/passport'),
|
|||||||
AccountController = require('../controllers/accounts');
|
AccountController = require('../controllers/accounts');
|
||||||
|
|
||||||
module.exports = function(app) {
|
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
|
* @api {post} /accounts Create account
|
||||||
* @apiVersion 1.0.0
|
* @apiVersion 1.0.0
|
||||||
|
|||||||
@@ -463,6 +463,83 @@ define({ "api": [
|
|||||||
"filename": "app/routes/accounts.js",
|
"filename": "app/routes/accounts.js",
|
||||||
"groupTitle": "Accounts"
|
"groupTitle": "Accounts"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "get",
|
||||||
|
"url": "/accounts",
|
||||||
|
"title": "List accounts",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"name": "Retrieve_accounts",
|
||||||
|
"group": "Accounts",
|
||||||
|
"header": {
|
||||||
|
"fields": {
|
||||||
|
"Header": [
|
||||||
|
{
|
||||||
|
"group": "Header",
|
||||||
|
"type": "String",
|
||||||
|
"optional": false,
|
||||||
|
"field": "Content-Type",
|
||||||
|
"description": "<p>application/json</p> "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"group": "Header",
|
||||||
|
"type": "String",
|
||||||
|
"optional": false,
|
||||||
|
"field": "Authorization",
|
||||||
|
"description": "<p>The valid JWT token provided by the {post} /users/login resource</p> "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"examples": [
|
||||||
|
{
|
||||||
|
"title": "Authorization header example:",
|
||||||
|
"content": "\"Authorization\": \"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTVlNmU0ZTAwNTIzMGY0OTI3MWM3MDc4IiwiaWF0IjoxNDQxMTk1MjMyfQ.eWh9nuXVVSVDKKCmTMDoc9FBU55-KgkiOJH1hrdQRTQ\"",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"fields": {
|
||||||
|
"401": [
|
||||||
|
{
|
||||||
|
"group": "401",
|
||||||
|
"type": "<p>json</p> ",
|
||||||
|
"optional": false,
|
||||||
|
"field": "AuthenticationFailed",
|
||||||
|
"description": "<p>The user can't be found.</p> "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"examples": [
|
||||||
|
{
|
||||||
|
"title": "AuthenticationFailed:",
|
||||||
|
"content": "HTTP/1.1 401 Not Found\n{\n \"message\": \"Authentication failed\"\n}",
|
||||||
|
"type": "json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"success": {
|
||||||
|
"fields": {
|
||||||
|
"200": [
|
||||||
|
{
|
||||||
|
"group": "200",
|
||||||
|
"type": "<p>json</p> ",
|
||||||
|
"optional": false,
|
||||||
|
"field": "accounts",
|
||||||
|
"description": "<p>List of all accounts and their (sub)categories.</p> "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"examples": [
|
||||||
|
{
|
||||||
|
"title": "Success-Response:",
|
||||||
|
"content": "HTTP/1.1 200 OK\n [{\n \"name\": \"Home\",\n \"reference\": \"1234567890\",\n \"user_id\": \"55e6e4e005230f49271c7078\",\n \"_id\": \"55e8218912c65a1730c34858\",\n \"created_at\": \"2015-09-03T10:31:37.889Z\",\n \"categories\": [\n {\n \"key\": \"alimony_payments\",\n \"label\": \"Alimony Payments\",\n \"_id\": \"55e8218912c65a1730c34859\",\n \"sub_categories\": []\n },\n {\n \"key\": \"automobile_expenses\",\n \"label\": \"Automobile Expenses\",\n \"_id\": \"55e8218912c65a1730c3485a\",\n \"sub_categories\": [\n {\n \"label\": \"Car Payment\",\n \"key\": \"car_payment\",\n \"_id\": \"55e8218912c65a1730c3485d\"\n }\n ]\n }\n ]\n }]",
|
||||||
|
"type": "json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"filename": "app/routes/accounts.js",
|
||||||
|
"groupTitle": "Accounts"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "post",
|
"type": "post",
|
||||||
"url": "/accounts/:account_id/entries",
|
"url": "/accounts/:account_id/entries",
|
||||||
|
|||||||
@@ -463,6 +463,83 @@
|
|||||||
"filename": "app/routes/accounts.js",
|
"filename": "app/routes/accounts.js",
|
||||||
"groupTitle": "Accounts"
|
"groupTitle": "Accounts"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "get",
|
||||||
|
"url": "/accounts",
|
||||||
|
"title": "List accounts",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"name": "Retrieve_accounts",
|
||||||
|
"group": "Accounts",
|
||||||
|
"header": {
|
||||||
|
"fields": {
|
||||||
|
"Header": [
|
||||||
|
{
|
||||||
|
"group": "Header",
|
||||||
|
"type": "String",
|
||||||
|
"optional": false,
|
||||||
|
"field": "Content-Type",
|
||||||
|
"description": "<p>application/json</p> "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"group": "Header",
|
||||||
|
"type": "String",
|
||||||
|
"optional": false,
|
||||||
|
"field": "Authorization",
|
||||||
|
"description": "<p>The valid JWT token provided by the {post} /users/login resource</p> "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"examples": [
|
||||||
|
{
|
||||||
|
"title": "Authorization header example:",
|
||||||
|
"content": "\"Authorization\": \"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTVlNmU0ZTAwNTIzMGY0OTI3MWM3MDc4IiwiaWF0IjoxNDQxMTk1MjMyfQ.eWh9nuXVVSVDKKCmTMDoc9FBU55-KgkiOJH1hrdQRTQ\"",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"fields": {
|
||||||
|
"401": [
|
||||||
|
{
|
||||||
|
"group": "401",
|
||||||
|
"type": "<p>json</p> ",
|
||||||
|
"optional": false,
|
||||||
|
"field": "AuthenticationFailed",
|
||||||
|
"description": "<p>The user can't be found.</p> "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"examples": [
|
||||||
|
{
|
||||||
|
"title": "AuthenticationFailed:",
|
||||||
|
"content": "HTTP/1.1 401 Not Found\n{\n \"message\": \"Authentication failed\"\n}",
|
||||||
|
"type": "json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"success": {
|
||||||
|
"fields": {
|
||||||
|
"200": [
|
||||||
|
{
|
||||||
|
"group": "200",
|
||||||
|
"type": "<p>json</p> ",
|
||||||
|
"optional": false,
|
||||||
|
"field": "accounts",
|
||||||
|
"description": "<p>List of all accounts and their (sub)categories.</p> "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"examples": [
|
||||||
|
{
|
||||||
|
"title": "Success-Response:",
|
||||||
|
"content": "HTTP/1.1 200 OK\n [{\n \"name\": \"Home\",\n \"reference\": \"1234567890\",\n \"user_id\": \"55e6e4e005230f49271c7078\",\n \"_id\": \"55e8218912c65a1730c34858\",\n \"created_at\": \"2015-09-03T10:31:37.889Z\",\n \"categories\": [\n {\n \"key\": \"alimony_payments\",\n \"label\": \"Alimony Payments\",\n \"_id\": \"55e8218912c65a1730c34859\",\n \"sub_categories\": []\n },\n {\n \"key\": \"automobile_expenses\",\n \"label\": \"Automobile Expenses\",\n \"_id\": \"55e8218912c65a1730c3485a\",\n \"sub_categories\": [\n {\n \"label\": \"Car Payment\",\n \"key\": \"car_payment\",\n \"_id\": \"55e8218912c65a1730c3485d\"\n }\n ]\n }\n ]\n }]",
|
||||||
|
"type": "json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"filename": "app/routes/accounts.js",
|
||||||
|
"groupTitle": "Accounts"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "post",
|
"type": "post",
|
||||||
"url": "/accounts/:account_id/entries",
|
"url": "/accounts/:account_id/entries",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ define({
|
|||||||
"apidoc": "0.2.0",
|
"apidoc": "0.2.0",
|
||||||
"generator": {
|
"generator": {
|
||||||
"name": "apidoc",
|
"name": "apidoc",
|
||||||
"time": "2015-09-03T11:08:47.201Z",
|
"time": "2015-09-29T13:08:53.151Z",
|
||||||
"url": "http://apidocjs.com",
|
"url": "http://apidocjs.com",
|
||||||
"version": "0.13.1"
|
"version": "0.13.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"apidoc": "0.2.0",
|
"apidoc": "0.2.0",
|
||||||
"generator": {
|
"generator": {
|
||||||
"name": "apidoc",
|
"name": "apidoc",
|
||||||
"time": "2015-09-03T11:08:47.201Z",
|
"time": "2015-09-29T13:08:53.151Z",
|
||||||
"url": "http://apidocjs.com",
|
"url": "http://apidocjs.com",
|
||||||
"version": "0.13.1"
|
"version": "0.13.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,41 @@ describe('API /accounts', function() {
|
|||||||
globalServer.close();
|
globalServer.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('* List', function() {
|
||||||
|
it('should return the list of accounts', function(done) {
|
||||||
|
request(globalServer)
|
||||||
|
.get('/api/accounts')
|
||||||
|
.set('Authorization', 'JWT ' + token)
|
||||||
|
.set('Accept', 'application/json')
|
||||||
|
.expect(200)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.end( function(error, result) {
|
||||||
|
should.not.exist(error);
|
||||||
|
var accounts = result.body;
|
||||||
|
should.exist(accounts);
|
||||||
|
accounts.should.be.instanceof(Array).and.have.lengthOf(1);
|
||||||
|
var account = accounts[0];
|
||||||
|
account._id.should.be.equal(account_id);
|
||||||
|
account.name.should.be.equal('Default');
|
||||||
|
account.reference.should.be.equal('1234567890');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to list accounts without valid token', function(done) {
|
||||||
|
request(globalServer)
|
||||||
|
.get('/api/accounts')
|
||||||
|
.set('Authorization', 'JWT fake')
|
||||||
|
.expect(401, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to list accounts without token', function(done) {
|
||||||
|
request(globalServer)
|
||||||
|
.get('/api/accounts')
|
||||||
|
.expect(401, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('* Creation', function() {
|
describe('* Creation', function() {
|
||||||
it('should create an account', function(done) {
|
it('should create an account', function(done) {
|
||||||
request(globalServer)
|
request(globalServer)
|
||||||
|
|||||||
Reference in New Issue
Block a user