Include complete API and frontend sources for unified deployment
This commit is contained in:
1 parent
627b0ae60e
commit
d8fcae32b0
93 files changed
+53270
-3
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import sequelize from 'sequelize';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const { DataTypes, Model } = sequelize;
|
||||
|
||||
export default class Case extends Model {
|
||||
static initialize(sequelize) {
|
||||
Case.init(
|
||||
{
|
||||
id: { type: DataTypes.UUID, primaryKey: true },
|
||||
|
||||
name: { type: DataTypes.STRING },
|
||||
description: { type: DataTypes.TEXT },
|
||||
icon: { type: DataTypes.TEXT('medium'), allowNull: true },
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Case',
|
||||
tableName: 'cases',
|
||||
}
|
||||
);
|
||||
|
||||
Case.beforeCreate(c => {
|
||||
c.id = uuidv4();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {} from 'dotenv/config';
|
||||
import { Sequelize } from 'sequelize';
|
||||
import User from './user.js';
|
||||
import Team from './team.js';
|
||||
import Case from './case.js';
|
||||
import Mark from './mark.js';
|
||||
import UserInCase from './userInCase.js';
|
||||
import TeamInCase from './teamInCase.js';
|
||||
|
||||
const { DB_NAME, DB_USER, DB_PWD, DB_HOST } = process.env;
|
||||
|
||||
export const models = {
|
||||
Case,
|
||||
Team,
|
||||
User,
|
||||
Mark,
|
||||
UserInCase,
|
||||
TeamInCase,
|
||||
};
|
||||
|
||||
export const sequelize = new Sequelize(DB_NAME, DB_USER, DB_PWD, {
|
||||
host: DB_HOST,
|
||||
dialect: 'mysql',
|
||||
dialectOptions: { multipleStatements: true },
|
||||
define: {
|
||||
charset: 'utf8mb4',
|
||||
collate: 'utf8mb4_unicode_ci',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
paranoid: true,
|
||||
},
|
||||
logging: false,
|
||||
});
|
||||
|
||||
export default { sequelize, models };
|
||||
@@ -0,0 +1,36 @@
|
||||
import sequelize from 'sequelize';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import markTypes from '../config/markTypes.js';
|
||||
|
||||
const { DataTypes, Model } = sequelize;
|
||||
|
||||
export default class Mark extends Model {
|
||||
static initialize(sequelize) {
|
||||
Mark.init(
|
||||
{
|
||||
id: { type: DataTypes.UUID, primaryKey: true },
|
||||
|
||||
markType: {
|
||||
type: DataTypes.TINYINT.UNSIGNED,
|
||||
allowNull: false,
|
||||
validate: { isIn: [Object.values(markTypes)] },
|
||||
},
|
||||
|
||||
mark: { type: DataTypes.TINYINT.UNSIGNED, validate: { min: 0, max: 10 } },
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Mark',
|
||||
tableName: 'marks',
|
||||
}
|
||||
);
|
||||
|
||||
Mark.beforeCreate(m => {
|
||||
m.id = uuidv4();
|
||||
});
|
||||
|
||||
Mark.beforeBulkCreate(ms => {
|
||||
for (const m of ms) m.id = uuidv4();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { models } from './index.js';
|
||||
const { User, Team, Case, Mark, UserInCase, TeamInCase } = models;
|
||||
|
||||
export default function () {
|
||||
Mark.belongsTo(Team, { foreignKey: { name: 'teamId', allowNull: false }, as: 'team' });
|
||||
Team.hasMany(Mark, { foreignKey: { name: 'teamId', allowNull: false }, as: 'marks' });
|
||||
|
||||
Mark.belongsTo(User, { foreignKey: { name: 'userId', allowNull: false }, as: 'user' });
|
||||
User.hasMany(Mark, { foreignKey: { name: 'userId', allowNull: false }, as: 'marks' });
|
||||
|
||||
Mark.belongsTo(Case, { foreignKey: { name: 'caseId', allowNull: false }, as: 'case' });
|
||||
Case.hasMany(Mark, { foreignKey: { name: 'caseId', allowNull: false }, as: 'marks' });
|
||||
|
||||
Case.belongsToMany(User, { through: UserInCase, foreignKey: { name: 'caseId', allowNull: false }, as: 'users' });
|
||||
User.belongsToMany(Case, { through: UserInCase, foreignKey: { name: 'userId', allowNull: false }, as: 'cases' });
|
||||
|
||||
UserInCase.belongsTo(User, { foreignKey: { name: 'userId', allowNull: false }, as: 'user' });
|
||||
User.hasMany(UserInCase, { foreignKey: { name: 'userId', allowNull: false }, as: 'usersInCases' });
|
||||
|
||||
UserInCase.belongsTo(Case, { foreignKey: { name: 'caseId', allowNull: false }, as: 'case' });
|
||||
Case.hasMany(UserInCase, { foreignKey: { name: 'caseId', allowNull: false }, as: 'usersInCases' });
|
||||
|
||||
Case.belongsToMany(Team, { through: TeamInCase, foreignKey: { name: 'caseId', allowNull: false }, as: 'teams' });
|
||||
Team.belongsToMany(Case, { through: TeamInCase, foreignKey: { name: 'teamId', allowNull: false }, as: 'cases' });
|
||||
|
||||
TeamInCase.belongsTo(Team, { foreignKey: { name: 'teamId', allowNull: false }, as: 'team' });
|
||||
Team.hasMany(TeamInCase, { foreignKey: { name: 'teamId', allowNull: false }, as: 'teamsInCases' });
|
||||
|
||||
TeamInCase.belongsTo(Case, { foreignKey: { name: 'caseId', allowNull: false }, as: 'case' });
|
||||
Case.hasMany(TeamInCase, { foreignKey: { name: 'caseId', allowNull: false }, as: 'teamsInCases' });
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import sequelize from 'sequelize';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const { DataTypes, Model } = sequelize;
|
||||
|
||||
export default class Team extends Model {
|
||||
static initialize(sequelize) {
|
||||
Team.init(
|
||||
{
|
||||
id: { type: DataTypes.UUID, primaryKey: true },
|
||||
|
||||
name: { type: DataTypes.STRING },
|
||||
description: { type: DataTypes.TEXT },
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Team',
|
||||
tableName: 'teams',
|
||||
}
|
||||
);
|
||||
|
||||
Team.beforeCreate(t => {
|
||||
t.id = uuidv4();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import sequelize from 'sequelize';
|
||||
const { Model, DataTypes } = sequelize;
|
||||
|
||||
export default class TeamInCase extends Model {
|
||||
static initialize(sequelize) {
|
||||
TeamInCase.init(
|
||||
{ technicalComment: { type: DataTypes.TEXT, allowNull: true } },
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'TeamInCase',
|
||||
tableName: 'teams_in_cases',
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import sequelize from 'sequelize';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const { DataTypes, Model } = sequelize;
|
||||
|
||||
export default class User extends Model {
|
||||
static initialize(sequelize) {
|
||||
User.init(
|
||||
{
|
||||
id: { type: DataTypes.UUID, primaryKey: true },
|
||||
isAdmin: { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: false },
|
||||
role: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: 'expert',
|
||||
allowNull: false,
|
||||
validate: { isIn: [['expert', 'technical']] },
|
||||
},
|
||||
|
||||
login: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: 'login',
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
set(val) {
|
||||
this.setDataValue('password', bcrypt.hashSync(val, bcrypt.genSaltSync()));
|
||||
},
|
||||
},
|
||||
passwordForAdmin: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
iat: { type: DataTypes.BIGINT },
|
||||
sessionId: { type: DataTypes.UUID },
|
||||
|
||||
firstName: { type: DataTypes.STRING, allowNull: true, validate: { len: [1, 50] } },
|
||||
middleName: { type: DataTypes.STRING, allowNull: true, validate: { len: [0, 50] } },
|
||||
lastName: { type: DataTypes.STRING, allowNull: true, validate: { len: [1, 50] } },
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'User',
|
||||
tableName: 'users',
|
||||
}
|
||||
);
|
||||
|
||||
User.beforeCreate(user => {
|
||||
user.id = uuidv4();
|
||||
});
|
||||
}
|
||||
|
||||
fullName() {
|
||||
return this.firstName + ' ' + this.lastName;
|
||||
}
|
||||
|
||||
validatePassword(password) {
|
||||
return bcrypt.compareSync(password, this.password);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import sequelize from 'sequelize';
|
||||
const { Model } = sequelize;
|
||||
|
||||
export default class UserInCase extends Model {
|
||||
static initialize(sequelize) {
|
||||
UserInCase.init(
|
||||
{},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'UserInCase',
|
||||
tableName: 'users_in_cases',
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user