| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- var passport = require('../security/passport'),
- AccountController = require('../controllers/accounts');
-
- module.exports = function(app) {
- /**
- * @api {post} /accounts Create account
- * @apiVersion 1.0.0
- * @apiName Create account
- * @apiGroup Accounts
- *
- * @apiParam {String} name Name for the new account
- * @apiParam {String} reference A reference (bank account number) for the new account
- * @apiParamExample {json} Request-Example:
- * {
- * name: 'Home',
- * reference: '1234567890'
- * }
- *
- * @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 (201) {Object} account The new account with its (sub)categories.
- * @apiSuccessExample Success-Response:
- * HTTP/1.1 201 Created
- * {
- * "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"
- * }
- * ]
- * }
- * ]
- * }
- *
- * @apiError (400) {json} BadRequest The user can't be found.
- *
- * @apiErrorExample BadRequest:
- * HTTP/1.1 400 Bad Request
- * [
- * {
- * "field": "name",
- * "rule": "required",
- * "message": "Path `name` is required."
- * }
- * ]
- *
- */
- app.post('/api/accounts', passport.jwt, AccountController.create);
- /**
- * @api {delete} /accounts/:account_id Delete account
- * @apiVersion 1.0.0
- * @apiName Delete account
- * @apiGroup Accounts
- *
- * @apiParam {String} account_id The account to delete
- *
- * @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 (204) -
- * @apiSuccessExample Success-Response:
- * HTTP/1.1 204 No Content
- *
- * @apiError (404) {json} AccountNotFound The account can't be found.
- * @apiErrorExample AccountNotFound:
- * HTTP/1.1 404 Not Found
- * {
- * "message": "Unknown account"
- * }
- */
- app.delete('/api/accounts/:account_id', passport.jwt, AccountController.delete);
- /**
- * @api {get} /accounts/:account_id Get account
- * @apiVersion 1.0.0
- * @apiName Get account
- * @apiGroup Accounts
- *
- * @apiParam {String} account_id The given account
- *
- * @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) {Object} account The account with its (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"
- * }
- * ]
- * }
- * ]
- * }
- *
- * @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', passport.jwt, AccountController.get);
-
- /**
- * @api {put} /accounts/:account_id Modify account
- * @apiVersion 1.0.0
- * @apiName Modify account
- * @apiGroup Accounts
- *
- * @apiParam {String} account_id The account id to modify
- * @apiParam {String} name Name for the new account
- * @apiParam {String} reference A reference (bank account number) for the new account
- * @apiParamExample {json} Request-Example:
- * {
- * name: 'Home',
- * reference: '1234567890'
- * }
- *
- * @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 {String} username Username of the User.
- * @apiSuccess {String} token The JWT valid token.
- * @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"
- * }
- * ]
- * }
- * ]
- * }
- *
- * @apiError (400) {json} BadRequest The user can't be found.
- * @apiErrorExample BadRequest:
- * HTTP/1.1 400 Bad Request
- * [
- * {
- * "field": "name",
- * "rule": "required",
- * "message": "Path `name` is required."
- * }
- * ]
- * @apiError (404) {json} AccountNotFound The account can't be found.
- * @apiErrorExample AccountNotFound:
- * HTTP/1.1 404 Not Found
- * {
- * "message": "Unknown account"
- * }
- */
- app.put('/api/accounts/:account_id', passport.jwt, AccountController.modify);
- /**
- * @api {post} /accounts/:account_id/entries Create entry
- * @apiVersion 1.0.0
- * @apiName Create entry
- * @apiGroup Entries
- *
- * @apiParam {String} account_id The account id to populate
- * @apiParam {String} amount Amount of the entry
- * @apiParam {String} date Date of the bill/deposit
- * @apiParam {String} [category] Category id of the bill/deposit
- * @apiParam {String} [sub_category] Sub category id of the bill/deposit
- * @apiParam {String} [label] A label for the entry
- * @apiParamExample {json} Request-Example:
- * {
- * amount: 1000,
- * date: 2015-09-03T10:04:11.481Z
- * }
- *
- * @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 (201) {Object} entry The created entry.
- * @apiSuccess (201) {Object[]} entries All account's entries
- * @apiSuccess (201) {Number} balance The account's total balance
- * @apiSuccessExample Success-Response:
- * HTTP/1.1 201 Created
- * {
- * entry: {
- * _id: '',
- * account_id: '1000',
- * type: 'DEPOSIT'
- * amount: 1000,
- * date: 2015-09-03T10:04:11.481Z
- * },
- * entries: [
- * {
- * _id: '',
- * account_id: '1000',
- * type: 'DEPOSIT'
- * amount: 1000,
- * date: 2015-09-03T10:04:11.481Z
- * }
- * ],
- * balance: 1000
- * }
- *
- * @apiError (400) {json} BadRequest The user can't be found.
- * @apiErrorExample BadRequest:
- * HTTP/1.1 400 Bad Request
- * [
- * {
- * "field": "amount",
- * "rule": "required",
- * "message": "Path `amount` is required."
- * }
- * ]
- *
- * @apiError (404) {json} AccountNotFound The account can't be found.
- * @apiErrorExample AccountNotFound:
- * HTTP/1.1 404 Not Found
- * {
- * "message": "Unknown account"
- * }
- */
- app.post('/api/accounts/:account_id/entries', passport.jwt, AccountController.add_entry);
- /**
- * @api {post} /accounts/:account_id/entries/:entry_id Modify entry
- * @apiVersion 1.0.0
- * @apiName Modify entry
- * @apiGroup Entries
- *
- * @apiParam {String} account_id The owner account
- * @apiParam {String} entry_id The entry to modify
- * @apiParam {String} amount Amount of the entry
- * @apiParam {String} date Date of the bill/deposit
- * @apiParam {String} [category] Category id of the bill/deposit
- * @apiParam {String} [sub_category] Sub category id of the bill/deposit
- * @apiParam {String} [label] A label for the entry
- * @apiParamExample {json} Request-Example:
- * {
- * amount: 1000,
- * date: 2015-09-03T10:04:11.481Z
- * }
- *
- * @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) {Object} entry The created entry.
- * @apiSuccess (200) {Object[]} entries All account's entries
- * @apiSuccess (200) {Number} balance The account's total balance
- * @apiSuccessExample Success-Response:
- * HTTP/1.1 200 OK
- * {
- * entry: {
- * _id: '',
- * account_id: '1000',
- * type: 'DEPOSIT'
- * amount: 1000,
- * date: 2015-09-03T10:04:11.481Z
- * },
- * entries: [
- * {
- * _id: '',
- * account_id: '1000',
- * type: 'DEPOSIT'
- * amount: 1000,
- * date: 2015-09-03T10:04:11.481Z
- * }
- * ],
- * balance: 1000
- * }
- *
- * @apiError (400) {json} BadRequest The user can't be found.
- * @apiErrorExample BadRequest:
- * HTTP/1.1 400 Bad Request
- * [
- * {
- * "field": "amount",
- * "rule": "required",
- * "message": "Path `amount` is required."
- * }
- * ]
- *
- * @apiError (404) {json} AccountNotFound The account can't be found.
- * @apiErrorExample AccountNotFound:
- * HTTP/1.1 404 Not Found
- * {
- * "message": "Unknown account"
- * }
- * @apiError (404) {json} EntryNotFound The entry can't be found.
- * @apiErrorExample AccountNotFound:
- * HTTP/1.1 404 Not Found
- */
- app.put('/api/accounts/:account_id/entries/:entry_id', passport.jwt, AccountController.modify_entry);
-
- /**
- * @api {delete} /accounts/:account_id/entries/:entry_id Delete entry
- * @apiVersion 1.0.0
- * @apiName Delete entry
- * @apiGroup Entries
- *
- * @apiParam {String} account_id The owner account
- * @apiParam {String} entry_id The entry to delete
- *
- * @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 (204) -
- * @apiSuccessExample Success-Response:
- * HTTP/1.1 204 No Content
- *
- * @apiError (404) {json} AccountNotFound The account can't be found.
- * @apiErrorExample AccountNotFound:
- * HTTP/1.1 404 Not Found
- * {
- * "message": "Unknown account"
- * }
- * @apiError (404) {json} EntryNotFound The entry can't be found.
- * @apiErrorExample AccountNotFound:
- * HTTP/1.1 404 Not Found
- */
- app.delete('/api/accounts/:account_id/entries/:entry_id', passport.jwt, AccountController.delete_entry);
-
- app.get('/api/accounts/:account_id/entries', passport.jwt, AccountController.list_entries);
-
- };
|