From cec2d85801fad2136c9b712ad5d1409770ea612b Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Mon, 16 Mar 2026 09:33:22 +0330 Subject: [PATCH] add: rent fields to company --- database/migrations/.snapshot-dzone-db.json | 29 +++++++++++++++++++ .../migrations/Migration20260316055843.ts | 9 ++++++ .../companies/DTO/create-company.dto.ts | 17 ++++++++++- .../companies/entities/company.entity.ts | 9 ++++++ .../companies/services/companies.service.ts | 4 +-- 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 database/migrations/Migration20260316055843.ts diff --git a/database/migrations/.snapshot-dzone-db.json b/database/migrations/.snapshot-dzone-db.json index 1f253af..a2f3f34 100644 --- a/database/migrations/.snapshot-dzone-db.json +++ b/database/migrations/.snapshot-dzone-db.json @@ -3636,6 +3636,35 @@ "default": "true", "mappedType": "boolean" }, + "is_rented": { + "name": "is_rented", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, + "rent_contract_images": { + "name": "rent_contract_images", + "type": "jsonb", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "json" + }, + "rent_end_at": { + "name": "rent_end_at", + "type": "timestamptz", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "length": 6, + "mappedType": "datetime" + }, "status": { "name": "status", "type": "company_status", diff --git a/database/migrations/Migration20260316055843.ts b/database/migrations/Migration20260316055843.ts new file mode 100644 index 0000000..4d8e08b --- /dev/null +++ b/database/migrations/Migration20260316055843.ts @@ -0,0 +1,9 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20260316055843 extends Migration { + + override async up(): Promise { + this.addSql(`alter table "company" add column "is_rented" boolean not null default false, add column "rent_contract_images" jsonb null, add column "rent_end_at" timestamptz null;`); + } + +} diff --git a/src/modules/companies/DTO/create-company.dto.ts b/src/modules/companies/DTO/create-company.dto.ts index 776d42a..b7d1bf0 100644 --- a/src/modules/companies/DTO/create-company.dto.ts +++ b/src/modules/companies/DTO/create-company.dto.ts @@ -1,4 +1,4 @@ -import { ApiProperty, PickType } from "@nestjs/swagger"; +import { ApiProperty, ApiPropertyOptional, PickType } from "@nestjs/swagger"; import { Type } from "class-transformer"; import { ArrayMinSize, @@ -87,6 +87,21 @@ export class CreateCompanyDto extends PickType(CompleteRegistrationDto, ["phone" @ApiProperty({ description: "وضعیت فعالیت", example: true }) isActive?: boolean; + @IsBoolean() + @ApiProperty({ description: "وضعیت اجاره", example: true }) + isRented: boolean; + + @IsOptional() + @IsDateString() + @ApiPropertyOptional({ description: " تاریخ پایان قرارداد اجاره در صورتیکه اجاره ای است" }) + rentEndAt?: string; + + @IsOptional() + @IsArray() + @ValidateNested({ each: true }) + @ApiPropertyOptional({ description: "تصاویر قرارداد اجاره" }) + rentContractImages?: string[]; + @IsNotEmpty({ message: CompanyMessage.INDUSTRY_ID_REQUIRED }) @IsUUID("7", { message: CompanyMessage.INDUSTRY_ID_SHOULD_BE_UUID }) @ApiProperty({ description: "شناسه صنعت", example: "123e4567-e89b-12d3-a456-426614174000" }) diff --git a/src/modules/companies/entities/company.entity.ts b/src/modules/companies/entities/company.entity.ts index d0868fb..da1f786 100644 --- a/src/modules/companies/entities/company.entity.ts +++ b/src/modules/companies/entities/company.entity.ts @@ -54,6 +54,15 @@ export class Company extends BaseEntity { @Property({ type: "boolean", default: true }) isActive!: boolean & Opt; + @Property({ type: "boolean", default: false }) + isRented!: boolean & Opt; + + @Property({ type: "json", nullable: true }) + rentContractImages?: string[]; + + @Property({ nullable: true }) + rentEndAt?: Date; + @Enum({ items: () => CompanyStatus, nativeEnumName: "company_status", nullable: false }) status!: CompanyStatus; diff --git a/src/modules/companies/services/companies.service.ts b/src/modules/companies/services/companies.service.ts index e021ffc..2a67faf 100644 --- a/src/modules/companies/services/companies.service.ts +++ b/src/modules/companies/services/companies.service.ts @@ -30,7 +30,7 @@ export class CompaniesService { private readonly passwordService: PasswordService, private readonly em: EntityManager, private readonly companyRequestRepository: CompanyRequestRepository, - ) {} + ) { } async create(createDto: CreateCompanyDto, business: Business) { const em = this.em.fork(); @@ -452,7 +452,7 @@ export class CompaniesService { business, chiefExecutiveOfficer: "chiefExecutiveOfficer" in createDto ? createDto.chiefExecutiveOfficer : `${createDto.firstName} ${createDto.lastName}`, email: createDto.email, - phone: createDto.phone, + phone: createDto.phone }); await em.persistAndFlush(company);