Revert "converted import syntax to commonJS"

This reverts commit 5ab0d62b
This commit is contained in:
Aster Fialla
2026-02-17 17:25:18 -05:00
parent 321fe7f0a9
commit 35b454bc80
8 changed files with 801 additions and 769 deletions

122
src/db.js
View File

@@ -1,5 +1,5 @@
const {DataTypes, sequelize, Sequelize} = require('sequelize');
const {env} = require('dotenv');
import {DataTypes, Sequelize} from 'sequelize';
import * as env from 'dotenv';
env.config();
@@ -10,75 +10,75 @@ if (!password) {
process.exit(1);
}
const database = {
const db = {};
sequelize: new Sequelize('postgres', 'postgres', password, {
host: 'localhost',
logging: false,
dialect: 'postgres'
}),
const sequelize = new Sequelize('postgres', 'postgres', password, {
host: 'localhost',
logging: false,
dialect: 'postgres'
});
Sequelize: Sequelize,
db.sequelize = sequelize;
db.Sequelize = Sequelize;
members: sequelize.define('Member', {
userid: {
type: DataTypes.STRING,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
displayname: {
type: DataTypes.STRING,
},
propic: {
type: DataTypes.STRING,
},
proxy: {
type: DataTypes.STRING,
}
}),
db.members = sequelize.define('Member', {
userid: {
type: DataTypes.STRING,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
displayname: {
type: DataTypes.STRING,
},
propic: {
type: DataTypes.STRING,
},
proxy: {
type: DataTypes.STRING,
}
});
systems: sequelize.define('System', {
userid: {
type: DataTypes.STRING,
},
fronter: {
type: DataTypes.STRING
},
grouptag: {
type: DataTypes.STRING
},
autoproxy: {
type: DataTypes.BOOLEAN,
}
}),
db.systems = sequelize.define('System', {
userid: {
type: DataTypes.STRING,
},
fronter: {
type: DataTypes.STRING
},
grouptag: {
type: DataTypes.STRING
},
autoproxy: {
type: DataTypes.BOOLEAN,
}
})
/**
* Checks Sequelize database connection.
*/
check_connection: async function () {
/**
* Checks Sequelize database connection.
*/
db.check_connection = async function() {
await sequelize.authenticate().then(async () => {
console.log('Connection has been established successfully.');
await this.syncModels();
await syncModels();
}).catch(err => {
console.error('Unable to connect to the database:', err);
process.exit(1);
});
},
}
/**
* Syncs Sequelize models.
*/
async syncModels() {
await this.sequelize.sync().then(() => {
console.log('Models synced successfully.');
}).catch((err) => {
console.error('Syncing models did not work', err);
process.exit(1);
});
}
};
/**
* Syncs Sequelize models.
*/
async function syncModels() {
await sequelize.sync().then(() => {
console.log('Models synced successfully.');
}).catch((err) => {
console.error('Syncing models did not work', err);
process.exit(1);
});
}
module.exports = database;
export const database = db;