From f8b74cb5eff0ab7dca3ff43ae0583f113eb146a0 Mon Sep 17 00:00:00 2001 From: webserver-lab Date: Sun, 31 May 2026 14:20:34 +0330 Subject: [PATCH] ddd --- src/models/Applicant.ts | 18 ++++- src/models/Job.ts | 46 ++++++++++++ src/models/JobCategory.ts | 16 ++-- src/models/JobRequest.ts | 12 ++- src/models/PersonalInfo.ts | 148 ++++++++++--------------------------- src/models/index.ts | 12 +++ 6 files changed, 131 insertions(+), 121 deletions(-) create mode 100644 src/models/Job.ts diff --git a/src/models/Applicant.ts b/src/models/Applicant.ts index 303f937..266396f 100644 --- a/src/models/Applicant.ts +++ b/src/models/Applicant.ts @@ -2,18 +2,22 @@ import { Model, DataTypes, Sequelize, Optional } from "sequelize"; export interface ApplicantAttributes { id: string; + isCompleted:boolean, + formStep:number, createdAt?: Date; updatedAt?: Date; } export interface ApplicantCreationAttributes - extends Optional {} + extends Optional {} export class Applicant extends Model implements ApplicantAttributes { public id!: string; + public isCompleted!: boolean; + public formStep!:number; public readonly createdAt!: Date; public readonly updatedAt!: Date; @@ -24,7 +28,17 @@ export class Applicant type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, - allowNull: false + allowNull: false, + }, + isCompleted:{ + type:DataTypes.BOOLEAN, + allowNull:false, + defaultValue:false + }, + formStep:{ + type:DataTypes.INTEGER, + allowNull:false, + defaultValue:0 } }, { diff --git a/src/models/Job.ts b/src/models/Job.ts new file mode 100644 index 0000000..51d949f --- /dev/null +++ b/src/models/Job.ts @@ -0,0 +1,46 @@ +import { DataTypes, Model, Sequelize } from "sequelize"; + +export class Job extends Model { + public id!: string; + public jobCategoryId!: string; + public title!: string; // نام شغل + public isActive!: boolean; // اختیاری + + static initModel(sequelize: Sequelize) { + Job.init( + { + id: { + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, + primaryKey: true, + }, + jobCategoryId: { + type: DataTypes.UUID, + allowNull: false, + references: { + model: "job_categories", + key: "id", + }, + onDelete: "CASCADE", + onUpdate: "CASCADE", + }, + title: { + type: DataTypes.STRING, + allowNull: false, + }, + isActive: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: true, + }, + }, + { + sequelize, + tableName: "jobs", + timestamps: true, + } + ); + + return Job; + } +} diff --git a/src/models/JobCategory.ts b/src/models/JobCategory.ts index 9f4d6a3..bdcaa87 100644 --- a/src/models/JobCategory.ts +++ b/src/models/JobCategory.ts @@ -18,9 +18,9 @@ export class JobCategory extends Model { type: DataTypes.UUID, allowNull: false, references: { - model: 'centers', - key: 'id' - } + model: "centers", + key: "id", + }, }, name: { type: DataTypes.STRING, @@ -32,11 +32,11 @@ export class JobCategory extends Model { allowNull: false, }, }, - { - sequelize, - tableName: "job_categories", - timestamps: true - } + { + sequelize, + tableName: "job_categories", + timestamps: true, + }, ); return JobCategory; } diff --git a/src/models/JobRequest.ts b/src/models/JobRequest.ts index c62980d..08d2159 100644 --- a/src/models/JobRequest.ts +++ b/src/models/JobRequest.ts @@ -44,10 +44,14 @@ export class JobRequest extends Model { key: "id", }, }, - jobTitle: { - type: DataTypes.STRING, - allowNull: false, - }, + // jobId: { + // type: DataTypes.UUID, + // allowNull: false, + // references: { + // model: "job", // نام جدول رسته‌ها + // key: "id", + // }, + // }, description: { type: DataTypes.TEXT, allowNull: true, diff --git a/src/models/PersonalInfo.ts b/src/models/PersonalInfo.ts index f4b2a57..47a023f 100644 --- a/src/models/PersonalInfo.ts +++ b/src/models/PersonalInfo.ts @@ -3,32 +3,31 @@ import { Model, DataTypes, Sequelize, Optional } from "sequelize"; export interface PersonalInfoAttributes { id: string; applicantId: string; - maritalStatus?: string; militaryStatus?: string; - fatherEducation?: string; fatherJob?: string; - motherEducation?: string; motherJob?: string; - housingStatus?: string; city?: string; address?: string; - homePhone?: string; mobilePhone?: string; emergencyPhone?: string; email?: string; - residenceDuration?: number; - isVeteran?: boolean; - hasCriminalRecord?: boolean; criminalDescription?: string; + // فیلدهای جدید + spouseName?: string; + spouseEducation?: string; + spouseJob?: string; + spouseWorkplace?: string; + childrenCount?: number; + createdAt?: Date; updatedAt?: Date; } @@ -44,32 +43,31 @@ export class PersonalInfo { public id!: string; public applicantId!: string; - public maritalStatus?: string; public militaryStatus?: string; - public fatherEducation?: string; public fatherJob?: string; - public motherEducation?: string; public motherJob?: string; - public housingStatus?: string; public city?: string; public address?: string; - public homePhone?: string; public mobilePhone?: string; public emergencyPhone?: string; public email?: string; - public residenceDuration?: number; - public isVeteran?: boolean; - public hasCriminalRecord?: boolean; public criminalDescription?: string; + // فیلدهای جدید + public spouseName?: string; + public spouseEducation?: string; + public spouseJob?: string; + public spouseWorkplace?: string; + public childrenCount?: number; + public readonly createdAt!: Date; public readonly updatedAt!: Date; @@ -80,107 +78,43 @@ export class PersonalInfo type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, - allowNull: false + allowNull: false, }, - - applicantId: { - type: DataTypes.UUID, - allowNull: false - }, - - maritalStatus: { - type: DataTypes.STRING, - allowNull: true - }, - - militaryStatus: { - type: DataTypes.STRING, - allowNull: true - }, - - fatherEducation: { - type: DataTypes.STRING, - allowNull: true - }, - - fatherJob: { - type: DataTypes.STRING, - allowNull: true - }, - - motherEducation: { - type: DataTypes.STRING, - allowNull: true - }, - - motherJob: { - type: DataTypes.STRING, - allowNull: true - }, - - housingStatus: { - type: DataTypes.STRING, - allowNull: true - }, - - city: { - type: DataTypes.STRING, - allowNull: true - }, - - address: { - type: DataTypes.TEXT, - allowNull: true - }, - - homePhone: { - type: DataTypes.STRING, - allowNull: true - }, - - mobilePhone: { - type: DataTypes.STRING, - allowNull: true - }, - - emergencyPhone: { - type: DataTypes.STRING, - allowNull: true - }, - + applicantId: { type: DataTypes.UUID, allowNull: false }, + maritalStatus: { type: DataTypes.STRING, allowNull: true }, + militaryStatus: { type: DataTypes.STRING, allowNull: true }, + fatherEducation: { type: DataTypes.STRING, allowNull: true }, + fatherJob: { type: DataTypes.STRING, allowNull: true }, + motherEducation: { type: DataTypes.STRING, allowNull: true }, + motherJob: { type: DataTypes.STRING, allowNull: true }, + housingStatus: { type: DataTypes.STRING, allowNull: true }, + city: { type: DataTypes.STRING, allowNull: true }, + address: { type: DataTypes.TEXT, allowNull: true }, + homePhone: { type: DataTypes.STRING, allowNull: true }, + mobilePhone: { type: DataTypes.STRING, allowNull: true }, + emergencyPhone: { type: DataTypes.STRING, allowNull: true }, email: { type: DataTypes.STRING, allowNull: true, - validate: { - isEmail: true - } + validate: { isEmail: true }, }, + residenceDuration: { type: DataTypes.INTEGER, allowNull: true }, + isVeteran: { type: DataTypes.BOOLEAN, defaultValue: false }, + hasCriminalRecord: { type: DataTypes.BOOLEAN, defaultValue: false }, + criminalDescription: { type: DataTypes.TEXT, allowNull: true }, - residenceDuration: { - type: DataTypes.INTEGER, - allowNull: true - }, - - isVeteran: { - type: DataTypes.BOOLEAN, - defaultValue: false - }, - - hasCriminalRecord: { - type: DataTypes.BOOLEAN, - defaultValue: false - }, - - criminalDescription: { - type: DataTypes.TEXT, - allowNull: true - } + // تعریف فیلدهای جدید در Init + spouseName: { type: DataTypes.STRING, allowNull: true }, + spouseEducation: { type: DataTypes.STRING, allowNull: true }, + spouseJob: { type: DataTypes.STRING, allowNull: true }, + spouseWorkplace: { type: DataTypes.STRING, allowNull: true }, + childrenCount: { type: DataTypes.INTEGER, allowNull: true }, }, { sequelize, tableName: "personal_infos", - timestamps: true - } + timestamps: true, + }, ); return PersonalInfo; diff --git a/src/models/index.ts b/src/models/index.ts index e35920a..c2c2c08 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -18,6 +18,7 @@ import { JobInfo } from "./JobInfo"; import { JobRequest } from "./JobRequest"; import { Center } from "./Center"; import { JobCategory } from "./JobCategory"; +import { Job } from "./Job"; // تنظیمات اتصال به دیتابیس const sequelize = new Sequelize("employee_form", "postgres", "root", { @@ -48,6 +49,7 @@ const models = { Referral: Referral.initModel(sequelize), JobCategory: JobCategory.initModel(sequelize), JobRequest: JobRequest.initModel(sequelize), + Job: Job.initModel(sequelize), }; // Role.hasMany(User, { foreignKey: "roleId" }); // User.belongsTo(Role, { foreignKey: "roleId" }); @@ -216,6 +218,16 @@ Applicant.hasMany(JobRequest, { foreignKey: "applicantId", as: "jobRequests" }); JobRequest.belongsTo(Applicant, { foreignKey: "applicantId", as: "applicant" }); Center.hasMany(JobRequest, { foreignKey: "centerId", as: "applications" }); JobRequest.belongsTo(Center, { foreignKey: "centerId", as: "center" }); + +JobCategory.hasMany(Job, { + foreignKey: "jobCategoryId", + as: "jobs", +}); + +Job.belongsTo(JobCategory, { + foreignKey: "jobCategoryId", + as: "category", +}); // ۲. برقراری روابط (Associations) // این حلقه متد associate را در هر کلاسی که تعریف شده باشد فراخوانی می‌کند Object.values(models).forEach((model: any) => {