Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Invalid position given by 'W033' #831

Open
Dadda97 opened this issue Aug 3, 2020 · 0 comments
Open

Invalid position given by 'W033' #831

Dadda97 opened this issue Aug 3, 2020 · 0 comments

Comments

@Dadda97
Copy link

Dadda97 commented Aug 3, 2020

JSHint returned a point that did not exist in the document being edited.
Rule: W033
Requested point: 21:47

var http = require('http');
var mysql = require('mysql')
var url = require('url')
const headers = {
	"Content-Type": "application/json"
}

const db_connection = mysql.createPool({
	connectionLimit: 10,
	host: 'db',
	user: 'node',
	password: 'password',
	database: 'node'
});

// db_connection.connect();

//create a server object:
const server = http.createServer((req, res) => {
	res.setHeader('Access-Control-Allow-Origin', '*');
	let api = url.parse(req.url, true).pathname
	switch (req.method) {
		case 'GET':
			try {
				// res.write(db_connection.query("SELECT * FROM USER_PRIVILEGES"))
				let result = [];
				db_connection.getConnection(function(err, conn) {
					if (err) res.write("Error")
					else {
						let query
						if (!api.includes("floor"))
							query = "SELECT * FROM DATA"
						else {
							let floor = api.split('/')[2]
							console.log(floor)
							query = "SELECT * FROM DATA WHERE (Location = \"" + floor + "\")"
						}
						conn.query(query, function(err, rows) {
							if (err) res.write("Error in query")
							else {
								rows.forEach(element => {
									str = `{"id": "${element.id}","Time": "${element.Time}","Location": "${element.Location}"}`
									result.push(JSON.parse(str))
								});
								result = JSON.stringify(result)
								res.writeHead(200)
								res.write(result)
								res.end()
							}
						})
					}
				})
			} catch (error) {
				console.log(error)
			}
			break
		case 'POST':
			let received = ""
			req.on('data', chunk => {
				console.log(`Received ${chunk.length} bytes of data`)
				received += chunk
			})
			req.on('end', () => {
				console.log("No more data")
				let obj = JSON.parse(received)
				console.log(obj.id)
				db_connection.getConnection(function(err, conn) {
					if (err) res.write("Cannot get DB connection")
					else {
						conn.query(`INSERT INTO DATA values ('${obj['id']}', '${obj['Time']}', '${obj['Location']}')`, function(err, rows) {
							if (err) res.write("Error in insert")
							else {
								res.writeHead(200, headers)
								res.write(`1 record inserted`)
								res.end()
							}
						})
					}
				})
			})
			break
		default:
			res.writeHead(405, headers)
			res.end(`${JSON.stringify({error: 'Method not allowed', method: req.method})}\n`)
	}
}).listen(3000); //the server object listens on port 8080

Debug information:

Atom version: 1.49.0
linter-jshint version: v3.1.19
JSHint version: jshint v2.11.0
Hours since last Atom restart: 0
Platform: linux
Current file's scopes: [
  "unknown"
]
linter-jshint configuration: {
  "executablePath": "",
  "lintInlineJavaScript": false,
  "disableWhenNoJshintrcFileInPath": false,
  "scopes": [
    "source.js",
    "source.js-semantic"
  ],
  "jshintFileName": ".jshintrc",
  "jshintignoreFilename": ".jshintignore"
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant