This commit is contained in:
2026-03-07 12:44:26 +03:30
parent 993c024cd5
commit 4f6235a074
4 changed files with 49 additions and 10 deletions
+33 -4
View File
@@ -9,6 +9,7 @@ import { CompanyMessage } from "../../common/enums/message.enum";
import { Business } from "../businesses/entities/business.entity"; import { Business } from "../businesses/entities/business.entity";
import { Company } from "../companies/entities/company.entity"; import { Company } from "../companies/entities/company.entity";
import { BarnameStatus } from "./enums/bill-type.enum"; import { BarnameStatus } from "./enums/bill-type.enum";
import { UpdateBarnameAsWatcherDto } from "./dto/update-barname-watcher.dto";
// import { CompaniesService } from "../companies/services/companies.service"; // import { CompaniesService } from "../companies/services/companies.service";
@@ -37,6 +38,26 @@ export class BarnameService {
return bill 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) { async findAll(queryDto: BillListQueryDto, businessId: string) {
const [bills, count] = await this.billRepository.getBillsList(queryDto, businessId); const [bills, count] = await this.billRepository.getBillsList(queryDto, businessId);
@@ -48,11 +69,11 @@ export class BarnameService {
} }
async findOne(id: string, businessId: string) { async findOne(id: string, businessId: string) {
const bill = await this.billRepository.findOne({ id, business: { id: businessId } }, { populate: [] }); const barname = await this.findOneOrFail(id)
if (!bill) { if (barname.business.id !== businessId) {
throw new BadRequestException("Bill not found"); throw new BadRequestException("This business doenst belongs to you")
} }
return { bill }; return barname;
} }
async remove(id: string, businessId: string) { async remove(id: string, businessId: string) {
@@ -67,4 +88,12 @@ export class BarnameService {
await this.em.removeAndFlush(bill); await this.em.removeAndFlush(bill);
return { deleted: true }; 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
}
} }
@@ -33,7 +33,7 @@ export class CreateBarnameDto {
carType: string; carType: string;
@ApiPropertyOptional() @ApiPropertyOptional()
@IsString({each:true}) @IsString({ each: true })
@IsArray() @IsArray()
attachments: string[]; attachments: string[];
@@ -1,10 +1,15 @@
import { ApiProperty } from "@nestjs/swagger"; import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsDateString } from "class-validator"; import { IsDateString, IsOptional, IsString } from "class-validator";
export class UpdateBarnameAsWatcherDto { export class UpdateBarnameAsWatcherDto {
@ApiProperty() @ApiProperty()
@IsDateString() @IsDateString()
exitAt: string; exitedAt: string;
@ApiPropertyOptional()
@IsString()
@IsOptional()
watcherDescription: string;
} }
@@ -35,15 +35,20 @@ export class Barname extends BaseEntity {
@Property({ type: 'string', nullable: true }) @Property({ type: 'string', nullable: true })
description?: string; description?: string;
@Property({ type: 'json' }) @Property({ type: 'json' })
attachments: string[]; attachments: string[];
@Property({ nullable: true }) @Property({ nullable: true })
exitAt?: Date; exitAt?: string;
@Property({ nullable: true })
exitedAt?: string;
@Property() @Property()
status: BarnameStatus & Opt status: BarnameStatus & Opt
@Property({ type: 'string', nullable: true })
watcherDescription?: string;
[EntityRepositoryType]?: BarnameRepository; [EntityRepositoryType]?: BarnameRepository;
} }