+ Add groups demande validation routes
This commit is contained in:
parent
34c754a53e
commit
f9289f2228
|
@ -114,7 +114,7 @@ class NanoCreditController extends Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateGroup(Request $request)
|
public function validateGroupDemand(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'id_demande' => 'required|integer|min:0|not_in:0',
|
'id_demande' => 'required|integer|min:0|not_in:0',
|
||||||
|
@ -155,8 +155,9 @@ class NanoCreditController extends Controller
|
||||||
$demande->save();
|
$demande->save();
|
||||||
// Notififier le createur
|
// Notififier le createur
|
||||||
$data = new \stdClass();
|
$data = new \stdClass();
|
||||||
$data->item = "accepted_user_group_validation";
|
$data->screen = "notificationview";
|
||||||
$data->id_group = $group->id;
|
$data->data = new \stdClass();;
|
||||||
|
$data->data->id = $request->id_demande;
|
||||||
$this->sendPushNotificationToUser($group->createur->user_code,
|
$this->sendPushNotificationToUser($group->createur->user_code,
|
||||||
trans('notifications.accepted_group_validation_request', ['name' => $sponsor->lastname . ' ' . $sponsor->firstname]), $data);
|
trans('notifications.accepted_group_validation_request', ['name' => $sponsor->lastname . ' ' . $sponsor->firstname]), $data);
|
||||||
|
|
||||||
|
@ -266,22 +267,45 @@ class NanoCreditController extends Controller
|
||||||
$demande->save();
|
$demande->save();
|
||||||
|
|
||||||
$data = new \stdClass();
|
$data = new \stdClass();
|
||||||
$data->item = "user_group_validation";
|
$data->screen = "demandeValidationGroupe";
|
||||||
$data->id_demande = $demande->id;
|
$data->data = new \stdClass();
|
||||||
|
$data->data->id = $demande->id;
|
||||||
|
|
||||||
$this->sendPushNotificationToUser($sponsor_code,
|
$this->sendPushNotificationToUser($sponsor_code,
|
||||||
trans('notifications.group_validation_request', ['name' => $sender->lastname . ' ' . $sender->firstname]), $data);
|
trans('notifications.group_validation_request', ['name' => $sender->lastname . ' ' . $sender->firstname]), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getGroupDemand($id_demand)
|
||||||
|
{
|
||||||
|
|
||||||
|
$demand = collect(DB::select('SELECT * FROM users_groups_demandes_validations ugd
|
||||||
|
INNER JOIN infos_users_groups ug ON ug.id = ugd.id_group WHERE ugd.id = :id;', ['id' => $id_demand]))->first();
|
||||||
|
if ($demand)
|
||||||
|
return $this->successResponse($demand);
|
||||||
|
else
|
||||||
|
return $this->errorResponse(trans('errors.model_not_found', ['model' => 'groupValidationDemand']), Response::HTTP_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllGroupDemand($id_user)
|
||||||
|
{
|
||||||
|
|
||||||
|
$demands = DB::select('SELECT * FROM users_groups_demandes_validations ugd
|
||||||
|
INNER JOIN infos_users_groups ug ON ug.id = ugd.id_group WHERE ugd.id_sponsor = :id;', ['id' => $id_user]);
|
||||||
|
|
||||||
|
return $this->successResponse($demands);
|
||||||
|
}
|
||||||
|
|
||||||
private function checkSponsorIdentification($code_sponsor, $id, $init_country)
|
private function checkSponsorIdentification($code_sponsor, $id, $init_country)
|
||||||
{
|
{
|
||||||
$sponsor = User::where('user_code', $code_sponsor)->first();
|
$sponsor = User::where('user_code', $code_sponsor)->first();
|
||||||
|
if ($sponsor) {
|
||||||
//Verifier s'il appartient a un groupe
|
//Verifier s'il appartient a un groupe
|
||||||
if (isset($sponsor->group_id))
|
if (isset($sponsor->group_id))
|
||||||
return $this->errorResponse(trans('errors.sponsor_belongs_to_group', ['id' => $id]));
|
return $this->errorResponse(trans('errors.sponsor_belongs_to_group', ['id' => $id]));
|
||||||
$sponsor_country = $sponsor->network->country->id;
|
$sponsor_country = $sponsor->network->country->id;
|
||||||
if ($init_country != $sponsor_country)
|
if ($init_country != $sponsor_country)
|
||||||
return $this->errorResponse(trans('errors.sponsor_not_registered_in_same_country', ['id' => $id]));
|
return $this->errorResponse(trans('errors.sponsor_not_registered_in_same_country', ['id' => $id]));
|
||||||
if ($sponsor) {
|
|
||||||
return $this->checkUserIdentification($sponsor->id, $id);
|
return $this->checkUserIdentification($sponsor->id, $id);
|
||||||
} else {
|
} else {
|
||||||
return $this->errorResponse(trans('errors.sponsor_not_found', ['id' => $id]));
|
return $this->errorResponse(trans('errors.sponsor_not_found', ['id' => $id]));
|
||||||
|
|
|
@ -72,6 +72,13 @@ $router->group(['prefix' => '/identifications'], function () use ($router) {
|
||||||
// Users groups routes
|
// Users groups routes
|
||||||
$router->group(['prefix' => '/groups'], function () use ($router) {
|
$router->group(['prefix' => '/groups'], function () use ($router) {
|
||||||
$router->post('', 'NanoCreditController@createGroup');
|
$router->post('', 'NanoCreditController@createGroup');
|
||||||
$router->put('', 'NanoCreditController@validateGroup');
|
$router->put('', 'NanoCreditController@updateGroup');
|
||||||
$router->post('update', 'NanoCreditController@updateGroup');
|
|
||||||
|
// Demandes de validation
|
||||||
|
$router->group(['prefix' => '/demands'], function () use ($router) {
|
||||||
|
$router->get('{id_demand}', 'NanoCreditController@getGroupDemand');
|
||||||
|
$router->get('all/{id_user}', 'NanoCreditController@getAllGroupDemand');
|
||||||
|
$router->post('validate', 'NanoCreditController@validateGroupDemand');
|
||||||
|
$router->post('cancel', 'NanoCreditController@cancelGroupDemand');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue