AutoCallManu/index.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-12-06 08:46:58 +01:00
const { launchWeb } = require('./web.js');
const { EventEmitter } = require('events');
const Sequelize = require('sequelize');
const sequelize = new Sequelize("database", "user", "password", {
host: "localhost",
dialect: "sqlite",
logging: false,
storage: "database.sqlite",
});
const contactsDB = sequelize.define("contacts", {
phone: {
type: Sequelize.STRING,
primaryKey: true,
},
firstName: {
type: Sequelize.STRING,
},
lastName: {
type: Sequelize.STRING,
},
called: {
type: Sequelize.INTEGER,// 0: not called - 1: called - 2: ongoing call (- 3: no response ?)
defaultValue: false,
},
vote: {
type: Sequelize.BOOLEAN,
defaultValue: false,
}
});
contactsDB.sync();
global.database = {};
global.database.contacts = contactsDB
const submitEvent = new EventEmitter();
launchWeb(submitEvent);
submitEvent.on('call', async (call) => {
let vote;
if(call.vote) {
console.log(`${call.phone} va voter`);
vote = 1;
} else {
console.log(`${call.phone} ne va pas voter`);
vote = 0;
}
await global.database.contacts.update({ vote: vote }, { where: { phone: call.phone } })
});
submitEvent.on('add', (request) => {
console.log(request);
});