correctly extract regitration id from _id
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 7 Dec 2012 15:10:25 +0000 (16:10 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 7 Dec 2012 15:10:25 +0000 (16:10 +0100)
angular-server.pl

index 1daf2ef..62c2651 100755 (executable)
@@ -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} ) {