feat: add more seedders

This commit is contained in:
Ahmed Bouhuolia
2024-08-20 23:40:23 +02:00
parent 3200d65d90
commit 4a05ccc692
9 changed files with 204 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
import { SeedDemoAbstract } from './SeedDemoAbstract';
export class SeedDemoAccountCustomers extends SeedDemoAbstract {
/**
* Retrieves the seeder file mapping.
*/
get mapping() {
return [
{ from: 'Customer Type', to: 'customerType' },
{ from: 'First Name', to: 'firstName' },
{ from: 'Last Name', to: 'lastName' },
{ from: 'Display Name', to: 'displayName' },
{ from: 'Email', to: 'email' },
{ from: 'Work Phone Number', to: 'workPhone' },
{ from: 'Personal Phone Number', to: 'personalPhone' },
{ from: 'Company Name', to: 'companyName' },
{ from: 'Website', to: 'website' },
{ from: 'Active', to: 'active' },
];
}
/**
* Retrieves the seeder file name.
* @returns {string}
*/
get importFileName() {
return `customers.csv`;
}
/**
* Retrieve the resource name of the seeder.
* @returns {string}
*/
get resource() {
return 'Customer';
}
}

View File

@@ -0,0 +1,39 @@
import { SeedDemoAbstract } from './SeedDemoAbstract';
export class SeedDemoAccountExpenses extends SeedDemoAbstract {
/**
* Retrieves the seeder file mapping.
*/
get mapping() {
return [
{ from: 'Payment Account', to: 'paymentAccountId' },
{ from: 'Reference No.', to: 'referenceNo' },
{ from: 'Payment Date', to: 'paymentDate' },
{ from: 'Description', to: 'description' },
{ from: 'Publish', to: 'publish' },
{
from: 'Expense Account',
to: 'expenseAccountId',
group: 'categories',
},
{ from: 'Amount', to: 'amount', group: 'categories' },
{ from: 'Line Description', to: 'description', group: 'categories' },
];
}
/**
* Retrieves the seeder file name.
* @returns {string}
*/
get importFileName() {
return `Expenses.csv`;
}
/**
* Retrieve the resource name of the seeder.
* @returns {string}
*/
get resource() {
return 'Expense';
}
}

View File

@@ -0,0 +1,36 @@
import { SeedDemoAbstract } from './SeedDemoAbstract';
export class SeedDemoAccountManualJournals extends SeedDemoAbstract {
/**
* Retrieves the seeder file mapping.
*/
get mapping() {
return [
{ from: 'Date', to: 'date' },
{ from: 'Journal No', to: 'journalNumber' },
{ from: 'Reference No.', to: 'reference' },
{ from: 'Description', to: 'description' },
{ from: 'Publish', to: 'publish' },
{ from: 'Credit', to: 'credit', group: 'entries' },
{ from: 'Debit', to: 'debit', group: 'entries' },
{ from: 'Account', to: 'accountId', group: 'entries' },
{ from: 'Note', to: 'note', group: 'entries' },
];
}
/**
* Retrieves the seeder file name.
* @returns {string}
*/
get importFileName() {
return `manual-journals.csv`;
}
/**
* Retrieve the resource name of the seeder.
* @returns {string}
*/
get resource() {
return 'ManualJournal';
}
}

View File

@@ -0,0 +1,36 @@
import { SeedDemoAbstract } from './SeedDemoAbstract';
export class SeedDemoAccountVendors extends SeedDemoAbstract {
/**
* Retrieves the seeder file mapping.
*/
get mapping() {
return [
{ from: 'First Name', to: 'firstName' },
{ from: 'Last Name', to: 'lastName' },
{ from: 'Display Name', to: 'displayName' },
{ from: 'Email', to: 'email' },
{ from: 'Work Phone Number', to: 'workPhone' },
{ from: 'Personal Phone Number', to: 'personalPhone' },
{ from: 'Company Name', to: 'companyName' },
{ from: 'Website', to: 'website' },
{ from: 'Active', to: 'active' },
];
}
/**
* Retrieves the seeder file name.
* @returns {string}
*/
get importFileName() {
return `vendors.csv`;
}
/**
* Retrieve the resource name of the seeder.
* @returns {string}
*/
get resource() {
return 'Vendor';
}
}

View File

@@ -8,6 +8,10 @@ import { SeedDemoAccountItems } from '../DemoSeeders/SeedDemoItems';
import { ImportResourceApplication } from '@/services/Import/ImportResourceApplication';
import { getImportsStoragePath } from '@/services/Import/_utils';
import { OneClickDemo } from '@/system/models/OneclickDemo';
import { SeedDemoAccountCustomers } from '../DemoSeeders/SeedDemoCustomers';
import { SeedDemoAccountVendors } from '../DemoSeeders/SeedDemoVendors';
import { SeedDemoAccountManualJournals } from '../DemoSeeders/SeedDemoManualJournals';
import { SeedDemoAccountExpenses } from '../DemoSeeders/SeedDemoExpenses';
export class SeedInitialDemoAccountDataOnOrgBuild {
@Inject()
@@ -27,7 +31,13 @@ export class SeedInitialDemoAccountDataOnOrgBuild {
* Demo account seeder.
*/
get seedDemoAccountSeeders() {
return [SeedDemoAccountItems];
return [
SeedDemoAccountItems,
SeedDemoAccountCustomers,
SeedDemoAccountVendors,
SeedDemoAccountManualJournals,
SeedDemoAccountExpenses,
];
}
/**
@@ -79,9 +89,16 @@ export class SeedInitialDemoAccountDataOnOrgBuild {
seederInstance.mapping
);
// Commit the imported file.
await this.importApp.process(tenantId, importedFile.import.importId);
const re = await this.importApp.process(
tenantId,
importedFile.import.importId
);
console.log(re);
});
console.error(results.errors);
console.log(results.results);
if (results.errors) {
throw results.errors;
}