FIX_checkDuplicate in Enquiry
This commit is contained in:
parent
f06aee27d5
commit
906c19a476
@ -94,6 +94,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
$routes->get('enquiry/getQuickQuoteEnquiryList', 'EnquiryController::getQuickQuoteEnquiryList');
|
||||
$routes->get('enquiry/updateEnquiryInProgress', 'EnquiryController::updateEnquiryInProgress');
|
||||
$routes->get('enquiry/updateEnquiryStatus', 'EnquiryController::updateEnquiryStatus');
|
||||
$routes->get('enquiry/checkDuplicate', 'EnquiryController::checkDuplicate');
|
||||
|
||||
|
||||
//Proposal
|
||||
|
||||
@ -664,6 +664,62 @@ class EnquiryController extends ResourceController
|
||||
$this->enquiryModel->update($enquiryId, [ 'is_active' => $isActive]);
|
||||
return $this->respond(['status' => 'success','data' => $enquiryId ], 200);
|
||||
}
|
||||
|
||||
public function checkDuplicate()
|
||||
{
|
||||
$request = $this->request->getGet();
|
||||
|
||||
// Input field => DB column mapping
|
||||
$fieldMapping = [
|
||||
"reg_no" => "vehicle_no", // frontend → database
|
||||
"mobile" => "mobile",
|
||||
"email" => "email",
|
||||
];
|
||||
|
||||
$conditions = [];
|
||||
$inputField = null; // what user sent
|
||||
$dbField = null; // actual column
|
||||
|
||||
// Identify which field user sent
|
||||
foreach ($fieldMapping as $input => $column) {
|
||||
if (!empty($request[$input])) {
|
||||
$inputField = $input;
|
||||
$dbField = $column;
|
||||
$conditions[$column] = $request[$input];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$dbField) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'One of the following is required: email, reg_no, mobile'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
// Query builder
|
||||
$builder = $this->enquiryModel->where($dbField, $conditions[$dbField]);
|
||||
|
||||
// Exclude this ID if provided
|
||||
if (!empty($request['id'])) {
|
||||
$builder->where('id !=', $request['id']);
|
||||
}
|
||||
|
||||
$enquiry = $builder->first();
|
||||
|
||||
if ($enquiry) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'exists',
|
||||
'field' => $inputField // return the field user sent
|
||||
]);
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'not',
|
||||
'field' => $inputField
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user