(partId: number, quantity: number)
| 368 | } |
| 369 | |
| 370 | async function updatePartQuantity(partId: number, quantity: number) { |
| 371 | setLoading(true); |
| 372 | try { |
| 373 | const res = await fetch("/api/parts/update", { |
| 374 | method: "POST", |
| 375 | body: JSON.stringify({ id: partId, quantity }), |
| 376 | }).then((response) => |
| 377 | response |
| 378 | .json() |
| 379 | .then((data) => ({ status: response.status, body: data })) |
| 380 | ); |
| 381 | if (res.status !== 200) { |
| 382 | throw new Error(res.body.message); |
| 383 | } |
| 384 | console.log(res.body); |
| 385 | if (res.status == 200) { |
| 386 | notifications.show({ |
| 387 | title: "Quantity Updated", |
| 388 | message: `The quantity of ${res.body.body.productCode} was successfully updated to ${quantity}!`, |
| 389 | }); |
| 390 | updatePartInState(res.body.body); |
| 391 | } |
| 392 | } catch (e: ErrorCallback | any) { |
| 393 | console.error(e.message); |
| 394 | } |
| 395 | setLoading(false); |
| 396 | } |
| 397 | |
| 398 | async function navigatePage(page: number) { |
| 399 | setPage(page); |
no test coverage detected