async store(req, res) { const tracking = await Tracking.create(req.body) .then(() => { res.status(200).json({ status: 200, message: 'Data insert successfully', type: 'Success' }); console.log("Data updated successfully".green); }).catch((err) => { res.status(500).json({ status: 500, message: 'Error insert data', type: 'Failure' }); console.log(err.message.red); }); }
async store (req, res) { const { email } = req.body; if (await User.findOne({ email })) { return res.status(400).json({ error: 'User already exists' }); } const user = await User.create(req.body); return res.json(user); }
async store (req, res) { const ad = await Ad.create({ ...req.body, author: req.userId }) return res.json(ad) }
async store (req, res) { const { ad, content } = req.body; const purchaseAd = await Ad.findById(ad).populate('author'); const user = await User.findById(req.userId); const purchase = await Purchase.create({ user, ad: purchaseAd, content }); // Calls the queue Queue.create(PurchaseMail.key, { ad: purchaseAd, user, content }).save(); return res.send(purchase); }
Wishlist.findOne({ user: user }, (err, foundWishlist) => { if (err) { res.status(400).json({ message: "Couldn't find user wish list", err }); } else if (foundWishlist) { let productsInWishlist = foundWishlist.items.map(item => item.product); // check if the item already in the cart // if it's there increase the quantity by 1 if (productsInWishlist.includes(item.product)) { res.status(400).json({ message: "You already added this item", err }); } else { foundWishlist.items.push(item); foundWishlist.save().then(wishlist => { res.status(200).json({ message: "Added to wish List", wishlist }); }); } } else { Wishlist.create({ user: user, items: [item] }) .then(wishlist => { res.status(200).json({ message: "Added to wish List", wishlist }); }) .catch(err => { res.status(400).json({ message: "Couldn't add to wish List", err }); }); } });
const newNotification = await Notification.create({ title, message: text,
async store(req, res){ const product = await Product.create(req.body); return res.json(product); }
async store(req, res) { const product = await Product.create(req.body); return res.json(product); }
async store(req, res){ const product = await Product.create(req.body); return res.json(product); }
async store (req, res) { const { email } = req.body if (await User.findOne({ email })) { return res.status(400).json({ error: 'User already exists' }) } const user = await User.create(req.body) return res.json(user) }
async store (req, res) { const ad = await Ad.create({ ...req.body, author: req.userId }); return res.json(ad); }
async store(req, res) { const product = await Product.create(req.body); return res.json(product); }
async store(req, res) { const product = await Product.create(req.body) return res.json(product) }
async store(req, res) { const product = await Product.create(req.body); return res.json(product); }
async store(req, res) { const product = await Product.create(req.body); return res.json(product); }