spacedeck-open/routes/api/memberships.js
mntmn ebac854da8
Port Backend to SQLite/Sequelize (removes MongoDB), Support Electron (#14)
* The MongoDB/Mongoose data storage is removed in favor of Sequelize. This abstracts over SQLite or RDBMs like PostgreSQL and MSSQL. The default is SQLite, which significantly simplifies deployments in end-user environments.

* As Spacedeck now has no more mandatory server dependencies, we can wrap it in Electron and ship it as a desktop application.

* Removes docker-compose.yml

* First version of import UI
2018-04-12 16:40:58 +00:00

46 lines
1.0 KiB
JavaScript

"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();
const db = require('../../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const uuidv4 = require('uuid/v4');
router.get('/:membership_id/accept', function(req, res, next) {
if (req.user) {
db.Membership.findOne({where:{
_id: req.params.membership_id,
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);
});
} else {
res.status(200).json(mem);
}
} else {
res.status(404).json({"error": "not found"});
}
});
} else {
res.sendStatus(403);
}
});
module.exports = router;