mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
refactor: dtos validation
This commit is contained in:
@@ -17,6 +17,7 @@ import { InventoryAdjustment } from './models/InventoryAdjustment';
|
||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
||||
import { IPaginationMeta } from '@/interfaces/Model';
|
||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { CreateQuickInventoryAdjustmentDto } from './dtos/CreateQuickInventoryAdjustment.dto';
|
||||
|
||||
@Controller('inventory-adjustments')
|
||||
@ApiTags('inventory-adjustments')
|
||||
@@ -33,7 +34,7 @@ export class InventoryAdjustmentsController {
|
||||
description: 'The inventory adjustment has been successfully created.',
|
||||
})
|
||||
public async createQuickInventoryAdjustment(
|
||||
@Body() quickAdjustmentDTO: IQuickInventoryAdjustmentDTO,
|
||||
@Body() quickAdjustmentDTO: CreateQuickInventoryAdjustmentDto,
|
||||
): Promise<InventoryAdjustment> {
|
||||
return this.inventoryAdjustmentsApplicationService.createQuickInventoryAdjustment(
|
||||
quickAdjustmentDTO,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { InventoryAdjustment } from './models/InventoryAdjustment';
|
||||
import { GetInventoryAdjustmentService } from './queries/GetInventoryAdjustment.service';
|
||||
import { GetInventoryAdjustmentsService } from './queries/GetInventoryAdjustments.service';
|
||||
import { IPaginationMeta } from '@/interfaces/Model';
|
||||
import { CreateQuickInventoryAdjustmentDto } from './dtos/CreateQuickInventoryAdjustment.dto';
|
||||
|
||||
@Injectable()
|
||||
export class InventoryAdjustmentsApplicationService {
|
||||
@@ -39,7 +40,7 @@ export class InventoryAdjustmentsApplicationService {
|
||||
* @param {IQuickInventoryAdjustmentDTO} quickAdjustmentDTO - Quick inventory adjustment DTO.
|
||||
*/
|
||||
public async createQuickInventoryAdjustment(
|
||||
quickAdjustmentDTO: IQuickInventoryAdjustmentDTO,
|
||||
quickAdjustmentDTO: CreateQuickInventoryAdjustmentDto,
|
||||
): Promise<InventoryAdjustment> {
|
||||
return this.createQuickInventoryAdjustmentService.createQuickAdjustment(
|
||||
quickAdjustmentDTO,
|
||||
|
||||
@@ -17,6 +17,7 @@ import { Item } from '@/modules/Items/models/Item';
|
||||
import { Account } from '@/modules/Accounts/models/Account.model';
|
||||
import { BranchTransactionDTOTransformer } from '@/modules/Branches/integrations/BranchTransactionDTOTransform';
|
||||
import { WarehouseTransactionDTOTransform } from '@/modules/Warehouses/Integrations/WarehouseTransactionDTOTransform';
|
||||
import { CreateQuickInventoryAdjustmentDto } from '../dtos/CreateQuickInventoryAdjustment.dto';
|
||||
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
||||
import { ERRORS } from '../constants/InventoryAdjustments.constants';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
@@ -89,7 +90,7 @@ export class CreateQuickInventoryAdjustmentService {
|
||||
* @param {IQuickInventoryAdjustmentDTO} quickAdjustmentDTO - qucik adjustment DTO.
|
||||
*/
|
||||
public async createQuickAdjustment(
|
||||
quickAdjustmentDTO: IQuickInventoryAdjustmentDTO,
|
||||
quickAdjustmentDTO: CreateQuickInventoryAdjustmentDto,
|
||||
): Promise<InventoryAdjustment> {
|
||||
// Retrieve the adjustment account or throw not found error.
|
||||
const adjustmentAccount = await this.accountModel()
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsDate,
|
||||
IsEnum,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsPositive,
|
||||
IsString,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
enum IAdjustmentTypes {
|
||||
INCREMENT = 'increment',
|
||||
DECREMENT = 'decrement',
|
||||
}
|
||||
|
||||
export class CreateQuickInventoryAdjustmentDto {
|
||||
@ApiProperty({ description: 'Date of the inventory adjustment' })
|
||||
@IsNotEmpty()
|
||||
@IsDate()
|
||||
@Type(() => Date)
|
||||
date: Date;
|
||||
|
||||
@ApiProperty({ description: 'Type of adjustment', enum: IAdjustmentTypes })
|
||||
@IsNotEmpty()
|
||||
@IsEnum(IAdjustmentTypes)
|
||||
type: 'increment' | 'decrement';
|
||||
|
||||
@ApiProperty({ description: 'ID of the adjustment account' })
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
@IsPositive()
|
||||
adjustmentAccountId: number;
|
||||
|
||||
@ApiProperty({ description: 'Reason for the adjustment' })
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
reason: string;
|
||||
|
||||
@ApiProperty({ description: 'Description of the adjustment' })
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
description: string;
|
||||
|
||||
@ApiProperty({ description: 'Reference number' })
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
referenceNo: string;
|
||||
|
||||
@ApiProperty({ description: 'ID of the item being adjusted' })
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
@IsPositive()
|
||||
itemId: number;
|
||||
|
||||
@ApiProperty({ description: 'Quantity to adjust' })
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
@IsPositive()
|
||||
quantity: number;
|
||||
|
||||
@ApiProperty({ description: 'Cost of the item' })
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
@IsPositive()
|
||||
cost: number;
|
||||
|
||||
@ApiProperty({ description: 'Whether to publish the adjustment immediately' })
|
||||
@IsNotEmpty()
|
||||
@IsBoolean()
|
||||
publish: boolean;
|
||||
|
||||
@ApiPropertyOptional({ description: 'ID of the warehouse (optional)' })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@IsPositive()
|
||||
warehouseId?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'ID of the branch (optional)' })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@IsPositive()
|
||||
branchId?: number;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Knex } from 'knex';
|
||||
import { InventoryAdjustment } from '../models/InventoryAdjustment';
|
||||
import { CreateQuickInventoryAdjustmentDto } from '../dtos/CreateQuickInventoryAdjustment.dto';
|
||||
|
||||
type IAdjustmentTypes = 'increment' | 'decrement';
|
||||
|
||||
@@ -29,7 +30,7 @@ export interface IInventoryAdjustmentEventCreatedPayload {
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
export interface IInventoryAdjustmentCreatingPayload {
|
||||
quickAdjustmentDTO: IQuickInventoryAdjustmentDTO;
|
||||
quickAdjustmentDTO: CreateQuickInventoryAdjustmentDto;
|
||||
trx: Knex.Transaction;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user