Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
digibib
deichman
Commits
e5299844
Commit
e5299844
authored
Jun 09, 2021
by
Petter Goksøyr Åsen
Committed by
Petter Goksøyr Åsen
Jun 10, 2021
Browse files
DEICH-5941
add endpoint to search patrons by birthdate
Limited to patrons below upper age limit on children (<15 year olds)
parent
4918e70f
Changes
4
Hide whitespace changes
Inline
Side-by-side
koha/Deichman/Patron.pm
View file @
e5299844
...
...
@@ -97,6 +97,33 @@ sub Find {
return
$self
;
}
sub
FindByBirthdate
{
my
(
$self
,
$birthdate
)
=
@_
;
my
$dbh
=
$self
->
dbh
;
my
$q
=
"
WITH t AS (SELECT upperagelimit from categories where categorycode = 'B')
SELECT
dateofbirth,
TIMESTAMPDIFF(YEAR, dateofbirth, CURDATE()) AS age,
CONCAT(surname, ', ', firstname) AS name,
categorycode
FROM borrowers, t
WHERE
deleted_at IS NULL AND
dateofbirth = ? AND
TIMESTAMPDIFF(YEAR, dateofbirth, CURDATE()) < t.upperagelimit
";
my
$sth
=
$dbh
->
prepare
(
$q
);
warn
"
a
";
$sth
->
execute
(
$birthdate
)
or
Deichman::Exception::
Patron
->
throw
(
$dbh
->
errstr
);
warn
"
b
";
my
@patrons
;
while
(
my
$p
=
$sth
->
fetchrow_hashref
)
{
push
@patrons
,
$p
;
}
$self
->
{
patrons
}
=
\
@patrons
;
return
$self
;
}
sub
GetByCardNumber
{
my
(
$self
,
$cardnumber
)
=
@_
;
$cardnumber
or
Deichman::Exception::Patron::
NotFound
->
throw
();
...
...
koha/api/Auth.pm
View file @
e5299844
...
...
@@ -219,6 +219,7 @@ sub PermissionsEnabledPath {
["
/purresak/
",
["
superlibrarian
","
borrowers
"]],
["
/reserves/
",
["
superlibrarian
","
borrowers
"]],
["
/reports
",
["
superlibrarian
","
circulate
"]],
["
/patronsearch
",
["
superlibrarian
",
"
borrowers
"]],
);
foreach
my
$p
(
@paths
)
{
if
(
$path
and
substr
(
$path
,
0
,
length
(
$p
->
[
0
]))
eq
$p
->
[
0
])
{
...
...
koha/api/RESTAPI.pm
View file @
e5299844
...
...
@@ -108,6 +108,7 @@ mount "RESTAPI::Patron::PasswordRecovery";
mount
"
RESTAPI::Patron::Payment
";
mount
"
RESTAPI::Patron::Reserve
";
mount
"
RESTAPI::Patron::ValidatePIN
";
mount
"
RESTAPI::Patron::Search
";
mount
"
RESTAPI::PickList
";
mount
"
RESTAPI::PrintSlip
";
mount
"
RESTAPI::Reports
";
...
...
koha/api/RESTAPI/Patron/Search.pm
0 → 100644
View file @
e5299844
package
RESTAPI::Patron::
Search
;
use
strict
;
use
warnings
;
use
Raisin::
API
;
use
HTTP::
Status
qw(:constants)
;
use
Types::
Standard
qw(HashRef Any Int Str)
;
use
Try::
Tiny
;
use
Deichman::
Patron
;
use
Deichman::
Exception
;
desc
"
Patron search
";
resource
patronsearch
=>
sub
{
resource
findbybirthdate
=>
sub
{
params
(
requires
("
birthdate
",
type
=>
Str
,
desc
=>
"
patron birthdate in the format: %YYYY-%mm-%dd
"),
);
post
sub
{
warn
"
yo der
";
my
$params
=
shift
;
my
$p
=
Deichman::
Patron
->
new
()
->
FindByBirthdate
(
$params
->
{
birthdate
});
try
{
{
patrons
=>
$p
->
{
patrons
}
}
}
catch
{
app
->
logg
(
error
=>
$_
->
description
);
res
->
status
(
HTTP_INTERNAL_SERVER_ERROR
);
};
};
};
};
1
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment