From 4f6235a074f10c5d6e85f2d71410cd6a1e2dcb96 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sat, 7 Mar 2026 12:44:26 +0330 Subject: [PATCH] barname --- src/modules/barname/barname.service.ts | 37 +++++++++++++++++-- src/modules/barname/dto/create-barname.dto.ts | 2 +- .../barname/dto/update-barname-watcher.dto.ts | 11 ++++-- .../barname/entities/barname.entity.ts | 9 ++++- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/modules/barname/barname.service.ts b/src/modules/barname/barname.service.ts index ad73f98..6891f2b 100644 --- a/src/modules/barname/barname.service.ts +++ b/src/modules/barname/barname.service.ts @@ -9,6 +9,7 @@ import { CompanyMessage } from "../../common/enums/message.enum"; import { Business } from "../businesses/entities/business.entity"; import { Company } from "../companies/entities/company.entity"; import { BarnameStatus } from "./enums/bill-type.enum"; +import { UpdateBarnameAsWatcherDto } from "./dto/update-barname-watcher.dto"; // import { CompaniesService } from "../companies/services/companies.service"; @@ -37,6 +38,26 @@ export class BarnameService { return bill } + async updateBarname(id: string, dto: UpdateBarnameAsWatcherDto, business: Business, userId: string) { + const { exitedAt, watcherDescription } = dto; + + const barname = await this.findOne(id, business.id) + + console.log(userId) + + if (exitedAt) { + barname.exitedAt = exitedAt + } + + if (watcherDescription) { + barname.watcherDescription = watcherDescription + } + + await this.em.flush(); + + return barname + } + async findAll(queryDto: BillListQueryDto, businessId: string) { const [bills, count] = await this.billRepository.getBillsList(queryDto, businessId); @@ -48,11 +69,11 @@ export class BarnameService { } async findOne(id: string, businessId: string) { - const bill = await this.billRepository.findOne({ id, business: { id: businessId } }, { populate: [] }); - if (!bill) { - throw new BadRequestException("Bill not found"); + const barname = await this.findOneOrFail(id) + if (barname.business.id !== businessId) { + throw new BadRequestException("This business doenst belongs to you") } - return { bill }; + return barname; } async remove(id: string, businessId: string) { @@ -67,4 +88,12 @@ export class BarnameService { await this.em.removeAndFlush(bill); return { deleted: true }; } + + async findOneOrFail(id: string) { + const barname = await this.billRepository.findOne({ id }, { populate: ['company', 'business'] }); + if (!barname) { + throw new BadRequestException("barname not found"); + } + return barname + } } diff --git a/src/modules/barname/dto/create-barname.dto.ts b/src/modules/barname/dto/create-barname.dto.ts index 6a4100a..7787c1d 100644 --- a/src/modules/barname/dto/create-barname.dto.ts +++ b/src/modules/barname/dto/create-barname.dto.ts @@ -33,7 +33,7 @@ export class CreateBarnameDto { carType: string; @ApiPropertyOptional() - @IsString({each:true}) + @IsString({ each: true }) @IsArray() attachments: string[]; diff --git a/src/modules/barname/dto/update-barname-watcher.dto.ts b/src/modules/barname/dto/update-barname-watcher.dto.ts index 90aa201..c5e09c7 100644 --- a/src/modules/barname/dto/update-barname-watcher.dto.ts +++ b/src/modules/barname/dto/update-barname-watcher.dto.ts @@ -1,10 +1,15 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { IsDateString } from "class-validator"; +import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger"; +import { IsDateString, IsOptional, IsString } from "class-validator"; export class UpdateBarnameAsWatcherDto { @ApiProperty() @IsDateString() - exitAt: string; + exitedAt: string; + + @ApiPropertyOptional() + @IsString() + @IsOptional() + watcherDescription: string; } diff --git a/src/modules/barname/entities/barname.entity.ts b/src/modules/barname/entities/barname.entity.ts index 8b1ab30..fdc3e65 100644 --- a/src/modules/barname/entities/barname.entity.ts +++ b/src/modules/barname/entities/barname.entity.ts @@ -35,15 +35,20 @@ export class Barname extends BaseEntity { @Property({ type: 'string', nullable: true }) description?: string; - @Property({ type: 'json' }) attachments: string[]; @Property({ nullable: true }) - exitAt?: Date; + exitAt?: string; + + @Property({ nullable: true }) + exitedAt?: string; @Property() status: BarnameStatus & Opt + @Property({ type: 'string', nullable: true }) + watcherDescription?: string; + [EntityRepositoryType]?: BarnameRepository; }