repl.it
@rshetty/

OEF scheduler

Nodejs

No description

fork
loading
Files
  • index.js
  • ideas.txt
  • sample input.json
  • scheduler.js
  • Packager files
  • package-lock.json
  • package.json
index.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
// Begin POST handler
const http = require('http');
const Scheduler = require("./scheduler");
const server = http.createServer(function(request, response) {
  console.dir(request.param);

  if (request.method == 'POST') { // Checks for POST request
		var body = '';
    request.on('data', function(data) {
      body += data; // Appends data if key-value pair to body
    });

    request.on('end', function() {
			var scheduler = new Scheduler(JSON.parse(body));
			scheduler.getRanges();
			scheduler.sortByLowestAvailability();
			scheduler.createMatchQueue();
      // console.log(JSON.parse(body));
			
      response.end(JSON.stringify(scheduler.matchmake()));
    })
  }
})

const port = 3000;
server.listen(port);
console.log(`Listening on port ${port}`);

// End POST Handler