pengontrol bereaksi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Product from "../models/productModel.js";
export const getAllProducts = async (req, res) => {
try {
const products = await Product.findAll();
res.json(products);
} catch (error) {
res.json({ message: error.message });
}
}
export const getProductById = async (req, res) => {
try {
const product = await Product.findAll({
where: {
id: req.params.id
}
});
res.json(product[0]);
} catch (error) {
res.json({ message: error.message });
}
}
export const createProduct = async (req, res) => {
try {
await Product.create(req.body);
res.json({
"message": "Product Created"
});
} catch (error) {
res.json({ message: error.message });
}
}
export const updateProduct = async (req, res) => {
try {
await Product.update(req.body, {
where: {
id: req.params.id
}
});
res.json({
"message": "Product Updated"
});
} catch (error) {
res.json({ message: error.message });
}
}
export const deleteProduct = async (req, res) => {
try {
await Product.destroy({
where: {
id: req.params.id
}
});
res.json({
"message": "Product Deleted"
});
} catch (error) {
res.json({ message: error.message });
}
}
Panicky Pony