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 { export interface ApplicantAttributes {
id: string; id: string;
isCompleted:boolean,
formStep:number,
createdAt?: Date; createdAt?: Date;
updatedAt?: Date; updatedAt?: Date;
} }
export interface ApplicantCreationAttributes export interface ApplicantCreationAttributes
extends Optional<ApplicantAttributes, "id" | "createdAt" | "updatedAt"> {} extends Optional<ApplicantAttributes, "id" |"isCompleted" | "formStep" | "createdAt" | "updatedAt"> {}
export class Applicant export class Applicant
extends Model<ApplicantAttributes, ApplicantCreationAttributes> extends Model<ApplicantAttributes, ApplicantCreationAttributes>
implements ApplicantAttributes implements ApplicantAttributes
{ {
public id!: string; public id!: string;
public isCompleted!: boolean;
public formStep!:number;
public readonly createdAt!: Date; public readonly createdAt!: Date;
public readonly updatedAt!: Date; public readonly updatedAt!: Date;
@@ -24,7 +28,17 @@ export class Applicant
type: DataTypes.UUID, type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4, defaultValue: DataTypes.UUIDV4,
primaryKey: true, 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, type: DataTypes.UUID,
allowNull: false, allowNull: false,
references: { references: {
model: 'centers', model: "centers",
key: 'id' key: "id",
} },
}, },
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
@@ -32,11 +32,11 @@ export class JobCategory extends Model {
allowNull: false, allowNull: false,
}, },
}, },
{ {
sequelize, sequelize,
tableName: "job_categories", tableName: "job_categories",
timestamps: true timestamps: true,
} },
); );
return JobCategory; return JobCategory;
} }

View File

