diff --git a/database/migrations/.snapshot-dzone-db.json b/database/migrations/.snapshot-dzone-db.json index 74a0515..b9ef612 100644 --- a/database/migrations/.snapshot-dzone-db.json +++ b/database/migrations/.snapshot-dzone-db.json @@ -6411,17 +6411,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, - "length": 255, - "mappedType": "string" - }, - "weight": { - "name": "weight", - "type": "varchar(255)", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, + "nullable": true, "length": 255, "mappedType": "string" }, @@ -6451,7 +6441,7 @@ "unsigned": false, "autoincrement": false, "primary": false, - "nullable": false, + "nullable": true, "length": 255, "mappedType": "string" }, diff --git a/database/migrations/Migration20260307082551.ts b/database/migrations/Migration20260307082551.ts new file mode 100644 index 0000000..2133987 --- /dev/null +++ b/database/migrations/Migration20260307082551.ts @@ -0,0 +1,16 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20260307082551 extends Migration { + + override async up(): Promise { + this.addSql(`alter table "barname" alter column "description" type varchar(255) using ("description"::varchar(255));`); + this.addSql(`alter table "barname" alter column "description" drop not null;`); + } + + override async down(): Promise { + this.addSql(`alter table "barname" add column "weight" varchar(255) not null;`); + this.addSql(`alter table "barname" alter column "description" type varchar(255) using ("description"::varchar(255));`); + this.addSql(`alter table "barname" alter column "description" set not null;`); + } + +} diff --git a/database/migrations/Migration20260307082850.ts b/database/migrations/Migration20260307082850.ts new file mode 100644 index 0000000..26cdf0e --- /dev/null +++ b/database/migrations/Migration20260307082850.ts @@ -0,0 +1,15 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20260307082850 extends Migration { + + override async up(): Promise { + this.addSql(`alter table "barname" alter column "origin" type varchar(255) using ("origin"::varchar(255));`); + this.addSql(`alter table "barname" alter column "origin" drop not null;`); + } + + override async down(): Promise { + this.addSql(`alter table "barname" alter column "origin" type varchar(255) using ("origin"::varchar(255));`); + this.addSql(`alter table "barname" alter column "origin" set not null;`); + } + +} diff --git a/src/modules/barname/barname.controller.ts b/src/modules/barname/barname.controller.ts index 22b473c..2b8a29d 100644 --- a/src/modules/barname/barname.controller.ts +++ b/src/modules/barname/barname.controller.ts @@ -40,6 +40,12 @@ export class BarnameController { return this.billsService.findOne(paramDto.id, businessId); } + @ApiOperation({ summary: "Update Barname by watcher" }) + @Get(":id/watcher") + update(@Param() dto: ParamDto, @BusinessDec("id") businessId: string) { + return this.billsService.findOne(dto.id, businessId); + } + @ApiOperation({ summary: "Remove a barname" }) @Delete(":id") remove(@Param() paramDto: ParamDto, @BusinessDec("id") businessId: string) { diff --git a/src/modules/barname/barname.service.ts b/src/modules/barname/barname.service.ts index 5ee59c9..ad73f98 100644 --- a/src/modules/barname/barname.service.ts +++ b/src/modules/barname/barname.service.ts @@ -24,13 +24,13 @@ export class BarnameService { ) { } async createBarname(dto: CreateBarnameDto, business: Business, userId: string) { - const { description, driverName, driverPhone, carType, exitAt, origin, plaque, weight, attachments } = dto; + const { description, driverName, driverPhone, carType, exitAt, origin, plaque, attachments } = dto; const company = await this.em.findOne(Company, { business, user: { id: userId }, deletedAt: null }); if (!company) throw new BadRequestException(CompanyMessage.COMPANY_NOT_FOUND); const bill = this.em.create(Barname, - { carType, exitAt, origin, plaque, weight, business, description, driverName, driverPhone, company, attachments }); + { carType, exitAt, origin, plaque, business, description, driverName, driverPhone, company, attachments }); await this.em.persistAndFlush(bill); @@ -61,7 +61,7 @@ export class BarnameService { throw new BadRequestException("Bill not found"); } - if(bill.status != BarnameStatus.PENDING){ + if (bill.status != BarnameStatus.PENDING) { throw new BadRequestException("You can not remove "); } await this.em.removeAndFlush(bill); diff --git a/src/modules/barname/dto/create-barname.dto.ts b/src/modules/barname/dto/create-barname.dto.ts index 4ad426a..6a4100a 100644 --- a/src/modules/barname/dto/create-barname.dto.ts +++ b/src/modules/barname/dto/create-barname.dto.ts @@ -26,10 +26,6 @@ export class CreateBarnameDto { @IsOptional() origin: string; - @ApiPropertyOptional() - @IsString() - @IsOptional() - weight: string; @ApiPropertyOptional() @IsString() diff --git a/src/modules/barname/dto/update-barname-watcher.dto.ts b/src/modules/barname/dto/update-barname-watcher.dto.ts new file mode 100644 index 0000000..90aa201 --- /dev/null +++ b/src/modules/barname/dto/update-barname-watcher.dto.ts @@ -0,0 +1,10 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { IsDateString } from "class-validator"; + + +export class UpdateBarnameAsWatcherDto { + @ApiProperty() + @IsDateString() + exitAt: string; +} + diff --git a/src/modules/barname/dto/update-bill.dto.ts b/src/modules/barname/dto/update-barname.dto.ts similarity index 59% rename from src/modules/barname/dto/update-bill.dto.ts rename to src/modules/barname/dto/update-barname.dto.ts index b1239a5..7ddd447 100644 --- a/src/modules/barname/dto/update-bill.dto.ts +++ b/src/modules/barname/dto/update-barname.dto.ts @@ -2,4 +2,4 @@ import { PartialType } from "@nestjs/swagger"; import { CreateBarnameDto } from "./create-barname.dto"; -export class UpdateBillDto extends PartialType(CreateBarnameDto) {} +export class UpdateBarnameDto extends PartialType(CreateBarnameDto) {} diff --git a/src/modules/barname/entities/barname.entity.ts b/src/modules/barname/entities/barname.entity.ts index 5b248c9..8b1ab30 100644 --- a/src/modules/barname/entities/barname.entity.ts +++ b/src/modules/barname/entities/barname.entity.ts @@ -23,11 +23,8 @@ export class Barname extends BaseEntity { @Property({ type: 'string' }) driverPhone: string; - @Property({ type: 'string' }) - origin: string; - - @Property({ type: 'string' }) - weight: string; + @Property({ type: 'string', nullable: true }) + origin?: string; @Property({ type: 'string' }) carType: string; @@ -35,8 +32,8 @@ export class Barname extends BaseEntity { @Property({ type: 'string' }) plaque: string; - @Property({ type: 'string' }) - description: string; + @Property({ type: 'string', nullable: true }) + description?: string; @Property({ type: 'json' })