Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-163-generic #173-Ubuntu SMP Tue Oct 14 17:51:00 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/note.picotech.app/public_html/src/models/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const Label = sequelize.define('Label', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: DataTypes.STRING(100),
allowNull: false,
validate: {
len: [1, 100],
},
},
color: {
type: DataTypes.STRING(7), // Hex color code like #FF0000
allowNull: false,
defaultValue: '#2563eb',
validate: {
is: /^#[0-9A-F]{6}$/i, // Validate hex color
},
},
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id',
},
onDelete: 'CASCADE',
},
}, {
tableName: 'labels',
timestamps: true,
indexes: [
{
fields: ['user_id'],
},
{
fields: ['user_id', 'name'],
unique: true, // Prevent duplicate label names per user
},
],
});
// Instance methods
Label.prototype.toJSON = function() {
const values = { ...this.get() };
return values;
};
// Class methods
Label.findByUser = function(userId) {
return this.findAll({
where: {
user_id: userId,
},
order: [['name', 'ASC']],
});
};
module.exports = Label; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0034 ]-- |