Prechádzať zdrojové kódy

Use username rather than userId

sbkwgh 8 rokov pred
rodič
commit
27a05b0b79
2 zmenil súbory, kde vykonal 5 pridanie a 5 odobranie
  1. 1 1
      routes/ban.js
  2. 4 4
      test/ban.js

+ 1 - 1
routes/ban.js

@@ -17,7 +17,7 @@ router.all('*', (req, res, next) => {
 
 router.post('/', async (req, res) => {
 	try {
-		let user = await User.findById(req.body.userId)
+		let user = await User.findOne({ where: { username: req.body.username } })
 		if(!user) throw Errors.sequelizeValidation(Sequelize, {
 			error: 'user does not exist',
 			value: req.body.userId

+ 4 - 4
test/ban.js

@@ -89,7 +89,7 @@ describe('Ban', () => {
 				.send({
 					canCreatePosts: false,
 					canCreateThreads: false,
-					userId: userAccountId,
+					username: 'useraccount',
 					message: 'ban message'
 				})
 
@@ -109,7 +109,7 @@ describe('Ban', () => {
 				.send({
 					canCreatePosts: false,
 					canCreateThreads: false,
-					userId: userAccountId,
+					username: 'useraccount',
 					message: 'ban message'
 				})
 				.end((err, res) => {
@@ -127,7 +127,7 @@ describe('Ban', () => {
 				.send({
 					canCreatePosts: false,
 					canCreateThreads: false,
-					userId: 'not an id',
+					username: 'not a user',
 					message: 'ban message'
 				})
 				.end((err, res) => {
@@ -180,7 +180,7 @@ describe('Ban', () => {
 				.send({
 					canCreatePosts: false,
 					canCreateThreads: false,
-					userId: anotherUserAccountId,
+					username: 'anotheruseraccount',
 					message: 'ban message2'
 				})
 				.end((err, res) => {