Skip to content

Commit

Permalink
dem rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Salisbury committed Feb 13, 2017
1 parent 51ffe5d commit 6e028a0
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion api/routes/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,59 @@
$newRule->setRankId($rank);
$newRule->setNutrientId($nutrient);

$newRule->save();
if($newRule->save()){
$msg = "New Rule Saved";
} else {
$msg = "There was an error saving this rule";
}



$response_json = [
"status" => [
"code" => $response->getStatusCode(),
"message" => [$msg]
]
];

$response = $response->withJSON($response_json);
return $response;


});

$app->post('/rules/updateRuleById/{ruleId}', function($request, $response) {

$rule = CategoryRankNutrientQuery::create()->findPk($request->getAttribute("ruleId"));
print_r($rule);
$cat = $request->getParam('catId');


$nutrient = $request->getParam('nutrientId');

$rank = $request->getParam('rankId');


$rule->setThreshold($request->getParam('threshold'));
$rule->setUnits($request->getParam('units'));
$rule->setOperator($request->getParam('operator'));
$rule->setCategoryId($cat);
$rule->setRankId($rank);
$rule->setNutrientId($nutrient);

if($rule->save()){
$msg = "Rule updated.";
} else {
$msg = "There was an error saving this rule";
}


$response_json = [
"status" => [
"code" => $response->getStatusCode(),
"message" => [$msg]
]
];
$response = $response->withJSON($response_json);
return $response;
});

0 comments on commit 6e028a0

Please sign in to comment.