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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const Promotion = require("../../models/promotion");
exports.addpromotion = async (req, res) => {
try {
const addpromotionData = req.body;
console.log(addpromotionData);
await Promotion.create(addpromotionData);
res.send("create");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.getPromotion = async (req, res) => {
try {
let promotion = await Promotion.findAll();
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.deletePromotion = async (req, res) => {
try {
const promotionId = req.params.shopId;
await Promotion.destroy({
where: {
id: promotionId
}
});
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.getPromotionId = async (req, res) => {
try {
const promotionId = req.params.id;
let promotion = await Promotion.findOne({
where: {
id: promotionId
}
});
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.getUserId = async (req, res) => {
try {
const userId = req.params.id;
let promotion = await Promotion.findOne({
where: {
id: userId
}
});
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.updatePromotion = async (req, res) => {
try {
const promotionData = req.body;
const id = req.params.id;
await promotion.update(promotionData, { where: { id: id } });
res.status(200).send({ status: "done" });
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};