Files
competition-website/app/model/account.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

168 lines
3.5 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';
/**
* 账号模型 - Account
*
* 存储参赛者账号的全部信息,包括个人资料、联系方式和密码等。
* 表名:accounts
*/
module.exports = app => {
const { STRING, INTEGER, BOOLEAN, DATE } = app.Sequelize;
const Account = app.model.define('account', {
// 主键,自增
uid: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '账号唯一标识',
},
// 角色:contestant / admin
role: {
type: STRING(20),
allowNull: false,
defaultValue: 'contestant',
comment: '账号角色',
},
// 中文姓名
name_cn: {
type: STRING(50),
allowNull: false,
comment: '中文姓名',
},
// 英文姓名
name_en: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '英文姓名',
},
// 性别:male / female
gender: {
type: STRING(10),
allowNull: true,
defaultValue: null,
comment: '性别',
},
// 手机号码
phone: {
type: STRING(20),
allowNull: true,
defaultValue: null,
comment: '手机号码',
},
// 电子邮箱
email: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '电子邮箱',
},
// 身份证号,唯一
id_number: {
type: STRING(18),
allowNull: false,
unique: true,
comment: '身份证号',
},
// 登录密码(SHA256 哈希存储)
password: {
type: STRING(100),
allowNull: false,
comment: '登录密码',
},
// 密码盐值
salt: {
type: STRING(32),
allowNull: false,
comment: '密码盐值',
},
// 职位
position: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '职位',
},
// 专业
major: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '专业',
},
// 国家
country: {
type: STRING(50),
allowNull: true,
defaultValue: null,
comment: '国家',
},
// 地区
region: {
type: STRING(50),
allowNull: true,
defaultValue: null,
comment: '地区',
},
// 机构/单位(中文)
organization_cn: {
type: STRING(200),
allowNull: true,
defaultValue: null,
comment: '机构/单位(中文)',
},
// 机构/单位(英文)
organization_en: {
type: STRING(200),
allowNull: true,
defaultValue: null,
comment: '机构/单位(英文)',
},
// 账号是否已激活
activated: {
type: BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '账号激活状态',
},
// 总分
score: {
type: INTEGER,
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: 'accounts',
timestamps: false,
underscored: true,
indexes: [
{
unique: true,
fields: ['id_number'],
},
{
fields: ['role'],
},
],
});
return Account;
};