Files
competition-website/app/model/news.js
WorkBuddy a303cf2d53 chore: 后端首次基线提交
运行必须源码:app/(controller/model/service/middleware/lib/utils/validate/router)、config/、database/(migrations/seeders/sql)、启动脚本、app/public/templates 模板。
已忽略运行非必须:node_modules/、logs/、run/、app/public 运行时上传数据、.env*、构建/缓存产物。
2026-08-17 12:25:42 +08:00

118 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
/**
* 新闻模型 - News
*
* 存储新闻通知信息,支持置顶、微信公众号链接和按组别过滤显示。
* 表名:news
*/
module.exports = app => {
const { STRING, TEXT, BOOLEAN, DATE, INTEGER } = app.Sequelize;
const News = app.model.define('news', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '新闻唯一标识',
},
// 新闻标题
title: {
type: STRING(200),
allowNull: false,
comment: '新闻标题',
},
// 新闻正文内容(支持 HTML)
content: {
type: TEXT,
allowNull: true,
defaultValue: null,
comment: '新闻正文(微信链接型新闻可为空)',
},
// 微信公众号文章链接
wx_link: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '微信公众号文章链接',
},
// 新闻类型:content(内容型)/ wx_link(微信链接型)
news_type: {
type: STRING(20),
allowNull: false,
defaultValue: 'content',
comment: '新闻类型:content=内容型, wx_link=微信链接型',
},
// 发布时间
publish_time: {
type: DATE,
allowNull: false,
comment: '发布时间',
},
// 是否置顶
pinned: {
type: BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '是否置顶',
},
// 排序序号
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '排序序号,越小越靠前',
},
// 目标可见组别
group: {
type: STRING(20),
allowNull: false,
defaultValue: 'all',
comment: '目标可见组别',
},
// 标签(逗号分隔)
tags: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '标签,多个标签用逗号分隔',
},
// 记录创建时间
created_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
// 记录更新时间
updated_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '更新时间',
},
}, {
tableName: 'news',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['publish_time'],
},
{
fields: ['pinned', 'publish_time'],
},
{
fields: ['group'],
},
{
fields: ['sort_order'],
},
],
});
return News;
};