mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
fix: issues related to PUT operations
This commit is contained in:
@@ -28,8 +28,9 @@ export class EditBillService {
|
|||||||
private transformerDTO: BillDTOTransformer,
|
private transformerDTO: BillDTOTransformer,
|
||||||
|
|
||||||
@Inject(Bill.name) private billModel: TenantModelProxy<typeof Bill>,
|
@Inject(Bill.name) private billModel: TenantModelProxy<typeof Bill>,
|
||||||
@Inject(Vendor.name) private contactModel: TenantModelProxy<typeof Vendor>,
|
@Inject(Vendor.name) private vendorModel: TenantModelProxy<typeof Vendor>,
|
||||||
) {}
|
|
||||||
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits details of the given bill id with associated entries.
|
* Edits details of the given bill id with associated entries.
|
||||||
@@ -58,10 +59,9 @@ export class EditBillService {
|
|||||||
this.validators.validateBillExistance(oldBill);
|
this.validators.validateBillExistance(oldBill);
|
||||||
|
|
||||||
// Retrieve vendor details or throw not found service error.
|
// Retrieve vendor details or throw not found service error.
|
||||||
const vendor = await this.contactModel()
|
const vendor = await this.vendorModel()
|
||||||
.query()
|
.query()
|
||||||
.findById(billDTO.vendorId)
|
.findById(billDTO.vendorId)
|
||||||
.modify('vendor')
|
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
// Validate bill number uniqiness on the storage.
|
// Validate bill number uniqiness on the storage.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ToNumber } from '@/common/decorators/Validators';
|
import { ToNumber } from '@/common/decorators/Validators';
|
||||||
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
import { ItemEntryDto } from '@/modules/TransactionItemEntry/dto/ItemEntry.dto';
|
||||||
import { Type } from 'class-transformer';
|
import { Type, Transform } from 'class-transformer';
|
||||||
|
import { parseBoolean } from '@/utils/parse-boolean';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
ArrayMinSize,
|
ArrayMinSize,
|
||||||
@@ -31,6 +32,7 @@ export class BillEntryDto extends ItemEntryDto {
|
|||||||
})
|
})
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
@Transform(({ value }) => parseBoolean(value, false))
|
||||||
landedCost?: boolean;
|
landedCost?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,5 +213,5 @@ export class CommandBillDto {
|
|||||||
adjustment?: number;
|
adjustment?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateBillDto extends CommandBillDto {}
|
export class CreateBillDto extends CommandBillDto { }
|
||||||
export class EditBillDto extends CommandBillDto {}
|
export class EditBillDto extends CommandBillDto { }
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { BranchTransactionDTOTransformer } from '@/modules/Branches/integrations
|
|||||||
import { WarehouseTransactionDTOTransform } from '@/modules/Warehouses/Integrations/WarehouseTransactionDTOTransform';
|
import { WarehouseTransactionDTOTransform } from '@/modules/Warehouses/Integrations/WarehouseTransactionDTOTransform';
|
||||||
import { BrandingTemplateDTOTransformer } from '../../PdfTemplate/BrandingTemplateDTOTransformer';
|
import { BrandingTemplateDTOTransformer } from '../../PdfTemplate/BrandingTemplateDTOTransformer';
|
||||||
import { assocItemEntriesDefaultIndex } from '@/utils/associate-item-entries-index';
|
import { assocItemEntriesDefaultIndex } from '@/utils/associate-item-entries-index';
|
||||||
|
import { formatDateFields } from '@/utils/format-date-fields';
|
||||||
import { CreditNoteAutoIncrementService } from './CreditNoteAutoIncrement.service';
|
import { CreditNoteAutoIncrementService } from './CreditNoteAutoIncrement.service';
|
||||||
import { CreditNote } from '../models/CreditNote';
|
import { CreditNote } from '../models/CreditNote';
|
||||||
import {
|
import {
|
||||||
@@ -33,7 +34,7 @@ export class CommandCreditNoteDTOTransform {
|
|||||||
private readonly warehouseDTOTransform: WarehouseTransactionDTOTransform,
|
private readonly warehouseDTOTransform: WarehouseTransactionDTOTransform,
|
||||||
private readonly brandingTemplatesTransformer: BrandingTemplateDTOTransformer,
|
private readonly brandingTemplatesTransformer: BrandingTemplateDTOTransformer,
|
||||||
private readonly creditNoteAutoIncrement: CreditNoteAutoIncrementService,
|
private readonly creditNoteAutoIncrement: CreditNoteAutoIncrementService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms the credit/edit DTO to model.
|
* Transforms the credit/edit DTO to model.
|
||||||
@@ -70,7 +71,10 @@ export class CommandCreditNoteDTOTransform {
|
|||||||
autoNextNumber;
|
autoNextNumber;
|
||||||
|
|
||||||
const initialDTO = {
|
const initialDTO = {
|
||||||
...omit(creditNoteDTO, ['open', 'attachments']),
|
...formatDateFields(
|
||||||
|
omit(creditNoteDTO, ['open', 'attachments']),
|
||||||
|
['creditNoteDate'],
|
||||||
|
),
|
||||||
creditNoteNumber,
|
creditNoteNumber,
|
||||||
amount,
|
amount,
|
||||||
currencyCode: customerCurrencyCode,
|
currencyCode: customerCurrencyCode,
|
||||||
@@ -78,8 +82,8 @@ export class CommandCreditNoteDTOTransform {
|
|||||||
entries,
|
entries,
|
||||||
...(creditNoteDTO.open &&
|
...(creditNoteDTO.open &&
|
||||||
!oldCreditNote?.openedAt && {
|
!oldCreditNote?.openedAt && {
|
||||||
openedAt: moment().toMySqlDateTime(),
|
openedAt: moment().toMySqlDateTime(),
|
||||||
}),
|
}),
|
||||||
refundedAmount: 0,
|
refundedAmount: 0,
|
||||||
invoicesAmount: 0,
|
invoicesAmount: 0,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -185,5 +185,5 @@ export class CommandExpenseDto {
|
|||||||
attachments?: AttachmentDto[];
|
attachments?: AttachmentDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateExpenseDto extends CommandExpenseDto {}
|
export class CreateExpenseDto extends CommandExpenseDto { }
|
||||||
export class EditExpenseDto extends CommandExpenseDto {}
|
export class EditExpenseDto extends CommandExpenseDto { }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ enum DiscountType {
|
|||||||
Amount = 'amount',
|
Amount = 'amount',
|
||||||
}
|
}
|
||||||
|
|
||||||
class SaleEstimateEntryDto extends ItemEntryDto {}
|
class SaleEstimateEntryDto extends ItemEntryDto { }
|
||||||
|
|
||||||
class AttachmentDto {
|
class AttachmentDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -140,6 +140,7 @@ export class CommandSaleEstimateDto {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
attachments?: AttachmentDto[];
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ToNumber()
|
@ToNumber()
|
||||||
@@ -177,5 +178,5 @@ export class CommandSaleEstimateDto {
|
|||||||
adjustment?: number;
|
adjustment?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateSaleEstimateDto extends CommandSaleEstimateDto {}
|
export class CreateSaleEstimateDto extends CommandSaleEstimateDto { }
|
||||||
export class EditSaleEstimateDto extends CommandSaleEstimateDto {}
|
export class EditSaleEstimateDto extends CommandSaleEstimateDto { }
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import { ApiCommonHeaders } from '@/common/decorators/ApiCommonHeaders';
|
|||||||
@ApiExtraModels(TaxRateResponseDto)
|
@ApiExtraModels(TaxRateResponseDto)
|
||||||
@ApiCommonHeaders()
|
@ApiCommonHeaders()
|
||||||
export class TaxRatesController {
|
export class TaxRatesController {
|
||||||
constructor(private readonly taxRatesApplication: TaxRatesApplication) {}
|
constructor(private readonly taxRatesApplication: TaxRatesApplication) { }
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Create a new tax rate.' })
|
@ApiOperation({ summary: 'Create a new tax rate.' })
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { BranchTransactionDTOTransformer } from '@/modules/Branches/integrations
|
|||||||
import { WarehouseTransactionDTOTransform } from '@/modules/Warehouses/Integrations/WarehouseTransactionDTOTransform';
|
import { WarehouseTransactionDTOTransform } from '@/modules/Warehouses/Integrations/WarehouseTransactionDTOTransform';
|
||||||
import { VendorCredit } from '../models/VendorCredit';
|
import { VendorCredit } from '../models/VendorCredit';
|
||||||
import { assocItemEntriesDefaultIndex } from '@/utils/associate-item-entries-index';
|
import { assocItemEntriesDefaultIndex } from '@/utils/associate-item-entries-index';
|
||||||
|
import { formatDateFields } from '@/utils/format-date-fields';
|
||||||
import { VendorCreditAutoIncrementService } from './VendorCreditAutoIncrement.service';
|
import { VendorCreditAutoIncrementService } from './VendorCreditAutoIncrement.service';
|
||||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
@@ -30,7 +31,7 @@ export class VendorCreditDTOTransformService {
|
|||||||
private branchDTOTransform: BranchTransactionDTOTransformer,
|
private branchDTOTransform: BranchTransactionDTOTransformer,
|
||||||
private warehouseDTOTransform: WarehouseTransactionDTOTransform,
|
private warehouseDTOTransform: WarehouseTransactionDTOTransform,
|
||||||
private vendorCreditAutoIncrement: VendorCreditAutoIncrementService,
|
private vendorCreditAutoIncrement: VendorCreditAutoIncrementService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms the credit/edit vendor credit DTO to model.
|
* Transforms the credit/edit vendor credit DTO to model.
|
||||||
@@ -70,7 +71,10 @@ export class VendorCreditDTOTransformService {
|
|||||||
autoNextNumber;
|
autoNextNumber;
|
||||||
|
|
||||||
const initialDTO = {
|
const initialDTO = {
|
||||||
...omit(vendorCreditDTO, ['open', 'attachments']),
|
...formatDateFields(
|
||||||
|
omit(vendorCreditDTO, ['open', 'attachments']),
|
||||||
|
['vendorCreditDate'],
|
||||||
|
),
|
||||||
amount,
|
amount,
|
||||||
currencyCode: vendorCurrencyCode,
|
currencyCode: vendorCurrencyCode,
|
||||||
exchangeRate: vendorCreditDTO.exchangeRate || 1,
|
exchangeRate: vendorCreditDTO.exchangeRate || 1,
|
||||||
@@ -78,8 +82,8 @@ export class VendorCreditDTOTransformService {
|
|||||||
entries,
|
entries,
|
||||||
...(vendorCreditDTO.open &&
|
...(vendorCreditDTO.open &&
|
||||||
!oldVendorCredit?.openedAt && {
|
!oldVendorCredit?.openedAt && {
|
||||||
openedAt: moment().toMySqlDateTime(),
|
openedAt: moment().toMySqlDateTime(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
return composeAsync(
|
return composeAsync(
|
||||||
this.branchDTOTransform.transformDTO<VendorCredit>,
|
this.branchDTOTransform.transformDTO<VendorCredit>,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export function useEditProjectTimeEntry(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`projects/times/${id}`, values),
|
([id, values]) => apiRequest.put(`projects/times/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Invalidate specific project time entry.
|
// Invalidate specific project time entry.
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export function useEditProject(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`/projects/${id}`, values),
|
([id, values]) => apiRequest.put(`/projects/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Invalidate specific project.
|
// Invalidate specific project.
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export function useEditProjectTask(props) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(([id, values]) => apiRequest.post(`tasks/${id}`, values), {
|
return useMutation(([id, values]) => apiRequest.put(`tasks/${id}`, values), {
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
commonInvalidateQueries(queryClient);
|
commonInvalidateQueries(queryClient);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export function useEditAccount(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`accounts/${id}`, values),
|
([id, values]) => apiRequest.put(`accounts/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export function useEditBill(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`bills/${id}`, values),
|
([id, values]) => apiRequest.put(`bills/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export function useEditCreditNote(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`credit-notes/${id}`, values),
|
([id, values]) => apiRequest.put(`credit-notes/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export function useEditEstimate(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`sale-estimates/${id}`, values),
|
([id, values]) => apiRequest.put(`sale-estimates/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export function useEditInvoice(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`sale-invoices/${id}`, values),
|
([id, values]) => apiRequest.put(`sale-invoices/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Invalidate specific sale invoice.
|
// Invalidate specific sale invoice.
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export function useEditPaymentMade(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`bill-payments/${id}`, values),
|
([id, values]) => apiRequest.put(`bill-payments/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Common invalidation queries.
|
// Common invalidation queries.
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export function useEditPaymentReceive(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`payments-received/${id}`, values),
|
([id, values]) => apiRequest.put(`payments-received/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (data, [id, values]) => {
|
onSuccess: (data, [id, values]) => {
|
||||||
// Invalidate specific payment receive.
|
// Invalidate specific payment receive.
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export function useEditReceipt(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`sale-receipts/${id}`, values),
|
([id, values]) => apiRequest.put(`sale-receipts/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Invalidate specific receipt.
|
// Invalidate specific receipt.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export function useEditRolePermissionSchema(props) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(([id, values]) => apiRequest.post(`roles/${id}`, values), {
|
return useMutation(([id, values]) => apiRequest.put(`roles/${id}`, values), {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
commonInvalidateQueries(queryClient);
|
commonInvalidateQueries(queryClient);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export function useEditTaxRate(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`tax-rates/${id}`, values),
|
([id, values]) => apiRequest.put(`tax-rates/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, id) => {
|
onSuccess: (res, id) => {
|
||||||
commonInvalidateQueries(queryClient);
|
commonInvalidateQueries(queryClient);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export function useEditUser(props) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(([id, values]) => apiRequest.post(`users/${id}`, values), {
|
return useMutation(([id, values]) => apiRequest.put(`users/${id}`, values), {
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
queryClient.invalidateQueries([t.USER, id]);
|
queryClient.invalidateQueries([t.USER, id]);
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function useEditVendorCredit(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`vendor-credits/${id}`, values),
|
([id, values]) => apiRequest.put(`vendor-credits/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Common invalidate queries.
|
// Common invalidate queries.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export function useEditWarehouseTransfer(props) {
|
|||||||
const apiRequest = useApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
([id, values]) => apiRequest.post(`warehouse-transfers/${id}`, values),
|
([id, values]) => apiRequest.put(`warehouse-transfers/${id}`, values),
|
||||||
{
|
{
|
||||||
onSuccess: (res, [id, values]) => {
|
onSuccess: (res, [id, values]) => {
|
||||||
// Invalidate specific sale invoice.
|
// Invalidate specific sale invoice.
|
||||||
|
|||||||
Reference in New Issue
Block a user