|
Lines 205-210
const insertSampleHold = async ({
Link Here
|
| 205 |
return { hold, patron }; |
205 |
return { hold, patron }; |
| 206 |
}; |
206 |
}; |
| 207 |
|
207 |
|
|
|
208 |
const insertSampleCheckout = async ({ baseUrl, authHeader }) => { |
| 209 |
const { biblio, items, libraries, item_type } = await insertSampleBiblio({ |
| 210 |
item_count: 1, |
| 211 |
baseUrl, |
| 212 |
authHeader, |
| 213 |
}); |
| 214 |
const generatedPatron = await buildSampleObject({ |
| 215 |
object: "patron", |
| 216 |
values: { |
| 217 |
library_id: libraries[0].library_id, |
| 218 |
incorrect_address: null, |
| 219 |
patron_card_lost: null, |
| 220 |
}, |
| 221 |
baseUrl, |
| 222 |
authHeader, |
| 223 |
}); |
| 224 |
|
| 225 |
const patron = await insertObject({ |
| 226 |
type: "patron", |
| 227 |
object: generatedPatron, |
| 228 |
baseUrl, |
| 229 |
authHeader, |
| 230 |
}); |
| 231 |
|
| 232 |
const generatedCheckout = buildSampleObject({ |
| 233 |
object: "checkout", |
| 234 |
values: { |
| 235 |
patron_id: patron.patron_id, |
| 236 |
item_id: items[0].item_id, |
| 237 |
}, |
| 238 |
}); |
| 239 |
delete generatedCheckout.external_id; |
| 240 |
const checkout = await insertObject({ |
| 241 |
type: "checkout", |
| 242 |
object: generatedCheckout, |
| 243 |
baseUrl, |
| 244 |
authHeader, |
| 245 |
}); |
| 246 |
return { biblio, items, libraries, item_type, patron, checkout }; |
| 247 |
}; |
| 248 |
|
| 208 |
const deleteSampleObjects = async allObjects => { |
249 |
const deleteSampleObjects = async allObjects => { |
| 209 |
if (!Array.isArray(allObjects)) { |
250 |
if (!Array.isArray(allObjects)) { |
| 210 |
allObjects = [allObjects]; |
251 |
allObjects = [allObjects]; |
|
Lines 212-217
const deleteSampleObjects = async allObjects => {
Link Here
|
| 212 |
|
253 |
|
| 213 |
const pluralMap = { |
254 |
const pluralMap = { |
| 214 |
hold: "holds", |
255 |
hold: "holds", |
|
|
256 |
checkout: "checkouts", |
| 215 |
patron: "patrons", |
257 |
patron: "patrons", |
| 216 |
item: "items", |
258 |
item: "items", |
| 217 |
biblio: "biblios", |
259 |
biblio: "biblios", |
|
Lines 237-242
const deleteSampleObjects = async allObjects => {
Link Here
|
| 237 |
|
279 |
|
| 238 |
const deletionOrder = [ |
280 |
const deletionOrder = [ |
| 239 |
"holds", |
281 |
"holds", |
|
|
282 |
"checkouts", |
| 240 |
"patrons", |
283 |
"patrons", |
| 241 |
"items", |
284 |
"items", |
| 242 |
"biblios", |
285 |
"biblios", |
|
Lines 280-285
const deleteSampleObjects = async allObjects => {
Link Here
|
| 280 |
values: ids, |
323 |
values: ids, |
| 281 |
}); |
324 |
}); |
| 282 |
break; |
325 |
break; |
|
|
326 |
case "checkouts": |
| 327 |
ids = objects.map(i => i.checkout_id); |
| 328 |
await query({ |
| 329 |
sql: `DELETE FROM issues WHERE issue_id IN (${ids.map(() => "?").join(",")})`, |
| 330 |
values: ids, |
| 331 |
}); |
| 332 |
break; |
| 283 |
case "item_types": |
333 |
case "item_types": |
| 284 |
ids = objects.map(i => i.item_type_id); |
334 |
ids = objects.map(i => i.item_type_id); |
| 285 |
await query({ |
335 |
await query({ |
|
Lines 431-436
const insertObject = async ({ type, object, baseUrl, authHeader }) => {
Link Here
|
| 431 |
baseUrl, |
481 |
baseUrl, |
| 432 |
authHeader, |
482 |
authHeader, |
| 433 |
}); |
483 |
}); |
|
|
484 |
} else if (type == "checkout") { |
| 485 |
const { issuer, patron, ...checkout } = object; |
| 486 |
|
| 487 |
return apiPost({ |
| 488 |
endpoint: "/api/v1/checkouts", |
| 489 |
body: checkout, |
| 490 |
baseUrl, |
| 491 |
authHeader, |
| 492 |
}); |
| 434 |
} else { |
493 |
} else { |
| 435 |
throw Error(`Unsupported object type '${type}' to insert`); |
494 |
throw Error(`Unsupported object type '${type}' to insert`); |
| 436 |
} |
495 |
} |
|
Lines 441-446
const insertObject = async ({ type, object, baseUrl, authHeader }) => {
Link Here
|
| 441 |
module.exports = { |
500 |
module.exports = { |
| 442 |
insertSampleBiblio, |
501 |
insertSampleBiblio, |
| 443 |
insertSampleHold, |
502 |
insertSampleHold, |
|
|
503 |
insertSampleCheckout, |
| 444 |
insertObject, |
504 |
insertObject, |
| 445 |
deleteSampleObjects, |
505 |
deleteSampleObjects, |
| 446 |
}; |
506 |
}; |
| 447 |
- |
|
|