View | Details | Raw Unified | Return to bug 23893
Collapse All | Expand All

(-)a/Koha/Patron.pm (+24 lines)
Lines 1566-1571 sub to_api { Link Here
1566
    return $json_patron;
1566
    return $json_patron;
1567
}
1567
}
1568
1568
1569
sub attributes_from_api {
1570
    my ( $self, $attrs ) = @_;
1571
1572
    $attrs = $self->SUPER::attributes_from_api( $attrs );
1573
1574
    if ( exists $attrs->{lost} ) {
1575
        $attrs->{lost} = ($attrs->{lost}) ? 1 : 0;
1576
    }
1577
1578
    if ( exists $attrs->{ gonenoaddress} ) {
1579
        $attrs->{gonenoaddress} = ($attrs->{gonenoaddress}) ? 1 : 0;
1580
    }
1581
1582
    if ( exists $attrs->{lastseen} ) {
1583
        $attrs->{lastseen} = output_pref({ str => $attrs->{lastseen}, dateformat => 'sql' });
1584
    }
1585
1586
    if ( exists $attrs->{updated_on} ) {
1587
        $attrs->{updated_on} = output_pref({ str => $attrs->{updated_on}, dateformat => 'sql' });
1588
    }
1589
1590
    return $attrs;
1591
}
1592
1569
=head3 to_api_mapping
1593
=head3 to_api_mapping
1570
1594
1571
This method returns the mapping for representing a Koha::Patron object
1595
This method returns the mapping for representing a Koha::Patron object
(-)a/Koha/REST/V1/Patrons.pm (-7 / +3 lines)
Lines 123-131 sub add { Link Here
123
123
124
    return try {
124
    return try {
125
125
126
        my $body = _to_model( $c->validation->param('body') );
126
        my $patron = Koha::Patron->new_from_api( $c->validation->param('body') )->store;
127
128
        my $patron = Koha::Patron->new( _to_model($body) )->store;
129
127
130
        $c->res->headers->location( $c->req->url->to_string . '/' . $patron->borrowernumber );
128
        $c->res->headers->location( $c->req->url->to_string . '/' . $patron->borrowernumber );
131
        return $c->render(
129
        return $c->render(
Lines 196-206 sub update { Link Here
196
     }
194
     }
197
195
198
    return try {
196
    return try {
199
        my $body = _to_model($c->validation->param('body'));
200
197
201
        $patron->set($body)->store;
198
        $patron->set_from_api($c->validation->param('body'))->store;
202
        $patron->discard_changes;
199
        $patron->discard_changes;
203
        return $c->render( status => 200, openapi => $patron );
200
        return $c->render( status => 200, openapi => $patron->to_api );
204
    }
201
    }
205
    catch {
202
    catch {
206
        unless ( blessed $_ && $_->can('rethrow') ) {
203
        unless ( blessed $_ && $_->can('rethrow') ) {
207
- 

Return to bug 23893