(function(){ "use strict"; angular .module("app.repositories") .factory("repository.approval", approvalRepository); function approvalRepository(webApi, dataTableConstant, queryParamsModels){ return { getAllServices: getAllServices, getAllMoments: getAllMoments, getAllAssets: getAllAssets, getServicePreviewById: getServicePreviewById, removeAssetById: removeAssetById, approveServiceById: approveServiceById, rejectServiceById: rejectServiceById, approveMomentById: approveMomentById, rejectMomentById: rejectMomentById }; function getAllServices(currentPage, searchQuery, careProviderId, startDate, endDate, approvalStatusId, orderParam){ var queryParams = new queryParamsModels.ApprovalServicesFilter(); queryParams.pageNumber = currentPage || dataTableConstant.CURRENT_PAGE; queryParams.pageSize = dataTableConstant.ITEMS_PER_PAGE; if (searchQuery) queryParams.searchQuery = searchQuery; if (careProviderId) queryParams.careProviderId = careProviderId; if (startDate) queryParams.startDate = startDate; if (endDate) queryParams.endDate = endDate; if (approvalStatusId || approvalStatusId == 0) queryParams.status = approvalStatusId; if (orderParam) queryParams.order = orderParam; queryParams = excludeNullable(queryParams); return webApi.getAllServices({ before: [], after: queryParams }) } /** * Get assets with applied filters. */ function getAllAssets(currentPage, searchQuery, startDate, endDate, locationId, careProviderId, orderParam) { var queryParams = new queryParamsModels.ApprovalAssetsFilter(); queryParams.pageNumber = currentPage || dataTableConstant.CURRENT_PAGE; queryParams.pageSize = dataTableConstant.ITEMS_PER_PAGE; if (searchQuery) queryParams.searchQuery = searchQuery; if (startDate) queryParams.startDate = startDate; if (endDate) queryParams.endDate = endDate; if (locationId) queryParams.locationId = locationId; if (careProviderId) queryParams.careProviderId = careProviderId; if (orderParam) queryParams.order = orderParam; queryParams = excludeNullable(queryParams); return webApi.getAllAssets({ before: [], after: queryParams }) } function getAllMoments(currentPage, searchQuery, careProviderId, startDate, endDate, approvalStatusId, orderParam){ var queryParams = new queryParamsModels.ApprovalMomentsFilter(); queryParams.pageNumber = currentPage || dataTableConstant.CURRENT_PAGE; queryParams.pageSize = dataTableConstant.ITEMS_PER_PAGE; if (searchQuery) queryParams.searchQuery = searchQuery; if (careProviderId) queryParams.careProviderId = careProviderId; if (startDate) queryParams.startDate = startDate; if (endDate) queryParams.endDate = endDate; if (approvalStatusId || approvalStatusId == 0) queryParams.status = approvalStatusId; if (orderParam) queryParams.order = orderParam; queryParams = excludeNullable(queryParams); return webApi.getAllMoments({ before: [], after: queryParams }) } function getServicePreviewById(id){ return webApi.getServicePreviewById({ "url": { "id": id } }); } function removeAssetById(id){ return webApi.removeAssetById({ "url": { "id": id } }); } function approveServiceById(id){ return webApi.approveServiceById({ "url": { id: id } }); } function rejectServiceById(id, annotation){ return webApi.rejectServiceById({ "url": { id: id }, "data": annotation }); } function approveMomentById(id){ return webApi.approveMomentById({ "url": { id: id } }); } function rejectMomentById(id, annotation){ return webApi.rejectMomentById({ "url": { id: id }, "data": annotation }); } /* Internal functionality */ function excludeNullable(model) { var result = {}; for (var key in model) { if (model.hasOwnProperty(key)) { if (model[key] != null && model[key] != "") { result[key] = model[key]; } } } return result; } } // IoC container. approvalRepository.$inject = [ "webApi", "appConstant.dataTable", "appModels.queryParams" ]; })();