fix: edit/create account

This commit is contained in:
Ahmed Bouhuolia
2025-11-07 22:20:06 +02:00
parent 8161439365
commit 80abd1f66f
5 changed files with 11 additions and 16 deletions

View File

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

View File

@@ -17,7 +17,7 @@ export class CommandAccountValidators {
@Inject(Account.name)
private readonly accountModel: TenantModelProxy<typeof Account>,
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) => {

View File

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

View File

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

View File

@@ -17,7 +17,7 @@ export class EditAccount {
@Inject(Account.name)
private readonly accountModel: TenantModelProxy<typeof Account>,
) {}
) { }
/**
* 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, {