mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-14 20:15:28 +10:00
* converted import syntax to ES modules
removed unused methods
* got test sort of working (jest set up is not crashing but also not mocking correctly)
* adjusted beforeeach/beforeall so more pass
* more correct test setup
* converted import syntax to commonJS
removed unused methods
* got test sort of working (jest set up is not crashing but also not mocking correctly)
* adjusted beforeeach/beforeall so more pass
* more correct test setup
* more correct dockerfile and compose.yaml
* Revert "converted import syntax to commonJS"
This reverts commit 5ab0d62b
* updated jest to sort of work with es6
* separating out enum return from method return
* mostly working except for the weirdest error
* nevermind it wasn't actually working, gonna move on for now
* added babel to convert es modules to cjs
* finally figured out issue with tests (referencing the method directly in the test.each calls the real method not the mock in beforeEach())
* setup fixed more
* added error handling parseMemberCommand test
* renamed db to database
more tests and fixing logic for memberhelper
* upgraded fluxer.js
* moved import to helpers folder
* moved import to helpers folder
* more tests for member helper
* think i fixed weird error with webhook sending error when a user has no members
* simplified sendMessageAsAttachment
* added return to addFullMember so that addNewMember can reference it properly in strings
* test setup for messagehelper and webhookhelper
* readded line i shouldn't have removed in sendMessageAsMember
* fixed test and logic
* added test for memberHelper
* updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly
* added tests for parseProxyTags and updated logic
* added "return" so tests dont terminate on failure and deleted env.jest
* finished tests for messageHelper!
* more cases for messageHelper just in case
* updating docstring for messageHelper parseProxyTags
* more tests for webhookhelper
* deleted extra file added during merge
* removed confusing brackets from enum docs
* finally mocking correctly
* adding more cases to messageHelper tests
* updating enums
* removed error response when proxy is sent without content
* , updated tests for webhookHelper and removed error response when proxy is sent without content
* added debounce to count guilds properly
* added todo note
* added tests for updateDisplayName
* edited help message trigger for updatePropic
* update message helper test to include space case
* update bot to suppress errors from API
* fixed bug for import not sending help text, added help text if you type a unrecognized command
* updated to be enum
* updated member helper and tests
* edit enums, tweak import content command
* removed unnecessary await and console.log
* made it easier to make a member
* added nicer error listing to importHelper
* updated documentation
* Merge branch 'main' of https://github.com/pieartsy/PluralFlux into add-tests
---------
Co-authored-by: Aster Fialla <asterfialla@gmail.com>
84 lines
1.7 KiB
JavaScript
84 lines
1.7 KiB
JavaScript
import {DataTypes, Sequelize} from 'sequelize';
|
|
import * as env from 'dotenv';
|
|
|
|
env.config();
|
|
|
|
const password = process.env.POSTGRES_PASSWORD;
|
|
|
|
if (!password) {
|
|
console.error("Missing POSTGRES_PWD environment variable.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const db = {};
|
|
|
|
const sequelize = new Sequelize('postgres', 'postgres', password, {
|
|
host: 'localhost',
|
|
logging: false,
|
|
dialect: 'postgres'
|
|
});
|
|
|
|
db.sequelize = sequelize;
|
|
db.Sequelize = Sequelize;
|
|
|
|
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,
|
|
}
|
|
});
|
|
|
|
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.
|
|
*/
|
|
db.check_connection = async function() {
|
|
await sequelize.authenticate().then(async () => {
|
|
console.log('Connection has been established successfully.');
|
|
await syncModels();
|
|
}).catch(err => {
|
|
console.error('Unable to connect to the database:', 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);
|
|
});
|
|
}
|
|
|
|
export const database = db; |