mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
refactor(nestjs): Implement users module
This commit is contained in:
@@ -37,15 +37,15 @@ export class CurrenciesController {
|
||||
return this.currenciesApp.createCurrency(dto);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@Put(':code')
|
||||
@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('id') id: number, @Body() dto: EditCurrencyDto) {
|
||||
return this.currenciesApp.editCurrency(Number(id), dto);
|
||||
edit(@Param('code') code: string, @Body() dto: EditCurrencyDto) {
|
||||
return this.currenciesApp.editCurrency(code, dto);
|
||||
}
|
||||
|
||||
@Delete(':code')
|
||||
|
||||
@@ -27,8 +27,8 @@ export class CurrenciesApplication {
|
||||
/**
|
||||
* Edits an existing currency.
|
||||
*/
|
||||
public editCurrency(currencyId: number, currencyDTO: EditCurrencyDto) {
|
||||
return this.editCurrencyService.editCurrency(currencyId, currencyDTO);
|
||||
public editCurrency(currencyCode: string, currencyDTO: EditCurrencyDto) {
|
||||
return this.editCurrencyService.editCurrency(currencyCode, currencyDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,22 +12,21 @@ export class EditCurrencyService {
|
||||
|
||||
/**
|
||||
* Edit details of the given currency.
|
||||
* @param {number} tenantId
|
||||
* @param {number} currencyId
|
||||
* @param {ICurrencyDTO} currencyDTO
|
||||
* @param {number} currencyCode - Currency code.
|
||||
* @param {ICurrencyDTO} currencyDTO - Edit currency dto.
|
||||
*/
|
||||
public async editCurrency(
|
||||
currencyId: number,
|
||||
currencyCode: string,
|
||||
currencyDTO: EditCurrencyDto,
|
||||
): Promise<Currency> {
|
||||
const foundCurrency = await this.currencyModel()
|
||||
.query()
|
||||
.findOne('id', currencyId)
|
||||
.findOne('currencyCode', currencyCode)
|
||||
.throwIfNotFound();
|
||||
|
||||
const currency = await this.currencyModel()
|
||||
.query()
|
||||
.patchAndFetchById(currencyId, {
|
||||
.patchAndFetchById(foundCurrency.id, {
|
||||
...currencyDTO,
|
||||
});
|
||||
return currency;
|
||||
|
||||
Reference in New Issue
Block a user