Server IP : 162.213.251.212 / Your IP : 3.17.76.80 [ Web Server : LiteSpeed System : Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : allssztx ( 535) PHP Version : 8.1.31 Disable Function : NONE Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/allssztx/clarkesmusicservices.com/routes/ |
Upload File : |
const express = require("express") const Music = require("../schema/Music") const router = express.Router() router.post('/like', async (req, res) => { try { const { user, music } = req.body console.log('req.body', req.body) const musicObj = await Music.findById(music) if (musicObj) { if (!musicObj.likes.includes(user)) { musicObj.likes.push(user) await musicObj.save() return res.json({ success: true, music: musicObj }) } return res.json({ success: false, error: 'Already Liked by You!' }) } return res.json({ success: false, error: 'Something Went Wrong' }) } catch (error) { return res.json({ success: false, error: error.message }) } }) router.post('/unlike', async (req, res) => { try { const { user, music } = req.body console.log('req.body', req.body) const musicObj = await Music.findById(music) if (musicObj) { if (musicObj.likes.includes(user)) { const index = musicObj.likes.indexOf(user) musicObj.splice(index, 1) await musicObj.save() return res.json({ success: true, music: musicObj }) } return res.json({ success: false, error: 'Not Liked by You!' }) } return res.json({ success: false, error: 'Something Went Wrong' }) } catch (error) { return res.json({ success: false, error: error.message }) } }) module.exports = router