function getWallet( req, res ){ var body = jsonBuilder.getBuilder(res); try{ if (!req.currentUser){ throw new Error('UNAUTHORIZED'); } if (req.currentUser.capabilities.indexOf('wallets') == -1){ throw new Error('FORBIDEN'); } if (!req.params.walletId){ throw new Error('ERROR_WALLETS_INVALID_ID_PARAM'); } var walletId = parseInt(req.params.walletId); if (walletId === NaN){ throw new Error('ERROR_WALLETS_INVALID_ID_PARAM'); } walletModel.getWalletById( req.currentUser.user_id, walletId, function(err, list){ if (err){ body.buildError(err); } else { body.build(list); } }); } catch(err) { body.buildError(err); } };
function deleteList( req, res ){ var body = jsonBuilder.getBuilder(res); try { if (!req.currentUser){ throw new Error('UNAUTHORIZED'); } if (req.currentUser.capabilities.indexOf('lists') == -1){ throw new Error('FORBIDEN'); } var listId = req.params.listId || null; if (!listId){ throw new Error('ERROR_LISTS_INVALID_ID_PARAM'); } listModel.getListById( req.currentUser.user_id, listId, function(err, data){ if (err){ body.buildError(err); } else { data.list.delete(function(err){ if (err){ body.buildError(err); } else { body.build(); } }); } }); } catch(err) { body.buildError(err); } };
// route functions function findWallets( req, res ){ // Response controller var json = jsonBuilder.getBuilder(res); // Validations try{ var search = {}; search.find = req.query._search || null; search.page = req.query._page || 0; search.items = req.query._items_per_page || 9; search.sort = req.query._sort || null; // validations if (!req.currentUser){ throw new Error('UNAUTHORIZED'); } if (req.currentUser.capabilities.indexOf('wallets') == -1){ throw new Error('FORBIDEN'); } if (search.find != null && typeof search.find !== 'string'){ throw new Error('ERROR_WALLETS_INVALID_SEARCH_QUERY'); } if (!Number.isInteger(search.page)){ throw new Error('ERROR_WALLETS_INVALID_PAGE'); } if (!Number.isInteger(search.items)){ throw new Error('ERROR_WALLETS_INVALID_LIST_SIZE'); }; if (search.sort !== null && typeof search.sort !== 'string'){ throw new Error('ERROR_WALLETS_INVALID_SORT'); } search.user_id = req.currentUser.user_id; walletModel.find( search, function( err, lists ){ if (err){ json.buildError(err); } else { json.build(lists); } }); } catch (err){ json.buildError(err); } };
function saveWallet( req, res ){ var body = jsonBuilder.getBuilder(res); try { if (!req.currentUser){ throw new Error('UNAUTHORIZED'); } if (req.currentUser.capabilities.indexOf('wallets') == -1){ throw new Error('FORBIDEN'); } var walletData = {}; walletData.user_id = req.currentUser.user_id; walletData.wallet_id = req.params.walletId || null; walletData.wallet_name = req.body.wallet_name || null; walletData.wallet_id = parseInt(walletData.wallet_id); if (walletData.wallet_name && walletData.wallet_name.length <= 1){ throw new Error('ERROR_WALLETS_INVALID_NAME_PARAM'); } if (walletData.wallet_id === NaN){ throw new Error('ERROR_WALLETS_INVALID_ID_PARAM'); } walletModel.getWalletById(walletData.user_id, walletData.wallet_id, function(err, data){ if (err){ body.buildError(err); return; } data.wallet.wallet_name = walletData.wallet_name; data.wallet.save(function(err){ if (err){ body.buildError(err); } else { body.build({ wallet: data.wallet.export() }); } }); }); } catch(err) { body.buildError(err); } };
function saveList( req, res ){ var body = jsonBuilder.getBuilder(res); try { if (!req.currentUser){ throw new Error('UNAUTHORIZED'); } if (req.currentUser.capabilities.indexOf('lists') == -1){ throw new Error('FORBIDEN'); } var listData = {}; listData.user_id = req.currentUser.user_id; listData.list_id = req.params.listId || null; listData.list_name = req.body.list_name || null; listData.list_id = parseInt(listData.list_id); if (listData.list_name && listData.list_name.length <= 1){ throw new Error('ERROR_LISTS_INVALID_NAME_PARAM'); } if (listData.list_id === NaN){ throw new Error('ERROR_LISTS_INVALID_ID_PARAM'); } listModel.getListById(listData.user_id, listData.list_id, function(err, data){ if (err){ body.buildError(err); return; } data.list.list_name = listData.list_name; data.list.save(function(err){ if (err){ body.buildError(err); } else { body.build({ list: data.list.export() }); } }); }); } catch(err) { body.buildError(err); } };
function insertWallet( req, res ){ var body = jsonBuilder.getBuilder(res); try{ if (!req.currentUser){ throw new Error('UNAUTHORIZED'); } if (req.currentUser.capabilities.indexOf('wallets') == -1){ throw new Error('FORBIDEN'); } var walletData = {}; walletData.user_id = req.currentUser.user_id || null; walletData.wallet_name = req.body.wallet_name || null; if (!walletData.user_id){ throw new Error('ERROR_LISTS_INVALID_USER_PARAM'); } if (!walletData.wallet_name || (walletData.wallet_name && walletData.wallet_name.length <= 1)){ throw new Error('ERROR_LIST_INVALID_NAME_PARAM'); } walletModel.insertWallet(walletData, function(err, data){ if (err){ body.buildError(err); } else { body.build(data); } }); } catch(err) { body.buildError(err); } };
function prepBuildFiles(projectPath) { var buildModule = require(path.resolve(projectPath, 'cordova/lib/builders/builders')); buildModule.getBuilder('gradle').prepBuildFiles(); }