Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

44 changes: 28 additions & 16 deletions controllers/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 8 additions & 0 deletions test/start.mjs
Original file line number Diff line number Diff line change
@@ -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);
});
Loading