1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 'use strict';
- const {
- Model
- } = require('sequelize');
- module.exports = (sequelize, DataTypes) => {
- class Contact extends Model {
- /**
- * Helper method for defining associations.
- * This method is not a part of Sequelize lifecycle.
- * The `models/index` file will call this method automatically.
- */
- static associate(models) {
- // define association here
- }
- }
-
- Contact.init({
- id: {
- type: DataTypes.INTEGER,
- primaryKey: true,
- autoIncrement: true
- },
- name: {
- type: DataTypes.STRING(100),
- allowNull: false,
- comment: '联系人姓名'
- },
- email: {
- type: DataTypes.STRING(255),
- allowNull: false,
- validate: {
- isEmail: true
- },
- comment: '联系人邮箱'
- },
- phone: {
- type: DataTypes.STRING(20),
- allowNull: true,
- comment: '联系电话'
- },
- company: {
- type: DataTypes.STRING(200),
- allowNull: true,
- comment: '公司名称'
- },
- subject: {
- type: DataTypes.STRING(200),
- allowNull: false,
- comment: '留言主题'
- },
- message: {
- type: DataTypes.TEXT,
- allowNull: false,
- comment: '留言内容'
- },
- status: {
- type: DataTypes.INTEGER,
- defaultValue: 0,
- comment: '处理状态:0-未处理,1-已处理'
- },
- isEmailSent: {
- type: DataTypes.BOOLEAN,
- defaultValue: false,
- comment: '是否已发送邮件通知'
- }
- }, {
- sequelize,
- modelName: 'Contact',
- tableName: 'contacts',
- timestamps: true,
- indexes: [
- {
- fields: ['email']
- },
- {
- fields: ['status']
- },
- {
- fields: ['createdAt']
- }
- ]
- });
-
- return Contact;
- };
|