Selaa lähdekoodia

Use instance field this.Posts instead of passing in posts

sbkwgh 8 vuotta sitten
vanhempi
commit
2b464acc37
2 muutettua tiedostoa jossa 4 lisäystä ja 3 poistoa
  1. 3 2
      models/thread.js
  2. 1 1
      routes/thread.js

+ 3 - 2
models/thread.js

@@ -20,9 +20,10 @@ module.exports = (sequelize, DataTypes) => {
 		}
 	}, {
 		instanceMethods: {
-			async getMeta (limit, posts) {
+			async getMeta (limit) {
 				let meta = {}
-
+				
+				let posts = this.Posts
 				let firstPost = posts[0]
 				let lastPost = posts.slice(-1)[0]
 

+ 1 - 1
routes/thread.js

@@ -13,7 +13,7 @@ router.get('/:thread_id', async (req, res) => {
 		}) 
 		if(!thread) throw Errors.invalidParameter('id', 'thread does not exist')
 		
-		let meta = await thread.getMeta(limit, thread.Posts)
+		let meta = await thread.getMeta(limit)
 
 		res.json(Object.assign( thread.toJSON(), { meta } ))