barname
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export class CreateBarnameDto {
|
||||
carType: string;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsString({each:true})
|
||||
@IsString({ each: true })
|
||||
@IsArray()
|
||||
attachments: string[];
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user