@@ -44,10 +44,14 @@ export class JobRequest extends Model {
key: "id", key: "id",
}, },
}, },
jobTitle: { // jobId: {
type: DataTypes.STRING, // type: DataTypes.UUID,
allowNull: false, // allowNull: false,
}, // references: {
// model: "job", // نام جدول رسته‌ها
// key: "id",
// },
// },
description: { description: {
type: DataTypes.TEXT, type: DataTypes.TEXT,
allowNull: true, allowNull: true,

View File

@@ -3,32 +3,31 @@ import { Model, DataTypes, Sequelize, Optional } from "sequelize";
export interface PersonalInfoAttributes { export interface PersonalInfoAttributes {
id: string; id: string;
applicantId: string; applicantId: string;
maritalStatus?: string; maritalStatus?: string;
militaryStatus?: string; militaryStatus?: string;
fatherEducation?: string; fatherEducation?: string;
fatherJob?: string; fatherJob?: string;
motherEducation?: string; motherEducation?: string;
motherJob?: string; motherJob?: string;
housingStatus?: string; housingStatus?: string;
city?: string; city?: string;
address?: string; address?: string;
homePhone?: string; homePhone?: string;
mobilePhone?: string; mobilePhone?: string;
emergencyPhone?: string; emergencyPhone?: string;
email?: string; email?: string;
residenceDuration?: number; residenceDuration?: number;
isVeteran?: boolean; isVeteran?: boolean;
hasCriminalRecord?: boolean; hasCriminalRecord?: boolean;
criminalDescription?: string; criminalDescription?: string;
// فیلدهای جدید
spouseName?: string;
spouseEducation?: string;
spouseJob?: string;
spouseWorkplace?: string;
childrenCount?: number;
createdAt?: Date; createdAt?: Date;
updatedAt?: Date; updatedAt?: Date;
} }
@@ -44,32 +43,31 @@ export class PersonalInfo
{ {
public id!: string; public id!: string;
public applicantId!: string; public applicantId!: string;
public maritalStatus?: string; public maritalStatus?: string;
public militaryStatus?: string; public militaryStatus?: string;
public fatherEducation?: string; public fatherEducation?: string;
public fatherJob?: string; public fatherJob?: string;
public motherEducation?: string; public motherEducation?: string;
public motherJob?: string; public motherJob?: string;
public housingStatus?: string; public housingStatus?: string;
public city?: string; public city?: string;
public address?: string; public address?: string;
public homePhone?: string; public homePhone?: string;
public mobilePhone?: string; public mobilePhone?: string;
public emergencyPhone?: string; public emergencyPhone?: string;
public email?: string; public email?: string;
public residenceDuration?: number; public residenceDuration?: number;
public isVeteran?: boolean; public isVeteran?: boolean;
public hasCriminalRecord?: boolean; public hasCriminalRecord?: boolean;
public criminalDescription?: string; public criminalDescription?: string;
// فیلدهای جدید
public spouseName?: string;
public spouseEducation?: string;
public spouseJob?: string;
public spouseWorkplace?: string;
public childrenCount?: number;
public readonly createdAt!: Date; public readonly createdAt!: Date;
public readonly updatedAt!: Date; public readonly updatedAt!: Date;
@@ -80,107 +78,43 @@ export class PersonalInfo
type: DataTypes.UUID, type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4, defaultValue: DataTypes.UUIDV4,
primaryKey: true, primaryKey: true,
allowNull: false allowNull: false,
}, },
applicantId: { type: DataTypes.UUID, allowNull: false },
applicantId: { maritalStatus: { type: DataTypes.STRING, allowNull: true },
type: DataTypes.UUID, militaryStatus: { type: DataTypes.STRING, allowNull: true },
allowNull: false fatherEducation: { type: DataTypes.STRING, allowNull: true },
}, fatherJob: { type: DataTypes.STRING, allowNull: true },
motherEducation: { type: DataTypes.STRING, allowNull: true },
maritalStatus: { motherJob: { type: DataTypes.STRING, allowNull: true },
type: DataTypes.STRING, housingStatus: { type: DataTypes.STRING, allowNull: true },
allowNull: true city: { type: DataTypes.STRING, allowNull: true },
}, address: { type: DataTypes.TEXT, allowNull: true },
homePhone: { type: DataTypes.STRING, allowNull: true },
militaryStatus: { mobilePhone: { type: DataTypes.STRING, allowNull: true },
type: DataTypes.STRING, emergencyPhone: { type: DataTypes.STRING, allowNull: true },
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: { email: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
validate: { validate: { isEmail: true },
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: { // تعریف فیلدهای جدید در Init
type: DataTypes.INTEGER, spouseName: { type: DataTypes.STRING, allowNull: true },
allowNull: true spouseEducation: { type: DataTypes.STRING, allowNull: true },
}, spouseJob: { type: DataTypes.STRING, allowNull: true },
spouseWorkplace: { type: DataTypes.STRING, allowNull: true },
isVeteran: { childrenCount: { type: DataTypes.INTEGER, allowNull: true },
type: DataTypes.BOOLEAN,
defaultValue: false
},
hasCriminalRecord: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
criminalDescription: {
type: DataTypes.TEXT,
allowNull: true
}
}, },
{ {
sequelize, sequelize,
tableName: "personal_infos", tableName: "personal_infos",
timestamps: true timestamps: true,
} },
); );
return PersonalInfo; return PersonalInfo;

View File

@@ -18,6 +18,7 @@ import { JobInfo } from "./JobInfo";
import { JobRequest } from "./JobRequest"; import { JobRequest } from "./JobRequest";
import { Center } from "./Center"; import { Center } from "./Center";
import { JobCategory } from "./JobCategory"; import { JobCategory } from "./JobCategory";
import { Job } from "./Job";
// تنظیمات اتصال به دیتابیس // تنظیمات اتصال به دیتابیس
const sequelize = new Sequelize("employee_form", "postgres", "root", { const sequelize = new Sequelize("employee_form", "postgres", "root", {
@@ -48,6 +49,7 @@ const models = {
Referral: Referral.initModel(sequelize), Referral: Referral.initModel(sequelize),
JobCategory: JobCategory.initModel(sequelize), JobCategory: JobCategory.initModel(sequelize),
JobRequest: JobRequest.initModel(sequelize), JobRequest: JobRequest.initModel(sequelize),
Job: Job.initModel(sequelize),
}; };
// Role.hasMany(User, { foreignKey: "roleId" }); // Role.hasMany(User, { foreignKey: "roleId" });
// User.belongsTo(Role, { 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" }); JobRequest.belongsTo(Applicant, { foreignKey: "applicantId", as: "applicant" });
Center.hasMany(JobRequest, { foreignKey: "centerId", as: "applications" }); Center.hasMany(JobRequest, { foreignKey: "centerId", as: "applications" });
JobRequest.belongsTo(Center, { foreignKey: "centerId", as: "center" }); JobRequest.belongsTo(Center, { foreignKey: "centerId", as: "center" });
JobCategory.hasMany(Job, {
foreignKey: "jobCategoryId",
as: "jobs",
});
Job.belongsTo(JobCategory, {
foreignKey: "jobCategoryId",
as: "category",
});
// ۲. برقراری روابط (Associations) // ۲. برقراری روابط (Associations)
// این حلقه متد associate را در هر کلاسی که تعریف شده باشد فراخوانی می‌کند // این حلقه متد associate را در هر کلاسی که تعریف شده باشد فراخوانی می‌کند
Object.values(models).forEach((model: any) => { Object.values(models).forEach((model: any) => {