Add endpoint to fetch agents

This commit is contained in:
Djery-Tom 2022-03-01 18:28:36 +01:00
parent 33bd6d3d7f
commit 57ab240070
5 changed files with 106 additions and 5 deletions

View File

@ -257,4 +257,88 @@ class HelperController extends Controller
Log::error($t->getMessage() . " :\n" . $t->getTraceAsString()); Log::error($t->getMessage() . " :\n" . $t->getTraceAsString());
} }
} }
/**
* @OA\Post(
* path="/agents",
* summary="Rechercher un agent",
* tags={"Agents"},
* security={{"api_key":{}}},
* @OA\RequestBody(
* description="Corps de la requete",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="dial_code",
* type="string",
* description="Dial code du pays",
* example= "+237",
* ),
* @OA\Property(property="name",
* type="string",
* example="tom",
* description="Nom de l'agent"
* ),
* @OA\Property(property="phone",
* type="string",
* example="0452366562",
* description="Numero de telephone"
* ),
* @OA\Property(property="id",
* type="integer",
* example = 12,
* description="ID de l'agent"
* )
* )
* )
* ),
* @OA\Response(
* response=200,
* description="OK",
* @OA\JsonContent(
* ref="#/components/schemas/ApiResponse",
* example = {
* "status" : 200,
* "response" : "Votre requête de rattachement de votre compte bancaire a été prise en compte, vous recevrez un mail de confirmation dès lors que la banque aura validé votre code IBAN",
* "error":null
* }
* )
* )
* )
*/
// Option de recherche des agents geolocalisés
public function getAgents(Request $request)
{
$this->validate($request, [
'name' => 'string',
'phone' => 'string',
'id' => 'integer',
'dial_code' => 'required|string|min:2'
]);
$name = $request->input('name');
$phone = $request->input('phone');
$id = $request->input('id');
$dial_code = $request->input('dial_code');
$perPage = current(DB::select("SELECT valeur_int FROM adminConfig WHERE cle = 'pas_chargement' LIMIT 1"))->valeur_int ?? 10;
$query = AgentPlus::where('category', 'geolocated')->where('code_dial', $dial_code)->where('etat', 1)->distinct();
if (!empty($name)) {
$query = $query->where('lastname', 'like', '%' . $name . '%')->orWhere('firstname', 'like', '%' . $name . '%');
}
if (!empty($phone)) {
$query = $query->where('phone', 'like', '%' . $phone . '%')->orWhere('transactionNumber', 'like', '%' . $phone . '%');
}
if (!empty($id)) {
$query = $query->where('id', $id);
}
$agents = $query->selectRaw('id , firstname, lastname, adresse , email , longitude , latitude , phone , transactionNumber , openHours , closeHours , solde , network, country')->paginate($perPage);
return $this->successResponse($agents);
}
} }

View File

