import { DataTypes } from 'sequelize'; import sequelize from '../db/config.js'; const Project = sequelize.define('Project', { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, portal: { type: DataTypes.STRING(50), allowNull: false, }, portalProjectId: { type: DataTypes.STRING(100), allowNull: false, field: 'portal_project_id', }, title: { type: DataTypes.STRING, allowNull: false, }, description: { type: DataTypes.TEXT('long'), allowNull: true, }, company: { type: DataTypes.STRING, allowNull: true, }, location: { type: DataTypes.STRING, allowNull: true, }, rate: { type: DataTypes.STRING(100), allowNull: true, }, url: { type: DataTypes.STRING(500), allowNull: false, }, publishedAt: { type: DataTypes.DATE, allowNull: true, field: 'published_at', }, // Abgleich mit Akquise und Opportunities (services/appliedCheck.js). Die // Spalten zieht initScannerDatabase() per ALTER TABLE nach. alreadyApplied: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, field: 'already_applied', }, appliedRefs: { type: DataTypes.TEXT, allowNull: true, field: 'applied_refs', comment: 'JSON array: [{ type, id, title, consultant, reason }]', get() { const rawValue = this.getDataValue('appliedRefs'); try { return rawValue ? JSON.parse(rawValue) : []; } catch { return []; } }, set(value) { this.setDataValue('appliedRefs', value ? JSON.stringify(value) : null); }, }, appliedCheckAt: { type: DataTypes.DATE, allowNull: true, field: 'applied_check_at', }, }, { tableName: 'projects', indexes: [ { unique: true, fields: ['portal', 'portal_project_id'], }, ], timestamps: true, updatedAt: false, // projects are immutable once scraped, we only track when they were created createdAt: 'created_at', }); export default Project;