Skip to content

Commit

Permalink
[notifications] Fix a bug on the notification registration
Browse files Browse the repository at this point in the history
  • Loading branch information
LaercioSantana committed Oct 9, 2016
1 parent b2c325a commit 1751710
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 0 additions & 3 deletions application/controllers/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ function registerNotification($idRoute){
$this->loadModel();
$result = $this->messages_model->insertNotificationRegistration($registry);

if(!$result)//exist conflict registry
return $this->makeJsonRespose(["error" => "CONFLICT"], 409);

return $this->makeJsonRespose($registry, 201);
}else
return $this->makeJsonRespose($validator->errors, 400);
Expand Down
16 changes: 12 additions & 4 deletions application/models/Messages_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ public function insertNotificationRegistration($notificationRegistration){
$registry->id_routes = $notificationRegistration->id_routes;
$registry->registration_token_firebase = $notificationRegistration->registration_token_firebase;

$this->db->insert(self::registeredNotificationsTable, $registry);

if($this->db->affected_rows() < 1)
return false;
//check if existing entry
$search = $this->db->select("email")
->from(self::registeredNotificationsTable)
->where("email = '{$registry->email}' AND id_routes = '$notificationRegistration->id_routes'")
->get()->result();

if(count($search) < 1)//insert
$this->db->insert(self::registeredNotificationsTable, $registry);
else{//update only firebase token
$this->db->where("email = '{$registry->email}' AND id_routes = '$notificationRegistration->id_routes'");
$this->db->update(self::registeredNotificationsTable, array("registration_token_firebase" => $notificationRegistration->registration_token_firebase));
}

return true;

Expand Down

0 comments on commit 1751710

Please sign in to comment.