mirror of
https://github.com/koodiklinikka/koodiklinikka.fi-api.git
synced 2026-01-26 03:34:03 +00:00
* remove newrelic from use in devenv * add endpoint for membership payments * fix some wierd spaces * minor code styling and logging stuff * replace non-breaking spaces with normal ones * remove duplicate function * minor code styling * add functionality for writing new member to google sheets * add config example * update example config, start using config in google credentials * remove var creds from google sheets auth * rename config.example to config.template and fix readme * add async and google-spreadsheet packages * rename workingWithRows to addRow * return missing header from readme * minor code styling * flatten google config structure, add address fields * add request validation to membership endpoint * fix config field names * more error handling, fix indentation
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
var validator = require('validator');
|
|
var slack = require('../services/slack');
|
|
var github = require('../services/github');
|
|
|
|
module.exports = function (app) {
|
|
/*
|
|
* POST /invites
|
|
* Endpoint for sending invitations automatically
|
|
*/
|
|
|
|
app.post('/invites', function(req, res, next) {
|
|
|
|
if(!validator.isEmail(req.body.email)) {
|
|
return res.status(400).send('invalid_email');
|
|
}
|
|
|
|
function success() {
|
|
res.status(200).end();
|
|
}
|
|
|
|
function alreadyInvited(email) {
|
|
res.status(400).send('already_invited');
|
|
}
|
|
|
|
slack
|
|
.createInvite(req.body.email)
|
|
.then(function() {
|
|
github
|
|
.findUserByEmail(req.body.email)
|
|
.then(github.inviteToOrg)
|
|
.then(function(user) {
|
|
var message = 'User ' + user.login + ' invited to GitHub organization.'
|
|
slack.createMessage(message);
|
|
})
|
|
.catch(function(err) {
|
|
var message = 'Creating GitHub invitation failed for: ' + req.body.email + ' reason: ' + err;
|
|
slack.createMessage(message);
|
|
});
|
|
})
|
|
.then(success)
|
|
.catch(function(err) {
|
|
|
|
if(err === 'already_invited') {
|
|
return alreadyInvited(req.body.email);
|
|
}
|
|
|
|
var message = 'Creating automatic invitation failed for: ' + req.body.email + ' reason: ' + err;
|
|
slack.createMessage(message);
|
|
|
|
console.error(err);
|
|
|
|
var error = new Error('Creating slack invitation failed');
|
|
return next(error);
|
|
});
|
|
});
|
|
|
|
};
|