(pc: string, quantity: number)
| 281 | } |
| 282 | |
| 283 | async function getPartInfoFromLCSC(pc: string, quantity: number) { |
| 284 | // fetch part info from LCSC |
| 285 | // return part info |
| 286 | try { |
| 287 | const res = await fetch("/api/parts", { |
| 288 | method: "POST", |
| 289 | body: JSON.stringify({ pc: pc, quantity }), |
| 290 | }).then((response) => |
| 291 | response |
| 292 | .json() |
| 293 | .then((data) => ({ status: response.status, body: data })) |
| 294 | ); |
| 295 | if (res.status !== 200) { |
| 296 | throw new Error(res.body.message); |
| 297 | } |
| 298 | if (res.body.message == "Part updated") { |
| 299 | notifications.show({ |
| 300 | title: "Part Updated", |
| 301 | message: `The quantity of the part (${res.body.body.productCode}) was successfully updated to ${res.body.body.quantity}!`, |
| 302 | }); |
| 303 | updatePartInState(res.body.body); |
| 304 | } |
| 305 | if (res.body.message == "Part created") { |
| 306 | notifications.show({ |
| 307 | title: "Part Added", |
| 308 | message: `The part ${res.body.body.productCode} was successfully added!`, |
| 309 | }); |
| 310 | console.log("PART CREATED"); |
| 311 | // if(Math.ceil(itemCountState / itemsPerPage) > Math.ceil(res.body.itemCount)) { |
| 312 | |
| 313 | getParts(activePage); |
| 314 | setParentCatalogNamesState( |
| 315 | res.body.parentCatalogNames |
| 316 | .filter((item) => item.parentCatalogName !== null) |
| 317 | .map((item) => item.parentCatalogName) |
| 318 | ); |
| 319 | setItemCountState(res.body.itemCount); |
| 320 | } |
| 321 | // console.log(res.body); |
| 322 | // await getParts(); |
| 323 | } catch (e: ErrorCallback | any) { |
| 324 | console.error(e.message); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | async function deletePart(partId: number) { |
| 329 | // setLoading(true) |
no test coverage detected