input UpdateClubInput {
id: ID!
name: String
position: String
league: String
}
mutation {
UpdateClub(input: UpdateClubInput!): Club
}
app.post('/api/search', async function(req, res) {
var query = {}
var reserveNomersIds;
var filter = {}
//price
if (req.body.min && req.body.max) {
query.cost_per_night = {$gte: req.body.min, $lte: req.body.max}
//по возрастанию
filter.cost_per_night = 1
}
//dates
if (req.body.from && req.body.to) {
reserveNomersIds = await Reservation.distinct("nomer", {
from: {
$lt: new Date(req.body.to)},
to: {$gt: new Date(req.body.from)
}
});
}
if (req.body.guests > 1) {
query.occupancy = {$gte: req.body.guests}
}
if (req.body.search) {
query.city = { $regex: req.body.search.toLowerCase() }
}
try {
var result = await Nomer
.find({ _id: { $nin: reserveNomersIds}, query})
.sort(filter);
res.json(result);
} catch (e) {
res.send(e);
}
})
function isAuthenticated(req, res, next) {
const { token } = req.body;
console.log('isAuthenticated token',token)
const user = auth.checkToken();
// Проверем есть ли пользователь с таким токеном,
// Если есть, то в user сохраняем объект с пользователем.
// 777,admin,admin,706669f29acdc5a14d2a2a1f24e45bd898db6898
if (user) {
req.user = user;
return next();
} else {
res.json({ message: "ERROR_AUTH_TOKEN", data: {}});
}
}
app.post("/api/v1/links/get_links", isAuthenticated, async (req, res) => {
//777 - это ID пользователя
const userLinks = await links.getUserLinksByID(db, req.user.id);
res.json({ message: "USER_LINKS", data: { userLinks } });
});
const { spawn } = require('child_process');
function run_cmd(cmd, args, callBack) {
const child = spawn(cmd, args);
let resp = "";
child.stdout.on('data', function (buffer) { resp += buffer.toString() });
child.stdout.on('end', function() { callBack (resp) });
child.stdout.on('error', callBack);
};
run_cmd("./go.js", ["-l"], function(err, text) {
if (err) return console.error(err);
console.log(text)
});
module.exports = class Mod {
constructor({ io }) {
this.io = io;
}
run() {
this.io.something();
}
}
var express = require('express')
, app = express()
, path = require('path')
, server = require('http').createServer(app)
, io = require('socket.io')(server)
, Mod = require("./mod")
const mod = new Mod({ io });
mod.run();
server.listen(8080);
app.use(express.static(path.join(__dirname, 'public'));