mirror of
https://github.com/Febbweiss/CloudBudget.git
synced 2026-03-04 22:35:38 +00:00
Feature: add account entries listing + fix entry date in response
This commit is contained in:
@@ -79,8 +79,8 @@ var list_entries = function(account_id, entry, callback ) {
|
||||
}
|
||||
|
||||
Entry
|
||||
.find({account_id: account_id})
|
||||
.sort({date: -1})
|
||||
.find({account_id: account_id}, {created_at: 0, __v: 0})
|
||||
.sort({date: -1,})
|
||||
.exec(function(errors, entries) {
|
||||
if( errors ) {
|
||||
return callback(errors);
|
||||
@@ -88,7 +88,7 @@ var list_entries = function(account_id, entry, callback ) {
|
||||
return callback( null, {
|
||||
entry: entry,
|
||||
entries: entries,
|
||||
balance: data[0].balance
|
||||
balance: data ? data[0].balance : 0
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -175,7 +175,7 @@ module.exports = {
|
||||
sub_category: data.sub_category ? new ObjectId(data.sub_category) : undefined,
|
||||
label: data.label,
|
||||
amount: data.amount,
|
||||
date: new Date(data.date),
|
||||
date: data.date,
|
||||
type: data.amount >= 0 ? 'DEPOSIT' : 'BILL'
|
||||
});
|
||||
|
||||
|
||||
@@ -294,6 +294,48 @@ module.exports = function(app) {
|
||||
*/
|
||||
app.put('/api/accounts/:account_id', passport.jwt, AccountController.modify);
|
||||
|
||||
/**
|
||||
* @api {get} /accounts/:account_id/entries List account entries
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName List entries
|
||||
* @apiGroup Entries
|
||||
*
|
||||
* @apiParam {String} account_id The account id to retrieve
|
||||
*
|
||||
* @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} entries List of all account entries.
|
||||
* @apiSuccessExample Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* [
|
||||
* {
|
||||
* _id: '',
|
||||
* account_id: '1000',
|
||||
* type: 'DEPOSIT'
|
||||
* amount: 1000,
|
||||
* date: 2015-09-03T10:04:11.481Z
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @apiError (404) {json} AccountNotFound The account can't be found.
|
||||
* @apiErrorExample AccountNotFound:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {
|
||||
* "message": "Unknown account"
|
||||
* }
|
||||
*/
|
||||
app.get('/api/accounts/:account_id/entries', passport.jwt, AccountController.list_entries);
|
||||
|
||||
/**
|
||||
* @api {post} /accounts/:account_id/entries Create entry
|
||||
* @apiVersion 1.0.0
|
||||
|
||||
Reference in New Issue
Block a user