{"size": 1474, "ext": "js", "max_stars_repo_path": "server/src/database/models/attachment.js", "max_stars_repo_name": "connect-foundation/2019-06", "max_stars_repo_stars_event_min_datetime": "2019-11-04T04:35:11.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-30T04:54:03.000Z", "max_issues_repo_path": "server/src/database/models/attachment.js", "max_issues_repo_name": "connect-foundation/2019-06", "max_issues_repo_issues_event_min_datetime": "2019-11-06T06:24:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T19:58:59.000Z", "max_forks_repo_path": "server/src/database/models/attachment.js", "max_forks_repo_name": "connect-foundation/2019-06", "max_forks_repo_forks_event_min_datetime": "2019-11-08T09:33:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-24T04:40:05.000Z"}
{"max_stars_count": 27, "max_issues_count": 187, "max_forks_count": 9, "avg_line_length": 22.0, "max_line_length": 92, "alphanum_fraction": 0.5569877883}
const model = (sequelize, DataTypes) => {
  const Attachment = sequelize.define(
    'Attachment',
    {
      no: {
        type: DataTypes.BIGINT.UNSIGNED,
        primaryKey: true,
        autoIncrement: true,
      },
      mail_template_id: {
        type: DataTypes.BIGINT.UNSIGNED,
        allowNull: false,
      },
      type: {
        type: DataTypes.STRING(255),
        allowNull: false,
      },
      name: {
        type: DataTypes.STRING(255),
        allowNull: false,
      },
      url: {
        type: DataTypes.TEXT,
        allowNull: false,
      },
      size: {
        type: DataTypes.INTEGER.UNSIGNED,
        allowNull: false,
      },
    },
    {
      freezeTableName: true,
      timestamps: false,
      paranoid: false,
      underscored: true,
      tableName: 'tbl_attachment',
      charset: 'utf8',
      collate: 'utf8_general_ci',
    },
  );

  Attachment.associate = ({ MailTemplate }) => {
    Attachment.belongsTo(MailTemplate, { foreignKey: 'mail_template_id', targetKey: 'no' });
  };

  Attachment.findAllByMailTemplateNo = ({ no }) => {
    return Attachment.findAll({
      where: {
        mail_template_id: no,
      },
      attributes: { exclude: ['url'] },
      raw: true,
    });
  };

  Attachment.findAttachmentAndMailTemplateByPk = no => {
    return Attachment.findByPk(no, {
      include: [{ model: sequelize.models.MailTemplate }],
      raw: true,
    });
  };

  return Attachment;
};

export default model;
