diff --git a/packages/server/src/modules/Accounts/Accounts.controller.ts b/packages/server/src/modules/Accounts/Accounts.controller.ts index 5d0413f6d..31bc86158 100644 --- a/packages/server/src/modules/Accounts/Accounts.controller.ts +++ b/packages/server/src/modules/Accounts/Accounts.controller.ts @@ -7,6 +7,7 @@ import { Get, Query, ParseIntPipe, + Put, } from '@nestjs/common'; import { AccountsApplication } from './AccountsApplication.service'; import { CreateAccountDTO } from './CreateAccount.dto'; @@ -46,7 +47,7 @@ export class AccountsController { return this.accountsApplication.createAccount(accountDTO); } - @Post(':id') + @Put(':id') @ApiOperation({ summary: 'Edit the given account.' }) @ApiResponse({ status: 200, diff --git a/packages/server/src/modules/Accounts/CommandAccountValidators.service.ts b/packages/server/src/modules/Accounts/CommandAccountValidators.service.ts index 882954995..ef6cdf3f8 100644 --- a/packages/server/src/modules/Accounts/CommandAccountValidators.service.ts +++ b/packages/server/src/modules/Accounts/CommandAccountValidators.service.ts @@ -17,7 +17,7 @@ export class CommandAccountValidators { @Inject(Account.name) private readonly accountModel: TenantModelProxy, private readonly accountRepository: AccountRepository, - ) {} + ) { } /** * Throws error if the account was prefined. @@ -115,7 +115,7 @@ export class CommandAccountValidators { accountName: string, notAccountId?: number, ) { - const foundAccount = await this.accountModel + const foundAccount = await this.accountModel() .query() .findOne('name', accountName) .onBuild((query) => { diff --git a/packages/server/src/modules/Accounts/CreateAccount.dto.ts b/packages/server/src/modules/Accounts/CreateAccount.dto.ts index 22392ff76..148b062e5 100644 --- a/packages/server/src/modules/Accounts/CreateAccount.dto.ts +++ b/packages/server/src/modules/Accounts/CreateAccount.dto.ts @@ -1,7 +1,7 @@ +import { IsOptional, ToNumber } from '@/common/decorators/Validators'; import { ApiProperty } from '@nestjs/swagger'; import { IsString, - IsOptional, IsInt, MinLength, MaxLength, @@ -65,7 +65,7 @@ export class CreateAccountDTO { description?: string; @IsOptional() - @IsInt() + @ToNumber() @ApiProperty({ description: 'ID of the parent account', example: 1, diff --git a/packages/server/src/modules/Accounts/EditAccount.dto.ts b/packages/server/src/modules/Accounts/EditAccount.dto.ts index 2def3a3b3..9a7d25321 100644 --- a/packages/server/src/modules/Accounts/EditAccount.dto.ts +++ b/packages/server/src/modules/Accounts/EditAccount.dto.ts @@ -1,11 +1,6 @@ +import { IsString, MinLength, MaxLength } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; -import { - IsString, - IsOptional, - IsInt, - MinLength, - MaxLength, -} from 'class-validator'; +import { IsOptional, ToNumber } from '@/common/decorators/Validators'; export class EditAccountDTO { @IsString() @@ -45,7 +40,7 @@ export class EditAccountDTO { description?: string; @IsOptional() - @IsInt() + @ToNumber() @ApiProperty({ description: 'The parent account ID of the account', example: 1, diff --git a/packages/server/src/modules/Accounts/EditAccount.service.ts b/packages/server/src/modules/Accounts/EditAccount.service.ts index 330f72496..22c0d6bcb 100644 --- a/packages/server/src/modules/Accounts/EditAccount.service.ts +++ b/packages/server/src/modules/Accounts/EditAccount.service.ts @@ -17,7 +17,7 @@ export class EditAccount { @Inject(Account.name) private readonly accountModel: TenantModelProxy, - ) {} + ) { } /** * Authorize the account editing. @@ -85,8 +85,7 @@ export class EditAccount { // Update the account on the storage. const account = await this.accountModel() .query(trx) - .findById(accountId) - .updateAndFetch({ ...accountDTO }); + .updateAndFetchById(accountId, { ...accountDTO }); // Triggers `onAccountEdited` event. // await this.eventEmitter.emitAsync(events.accounts.onEdited, {