mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
refactor(nestjs): wip
This commit is contained in:
@@ -37,15 +37,15 @@ export class CurrenciesController {
|
||||
return this.currenciesApp.createCurrency(dto);
|
||||
}
|
||||
|
||||
@Put(':code')
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: 'Edit an existing currency' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Currency ID' })
|
||||
@ApiBody({ type: EditCurrencyDto })
|
||||
@ApiOkResponse({ description: 'The currency has been successfully updated.' })
|
||||
@ApiNotFoundResponse({ description: 'Currency not found.' })
|
||||
@ApiBadRequestResponse({ description: 'Invalid input data.' })
|
||||
edit(@Param('code') code: string, @Body() dto: EditCurrencyDto) {
|
||||
return this.currenciesApp.editCurrency(code, dto);
|
||||
edit(@Param('id') id: number, @Body() dto: EditCurrencyDto) {
|
||||
return this.currenciesApp.editCurrency(id, dto);
|
||||
}
|
||||
|
||||
@Delete(':code')
|
||||
|
||||
@@ -27,8 +27,8 @@ export class CurrenciesApplication {
|
||||
/**
|
||||
* Edits an existing currency.
|
||||
*/
|
||||
public editCurrency(currencyCode: string, currencyDTO: EditCurrencyDto) {
|
||||
return this.editCurrencyService.editCurrency(currencyCode, currencyDTO);
|
||||
public editCurrency(currencyId: number, currencyDTO: EditCurrencyDto) {
|
||||
return this.editCurrencyService.editCurrency(currencyId, currencyDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,21 +12,22 @@ export class EditCurrencyService {
|
||||
|
||||
/**
|
||||
* Edit details of the given currency.
|
||||
* @param {number} currencyCode - Currency code.
|
||||
* @param {number} currencyId - Currency ID.
|
||||
* @param {ICurrencyDTO} currencyDTO - Edit currency dto.
|
||||
*/
|
||||
public async editCurrency(
|
||||
currencyCode: string,
|
||||
currencyId: number,
|
||||
currencyDTO: EditCurrencyDto,
|
||||
): Promise<Currency> {
|
||||
const foundCurrency = await this.currencyModel()
|
||||
const foundCurrency = this.currencyModel()
|
||||
.query()
|
||||
.findOne('currencyCode', currencyCode)
|
||||
.findById(currencyId)
|
||||
.throwIfNotFound();
|
||||
|
||||
// Directly use the provided ID to update the currency
|
||||
const currency = await this.currencyModel()
|
||||
.query()
|
||||
.patchAndFetchById(foundCurrency.id, {
|
||||
.patchAndFetchById(currencyId, {
|
||||
...currencyDTO,
|
||||
});
|
||||
return currency;
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { IsString } from 'class-validator';
|
||||
import { IsNotEmpty } from "class-validator";
|
||||
import { IsString } from "class-validator";
|
||||
|
||||
export class CreateCurrencyDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
currencyName: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
currencyCode: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
currencySign: string;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { IsString } from 'class-validator';
|
||||
import { IsNotEmpty } from "class-validator";
|
||||
import { IsString } from "class-validator";
|
||||
|
||||
export class EditCurrencyDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
currencyName: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
currencySign: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user