From 2a8c2760eb96919e847ad9a7aa39bc75f6726ba6 Mon Sep 17 00:00:00 2001 From: sonyerg Date: Sun, 13 Apr 2025 20:31:53 +1200 Subject: [PATCH 1/3] test --- test/start.mjs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/start.mjs diff --git a/test/start.mjs b/test/start.mjs new file mode 100644 index 0000000..d6812f0 --- /dev/null +++ b/test/start.mjs @@ -0,0 +1,8 @@ +import { expect } from "chai"; + +it("should add numbers correctly", () => { + const num1 = 3; + const num2 = 5; + + expect(num1 + num2).to.equal(8); +}); From b7862b7b9b53888f545e5db30bfc9ccf0d116e01 Mon Sep 17 00:00:00 2001 From: sonyerg Date: Sun, 13 Apr 2025 20:32:55 +1200 Subject: [PATCH 2/3] typo --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c049e44..f11c4ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,10 +11,9 @@ jobs: container: image: node:20 steps: - - uses: actions/chackout@v3 + - uses: actions/checkout@v3 with: node-version: 20 - run: npm ci - run: npm test - run: npm run build - \ No newline at end of file From 3c55eb6bfaa93a8959d5ee6585511f8a17982c10 Mon Sep 17 00:00:00 2001 From: sonyerg Date: Thu, 17 Apr 2025 09:14:10 +1200 Subject: [PATCH 3/3] fix image not showing in product-details --- controllers/shop.js | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/controllers/shop.js b/controllers/shop.js index 683564f..c6492aa 100644 --- a/controllers/shop.js +++ b/controllers/shop.js @@ -57,25 +57,37 @@ exports.getProducts = (req, res, next) => { }); }; -exports.getProduct = (req, res, next) => { +exports.getProduct = async (req, res, next) => { const prodId = req.params.productId; - Product.findById(prodId) - .then((product) => { - if (!product) { - return res.redirect("/products"); - } - res.render("shop/product-detail", { - path: `/products`, - pageTitle: product.title, - product: product, - }); - }) - .catch((err) => { - const error = new Error(err); - error.httpStatusCode = 500; - return next(error); + try { + const product = await Product.findById(prodId); + + if (!product) { + return res.redirect("/products"); + } + + const command = new GetObjectCommand({ + Bucket: process.env.BUCKET_NAME, + Key: product.imageName, + }); + + const imageUrl = await getSignedUrl(req.s3, command, { + expiresIn: 3600, + }); + + product.imageUrl = imageUrl; + + res.render("shop/product-detail", { + path: `/products`, + pageTitle: product.title, + product: product, }); + } catch (err) { + const error = new Error(err); + error.httpStatusCode = 500; + return next(error); + } }; exports.getIndex = (req, res, next) => {