Переглянути джерело

Implement locked/unlocked thread route

sbkwgh 8 роки тому
батько
коміт
8e686265c6
1 змінених файлів з 27 додано та 0 видалено
  1. 27 0
      routes/thread.js

+ 27 - 0
routes/thread.js

@@ -91,6 +91,33 @@ router.all('*', (req, res, next) => {
 	}
 })
 
+router.put('/:thread_id', async (req, res) => {
+	try {
+		let thread = await Thread.findById(req.params.thread_id)
+
+		if(!thread) {
+			res.status(400)
+			res.json({ errors: 
+				[Errors.invalidParameter('threadId', 'thread does not exist')]
+			})
+		} else {
+			if(req.body.locked) {
+				await thread.update({ locked: true })
+			} else {
+				await thread.update({ locked: false })
+			}
+
+			res.json({ success: true })
+		}
+	} catch (e) {
+		console.log(e)
+		res.status(500)
+		res.json({
+			errors: [Errors.unknown]
+		})
+	}
+})
+
 router.post('/', async (req, res) => {
 	let validationErrors = []