Work on attributes

This commit is contained in:
sctn4elk 2024-06-03 00:18:25 -05:00
parent 3e20b57008
commit c67b95240b
4 changed files with 19 additions and 8 deletions

View File

@ -105,7 +105,7 @@ class AttributeController extends BaseController {
}
$jsonPayload = file_get_contents('php://input');
$input = json_decode($jsonPayload, TRUE);
if (! $this->validateAttribute($input)) {
return $this->unprocessableEntityResponse("validateAttribute");
}
@ -113,11 +113,12 @@ class AttributeController extends BaseController {
if ($input['LOYALTY_MEMBER_ID'] != null) {
$this->attributeModel->memberId = $input['LOYALTY_MEMBER_ID'];
$this->attributeModel->attributeId = $input['LOYALTY_ATTRIBUTE_ID'];
$result = $this->attributeModel->findMemberAttribute();
if (! $result) {
return $this->notFoundResponse("attributeModel->findMemberAttribute");
}
$response = $this->attributeModel->updateMemberAttribute($input);
unset($this->attributeModel->memberId);
} else {

View File

@ -24,7 +24,10 @@ class AttributeModel extends Database {
public function findMemberAttribute()
{
return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ? AND loyalty_attribute_id = ?", ["ii", $this->memberId, $this->attributeId]);
$query = "SELECT * FROM loyalty_member_view WHERE loyalty_member_id = " . $this->memberId;
$query .= " AND loyalty_attribute_id = " . $this->attributeId;
return $this->processQuery($query);
}
public function insertAttribute($inputModel)
@ -64,15 +67,21 @@ class AttributeModel extends Database {
"LOYALTY_VALUE": "http://localhost/CustomerRewardsRESTAPI/public/images/1.jpg"
}
*/
$keys = array_keys($jsonPayLoad);
$n = count($keys);
$query .= "CALL update_member_attribute_proc (" . $jsonPayLoad[$keys[0]] . ", ";
$query = "CALL update_loyalty_member_attribute_proc (" . $jsonPayLoad[$keys[0]] . ", ";
for($i = 1; $i < $n-1; $i++) {
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
if($i == 3) {
$query .= $jsonPayLoad[$keys[$i]] . ", ";
}
else {
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
}
}
$query .= $jsonPayLoad[$keys[$i]] . ")";
$rowCount = $this->processStatement($query);
return $rowCount;
}

View File

@ -69,7 +69,7 @@ class CustomerModel extends Database {
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
}
$query .= $jsonPayLoad[$keys[$i]] . ")";
//return var_dump($query);
$rowCount = $this->processStatement($query);
return $rowCount;
}

View File

@ -100,7 +100,8 @@ class Database {
{
$response['status_code_header'] = 'HTTP/1.1 422 Unprocessable Query';
$response['body'] = json_encode([
'error' => 'Invalid query'
'error' => 'Invalid query',
'message' => $msg
]);
$this->strErrorDesc = 'Unprocessable Query';
$this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Query';