35 lines
1.5 KiB
JavaScript
Raw Permalink 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';
/**
* 主体表模型(subjects)
*
* 「主体」= 租户 / 公司 / 门店,是本系统所有业务数据的归属单位:
* 设备、NVR、摄像头、工作台、扫码记录都挂在主体下,接口按主体隔离。
*
* - `adminUserId`:管理员(默认就是创建人),只有管理员能改主体信息、加/删成员
* - `expireAt`:使用期限,到期后该主体不可进入(接口返回 403 subject_expired)
*/
module.exports = (app) => {
const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize;
const Subject = app.model.define('subject', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
name: { type: STRING(64), allowNull: false, comment: '主体名称' },
adminUserId: { type: BIGINT.UNSIGNED, allowNull: false, comment: '管理员 users.id(默认创建人)' },
expireAt: { type: DATE, allowNull: false, comment: '使用期限(到期后不可进入)' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1启用 0停用' },
remark: { type: STRING(255), comment: '备注' },
}, {
tableName: 'subjects',
paranoid: true,
comment: '主体表',
});
Subject.associate = function() {
app.model.Subject.belongsTo(app.model.User, { foreignKey: 'admin_user_id', as: 'admin' });
app.model.Subject.hasMany(app.model.SubjectMember, { foreignKey: 'subject_id', as: 'members' });
};
return Subject;
};