|
Lines 212-217
const insertSampleHold = async ({
Link Here
|
| 212 |
return { hold, patron }; |
212 |
return { hold, patron }; |
| 213 |
}; |
213 |
}; |
| 214 |
|
214 |
|
|
|
215 |
const insertSampleCheckout = async ({ baseUrl, authHeader }) => { |
| 216 |
let client = APIClient.default; |
| 217 |
|
| 218 |
const { biblio, items, libraries, item_type } = await insertSampleBiblio({ |
| 219 |
item_count: 1, |
| 220 |
baseUrl, |
| 221 |
authHeader, |
| 222 |
}); |
| 223 |
const generatedPatron = await buildSampleObject({ |
| 224 |
object: "patron", |
| 225 |
values: { |
| 226 |
library_id: libraries[0].library_id, |
| 227 |
incorrect_address: null, |
| 228 |
patron_card_lost: null, |
| 229 |
}, |
| 230 |
baseUrl, |
| 231 |
authHeader, |
| 232 |
}); |
| 233 |
|
| 234 |
const patron = await insertObject({ |
| 235 |
type: "patron", |
| 236 |
object: generatedPatron, |
| 237 |
baseUrl, |
| 238 |
authHeader, |
| 239 |
}); |
| 240 |
|
| 241 |
const generatedCheckout = buildSampleObject({ |
| 242 |
object: "checkout", |
| 243 |
values: { |
| 244 |
patron_id: patron.patron_id, |
| 245 |
item_id: items[0].item_id, |
| 246 |
}, |
| 247 |
}); |
| 248 |
delete generatedCheckout.external_id; |
| 249 |
const checkout = await insertObject({ |
| 250 |
type: "checkout", |
| 251 |
object: generatedCheckout, |
| 252 |
baseUrl, |
| 253 |
authHeader, |
| 254 |
}); |
| 255 |
return { biblio, items, libraries, item_type, patron, checkout }; |
| 256 |
}; |
| 257 |
|
| 215 |
const deleteSampleObjects = async allObjects => { |
258 |
const deleteSampleObjects = async allObjects => { |
| 216 |
if (!Array.isArray(allObjects)) { |
259 |
if (!Array.isArray(allObjects)) { |
| 217 |
allObjects = [allObjects]; |
260 |
allObjects = [allObjects]; |
|
Lines 219-224
const deleteSampleObjects = async allObjects => {
Link Here
|
| 219 |
|
262 |
|
| 220 |
const deletionOrder = [ |
263 |
const deletionOrder = [ |
| 221 |
"hold", |
264 |
"hold", |
|
|
265 |
"checkout", |
| 222 |
"patron", |
266 |
"patron", |
| 223 |
"item", |
267 |
"item", |
| 224 |
"items", |
268 |
"items", |
|
Lines 276-281
const deleteSampleObjects = async allObjects => {
Link Here
|
| 276 |
values: [objects[type].hold_id], |
320 |
values: [objects[type].hold_id], |
| 277 |
}); |
321 |
}); |
| 278 |
break; |
322 |
break; |
|
|
323 |
case "checkout": |
| 324 |
await query({ |
| 325 |
sql: "DELETE FROM issues WHERE issue_id = ?", |
| 326 |
values: [objects[type].checkout_id], |
| 327 |
}); |
| 328 |
break; |
| 279 |
case "item_type": |
329 |
case "item_type": |
| 280 |
await query({ |
330 |
await query({ |
| 281 |
sql: "DELETE FROM itemtypes WHERE itemtype = ?", |
331 |
sql: "DELETE FROM itemtypes WHERE itemtype = ?", |
|
Lines 289-295
const deleteSampleObjects = async allObjects => {
Link Here
|
| 289 |
}); |
339 |
}); |
| 290 |
break; |
340 |
break; |
| 291 |
default: |
341 |
default: |
| 292 |
console.log( |
342 |
throw Error( |
| 293 |
`Not implemented yet: cannot deleted object '${type}'` |
343 |
`Not implemented yet: cannot deleted object '${type}'` |
| 294 |
); |
344 |
); |
| 295 |
} |
345 |
} |
|
Lines 438-445
const insertObject = async ({ type, object, baseUrl, authHeader }) => {
Link Here
|
| 438 |
}, |
488 |
}, |
| 439 |
body: hold, |
489 |
body: hold, |
| 440 |
}); |
490 |
}); |
|
|
491 |
} else if (type == "checkout") { |
| 492 |
const { issuer, patron, ...checkout } = object; |
| 493 |
|
| 494 |
return client.koha.post({ |
| 495 |
endpoint: `${baseUrl}/api/v1/checkouts`, |
| 496 |
headers: { |
| 497 |
"Content-Type": "application/json", |
| 498 |
Authorization: authHeader, |
| 499 |
}, |
| 500 |
body: checkout, |
| 501 |
}); |
| 441 |
} else { |
502 |
} else { |
| 442 |
return false; |
503 |
throw Error(`Unsupported object type '${type}' to insert`); |
| 443 |
} |
504 |
} |
| 444 |
|
505 |
|
| 445 |
return true; |
506 |
return true; |
|
Lines 448-453
const insertObject = async ({ type, object, baseUrl, authHeader }) => {
Link Here
|
| 448 |
module.exports = { |
509 |
module.exports = { |
| 449 |
insertSampleBiblio, |
510 |
insertSampleBiblio, |
| 450 |
insertSampleHold, |
511 |
insertSampleHold, |
|
|
512 |
insertSampleCheckout, |
| 451 |
insertObject, |
513 |
insertObject, |
| 452 |
deleteSampleObjects, |
514 |
deleteSampleObjects, |
| 453 |
}; |
515 |
}; |
| 454 |
- |
|
|