mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 23:30:32 +00:00
refactor: dtos openapi
This commit is contained in:
@@ -2,12 +2,14 @@ import { Type } from 'class-transformer';
|
|||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
IsDate,
|
IsDate,
|
||||||
|
IsNotEmpty,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
export class BillPaymentEntryDto {
|
export class BillPaymentEntryDto {
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@@ -19,48 +21,98 @@ export class BillPaymentEntryDto {
|
|||||||
|
|
||||||
export class CommandBillPaymentDTO {
|
export class CommandBillPaymentDTO {
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the vendor',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
vendorId: number;
|
vendorId: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The amount of the bill payment',
|
||||||
|
example: 100,
|
||||||
|
})
|
||||||
amount?: number;
|
amount?: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the payment account',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
paymentAccountId: number;
|
paymentAccountId: number;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The payment number of the bill payment',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
paymentNumber?: string;
|
paymentNumber?: string;
|
||||||
|
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@Type(() => Date)
|
@Type(() => Date)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The payment date of the bill payment',
|
||||||
|
example: '2021-01-01',
|
||||||
|
})
|
||||||
paymentDate: Date | string;
|
paymentDate: Date | string;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The exchange rate of the bill payment',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
exchangeRate?: number;
|
exchangeRate?: number;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The statement of the bill payment',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
statement?: string;
|
statement?: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
reference?: string;
|
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => BillPaymentEntryDto)
|
@Type(() => BillPaymentEntryDto)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The entries of the bill payment',
|
||||||
|
example: [
|
||||||
|
{
|
||||||
|
billId: 1,
|
||||||
|
paymentAmount: 100,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
entries: BillPaymentEntryDto[];
|
entries: BillPaymentEntryDto[];
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the branch',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
branchId?: number;
|
branchId?: number;
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => AttachmentLinkDto)
|
@Type(() => AttachmentLinkDto)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The attachments of the bill payment',
|
||||||
|
example: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
type: 'bill',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
attachments?: AttachmentLinkDto[];
|
attachments?: AttachmentLinkDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsNotEmpty, IsOptional, IsPositive, IsString } from 'class-validator';
|
import { IsNotEmpty, IsOptional, IsPositive, IsString } from 'class-validator';
|
||||||
import { IsDate } from 'class-validator';
|
import { IsDate } from 'class-validator';
|
||||||
import { IsNumber } from 'class-validator';
|
import { IsNumber } from 'class-validator';
|
||||||
@@ -5,31 +6,59 @@ import { IsNumber } from 'class-validator';
|
|||||||
export class CreditNoteRefundDto {
|
export class CreditNoteRefundDto {
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the from account',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
fromAccountId: number;
|
fromAccountId: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsPositive()
|
@IsPositive()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The amount of the credit note refund',
|
||||||
|
example: 100,
|
||||||
|
})
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsPositive()
|
@IsPositive()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The exchange rate of the credit note refund',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
exchangeRate?: number;
|
exchangeRate?: number;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The reference number of the credit note refund',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
referenceNo: string;
|
referenceNo: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The description of the credit note refund',
|
||||||
|
example: 'Credit note refund',
|
||||||
|
})
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The date of the credit note refund',
|
||||||
|
example: '2021-01-01',
|
||||||
|
})
|
||||||
date: Date;
|
date: Date;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the branch',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
branchId?: number;
|
branchId?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
import { AttachmentLinkDto } from '@/modules/Attachments/dtos/Attachment.dto';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import { IsArray, ValidateNested } from 'class-validator';
|
import { IsArray, IsNotEmpty, ValidateNested } from 'class-validator';
|
||||||
import { IsString } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import { IsDateString, IsNumber, IsOptional } from 'class-validator';
|
import { IsDateString, IsNumber, IsOptional } from 'class-validator';
|
||||||
import { IsInt } from 'class-validator';
|
import { IsInt } from 'class-validator';
|
||||||
@@ -27,47 +28,95 @@ export class PaymentReceivedEntryDto {
|
|||||||
|
|
||||||
export class CommandPaymentReceivedDto {
|
export class CommandPaymentReceivedDto {
|
||||||
@IsInt()
|
@IsInt()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({ description: 'The id of the customer', example: 1 })
|
||||||
customerId: number;
|
customerId: number;
|
||||||
|
|
||||||
@IsDateString()
|
@IsDateString()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The payment date of the payment received',
|
||||||
|
example: '2021-01-01',
|
||||||
|
})
|
||||||
paymentDate: Date | string;
|
paymentDate: Date | string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The amount of the payment received',
|
||||||
|
example: 100,
|
||||||
|
})
|
||||||
amount?: number;
|
amount?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The exchange rate of the payment received',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
exchangeRate?: number;
|
exchangeRate?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The reference number of the payment received',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
referenceNo?: string;
|
referenceNo?: string;
|
||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the deposit account',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
depositAccountId: number;
|
depositAccountId: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The payment receive number of the payment received',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
paymentReceiveNo?: string;
|
paymentReceiveNo?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The statement of the payment received',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
statement?: string;
|
statement?: string;
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => PaymentReceivedEntryDto)
|
@Type(() => PaymentReceivedEntryDto)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The entries of the payment received',
|
||||||
|
example: [{ invoiceId: 1, paymentAmount: 100 }],
|
||||||
|
})
|
||||||
entries: PaymentReceivedEntryDto[];
|
entries: PaymentReceivedEntryDto[];
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsInt()
|
@IsInt()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the branch',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
branchId?: number;
|
branchId?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => AttachmentLinkDto)
|
@Type(() => AttachmentLinkDto)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The attachments of the payment received',
|
||||||
|
example: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
type: 'bill',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
attachments?: AttachmentLinkDto[];
|
attachments?: AttachmentLinkDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
IsDate,
|
IsDate,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
|
IsNotEmpty,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsPositive,
|
IsPositive,
|
||||||
@@ -27,72 +29,140 @@ class AttachmentDto {
|
|||||||
|
|
||||||
export class CommandSaleReceiptDto {
|
export class CommandSaleReceiptDto {
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the customer',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
customerId: number;
|
customerId: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsPositive()
|
@IsPositive()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The exchange rate of the sale receipt',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
exchangeRate?: number;
|
exchangeRate?: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({ description: 'The id of the deposit account', example: 1 })
|
||||||
depositAccountId: number;
|
depositAccountId: number;
|
||||||
|
|
||||||
@IsDate()
|
@IsDate()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The date of the sale receipt',
|
||||||
|
example: '2021-01-01',
|
||||||
|
})
|
||||||
receiptDate: Date;
|
receiptDate: Date;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The receipt number of the sale receipt',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
receiptNumber?: string;
|
receiptNumber?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The reference number of the sale receipt',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
referenceNo?: string;
|
referenceNo?: string;
|
||||||
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Whether the sale receipt is closed',
|
||||||
|
example: false,
|
||||||
|
})
|
||||||
closed: boolean = false;
|
closed: boolean = false;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the warehouse',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
warehouseId?: number;
|
warehouseId?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the branch',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
branchId?: number;
|
branchId?: number;
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => SaleReceiptEntryDto)
|
@Type(() => SaleReceiptEntryDto)
|
||||||
@Min(1)
|
@Min(1)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The entries of the sale receipt',
|
||||||
|
example: [{ key: '123456' }],
|
||||||
|
})
|
||||||
entries: SaleReceiptEntryDto[];
|
entries: SaleReceiptEntryDto[];
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The receipt message of the sale receipt',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
receiptMessage?: string;
|
receiptMessage?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The statement of the sale receipt',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
statement?: string;
|
statement?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => AttachmentDto)
|
@Type(() => AttachmentDto)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The attachments of the sale receipt',
|
||||||
|
example: [{ key: '123456' }],
|
||||||
|
})
|
||||||
attachments?: AttachmentDto[];
|
attachments?: AttachmentDto[];
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the pdf template',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
pdfTemplateId?: number;
|
pdfTemplateId?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The discount of the sale receipt',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
discount?: number;
|
discount?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(DiscountType)
|
@IsEnum(DiscountType)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The discount type of the sale receipt',
|
||||||
|
example: DiscountType.Percentage,
|
||||||
|
})
|
||||||
discountType?: DiscountType;
|
discountType?: DiscountType;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The adjustment of the sale receipt',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
adjustment?: number;
|
adjustment?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
IsArray,
|
IsArray,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
|
IsNotEmpty,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
@@ -23,59 +25,131 @@ class AttachmentDto {
|
|||||||
|
|
||||||
export class CommandVendorCreditDto {
|
export class CommandVendorCreditDto {
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the vendor',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
vendorId: number;
|
vendorId: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The exchange rate of the vendor credit',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
exchangeRate?: number;
|
exchangeRate?: number;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The vendor credit number',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
vendorCreditNumber?: string;
|
vendorCreditNumber?: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The reference number of the vendor credit',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
referenceNo?: string;
|
referenceNo?: string;
|
||||||
|
|
||||||
@IsString() // ISO8601 date string
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The date of the vendor credit',
|
||||||
|
example: '2021-01-01',
|
||||||
|
})
|
||||||
vendorCreditDate: string;
|
vendorCreditDate: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The note of the vendor credit',
|
||||||
|
example: '123456',
|
||||||
|
})
|
||||||
note?: string;
|
note?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The open status of the vendor credit',
|
||||||
|
example: true,
|
||||||
|
})
|
||||||
open: boolean = false;
|
open: boolean = false;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The warehouse id of the vendor credit',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
warehouseId?: number;
|
warehouseId?: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The branch id of the vendor credit',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
branchId?: number;
|
branchId?: number;
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => VendorCreditEntryDto)
|
@Type(() => VendorCreditEntryDto)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The entries of the vendor credit',
|
||||||
|
example: [
|
||||||
|
{
|
||||||
|
itemId: 1,
|
||||||
|
quantity: 1,
|
||||||
|
unitPrice: 1,
|
||||||
|
discount: 1,
|
||||||
|
discountType: DiscountType.Percentage,
|
||||||
|
accountId: 1,
|
||||||
|
amount: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
entries: VendorCreditEntryDto[];
|
entries: VendorCreditEntryDto[];
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
@Type(() => AttachmentDto)
|
@Type(() => AttachmentDto)
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The attachments of the vendor credit',
|
||||||
|
example: [
|
||||||
|
{
|
||||||
|
key: '123456',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
attachments?: AttachmentDto[];
|
attachments?: AttachmentDto[];
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The discount of the vendor credit',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
discount?: number;
|
discount?: number;
|
||||||
|
|
||||||
@IsEnum(DiscountType)
|
@IsEnum(DiscountType)
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The discount type of the vendor credit',
|
||||||
|
example: DiscountType.Percentage,
|
||||||
|
})
|
||||||
discountType?: DiscountType;
|
discountType?: DiscountType;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The adjustment of the vendor credit',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
adjustment?: number;
|
adjustment?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { DeleteRefundVendorCreditService } from './commands/DeleteRefundVendorCr
|
|||||||
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
||||||
import { CreateRefundVendorCredit } from './commands/CreateRefundVendorCredit.service';
|
import { CreateRefundVendorCredit } from './commands/CreateRefundVendorCredit.service';
|
||||||
import { IRefundVendorCreditDTO } from './types/VendorCreditRefund.types';
|
import { IRefundVendorCreditDTO } from './types/VendorCreditRefund.types';
|
||||||
|
import { RefundVendorCreditDto } from './dtos/RefundVendorCredit.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VendorCreditsRefundApplication {
|
export class VendorCreditsRefundApplication {
|
||||||
@@ -23,7 +24,7 @@ export class VendorCreditsRefundApplication {
|
|||||||
*/
|
*/
|
||||||
public async createRefundVendorCredit(
|
public async createRefundVendorCredit(
|
||||||
vendorCreditId: number,
|
vendorCreditId: number,
|
||||||
refundVendorCreditDTO: IRefundVendorCreditDTO,
|
refundVendorCreditDTO: RefundVendorCreditDto,
|
||||||
): Promise<RefundVendorCredit> {
|
): Promise<RefundVendorCredit> {
|
||||||
return this.createRefundVendorCreditService.createRefund(
|
return this.createRefundVendorCreditService.createRefund(
|
||||||
vendorCreditId,
|
vendorCreditId,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { IRefundVendorCreditDTO } from './types/VendorCreditRefund.types';
|
|||||||
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
import { PublicRoute } from '../Auth/Jwt.guard';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { RefundVendorCreditDto } from './dtos/RefundVendorCredit.dto';
|
||||||
|
|
||||||
@Controller('vendor-credits')
|
@Controller('vendor-credits')
|
||||||
@ApiTags('vendor-credits-refunds')
|
@ApiTags('vendor-credits-refunds')
|
||||||
@@ -25,7 +26,7 @@ export class VendorCreditsRefundController {
|
|||||||
@ApiOperation({ summary: 'Create a refund for the given vendor credit.' })
|
@ApiOperation({ summary: 'Create a refund for the given vendor credit.' })
|
||||||
public async createRefundVendorCredit(
|
public async createRefundVendorCredit(
|
||||||
@Param('vendorCreditId') vendorCreditId: string,
|
@Param('vendorCreditId') vendorCreditId: string,
|
||||||
@Body() refundVendorCreditDTO: IRefundVendorCreditDTO,
|
@Body() refundVendorCreditDTO: RefundVendorCreditDto,
|
||||||
): Promise<RefundVendorCredit> {
|
): Promise<RefundVendorCredit> {
|
||||||
return this.vendorCreditsRefundApplication.createRefundVendorCredit(
|
return this.vendorCreditsRefundApplication.createRefundVendorCredit(
|
||||||
Number(vendorCreditId),
|
Number(vendorCreditId),
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
|
|||||||
import {
|
import {
|
||||||
IRefundVendorCreditCreatedPayload,
|
IRefundVendorCreditCreatedPayload,
|
||||||
IRefundVendorCreditCreatingPayload,
|
IRefundVendorCreditCreatingPayload,
|
||||||
IRefundVendorCreditDTO,
|
|
||||||
} from '../types/VendorCreditRefund.types';
|
} from '../types/VendorCreditRefund.types';
|
||||||
import { Account } from '@/modules/Accounts/models/Account.model';
|
import { Account } from '@/modules/Accounts/models/Account.model';
|
||||||
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
import { VendorCredit } from '@/modules/VendorCredit/models/VendorCredit';
|
||||||
@@ -17,9 +16,18 @@ import { events } from '@/common/events/events';
|
|||||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
import { ERRORS } from '../constants';
|
import { ERRORS } from '../constants';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { RefundVendorCreditDto } from '../dtos/RefundVendorCredit.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CreateRefundVendorCredit {
|
export class CreateRefundVendorCredit {
|
||||||
|
/**
|
||||||
|
* @param {UnitOfWork} uow - Unit of work.
|
||||||
|
* @param {EventEmitter2} eventPublisher - Event emitter.
|
||||||
|
* @param {BranchTransactionDTOTransformer} branchDTOTransform - Branch transaction DTO transformer.
|
||||||
|
* @param {TenantModelProxy<typeof RefundVendorCredit>} refundVendorCreditModel - Refund vendor credit model.
|
||||||
|
* @param {TenantModelProxy<typeof Account>} accountModel - Account model.
|
||||||
|
* @param {TenantModelProxy<typeof VendorCredit>} vendorCreditModel - Vendor credit model.
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private readonly uow: UnitOfWork,
|
private readonly uow: UnitOfWork,
|
||||||
private readonly eventPublisher: EventEmitter2,
|
private readonly eventPublisher: EventEmitter2,
|
||||||
@@ -40,12 +48,12 @@ export class CreateRefundVendorCredit {
|
|||||||
/**
|
/**
|
||||||
* Creates a refund vendor credit.
|
* Creates a refund vendor credit.
|
||||||
* @param {number} vendorCreditId
|
* @param {number} vendorCreditId
|
||||||
* @param {IRefundVendorCreditDTO} refundVendorCreditDTO
|
* @param {RefundVendorCreditDto} refundVendorCreditDTO
|
||||||
* @returns {Promise<IRefundVendorCredit>}
|
* @returns {Promise<IRefundVendorCredit>}
|
||||||
*/
|
*/
|
||||||
public createRefund = async (
|
public createRefund = async (
|
||||||
vendorCreditId: number,
|
vendorCreditId: number,
|
||||||
refundVendorCreditDTO: IRefundVendorCreditDTO,
|
refundVendorCreditDTO: RefundVendorCreditDto,
|
||||||
): Promise<RefundVendorCredit> => {
|
): Promise<RefundVendorCredit> => {
|
||||||
// Retrieve the vendor credit or throw not found service error.
|
// Retrieve the vendor credit or throw not found service error.
|
||||||
const vendorCredit = await this.vendorCreditModel()
|
const vendorCredit = await this.vendorCreditModel()
|
||||||
@@ -107,13 +115,13 @@ export class CreateRefundVendorCredit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Transformes the refund DTO to refund vendor credit model.
|
* Transformes the refund DTO to refund vendor credit model.
|
||||||
* @param {IVendorCredit} vendorCredit -
|
* @param {VendorCredit} vendorCredit -
|
||||||
* @param {IRefundVendorCreditDTO} vendorCreditDTO
|
* @param {RefundVendorCreditDto} vendorCreditDTO
|
||||||
* @returns {IRefundVendorCredit}
|
* @returns {IRefundVendorCredit}
|
||||||
*/
|
*/
|
||||||
public transformDTOToModel = (
|
public transformDTOToModel = (
|
||||||
vendorCredit: VendorCredit,
|
vendorCredit: VendorCredit,
|
||||||
vendorCreditDTO: IRefundVendorCreditDTO,
|
vendorCreditDTO: RefundVendorCreditDto,
|
||||||
) => {
|
) => {
|
||||||
const initialDTO = {
|
const initialDTO = {
|
||||||
vendorCreditId: vendorCredit.id,
|
vendorCreditId: vendorCredit.id,
|
||||||
@@ -126,7 +134,7 @@ export class CreateRefundVendorCredit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the deposit refund account type.
|
* Validate the deposit refund account type.
|
||||||
* @param {IAccount} account
|
* @param {Account} account
|
||||||
*/
|
*/
|
||||||
public validateRefundDepositAccountType(account: Account) {
|
public validateRefundDepositAccountType(account: Account) {
|
||||||
const supportedTypes = ['bank', 'cash', 'fixed-asset'];
|
const supportedTypes = ['bank', 'cash', 'fixed-asset'];
|
||||||
@@ -138,7 +146,7 @@ export class CreateRefundVendorCredit {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate vendor credit has remaining credits.
|
* Validate vendor credit has remaining credits.
|
||||||
* @param {IVendorCredit} vendorCredit
|
* @param {VendorCredit} vendorCredit
|
||||||
* @param {number} amount
|
* @param {number} amount
|
||||||
*/
|
*/
|
||||||
public validateVendorCreditRemainingCredit(
|
public validateVendorCreditRemainingCredit(
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Min } from 'class-validator';
|
||||||
|
import { IsString } from 'class-validator';
|
||||||
|
import { IsDate } from 'class-validator';
|
||||||
|
import { IsNotEmpty, IsNumber, IsOptional, IsPositive } from 'class-validator';
|
||||||
|
|
||||||
|
export class RefundVendorCreditDto {
|
||||||
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The amount of the refund',
|
||||||
|
example: 100,
|
||||||
|
})
|
||||||
|
amount: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@IsOptional()
|
||||||
|
@Min(0)
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The exchange rate of the refund',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
|
exchangeRate?: number;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsPositive()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the deposit account',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
|
depositAccountId: number;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The description of the refund',
|
||||||
|
example: 'Refund for vendor credit',
|
||||||
|
})
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
@IsDate()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The date of the refund',
|
||||||
|
example: '2021-01-01',
|
||||||
|
})
|
||||||
|
date: Date;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@IsOptional()
|
||||||
|
@IsPositive()
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the branch',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
|
branchId?: number;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user