refactor(nestjs): wip

This commit is contained in:
Ahmed Bouhuolia
2025-05-27 15:42:27 +02:00
parent 83c9392b74
commit b7a3c42074
33 changed files with 186 additions and 72 deletions

View File

@@ -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')

View File

@@ -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);
}
/**

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}