Skip to content

Commit

Permalink
chore(accounts): remove tech debt
Browse files Browse the repository at this point in the history
Removes technical debt by removing duplicate code.
  • Loading branch information
jniles committed Jan 2, 2025
1 parent a67a7ba commit 2f62192
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 65 deletions.
6 changes: 4 additions & 2 deletions client/src/modules/accounts/AccountStoreService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ function AccountStoreService($q, Accounts, AccountTypes, Store) {
const service = this;
let initialLoad = true;
let initTypeLoad = true;

service.accounts = accountStore;
service.types = typeStore;

const accounts = new Store();
const accountTypes = new Store();

const typeRequest = AccountTypes.getAccountType()
const typeRequest = AccountTypes.read()
.then((result) => {
accountTypes.setData(result);
initTypeLoad = false;
Expand All @@ -29,7 +31,7 @@ function AccountStoreService($q, Accounts, AccountTypes, Store) {

function accountStore(importedAccounts) {
if (importedAccounts || initialLoad) {
return Accounts.read(null, { detailed : 1 }, true)
return Accounts.read(null, { detailed: 1 }, true)
.then((result) => {
accounts.setData(result);
initialLoad = false;
Expand Down
11 changes: 3 additions & 8 deletions client/src/modules/accounts/accountCategories.service.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
angular.module('bhima.services')
.service('AccountCategoryService', AccountCategoryService);
.service('AccountCategoryService', AccountCategoryService);

AccountCategoryService.$inject = [
'PrototypeApiService', '$http', 'util',
];
AccountCategoryService.$inject = ['PrototypeApiService'];

/**
* Account Category Service
*
* A service wrapper for the /account/categories HTTP endpoint.
*/
function AccountCategoryService(Api) {
var baseUrl = '/accounts/categories/';
var service = new Api(baseUrl);

return service;
return new Api('/accounts/categories/');
}
18 changes: 2 additions & 16 deletions client/src/modules/accounts/accountTypes.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,15 @@ function AccountTypeService(Api, $http, util) {
const baseUrl = '/accounts/types/';
const service = new Api(baseUrl);

service.getAccountType = getAccountType;
service.getTypeText = getTypeText;

/**
* @helper
* This Method return a list of Account Type
* */
function getAccountType(id, params) {
const url = baseUrl.concat(id || '');
return $http.get(url, { params })
.then(util.unwrapHttpResponse);
}

/**
* @helper
* This Method return a text an Account Type
* */
function getTypeText(typeId, accountTypes) {
const accountText = accountTypes.filter((item) => {
return item.id === typeId;
});

return accountText[0].type;
const needle = accountTypes.find(item => item.id === typeId);
return needle.type;
}

return service;
Expand Down
40 changes: 20 additions & 20 deletions client/src/modules/functions/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ function FunctionManagementController(Functions, Modals, Notify, uiGridConstants

// options for the UI grid
vm.gridOptions = {
appScopeProvider: vm,
enableColumnMenus: false,
fastWatch: true,
flatEntityAccess: true,
enableSorting: true,
onRegisterApi: onRegisterApiFn,
columnDefs: [{
field: 'fonction_txt',
displayName: 'FORM.LABELS.DESIGNATION',
headerCellFilter: 'translate',
appScopeProvider : vm,
enableColumnMenus : false,
fastWatch : true,
flatEntityAccess : true,
enableSorting : true,
onRegisterApi : onRegisterApiFn,
columnDefs : [{
field : 'fonction_txt',
displayName : 'FORM.LABELS.DESIGNATION',
headerCellFilter : 'translate',
}, {
field: 'numEmployees',
displayName: 'TABLE.AGGREGATES.NUM_EMPLOYEES',
headerCellFilter: 'translate',
field : 'numEmployees',
displayName : 'TABLE.AGGREGATES.NUM_EMPLOYEES',
headerCellFilter : 'translate',
}, {
field: 'action',
width: 80,
displayName: '',
cellTemplate: '/modules/functions/templates/action.tmpl.html',
enableSorting: false,
enableFiltering: false,
field : 'action',
width : 80,
displayName : '',
cellTemplate : '/modules/functions/templates/action.tmpl.html',
enableSorting : false,
enableFiltering : false,
}],
};

Expand All @@ -59,7 +59,7 @@ function FunctionManagementController(Functions, Modals, Notify, uiGridConstants
function loadFunctions() {
vm.loading = true;

Functions.read(null, { detailed: 1 })
Functions.read(null, { detailed : 1 })
.then((data) => {
vm.gridOptions.data = data;
})
Expand Down
32 changes: 16 additions & 16 deletions client/src/modules/functions/functions.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ angular.module('bhima.routes')
.config(['$stateProvider', ($stateProvider) => {
$stateProvider
.state('functions', {
url: '/functions',
controller: 'FunctionManagementController as FunctionCtrl',
templateUrl: 'modules/functions/functions.html',
url : '/functions',
controller : 'FunctionManagementController as FunctionCtrl',
templateUrl : 'modules/functions/functions.html',
})

.state('functions.create', {
url: '/create',
params: {
isCreateState: { value: true },
url : '/create',
params : {
isCreateState : { value : true },
},
onEnter: ['$uibModal', '$transition$', functionModal],
onExit: ['$uibModalStack', closeModal],
onEnter : ['$uibModal', '$transition$', functionModal],
onExit : ['$uibModalStack', closeModal],
})

.state('functions.edit', {
url: '/:id/edit',
params: {
id: { value: null },
url : '/:id/edit',
params : {
id : { value : null },
},
onEnter: ['$uibModal', '$transition$', functionModal],
onExit: ['$uibModalStack', closeModal],
onEnter : ['$uibModal', '$transition$', functionModal],
onExit : ['$uibModalStack', closeModal],
});
}]);

function functionModal($modal, $transition) {
$modal.open({
templateUrl: 'modules/functions/modals/function.modal.html',
controller: 'FunctionModalController as FunctionModalCtrl',
resolve: { params: () => $transition.params('to') },
templateUrl : 'modules/functions/modals/function.modal.html',
controller : 'FunctionModalController as FunctionModalCtrl',
resolve : { params : () => $transition.params('to') },
}).result.catch(angular.noop);
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/functions/modals/function.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function FunctionModalController($state, Functions, Notify, AppCache, params) {
if (vm.batchCreate) {
$state.go('functions.create');
} else {
$state.go('functions', null, { reload: true });
$state.go('functions', null, { reload : true });
}
})
.catch(Notify.handleError);
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/admin/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function create(req, res, next) {

try {
const row = await db.exec(sql, [data]);
res.status(201).json({ id: row.insertId });
res.status(201).json({ id : row.insertId });
} catch (e) { next(e); }
}

Expand Down
6 changes: 5 additions & 1 deletion test/integration/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ describe('test/integration/functions The /functions API', () => {
fonction_txt: 'Anestiologiste',
};

const FUNCTION_KEY = ['id', 'fonction_txt', 'numEmployees'];
const FUNCTION_KEY = ['id', 'fonction_txt'];
const NUM_FUNCTIONS = 2;

it('GET /FUNCTIONS returns a list of function ', () => {
return agent.get('/functions')
.then((res) => {
helpers.api.listed(res, NUM_FUNCTIONS);
const [firstFunction] = res.body;
expect(firstFunction).to.have.keys([...FUNCTION_KEY, 'numEmployees']);
expect(firstFunction.numEmployees).to.equal(5);

})
.catch(helpers.handler);
});
Expand Down

0 comments on commit 2f62192

Please sign in to comment.