From: Dobrica Pavlinusic Date: Fri, 7 Dec 2012 15:10:25 +0000 (+0100) Subject: correctly extract regitration id from _id X-Git-Tag: 0.4~101 X-Git-Url: http://git.rot13.org/?p=angular-drzb;a=commitdiff_plain;h=c15679f515296efdd50e57430638c22532afd692 correctly extract regitration id from _id --- diff --git a/angular-server.pl b/angular-server.pl index 1daf2ef..62c2651 100755 --- a/angular-server.pl +++ b/angular-server.pl @@ -10,11 +10,7 @@ use Mojo::UserAgent; sub new_uuid { Time::HiRes::time * 100000 } -# based on -# http://docs.getangular.com/REST.Basic -# http://angular.getangular.com/data - -push @{app->static->paths}, 'app'; +push @{app->static->paths}, 'app'; # default angular-seed app directory my $couchdb = $ENV{COUCHDB} || 'http://localhost:5984'; @@ -127,12 +123,10 @@ any [ 'post' ] => '/data/:database/:entity' => sub { my $database = $self->param('database'); my $entity = $self->param('entity'); my $json = $self->req->json; - my $id = $json->{'$id'} # XXX we don't get it back from angular.js - || new_uuid; + my $id = $1 if $json->{'_id'} =~ m/^\Q$entity\E\.(.+)$/; + $id ||= new_uuid; warn "## $database $entity $id body ",dump($self->req->body, $json); - $json->{'$id'} ||= $id; # make sure $id is in there - my $new = _couchdb_put "/$database/$entity.$id" => $json; warn "new: ",dump($new); if ( $new->{ok} ) {