From 95c79604513ed5d09292fa49cd9d7f2489c6ccf4 Mon Sep 17 00:00:00 2001 From: Thomas Manson Date: Mon, 18 Jun 2018 14:29:04 +0200 Subject: [PATCH] * remove non existant saveCreditCard method call * continue on mailing (very small step) --- .../troncQueteur/troncQueteur.controller.js | 22 +-- .../app/troncs/troncQueteur/troncQueteur.html | 10 +- server/src/Entity/MailingSummaryEntity.php | 2 +- server/src/routes.php | 1 + server/src/routes/13-mailing.php | 135 ++++++++++++++++++ 5 files changed, 147 insertions(+), 23 deletions(-) create mode 100644 server/src/routes/13-mailing.php diff --git a/client/src/app/troncs/troncQueteur/troncQueteur.controller.js b/client/src/app/troncs/troncQueteur/troncQueteur.controller.js index deef2af..9e50d35 100644 --- a/client/src/app/troncs/troncQueteur/troncQueteur.controller.js +++ b/client/src/app/troncs/troncQueteur/troncQueteur.controller.js @@ -196,29 +196,13 @@ } else { - //savedSuccessfully function handle the save of data in adminMode - if(vm.current.tronc.type == 4) + if(vm.current.adminEditMode && vm.currentUserRole >= 4) { - if(vm.current.adminEditMode && vm.currentUserRole >= 4) - { - vm.current.tronc_queteur.$saveCreditCardAsAdmin(savedSuccessfully, onSaveError); - } - else - { - vm.current.tronc_queteur.$saveCreditCard(savedSuccessfully, onSaveError); - } + vm.current.tronc_queteur.$saveCoinsAsAdmin(savedSuccessfully, onSaveError); } else { - if(vm.current.adminEditMode && vm.currentUserRole >= 4) - { - vm.current.tronc_queteur.$saveCoinsAsAdmin(savedSuccessfully, onSaveError); - } - else - { - vm.current.tronc_queteur.$saveCoins(savedSuccessfully, onSaveError); - } - + vm.current.tronc_queteur.$saveCoins(savedSuccessfully, onSaveError); } } }; diff --git a/client/src/app/troncs/troncQueteur/troncQueteur.html b/client/src/app/troncs/troncQueteur/troncQueteur.html index db01758..ce7f691 100644 --- a/client/src/app/troncs/troncQueteur/troncQueteur.html +++ b/client/src/app/troncs/troncQueteur/troncQueteur.html @@ -358,9 +358,13 @@

Ce tronc est d'une année ANTÉRIEURE ({{tq.current.year_tronc_queteur}})
- + Required
diff --git a/server/src/Entity/MailingSummaryEntity.php b/server/src/Entity/MailingSummaryEntity.php index 5fddf42..f9a6646 100755 --- a/server/src/Entity/MailingSummaryEntity.php +++ b/server/src/Entity/MailingSummaryEntity.php @@ -3,7 +3,7 @@ use Monolog\Logger; -class NamedDonationEntity extends Entity +class MailingSummaryEntity extends Entity { public $ul_id ; public $secteur ; diff --git a/server/src/routes.php b/server/src/routes.php index d79f04b..452d376 100644 --- a/server/src/routes.php +++ b/server/src/routes.php @@ -13,4 +13,5 @@ include_once("../../src/routes/10-unite-locale.php"); include_once("../../src/routes/11-yearly-goals.php"); include_once("../../src/routes/12-named_donation.php"); +//include_once("../../src/routes/13-mailing.php"); diff --git a/server/src/routes/13-mailing.php b/server/src/routes/13-mailing.php new file mode 100644 index 0000000..81b5d8c --- /dev/null +++ b/server/src/routes/13-mailing.php @@ -0,0 +1,135 @@ +get('/{role-id:[4-9]}/ul/{ul-id}/mailing', function ($request, $response, $args) +{ + $decodedToken = $request->getAttribute('decodedJWT'); + try + { + $ulId = (int)$args['ul-id']; + $roleId = (int)$args['role-id']; + $params = $request->getQueryParams(); + + $namedDonationDBService = new NamedDonationDBService($this->db, $this->logger); + //$this->logger->addInfo("DailyStats list - UL ID '".$ulId."'' role ID : $roleId"); + $namedDonations = $namedDonationDBService->getNamedDonations($query, $deleted, $year, $ulId); + + + $response->getBody()->write(json_encode($namedDonations)); + + + + return $response; + } + catch(\Exception $e) + { + $this->logger->addError("Error while fetching the NamedDonation for a year($year), deleted($deleted), query($query)", array('decodedToken'=>$decodedToken, "Exception"=>$e)); + throw $e; + } + +}); + +/** + * + * get one named donation + * + */ +$app->get('/{role-id:[4-9]}/ul/{ul-id}/namedDonations/{id}', function ($request, $response, $args) +{ + $namedDonationEntity = null; + try + { + $ulId = (int)$args['ul-id']; + $id = (int)$args['id']; + $roleId = (int)$args['role-id']; + + $namedDonationDBService = new NamedDonationDBService($this->db, $this->logger); + + $namedDonationEntity = $namedDonationDBService->getNamedDonationById($id, $ulId, $roleId); + + $response->getBody()->write(json_encode($namedDonationEntity)); + return $response; + + } + catch(\Exception $e) + { + $this->logger->addError("Error while geting namedDonation $id", array("Exception"=>$e)); + throw $e; + } +}); + +/** + * + * Update named donation + * + */ +$app->put('/{role-id:[4-9]}/ul/{ul-id}/namedDonations/{id}', function ($request, $response, $args) +{ + $decodedToken = $request->getAttribute('decodedJWT'); + $namedDonationEntity = null; + try + { + $ulId = (int)$args['ul-id']; + $userId = (int)$decodedToken->getUid (); + + $namedDonationDBService = new NamedDonationDBService($this->db, $this->logger); + $input = $request->getParsedBody(); + $namedDonationEntity = new NamedDonationEntity($input, $this->logger); + + $namedDonationDBService->update($namedDonationEntity, $ulId, $userId); + } + catch(\Exception $e) + { + $this->logger->addError("Error while updating namedDonation", array('namedDonationEntity'=>$namedDonationEntity, "Exception"=>$e)); + throw $e; + } + return $response; +}); + + + +/** + * Create named donation + */ +$app->post('/{role-id:[4-9]}/ul/{ul-id}/namedDonations', function ($request, $response, $args) +{ + $decodedToken = $request->getAttribute('decodedJWT'); + $namedDonationEntity = null; + try + { + $ulId = (int)$args['ul-id']; + $userId = (int)$decodedToken->getUid (); + + $namedDonationDBService = new NamedDonationDBService($this->db, $this->logger); + $input = $request->getParsedBody(); + $namedDonationEntity = new NamedDonationEntity($input, $this->logger); + $namedDonationId = $namedDonationDBService->insert($namedDonationEntity, $ulId, $userId); + + $response->getBody()->write(json_encode(array("namedDonationId"=>$namedDonationId), JSON_NUMERIC_CHECK)); + } + catch(\Exception $e) + { + $this->logger->addError("error while creating named donation", array('namedDonationEntity'=>$namedDonationEntity, "Exception"=>$e)); + throw $e; + } + return $response; +}); + +