Forráskód Böngészése

Return ban instance with associated User object

sbkwgh 8 éve
szülő
commit
9daa227cd0
2 módosított fájl, 9 hozzáadás és 1 törlés
  1. 8 1
      routes/ban.js
  2. 1 0
      test/ban.js

+ 8 - 1
routes/ban.js

@@ -30,7 +30,14 @@ router.post('/', async (req, res) => {
 		})
 		await ban.setUser(user)
 
-		res.json(ban.toJSON())
+		let ret = await ban.reload({
+			include: [{
+				model: User,
+				attributes: ['username', 'description', 'color', 'createdAt']
+			}]
+		})
+		
+		res.json(ret.toJSON())
 	} catch (e) {
 		if(e instanceof Sequelize.ValidationError) {
 			res.status(400)

+ 1 - 0
test/ban.js

@@ -95,6 +95,7 @@ describe('Ban', () => {
 
 			res.should.be.json
 			res.should.have.status(200)
+			res.body.should.have.deep.property('User.username', 'useraccount')
 
 			let ban = await Ban.findById(1)
 			ban.should.have.property('canCreatePosts', false)