7b3fd1298d
- Implemented GET, POST, PUT, and DELETE endpoints for orders, shipping docks, and transactions. - Added Swagger annotations for API documentation. - Included error handling for database operations. - Configured pnpm workspace to ignore built dependencies for sqlite3.
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
"use strict";
|
|
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2020*/
|
|
/**
|
|
* Sequelize File
|
|
* @copyright 2020 Manaknightdigital Inc.
|
|
* @link https://manaknightdigital.com
|
|
* @license Proprietary Software licensing
|
|
* @author Ryan Wong
|
|
*
|
|
*/
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
let Sequelize = require("sequelize");
|
|
const basename = path.basename(__filename);
|
|
const { DataTypes } = require("sequelize");
|
|
|
|
let db = {};
|
|
|
|
// SQLite configuration - stores data in a file instead of MySQL server
|
|
let sequelize = new Sequelize({
|
|
dialect: "sqlite",
|
|
storage: "./database.sqlite", // Database file location
|
|
logging: console.log,
|
|
define: {
|
|
timestamps: false,
|
|
underscoredAll: true,
|
|
underscored: true,
|
|
},
|
|
});
|
|
|
|
// Sync database tables
|
|
sequelize
|
|
.sync({ alter: true })
|
|
.then(() => {
|
|
console.log("Database tables synchronized");
|
|
})
|
|
.catch((err) => {
|
|
console.error("Error synchronizing database:", err);
|
|
});
|
|
|
|
fs.readdirSync(__dirname)
|
|
.filter((file) => {
|
|
return (
|
|
file.indexOf(".") !== 0 &&
|
|
file !== basename &&
|
|
file.slice(-3) === ".js"
|
|
);
|
|
})
|
|
.forEach((file) => {
|
|
var model = require(path.join(__dirname, file))(sequelize, DataTypes);
|
|
db[model.name] = model;
|
|
});
|
|
|
|
Object.keys(db).forEach((modelName) => {
|
|
if (db[modelName].associate) {
|
|
db[modelName].associate(db);
|
|
}
|
|
});
|
|
|
|
db.sequelize = sequelize;
|
|
db.Sequelize = Sequelize;
|
|
|
|
module.exports = db;
|