-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.js
56 lines (41 loc) · 1.01 KB
/
queue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var queue = exports; exports.constructor = function queue() {};
var async = require('async');
var Hash = require('hashish');
var mysql = require('mysql');
var mysqlCli = mysql.createClient({
'host': 'localhost',
'database': 'haggle'
});
queue.post = function(req, res) {
var pid = req.params.pid;
var uid = req.params.uid;
var body = "";
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
getRequestedQueue(pid, uid);
});
};
queue.get = function(req, res) {
var pid = req.params.pid;
var body = "";
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
getRequestedQueue(pid);
});
};
function getRequestedQueue(pid, uid) {
var sql = 'INSERT INTO queue (pid, uid) VALUES (?, ?)';
mysqlCli.query(sql, [pid, uid], function(err, res) {
// something
});
}
function setRequestedQueue(pid) {
var sql = 'SELECT * FROM queue WHERE pid = ?';
mysqlCli.query(sql, [pid], function(err, res) {
// something
});
}