This commit is contained in:
2026-05-31 14:20:34 +03:30
parent 9503e29ae8
commit f8b74cb5ef
6 changed files with 131 additions and 121 deletions

View File

@@ -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<ApplicantAttributes, "id" | "createdAt" | "updatedAt"> {}
extends Optional<ApplicantAttributes, "id" |"isCompleted" | "formStep" | "createdAt" | "updatedAt"> {}
export class Applicant
extends Model<ApplicantAttributes, ApplicantCreationAttributes>
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
}
},
{

46
src/models/Job.ts Normal file
View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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;

View File

@@ -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) => {