Simplify valid_id helper

master
Daniel Berteaud 10 years ago
parent b7924cbf2f
commit 42a8962fdd
  1. 15
      vroom.pl

@ -104,9 +104,9 @@ helper valid_id => sub {
my $self = shift; my $self = shift;
my ($id) = @_; my ($id) = @_;
if ($id !~ m/^\d+$/){ if ($id !~ m/^\d+$/){
return {msg => 'INVALID_ID'}; return 0;
} }
return {ok => 1}; return 1;
}; };
########################## ##########################
@ -227,9 +227,8 @@ helper get_room_by_name => sub {
helper get_room_by_id => sub { helper get_room_by_id => sub {
my $self = shift; my $self = shift;
my ($id) = @_; my ($id) = @_;
my $res = $self->valid_id($id); if (!$self->valid_id($id)){
if (!$res->{ok}){ return 0;
return $res;
} }
my $sth = eval { my $sth = eval {
$self->db->prepare('SELECT * $self->db->prepare('SELECT *
@ -253,10 +252,8 @@ helper get_room_by_id => sub {
helper modify_room => sub { helper modify_room => sub {
my $self = shift; my $self = shift;
my ($room) = @_; my ($room) = @_;
my $res = {}; if (!$self->valid_id($room->{id})){
$res = $self->valid_id($room->{id}); return 0;
if (!$res->{ok}){
return $res;
} }
if (!$self->valid_room_name($room->{name})){ if (!$self->valid_room_name($room->{name})){
return 0; return 0;

Loading…
Cancel
Save