mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix: edit/create account
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
Get,
|
Get,
|
||||||
Query,
|
Query,
|
||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { AccountsApplication } from './AccountsApplication.service';
|
import { AccountsApplication } from './AccountsApplication.service';
|
||||||
import { CreateAccountDTO } from './CreateAccount.dto';
|
import { CreateAccountDTO } from './CreateAccount.dto';
|
||||||
@@ -46,7 +47,7 @@ export class AccountsController {
|
|||||||
return this.accountsApplication.createAccount(accountDTO);
|
return this.accountsApplication.createAccount(accountDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post(':id')
|
@Put(':id')
|
||||||
@ApiOperation({ summary: 'Edit the given account.' })
|
@ApiOperation({ summary: 'Edit the given account.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export class CommandAccountValidators {
|
|||||||
@Inject(Account.name)
|
@Inject(Account.name)
|
||||||
private readonly accountModel: TenantModelProxy<typeof Account>,
|
private readonly accountModel: TenantModelProxy<typeof Account>,
|
||||||
private readonly accountRepository: AccountRepository,
|
private readonly accountRepository: AccountRepository,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws error if the account was prefined.
|
* Throws error if the account was prefined.
|
||||||
@@ -115,7 +115,7 @@ export class CommandAccountValidators {
|
|||||||
accountName: string,
|
accountName: string,
|
||||||
notAccountId?: number,
|
notAccountId?: number,
|
||||||
) {
|
) {
|
||||||
const foundAccount = await this.accountModel
|
const foundAccount = await this.accountModel()
|
||||||
.query()
|
.query()
|
||||||
.findOne('name', accountName)
|
.findOne('name', accountName)
|
||||||
.onBuild((query) => {
|
.onBuild((query) => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
import { IsOptional, ToNumber } from '@/common/decorators/Validators';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
IsString,
|
IsString,
|
||||||
IsOptional,
|
|
||||||
IsInt,
|
IsInt,
|
||||||
MinLength,
|
MinLength,
|
||||||
MaxLength,
|
MaxLength,
|
||||||
@@ -65,7 +65,7 @@ export class CreateAccountDTO {
|
|||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsInt()
|
@ToNumber()
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'ID of the parent account',
|
description: 'ID of the parent account',
|
||||||
example: 1,
|
example: 1,
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
|
import { IsString, MinLength, MaxLength } from 'class-validator';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import {
|
import { IsOptional, ToNumber } from '@/common/decorators/Validators';
|
||||||
IsString,
|
|
||||||
IsOptional,
|
|
||||||
IsInt,
|
|
||||||
MinLength,
|
|
||||||
MaxLength,
|
|
||||||
} from 'class-validator';
|
|
||||||
|
|
||||||
export class EditAccountDTO {
|
export class EditAccountDTO {
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -45,7 +40,7 @@ export class EditAccountDTO {
|
|||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsInt()
|
@ToNumber()
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The parent account ID of the account',
|
description: 'The parent account ID of the account',
|
||||||
example: 1,
|
example: 1,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export class EditAccount {
|
|||||||
|
|
||||||
@Inject(Account.name)
|
@Inject(Account.name)
|
||||||
private readonly accountModel: TenantModelProxy<typeof Account>,
|
private readonly accountModel: TenantModelProxy<typeof Account>,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authorize the account editing.
|
* Authorize the account editing.
|
||||||
@@ -85,8 +85,7 @@ export class EditAccount {
|
|||||||
// Update the account on the storage.
|
// Update the account on the storage.
|
||||||
const account = await this.accountModel()
|
const account = await this.accountModel()
|
||||||
.query(trx)
|
.query(trx)
|
||||||
.findById(accountId)
|
.updateAndFetchById(accountId, { ...accountDTO });
|
||||||
.updateAndFetch({ ...accountDTO });
|
|
||||||
|
|
||||||
// Triggers `onAccountEdited` event.
|
// Triggers `onAccountEdited` event.
|
||||||
// await this.eventEmitter.emitAsync(events.accounts.onEdited, {
|
// await this.eventEmitter.emitAsync(events.accounts.onEdited, {
|
||||||
|
|||||||
Reference in New Issue
Block a user