Skip to content
Snippets Groups Projects
Commit 5525ff3b authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #12072 TIME 0:25 added query param to filter on emails type

parent a639ad59
No related branches found
No related tags found
No related merge requests found
...@@ -314,10 +314,32 @@ class EmailController ...@@ -314,10 +314,32 @@ class EmailController
$queryParams = $request->getQueryParams(); $queryParams = $request->getQueryParams();
if (!empty($queryParams['limit']) && !Validator::intVal()->validate($queryParams['limit'])) { if (!empty($queryParams['limit']) && !Validator::intVal()->validate($queryParams['limit'])) {
return $response->withStatus(403)->withJson(['errors' => 'Query limit is not an int val']); return $response->withStatus(400)->withJson(['errors' => 'Query limit is not an int value']);
} }
$emails = EmailModel::get(['select' => ['*'], 'where' => ['document->>\'id\' = ?'], 'data' => [$args['resId']], 'limit' => (int)$queryParams['limit']]); $where = ['document->>\'id\' = ?'];
if (!empty($queryParams['type'])) {
if (!Validator::stringType()->validate($queryParams['type'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query type is not a string value']);
}
if ($queryParams['type'] == 'ar') {
$where[] = "object LIKE '[AR]%'";
} else if ($queryParams['type'] == 'm2m') {
$where[] = 'message_exchange_id is not null';
} else if ($queryParams['type'] == 'email') {
$where[] = "object NOT LIKE '[AR]%'";
$where[] = 'message_exchange_id is null';
}
}
$emails = EmailModel::get([
'select' => ['*'],
'where' => $where,
'data' => [$args['resId']],
'limit' => (int)$queryParams['limit']
]);
foreach ($emails as $key => $email) { foreach ($emails as $key => $email) {
$emails[$key]['sender'] = json_decode($emails[$key]['sender']); $emails[$key]['sender'] = json_decode($emails[$key]['sender']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment