feat: more resources support importing

This commit is contained in:
Ahmed Bouhuolia
2024-04-05 02:00:12 +02:00
parent 3851d34ba4
commit dd9098bdc1
46 changed files with 1510 additions and 149 deletions

View File

@@ -3,6 +3,7 @@ import { Knex } from 'knex';
import { Importable } from '@/services/Import/Importable';
import { CreateBill } from './CreateBill';
import { IBillDTO } from '@/interfaces';
import { BillsSampleData } from './constants';
@Service()
export class BillsImportable extends Importable {
@@ -20,7 +21,6 @@ export class BillsImportable extends Importable {
createAccountDTO: IBillDTO,
trx?: Knex.Transaction
) {
console.log(JSON.stringify(createAccountDTO));
return this.createBillService.createBill(
tenantId,
createAccountDTO,
@@ -41,6 +41,6 @@ export class BillsImportable extends Importable {
* Retrieves the sample data that used to download accounts sample sheet.
*/
public sampleData(): any[] {
return [];
return BillsSampleData;
}
}

View File

@@ -23,12 +23,12 @@ export class BillsValidators {
/**
* Validates the bill amount is bigger than paid amount.
* @param {number} billAmount
* @param {number} paidAmount
* @param {number} billAmount
* @param {number} paidAmount
*/
public validateBillAmountBiggerPaidAmount(
billAmount: number,
paidAmount: number,
paidAmount: number
) {
if (billAmount < paidAmount) {
throw new ServiceError(ERRORS.BILL_AMOUNT_SMALLER_THAN_PAID_AMOUNT);
@@ -53,7 +53,10 @@ export class BillsValidators {
});
if (foundBills.length > 0) {
throw new ServiceError(ERRORS.BILL_NUMBER_EXISTS);
throw new ServiceError(
ERRORS.BILL_NUMBER_EXISTS,
'The bill number is not unique.'
);
}
}

View File

@@ -75,3 +75,49 @@ export const DEFAULT_VIEWS = [
columns: DEFAULT_VIEW_COLUMNS,
},
];
export const BillsSampleData = [
{
'Bill No.': 'B-101',
'Reference No.': 'REF0',
Date: '2024-01-01',
'Due Date': '2024-03-01',
Vendor: 'Gabriel Kovacek',
'Exchange Rate': 1,
Note: 'Vel in sit sint.',
Open: 'T',
Item: 'VonRueden, Ruecker and Hettinger',
Quantity: 100,
Rate: 100,
'Line Description': 'Id a vel quis vel aut.',
},
{
'Bill No.': 'B-102',
'Reference No.': 'REF0',
Date: '2024-01-01',
'Due Date': '2024-03-01',
Vendor: 'Gabriel Kovacek',
'Exchange Rate': 1,
Note: 'Quia ut dolorem qui sint velit.',
Open: 'T',
Item: 'Thompson - Reichert',
Quantity: 200,
Rate: 50,
'Line Description':
'Nesciunt in adipisci quia ab reiciendis nam sed saepe consequatur.',
},
{
'Bill No.': 'B-103',
'Reference No.': 'REF0',
Date: '2024-01-01',
'Due Date': '2024-03-01',
Vendor: 'Gabriel Kovacek',
'Exchange Rate': 1,
Note: 'Dolore aut voluptatem minus pariatur alias pariatur.',
Open: 'T',
Item: 'VonRueden, Ruecker and Hettinger',
Quantity: 100,
Rate: 100,
'Line Description': 'Quam eligendi provident.',
},
];