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
e9133867
Commit
e9133867
authored
Jun 11, 2021
by
Øyvind Julsrud
Committed by
Torstein
Jun 22, 2021
Browse files
DEICH-5925
: deichman.no: added koha endpoint and updated redux model
parent
c630f820
Changes
4
Hide whitespace changes
Inline
Side-by-side
deichman.no/components/NewPatronFormAdmin/ChildPatronAdminSearch.js
View file @
e9133867
...
...
@@ -34,7 +34,7 @@ const ChildPatronAdminSearch = () => {
const
router
=
useRouter
();
const
{
date
}
=
router
.
query
;
const
dispatch
=
useDispatch
();
const
{
childP
atrons
}
=
useSelector
(
state
=>
state
.
adminSearch
);
const
{
p
atrons
}
=
useSelector
(
state
=>
state
.
adminSearch
);
const
formik
=
useFormik
({
initialValues
:
initialValues
(
date
),
...
...
@@ -115,7 +115,7 @@ const ChildPatronAdminSearch = () => {
Resultat
for
<
b
>
{
formateDate
(
date
)}
<
/b
>
<
/h2
>
<
/Block
>
{
childP
atrons
?.
length
>
0
&&
(
{
p
atrons
?.
length
>
0
&&
(
<
Block
top
=
{
4
}
>
<
Table
full
responsive
>
<
Table
.
Head
>
...
...
@@ -126,7 +126,7 @@ const ChildPatronAdminSearch = () => {
<
/Table.Row
>
<
/Table.Head
>
<
Table
.
Body
>
{
childP
atrons
.
map
((
obj
,
idx
)
=>
(
{
p
atrons
.
map
((
obj
,
idx
)
=>
(
<
Fragment
key
=
{
idx
}
>
<
Table
.
Row
>
<
Table
.
Cell
label
=
"
Navn
"
>
...
...
deichman.no/server/routes/ansatt.js
0 → 100644
View file @
e9133867
const
routes
=
require
(
"
express
"
).
Router
();
const
CALL_ID_HEADER
=
"
Deichman-CallID
"
;
const
kohaEndpoint
=
process
.
env
.
INTERNAL_URL_KOHA
;
routes
.
post
(
"
/patronsearch/findbybirthdate
"
,
async
(
request
,
response
)
=>
{
const
deichmanCallId
=
request
.
headers
[
CALL_ID_HEADER
];
const
jwtToken
=
request
.
session
.
jwt_token
;
const
{
birthdate
}
=
request
.
body
;
try
{
const
kohaResponse
=
await
fetch
(
`
${
kohaEndpoint
}
/api/patronsearch/findbybirthdate`
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json; charset=utf-8
"
,
"
Deichman-CallID
"
:
deichmanCallId
,
Authorization
:
`Bearer
${
jwtToken
}
`
},
body
:
JSON
.
stringify
({
birthdate
:
birthdate
})
}
);
if
(
kohaResponse
.
status
===
200
)
{
const
{
patrons
}
=
await
kohaResponse
.
json
();
response
.
status
(
200
).
send
(
patrons
);
}
}
catch
(
error
)
{
response
.
status
(
500
).
json
({
error
:
"
Unable to get patron
"
});
}
});
module
.
exports
=
routes
;
deichman.no/server/routes/index.js
View file @
e9133867
...
...
@@ -27,6 +27,7 @@ const resources = require("./resources");
const
registration
=
require
(
"
./registration
"
);
const
search
=
require
(
"
./search
"
);
const
unauthenticated
=
require
(
"
./unauthenticated
"
);
const
ansatt
=
require
(
"
./ansatt
"
);
// Apply Deichman-CallID: {GUID} to all requests
routes
.
use
((
req
,
res
,
next
)
=>
{
...
...
@@ -59,5 +60,6 @@ routes.use("/resources", resources);
routes
.
use
(
"
/registration
"
,
registration
);
routes
.
use
(
"
/search
"
,
search
);
routes
.
use
(
"
/unauthenticated
"
,
unauthenticated
);
routes
.
use
(
"
/ansatt
"
,
ansatt
);
module
.
exports
=
routes
;
deichman.no/store/adminSearch/index.js
View file @
e9133867
// Actions
const
GET_CHILD_PATRONS_SUCCESS
=
"
admin/CHILD_PATRONS_SUCCESS
"
;
const
GET_CHILD_PATRONS_ERROR
=
"
admin/CHILD_PATRONS_ERROR
"
;
const
dummyValues
=
[
{
name
:
"
Barn 1
"
,
category
:
"
Barn
"
,
dateOfBirth
:
"
03.08.2016
"
,
},
{
name
:
"
Barn 2
"
,
category
:
"
Selvregistrert barn
"
,
dateOfBirth
:
"
03.08.2010
"
,
},
{
name
:
"
Test testesen
"
,
category
:
"
Barn
"
,
dateOfBirth
:
"
03.01.2021
"
,
}
];
const
initialState
=
{
childP
atrons
:
[]
p
atrons
:
[]
};
// Reducer
export
default
function
reducer
(
state
=
initialState
,
action
=
{})
{
switch
(
action
.
type
)
{
case
GET_CHILD_PATRONS_SUCCESS
:
return
{
...
state
,
childP
atrons
:
action
.
result
p
atrons
:
action
.
result
};
default
:
...
...
@@ -48,15 +28,28 @@ export function getChildPatronsError(err) {
return
{
type
:
GET_CHILD_PATRONS_ERROR
,
err
};
}
export
function
fetchChildPatrons
(
date
)
{
const
formatToKohaDate
=
date
=>
{
const
[
d1
,
d2
,
m1
,
m2
,
y1
,
y2
,
y3
,
y4
]
=
date
.
split
(
""
);
return
`
${
y1
}${
y2
}${
y3
}${
y4
}
-
${
m1
}${
m2
}
-
${
d1
}${
d2
}
`
;
};
export
const
fetchChildPatrons
=
birthdate
=>
{
return
async
dispatch
=>
{
try
{
// DEBUG FETCH CALL
setTimeout
(()
=>
{
dispatch
(
getChildPatronsSuccess
(
dummyValues
));
},
100
);
const
response
=
await
fetch
(
"
/api/ansatt/patronsearch/findbybirthdate
"
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json; charset=utf-8
"
},
credentials
:
"
include
"
,
body
:
JSON
.
stringify
({
birthdate
:
formatToKohaDate
(
birthdate
)})
});
const
patrons
=
await
response
.
json
();
dispatch
(
getChildPatronsSuccess
(
patrons
));
}
catch
(
err
)
{
dispatch
(
getChildPatronsError
(
err
));
}
};
}
}
;
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