mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: linking relation with id in importing
This commit is contained in:
@@ -88,7 +88,11 @@ export class CreateItem {
|
||||
* @param {IItemDTO} item
|
||||
* @return {Promise<IItem>}
|
||||
*/
|
||||
public async createItem(tenantId: number, itemDTO: IItemDTO): Promise<IItem> {
|
||||
public async createItem(
|
||||
tenantId: number,
|
||||
itemDTO: IItemDTO,
|
||||
trx?: Knex.Transaction
|
||||
): Promise<IItem> {
|
||||
const { Item } = this.tenancy.models(tenantId);
|
||||
|
||||
// Authorize the item before creating.
|
||||
@@ -111,7 +115,8 @@ export class CreateItem {
|
||||
} as IItemEventCreatedPayload);
|
||||
|
||||
return item;
|
||||
}
|
||||
},
|
||||
trx
|
||||
);
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,10 @@ export class ItemsValidators {
|
||||
}
|
||||
});
|
||||
if (foundItems.length > 0) {
|
||||
throw new ServiceError(ERRORS.ITEM_NAME_EXISTS);
|
||||
throw new ServiceError(
|
||||
ERRORS.ITEM_NAME_EXISTS,
|
||||
'The item name is already exist.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
packages/server/src/services/Items/ItemsImportable.ts
Normal file
34
packages/server/src/services/Items/ItemsImportable.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import { Importable } from '@/services/Import/Importable';
|
||||
import { IItemCreateDTO } from '@/interfaces';
|
||||
import { CreateItem } from './CreateItem';
|
||||
|
||||
@Service()
|
||||
export class ItemsImportable extends Importable {
|
||||
@Inject()
|
||||
private createItemService: CreateItem;
|
||||
|
||||
/**
|
||||
* Mapps the imported data to create a new item service.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerNewDTO} createDTO
|
||||
* @param {Knex.Transaction} trx
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async importable(
|
||||
tenantId: number,
|
||||
createDTO: IItemCreateDTO,
|
||||
trx?: Knex.Transaction<any, any[]>
|
||||
): Promise<void> {
|
||||
console.log(createDTO, tenantId, 'XX');
|
||||
await this.createItemService.createItem(tenantId, createDTO, trx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sample data of customers used to download sample sheet.
|
||||
*/
|
||||
public sampleData(): any[] {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user