Files
competition-website/app/model/news.js

142 lines
3.7 KiB
JavaScript
Raw Normal View History

'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: '标签,多个标签用逗号分隔',
},
// 草稿标记(R176)。成绩发布时会自动生成一条「成绩公示」预览新闻,
// 需人工编辑确认后才可对外发布 ⇒ 草稿期间必须前台不可见。
// 🔴 news.list / findById 的公开查询必须显式过滤 is_draft=0(默认值 0 保证历史 15 条不受影响)。
is_draft: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '草稿标记:0=已发布, 1=草稿(前台不可见)',
},
// 附件(R176)。用于成绩公示表的文件公示:管理员上传 xlsx/pdf 后,
// 详情页渲染成独立下载按钮,不依赖正文富文本里手写链接
// (手写链接在人工编辑正文时极易被误删)。
attachment_url: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '附件下载地址(相对路径 /public/news/xxx)',
},
attachment_name: {
type: STRING(200),
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;
};