sequelize_models.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Sequelize模型定义示例
  2. const { Sequelize, DataTypes } = require('sequelize');
  3. // 数据库连接配置
  4. const sequelize = new Sequelize('job_management', 'username', 'password', {
  5. host: 'localhost',
  6. dialect: 'mysql',
  7. });
  8. // 部门模型
  9. const Department = sequelize.define('Department', {
  10. name: {
  11. type: DataTypes.STRING(100),
  12. allowNull: false,
  13. },
  14. description: {
  15. type: DataTypes.TEXT,
  16. },
  17. });
  18. // 岗位模型
  19. const Job = sequelize.define('Job', {
  20. title: {
  21. type: DataTypes.STRING(100),
  22. allowNull: false,
  23. },
  24. location: {
  25. type: DataTypes.STRING(100),
  26. allowNull: false,
  27. },
  28. status: {
  29. type: DataTypes.ENUM('active', 'paused', 'draft'),
  30. defaultValue: 'draft',
  31. },
  32. pendingResumes: {
  33. type: DataTypes.INTEGER,
  34. defaultValue: 0,
  35. field: 'pending_resumes',
  36. },
  37. passedResumes: {
  38. type: DataTypes.INTEGER,
  39. defaultValue: 0,
  40. field: 'passed_resumes',
  41. },
  42. jobDescription: {
  43. type: DataTypes.TEXT,
  44. field: 'job_description',
  45. },
  46. requirements: {
  47. type: DataTypes.TEXT,
  48. },
  49. salaryRange: {
  50. type: DataTypes.STRING(50),
  51. field: 'salary_range',
  52. },
  53. });
  54. // 简历模型
  55. const Resume = sequelize.define('Resume', {
  56. candidateName: {
  57. type: DataTypes.STRING(100),
  58. allowNull: false,
  59. field: 'candidate_name',
  60. },
  61. email: {
  62. type: DataTypes.STRING(100),
  63. allowNull: false,
  64. },
  65. phone: {
  66. type: DataTypes.STRING(20),
  67. },
  68. status: {
  69. type: DataTypes.ENUM('pending', 'passed', 'rejected', 'interview'),
  70. defaultValue: 'pending',
  71. },
  72. resumeText: {
  73. type: DataTypes.TEXT,
  74. field: 'resume_text',
  75. },
  76. score: {
  77. type: DataTypes.DECIMAL(5, 2),
  78. defaultValue: 0.0,
  79. },
  80. });
  81. // 用户模型
  82. const User = sequelize.define('User', {
  83. username: {
  84. type: DataTypes.STRING(50),
  85. allowNull: false,
  86. unique: true,
  87. },
  88. passwordHash: {
  89. type: DataTypes.STRING(255),
  90. allowNull: false,
  91. field: 'password_hash',
  92. },
  93. role: {
  94. type: DataTypes.ENUM('admin', 'recruiter', 'viewer'),
  95. defaultValue: 'recruiter',
  96. },
  97. });
  98. // 关联关系
  99. Department.hasMany(Job, { foreignKey: 'department_id' });
  100. Job.belongsTo(Department, { foreignKey: 'department_id' });
  101. Job.hasMany(Resume, { foreignKey: 'job_id' });
  102. Resume.belongsTo(Job, { foreignKey: 'job_id' });
  103. module.exports = {
  104. sequelize,
  105. Department,
  106. Job,
  107. Resume,
  108. User,
  109. };