Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"env": {
"test": {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
}
}
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"env": {
"browser": true,
"es2021": true
"es2021": true,
"jest": true
},
"extends": "airbnb-base",
"overrides": [
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
node_modules/
logs/
.env
4 changes: 2 additions & 2 deletions config/db.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export const HOST = 'localhost';
export const USER = 'postgres';
export const PASSWORD = 'Barbaris179$';
export const DB = 'postgres';
export const dialect = 'postgres';
export const pool = {
export const DIALECT = 'postgres';
export const POOL = {
max: 5,
min: 0,
acquire: 30000,
Expand Down
2 changes: 1 addition & 1 deletion controllers/groups.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function findGroupById(req, res) {
GroupsDataAccess.findGroupByPk(id)
.then((data) => {
if (data) {
res.send(data);
res.status(200).send(data);
} else {
res.status(404).send({
message: `Cannot find group with id=${id}.`,
Expand Down
4 changes: 3 additions & 1 deletion controllers/junction.controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import UserGroupDataAccess from '../dal/junction.dal.js';
import db from '../models/index.js';

const t = await db.sequelize.transaction();
const t = async () => {
await db.sequelize.transaction();
};

export function createJunction(req, res) {
UserGroupDataAccess.createUserGroup(req.body)
Expand Down
15 changes: 0 additions & 15 deletions index.html

This file was deleted.

15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import createServer from './server.js';
import db, { addPredefinedDatatoDB } from './models/index.js';

db.sequelize.sync()
.then(() => {
addPredefinedDatatoDB();
console.log('Synced db.');
const server = createServer();
const port = 3000;
server.listen(port);
console.debug(`Server listening on port ${port}`);
})
.catch((err) => {
console.log(`Failed to sync db: ${err.message}`);
});
21 changes: 11 additions & 10 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import Sequelize from 'sequelize';
import {
DB, USER, PASSWORD, HOST, dialect as _dialect, pool as _pool, predefinedUsers, predefinedGroups,
} from '../config/db.config.js';
import * as dotenv from 'dotenv';
import { POOL, predefinedUsers, predefinedGroups } from '../config/db.config.js';
import usersModel from './users.model.js';
import groupsModel from './groups.model.js';
import userGroupModel from './junction.model.js';

const sequelize = new Sequelize(DB, USER, PASSWORD, {
host: HOST,
dialect: _dialect,
dotenv.config();

const sequelize = new Sequelize(process.env.DB, process.env.USER, process.env.PASSWORD, {
host: process.env.HOST,
dialect: process.env.DIALECT,
operatorsAliases: 0,

pool: {
max: _pool.max,
min: _pool.min,
acquire: _pool.acquire,
idle: _pool.idle,
max: POOL.max,
min: POOL.min,
acquire: POOL.acquire,
idle: POOL.idle,
},
});

Expand Down
Loading