updates.on('chat_invite_user', async (context, next) => {
const [user] = await api.users.get({
user_ids: context.eventMemberId,
name_case: 'nom'
});
await context.send(`Добро пожаловать, ${user.first_name} ${user.last_name}`);
});
import { VK } from 'vk-io';
const MY_GROUP_ID = 123456;
const vk = new VK({
// ...
pollingGroupId: MY_GROUP_ID
});
vk.updates.on('chat_invite_user', async (context, next) => {
const { eventMemberId } = context;
if (eventMemberId === -MY_GROUP_ID) {
console.log('It\'s invited my group!');
// ...
return;
}
console.log('Other invited', eventMemberId);
});
vk.updates.startPolling().catch(console.error);
getEmail() {
return new Promise((resolve, reject) => {
this.start();
this.db.query('SELECT * FROM contacts', (err, contacts) => {
if (err) {
reject(err);
return;
}
const emails = contacts
.map(contact => contact.email)
.filter(Boolean);
this.end();
resolve(emails);
});
});
}
_db.getEmail()
.then((emails) => {
console.log(emails)
})
.catch((error) => {
console.log('Error in the Query', error);
});
app.get('/chat/:chat', (req, res) => {
const chat = req.params.chat;
const json = {};
bot.telegram.getChat(chat).then((info) => {
json.success = true;
json.info = info;
res.json(json);
}).catch((error) => {
json.success = false;
json.info.error = error.code;
json.info.method = error.on.method;
json.info.description = error.description;
res.json(json);
});
});
app.get('/chat/:chat', async (req, res) => {
const { chat } = req.params;
const json = {};
try {
const info = await bot.telegram.getChat(chat);
json.success = true;
json.info = info;
} catch (error) {
json.success = false;
json.info.error = error.code;
json.info.method = error.on.method;
json.info.description = error.description;
}
res.json(json);
});
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)
});