Skip to content
This repository was archived by the owner on Aug 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules/
.env
node_modules
.yaml
store
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "groot-groups-service",
"version": "1.0.0",
"description": "service to serve acm group information",
"description": "a service to serve acm group information",
"main": "server.js",
"scripts": {
"test": "echo \"no test\""
"test": "echo \"no tests\""
},
"author": "ish",
"author": "ACM@UIUC",
"license": "ISC",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update author and licensing

"dependencies": {
"express": "^4.14.0"
"body-parser": "^1.15.2",
"express": "^4.14.0",
"js-yaml": "^3.7.0",
"jsonfile": "^2.4.0",
"request": "^2.78.0"
}
}
87 changes: 84 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,92 @@

var express = require('express');
var path = require("path");

var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));

var request = require('request');

var yaml = require('js-yaml');
var fs = require('fs');

function loadFile(filename)
{
var file;
try {
file = yaml.safeLoad(fs.readFileSync(filename, 'utf8'));
// console.log(file);
}catch (e) {
console.log("ERROR: " + e);
}
return file;
}


var sigs = loadFile("store/sigs.yaml");
var committees = loadFile("store/committees.yaml");

app.get("/groups", function(req, res){
return res.json(["sigs","committees"]);
});

app.get("/groups/:groupType", function(req, res){
var groupType = req.params.groupType;
if(groupType == "sigs")
return res.json(sigs);
else if(groupType == "committees")
return res.json(committees);
else
return res.json({"Error":"groupType does not exist, must be sig or committee"});
});

function getGroup(groupType, groupName)
{
for(var i = 0; i < groupType.length; i++)
{
// console.log(groupType[i]);
if(groupType[i].name.toLowerCase() == groupName.toLowerCase())
return groupType[i];
}
return {"Error":"Group does not exist"};
}

function checkIDs(res, group, netid)
{
for(var i = 0; i < group.netids.length; i++)
{
if(group.netids[i] == netid)
return res.json({"netid": netid, "isValid" : "true"});
}
return res.json({"isValid" : "false"});
}

app.get("/sigs", function(req, res) {
res.setHeader("Content-Type", "application/json");
res.sendFile(path.resolve(__dirname) + "/sigs.json");
app.get("/groups/:groupType/:groupName", function(req, res){
var groupType = req.params.groupType;
var groupName = req.params.groupName;
var netid = req.query.isMember;
if(groupType == "sigs")
{
var group = getGroup(sigs, groupName);
if(netid == undefined || group["Error"])
return res.json(group);
else
return checkIDs(res, group, netid);
}
else if(groupType == "committees")
{
var group = getGroup(committees, groupName);
if(netid == undefined || group["Error"])
return res.json(group);
else
return checkIDs(res, group, netid);
}
else
return res.json({"Error":"groupType does not exist, must be sig or committee"});
});

app.listen(9001, function() {
Expand Down
210 changes: 0 additions & 210 deletions sigs.json

This file was deleted.