fix CRM contacts
This commit is contained in:
@@ -249,11 +249,14 @@ class ContactsController extends BaseController
|
||||
];
|
||||
}, $contacts);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'items' => $items,
|
||||
'total' => count($items),
|
||||
]);
|
||||
return $this->response
|
||||
->setHeader('X-CSRF-TOKEN', csrf_hash())
|
||||
->setHeader('X-CSRF-HASH', csrf_token())
|
||||
->setJSON([
|
||||
'success' => true,
|
||||
'items' => $items,
|
||||
'total' => count($items),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +266,12 @@ class ContactsController extends BaseController
|
||||
public function ajaxStore()
|
||||
{
|
||||
$organizationId = $this->requireActiveOrg();
|
||||
$customerId = $this->request->getPost('customer_id');
|
||||
|
||||
// Поддержка JSON и form-urlencoded данных
|
||||
$jsonData = $this->request->getJSON(true);
|
||||
$rawInput = $jsonData ?? $this->request->getPost();
|
||||
|
||||
$customerId = $rawInput['customer_id'] ?? null;
|
||||
|
||||
// Проверяем клиента если указан
|
||||
if ($customerId) {
|
||||
@@ -279,10 +287,10 @@ class ContactsController extends BaseController
|
||||
$data = [
|
||||
'organization_id' => $organizationId,
|
||||
'customer_id' => $customerId ?: null,
|
||||
'name' => $this->request->getPost('name'),
|
||||
'email' => $this->request->getPost('email') ?: null,
|
||||
'phone' => $this->request->getPost('phone') ?: null,
|
||||
'position' => $this->request->getPost('position') ?: null,
|
||||
'name' => $rawInput['name'] ?? '',
|
||||
'email' => $rawInput['email'] ?? null,
|
||||
'phone' => $rawInput['phone'] ?? null,
|
||||
'position' => $rawInput['position'] ?? null,
|
||||
];
|
||||
|
||||
// Валидация
|
||||
@@ -304,17 +312,20 @@ class ContactsController extends BaseController
|
||||
])->setStatusCode(422);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'message' => 'Контакт создан',
|
||||
'item' => [
|
||||
'id' => $contactId,
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'phone' => $data['phone'],
|
||||
'position' => $data['position'],
|
||||
],
|
||||
]);
|
||||
return $this->response
|
||||
->setHeader('X-CSRF-TOKEN', csrf_hash())
|
||||
->setHeader('X-CSRF-HASH', csrf_token())
|
||||
->setJSON([
|
||||
'success' => true,
|
||||
'message' => 'Контакт создан',
|
||||
'item' => [
|
||||
'id' => $contactId,
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'phone' => $data['phone'],
|
||||
'position' => $data['position'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,11 +345,15 @@ class ContactsController extends BaseController
|
||||
])->setStatusCode(404);
|
||||
}
|
||||
|
||||
// Поддержка JSON и form-urlencoded данных
|
||||
$jsonData = $this->request->getJSON(true);
|
||||
$rawInput = $jsonData ?? $this->request->getPost();
|
||||
|
||||
$data = [
|
||||
'name' => $this->request->getPost('name'),
|
||||
'email' => $this->request->getPost('email') ?: null,
|
||||
'phone' => $this->request->getPost('phone') ?: null,
|
||||
'position' => $this->request->getPost('position') ?: null,
|
||||
'name' => $rawInput['name'] ?? '',
|
||||
'email' => $rawInput['email'] ?? null,
|
||||
'phone' => $rawInput['phone'] ?? null,
|
||||
'position' => $rawInput['position'] ?? null,
|
||||
];
|
||||
|
||||
// Валидация
|
||||
@@ -360,17 +375,20 @@ class ContactsController extends BaseController
|
||||
])->setStatusCode(422);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'message' => 'Контакт обновлён',
|
||||
'item' => [
|
||||
'id' => $id,
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'phone' => $data['phone'],
|
||||
'position' => $data['position'],
|
||||
],
|
||||
]);
|
||||
return $this->response
|
||||
->setHeader('X-CSRF-TOKEN', csrf_hash())
|
||||
->setHeader('X-CSRF-HASH', csrf_token())
|
||||
->setJSON([
|
||||
'success' => true,
|
||||
'message' => 'Контакт обновлён',
|
||||
'item' => [
|
||||
'id' => $id,
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'phone' => $data['phone'],
|
||||
'position' => $data['position'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,9 +410,12 @@ class ContactsController extends BaseController
|
||||
|
||||
$this->contactModel->delete($id);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'success' => true,
|
||||
'message' => 'Контакт удалён',
|
||||
]);
|
||||
return $this->response
|
||||
->setHeader('X-CSRF-TOKEN', csrf_hash())
|
||||
->setHeader('X-CSRF-HASH', csrf_token())
|
||||
->setJSON([
|
||||
'success' => true,
|
||||
'message' => 'Контакт удалён',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user