diff --git a/index.js b/index.js index 137366e..a48ed36 100644 --- a/index.js +++ b/index.js @@ -1,43 +1,13 @@ -const { launchWeb } = require("./web.js"); -const { EventEmitter } = require("events"); -const Sequelize = require("sequelize"); -require('dotenv').config() +import { launchWeb } from './web.js'; +import { EventEmitter } from 'events'; +import { loadDatabase } from './utils/database.js'; +import dotenv from 'dotenv'; +dotenv.config(); -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; +loadDatabase(); const submitEvent = new EventEmitter(); -launchWeb(submitEvent); +await launchWeb(submitEvent); submitEvent.on("call", async (call) => { let vote; diff --git a/package.json b/package.json index 96b2e37..8c609d5 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,14 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "type": "module", "author": "Ninjdai", "license": "MIT", "dependencies": { + "@adminjs/express": "^6.1.0", + "@adminjs/sequelize": "^4.1.1", + "adminjs": "^7.5.0", + "bcrypt": "^5.1.1", "dotenv": "^16.3.1", "express": "^4.18.2", "express-session": "^1.17.3", diff --git a/src/database/getUser.js b/src/database/getUser.js index a1f0f62..2eac5e7 100644 --- a/src/database/getUser.js +++ b/src/database/getUser.js @@ -10,4 +10,4 @@ async function getRandomUser() { }; } -module.exports = { getRandomUser }; +export { getRandomUser }; diff --git a/src/html/callHTML.js b/src/html/callHTML.js index 78bb181..400e722 100644 --- a/src/html/callHTML.js +++ b/src/html/callHTML.js @@ -1,9 +1,9 @@ -const { navbar } = require('../../utils/navbar.js'); +import { navbar } from '../../utils/navbar.js'; function generateCallHTML(phoneNumber, name, callcount, session) { const head = `