const { DataTypes, Model } = require("sequelize"); const sequelize = require("../../config/sequelize"); class Category extends Model { } const CategoryModel = () => { Category.init( { id: { autoIncrement: true, type: DataTypes.INTEGER, allowNull: false, primaryKey: true }, name: { type: DataTypes.STRING(255), allowNull: false }, parentId: { type: DataTypes.INTEGER, allowNull: true } }, { sequelize, tableName: 'category', timestamps: true, indexes: [ { name: "PRIMARY", unique: true, using: "BTREE", fields: [ { name: "id" }, ] }, ] } ); Category.prototype.toJSONFor = function () { return { id: this.id, name: this.name, parentId: this.parentId }; }; return Category; }; module.exports = CategoryModel;