2024-07-05: first commit
2024-07-10: revise list organization to enhance readability
-
callhandler
-
call fetchHandler
- call fetchFlyerList
- return flyer list, throw error if failed
- for each flyer, call fetchProductDetailsHandler
- call extractProductCodeList
- return all product code list extracted from flyer
- call fetchProductDetailsList
- return product details of the all product from product code list
- return product details list / null
- return null if caught error
- call extractProductCodeList
- push flyer to new filtered flyer list and assign fetched product details list to flyer only if the fetched product details list is not null / empty
- throw error if all fetched product list are null / empty
- throw error if caught error
- return filtered flyer list each with list of product details
- call fetchFlyerList
-
for each fetched flyer call parseAndUpdate
- database connection : Avien MySQL DataBase with Drizzle ORM using db
- call parseFlyer
- return parsed flyer data / null
- return false if failed to parse flyer as no information for further action
- call processFlyer
- call getFlyerID
- return exsiting flyerID / null
- return exsiting flyerID and isNew = false if existed flyer
- call addFlyer
- return new flyer id / null
- return exsiting flyerID and isNew = false
- return null and isNew = false if caught error
- call getFlyerID
- return false if fail to process flyer
- call processFlyerStore
- call getStoreID
- return if store is not in database
- otherwise, call addFlyerStore
- no return as all operations done by Drizzle ORM
- call getStoreID
- return false if flyer already existed (isNew = false)
- for each productdetail object from the flyer's productDetailsList call parseAndUpdateProduct
- call parseProduct
- return parsed product data or return null if caught error
- call parsePriceHistory
- return parsed price data or return null if caught error
- call parsePointHistory
- return parsed point data or return null if caught error
- return false if fail to parse product
- call processProduct
- call getProductID
- return exsiting product ID / null
- return exsiting product ID if existed product
- call addProduct
- call handleImage
- return uploaded image url (host by cloundinary)
- return new product id / null
- call handleImage
- return new product id / null
- call getProductID
- return false if fail to process product
- call processPriceHistory if price data successfully parsed
- call getPriceHistoryID
- return exsiting price ID / null
- return exsiting price ID if existed price record
- call addPriceHistory
- return new price id / null
- return new price id / null
- call getPriceHistoryID
- call processPointHistory if price data successfully parsed
- call getPointHistoryID
- return exsiting point ID / null
- return exsiting point ID if existed point record
- call addPointHistory
- return new point id / null
- return new point id / null
- call getPointHistoryID
- return true or return false if caught error
- call parseProduct
- return false if all fail to parse and update product
- return true or return false if caught error
-
throw error if all flyers are fail to parse and update product
-
catch and throw error