You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1016 B
JavaScript
35 lines
1016 B
JavaScript
'use strict';
|
|
|
|
const db = require('../config').database;
|
|
const { domain, name } = require('../config').server;
|
|
const initModels = require('../models/init-models');
|
|
|
|
const Sequelize = db.sequelize;
|
|
const models = initModels(Sequelize);
|
|
|
|
const ConnectionsModel = models.connections;
|
|
|
|
const addConnection = async data => {
|
|
const r = await ConnectionsModel.create({ ...data, connect_domain: domain, connect_name: name });
|
|
return r;
|
|
};
|
|
|
|
const updateConnection = async data => {
|
|
const r = await ConnectionsModel.update(
|
|
{
|
|
...data,
|
|
...(data.status === 'open' ? { opentime: Sequelize.fn('NOW') } : {}),
|
|
...(data.status === 'close' ? { closetime: Sequelize.fn('NOW') } : {}),
|
|
},
|
|
{ where: { channel_id: data.channel_id, sesson_id: data.sesson_id } },
|
|
);
|
|
return r;
|
|
};
|
|
|
|
const getConnection = async data => {
|
|
const r = await ConnectionsModel.findOne({ where: data });
|
|
return r;
|
|
};
|
|
|
|
module.exports = { addConnection, updateConnection, getConnection };
|