2017-04-07 01:29:05 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var config = require('config');
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
var url = require("url");
|
|
|
|
var path = require("path");
|
|
|
|
var crypto = require('crypto');
|
|
|
|
var glob = require('glob');
|
|
|
|
|
|
|
|
var express = require('express');
|
|
|
|
var router = express.Router();
|
|
|
|
|
2018-04-12 18:40:58 +02:00
|
|
|
const db = require('../../models/db');
|
|
|
|
const Sequelize = require('sequelize');
|
|
|
|
const Op = Sequelize.Op;
|
|
|
|
const uuidv4 = require('uuid/v4');
|
2017-04-07 01:29:05 +02:00
|
|
|
|
|
|
|
router.get('/:membership_id/accept', function(req, res, next) {
|
|
|
|
if (req.user) {
|
2018-04-12 18:40:58 +02:00
|
|
|
db.Membership.findOne({where:{
|
2017-04-07 01:29:05 +02:00
|
|
|
_id: req.params.membership_id,
|
2018-04-12 18:40:58 +02:00
|
|
|
code: req.query.code
|
|
|
|
}, include: ['space']}).then((mem) => {
|
|
|
|
if (mem) {
|
|
|
|
if (!mem.user) {
|
|
|
|
mem.state = "active";
|
|
|
|
mem.user_id = req.user._id;
|
|
|
|
|
|
|
|
mem.save().then(function() {
|
|
|
|
res.status(200).json(mem);
|
|
|
|
});
|
2017-04-07 01:29:05 +02:00
|
|
|
} else {
|
2018-04-12 18:40:58 +02:00
|
|
|
res.status(200).json(mem);
|
2017-04-07 01:29:05 +02:00
|
|
|
}
|
2018-04-12 18:40:58 +02:00
|
|
|
} else {
|
|
|
|
res.status(404).json({"error": "not found"});
|
2017-04-07 01:29:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.sendStatus(403);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|