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
2 changes: 2 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const telegramModule = require('./modules/telegram');
const urlModule = require('./modules/url');
const usersModule = require('./modules/users');
const viewsModule = require('./modules/views');
const matricesModule = require('./modules/matrices');

// Swagger documentation - enabled by default, protected by authentication
// Mounted on /api-docs to avoid conflicts with API routes
Expand Down Expand Up @@ -215,6 +216,7 @@ const registerApiRoutes = (basePath) => {
app.use(basePath, backupModule.routes);
app.use(basePath, searchModule.routes);
app.use(basePath, viewsModule.routes);
app.use(basePath, matricesModule.routes);
app.use(basePath, notificationsModule.routes);
};

Expand Down
86 changes: 86 additions & 0 deletions backend/migrations/20260223000001-create-matrices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

const { safeCreateTable, safeAddIndex } = require('../utils/migration-utils');

module.exports = {
async up(queryInterface, Sequelize) {
await safeCreateTable(queryInterface, 'matrices', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
uid: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
project_id: {
type: Sequelize.INTEGER,
allowNull: true,
references: {
model: 'projects',
key: 'id',
},
onUpdate: 'CASCADE',
onDelete: 'SET NULL',
},
user_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id',
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
x_axis_label_left: {
type: Sequelize.STRING(100),
allowNull: false,
defaultValue: 'Low Effort',
},
x_axis_label_right: {
type: Sequelize.STRING(100),
allowNull: false,
defaultValue: 'High Effort',
},
y_axis_label_top: {
type: Sequelize.STRING(100),
allowNull: false,
defaultValue: 'High Impact',
},
y_axis_label_bottom: {
type: Sequelize.STRING(100),
allowNull: false,
defaultValue: 'Low Impact',
},
created_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
});

await safeAddIndex(queryInterface, 'matrices', ['user_id'], {
name: 'matrices_user_id_idx',
});
await safeAddIndex(queryInterface, 'matrices', ['project_id'], {
name: 'matrices_project_id_idx',
});
},

async down(queryInterface) {
await queryInterface.dropTable('matrices');
},
};
58 changes: 58 additions & 0 deletions backend/migrations/20260223000002-create-task-matrices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

const { safeCreateTable, safeAddIndex } = require('../utils/migration-utils');

module.exports = {
async up(queryInterface, Sequelize) {
await safeCreateTable(queryInterface, 'task_matrices', {
task_id: {
type: Sequelize.INTEGER,
primaryKey: true,
references: {
model: 'tasks',
key: 'id',
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
matrix_id: {
type: Sequelize.INTEGER,
primaryKey: true,
references: {
model: 'matrices',
key: 'id',
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
quadrant_index: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
},
position: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
},
created_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
});

await safeAddIndex(queryInterface, 'task_matrices', ['matrix_id'], {
name: 'task_matrices_matrix_id_idx',
});
},

async down(queryInterface) {
await queryInterface.dropTable('task_matrices');
},
};
28 changes: 28 additions & 0 deletions backend/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const Notification = require('./notification')(sequelize);
const RecurringCompletion = require('./recurringCompletion')(sequelize);
const TaskAttachment = require('./task_attachment')(sequelize);
const Backup = require('./backup')(sequelize);
const Matrix = require('./matrix')(sequelize);
const TaskMatrix = require('./task_matrix')(sequelize);

User.hasMany(Area, { foreignKey: 'user_id' });
Area.belongsTo(User, { foreignKey: 'user_id' });
Expand Down Expand Up @@ -188,6 +190,30 @@ TaskAttachment.belongsTo(Task, { foreignKey: 'task_id' });
User.hasMany(Backup, { foreignKey: 'user_id', as: 'Backups' });
Backup.belongsTo(User, { foreignKey: 'user_id', as: 'User' });

// Matrix associations
User.hasMany(Matrix, { foreignKey: 'user_id', as: 'Matrices' });
Matrix.belongsTo(User, { foreignKey: 'user_id', as: 'User' });
Project.hasMany(Matrix, { foreignKey: 'project_id', as: 'Matrices' });
Matrix.belongsTo(Project, { foreignKey: 'project_id', as: 'Project' });

Matrix.belongsToMany(Task, {
through: TaskMatrix,
foreignKey: 'matrix_id',
otherKey: 'task_id',
as: 'Tasks',
});
Task.belongsToMany(Matrix, {
through: TaskMatrix,
foreignKey: 'task_id',
otherKey: 'matrix_id',
as: 'Matrices',
});

TaskMatrix.belongsTo(Task, { foreignKey: 'task_id' });
TaskMatrix.belongsTo(Matrix, { foreignKey: 'matrix_id' });
Task.hasMany(TaskMatrix, { foreignKey: 'task_id', as: 'TaskMatrices' });
Matrix.hasMany(TaskMatrix, { foreignKey: 'matrix_id', as: 'TaskMatrices' });

module.exports = {
sequelize,
User,
Expand All @@ -208,4 +234,6 @@ module.exports = {
RecurringCompletion,
TaskAttachment,
Backup,
Matrix,
TaskMatrix,
};
70 changes: 70 additions & 0 deletions backend/models/matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const { DataTypes } = require('sequelize');
const { uid } = require('../utils/uid');

module.exports = (sequelize) => {
const Matrix = sequelize.define(
'Matrix',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
uid: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
defaultValue: () => uid(),
},
name: {
type: DataTypes.STRING(255),
allowNull: false,
validate: {
notEmpty: true,
len: [1, 255],
},
},
project_id: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'projects',
key: 'id',
},
},
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id',
},
},
x_axis_label_left: {
type: DataTypes.STRING(100),
allowNull: false,
defaultValue: 'Low Effort',
},
x_axis_label_right: {
type: DataTypes.STRING(100),
allowNull: false,
defaultValue: 'High Effort',
},
y_axis_label_top: {
type: DataTypes.STRING(100),
allowNull: false,
defaultValue: 'High Impact',
},
y_axis_label_bottom: {
type: DataTypes.STRING(100),
allowNull: false,
defaultValue: 'Low Impact',
},
},
{
tableName: 'matrices',
}
);

return Matrix;
};
47 changes: 47 additions & 0 deletions backend/models/task_matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
const TaskMatrix = sequelize.define(
'TaskMatrix',
{
task_id: {
type: DataTypes.INTEGER,
primaryKey: true,
references: {
model: 'tasks',
key: 'id',
},
},
matrix_id: {
type: DataTypes.INTEGER,
primaryKey: true,
references: {
model: 'matrices',
key: 'id',
},
},
quadrant_index: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
validate: {
min: 0,
max: 3,
},
},
position: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
validate: {
min: 0,
},
},
},
{
tableName: 'task_matrices',
}
);

return TaskMatrix;
};
Loading
Loading