@ -257,7 +257,10 @@ class UserGroupController extends Controller
'password' => 'required', 'password' => 'required',
'limite_credit' => 'required|numeric|min:0|not_in:0', 'limite_credit' => 'required|numeric|min:0|not_in:0',
]); ]);
$group = UsersGroup::where('code_groupe', $request->code_groupe)->firstOrFail(); $group = UsersGroup::where('code_groupe', $request->code_groupe)->first();
if (!isset($group)) {
return $this->errorResponse(trans('errors.users_group_not_found'));
}
$user = User::findOrFail($group->id_createur); $user = User::findOrFail($group->id_createur);
if (!$this->checkPassword($request->password, $user->encrypted_password, $user->salt)) if (!$this->checkPassword($request->password, $user->encrypted_password, $user->salt))
return $this->errorResponse(trans('messages.incorrect_user_password')); return $this->errorResponse(trans('messages.incorrect_user_password'));
@ -419,11 +422,17 @@ ug.date_creation as date_creation_groupe , ug.createur , ug.sponsor1 , ug.sponso
'id_user' => 'required|integer|min:0|not_in:0' 'id_user' => 'required|integer|min:0|not_in:0'
]); ]);
$group = UsersGroup::where('code_groupe', $request->code_groupe)->firstOrFail(); $group = UsersGroup::where('code_groupe', $request->code_groupe)->first();
if (!isset($group)) {
return $this->errorResponse(trans('errors.users_group_not_found'));
}
if (!$group->actif) if (!$group->actif)
return $this->errorResponse(trans('errors.group_not_active')); return $this->errorResponse(trans('errors.group_not_active'));
$sponsor = User::where('user_code', $request->code_sponsor)->firstOrFail(); $sponsor = User::where('user_code', $request->code_sponsor)->first();
if (isset($sponsor)) {
return $this->errorResponse(trans('errors.sponsor_not_found', ['id' => $request->code_sponsor]));
}
if (!in_array($sponsor->id, [$group->id_sponsor1, $group->id_sponsor2, $group->id_sponsor3])) if (!in_array($sponsor->id, [$group->id_sponsor1, $group->id_sponsor2, $group->id_sponsor3]))
return $this->errorResponse(trans('errors.sponsor_code_not_match')); return $this->errorResponse(trans('errors.sponsor_code_not_match'));
@ -488,7 +497,10 @@ ug.date_creation as date_creation_groupe , ug.createur , ug.sponsor1 , ug.sponso
$user = User::findOrFail($request->id_user); $user = User::findOrFail($request->id_user);
$country_user = $user->network->country->id; $country_user = $user->network->country->id;
$group = UsersGroup::where('code_groupe', $request->code_groupe)->firstOrFail(); $group = UsersGroup::where('code_groupe', $request->code_groupe)->first();
if (!isset($group)) {
return $this->errorResponse(trans('errors.users_group_not_found'));
}
if ($group->id_createur != $request->id_user) if ($group->id_createur != $request->id_user)
return $this->errorResponse(trans('errors.not_group_creator')); return $this->errorResponse(trans('errors.not_group_creator'));

View File

@ -84,4 +84,5 @@ Paying network : :network :country',
"wallet_not_linked_to_bank_account" => "Your wallet is not linked to a bank account", "wallet_not_linked_to_bank_account" => "Your wallet is not linked to a bank account",
"update_banking_information" => "Update your banking information", "update_banking_information" => "Update your banking information",
"wallet_already_linked_to_bank_account" => "Your wallet is already linked to your bank account", "wallet_already_linked_to_bank_account" => "Your wallet is already linked to your bank account",
"users_group_not_found" => "This group code does not exist",
]; ];

View File

@ -84,4 +84,5 @@ Réseau payeur : :network :country',
"wallet_not_linked_to_bank_account" => "Votre wallet n'est pas rattaché à un compte bancaire", "wallet_not_linked_to_bank_account" => "Votre wallet n'est pas rattaché à un compte bancaire",
"update_banking_information" => "Mettez à jour vos informations bancaires", "update_banking_information" => "Mettez à jour vos informations bancaires",
"wallet_already_linked_to_bank_account" => "Votre wallet est déjà rattaché à votre compte bancaire", "wallet_already_linked_to_bank_account" => "Votre wallet est déjà rattaché à votre compte bancaire",
"users_group_not_found" => "Ce code de groupe n'existe pas",
]; ];

View File

@ -128,8 +128,11 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
//Notifications //Notifications
$router->post('notify-new-user', 'HelperController@notifyNewUser'); $router->post('notify-new-user', 'HelperController@notifyNewUser');
//QRCode for agents //QRCode
$router->get('qrcode/generate', 'QRCodeController@generate'); $router->get('qrcode/generate', 'QRCodeController@generate');
$router->get('qrcode/read', 'QRCodeController@read'); $router->get('qrcode/read', 'QRCodeController@read');
$router->get('qrcode/image', 'QRCodeController@image'); $router->get('qrcode/image', 'QRCodeController@image');
//User
$router->post('agents', 'HelperController@getAgents');
}); });