mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
refactor(nestjs): export and import module
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ResourceService } from './ResourceService';
|
||||
import { BranchesModule } from '../Branches/Branches.module';
|
||||
import { WarehousesModule } from '../Warehouses/Warehouses.module';
|
||||
import { AccountsExportable } from '../Accounts/AccountsExportable.service';
|
||||
import { AccountsModule } from '../Accounts/Accounts.module';
|
||||
|
||||
@Module({
|
||||
imports: [BranchesModule, WarehousesModule, AccountsModule],
|
||||
providers: [ResourceService],
|
||||
exports: [ResourceService],
|
||||
})
|
||||
|
||||
@@ -28,7 +28,7 @@ export class ResourceService {
|
||||
*/
|
||||
public getResourceModel(inputModelName: string) {
|
||||
const modelName = resourceToModelName(inputModelName);
|
||||
const resourceModel = this.moduleRef.get(modelName);
|
||||
const resourceModel = this.moduleRef.get(modelName, { strict: false });
|
||||
|
||||
if (!resourceModel) {
|
||||
throw new ServiceError(ERRORS.RESOURCE_MODEL_NOT_FOUND);
|
||||
@@ -46,7 +46,7 @@ export class ResourceService {
|
||||
const resourceModel = this.getResourceModel(modelName);
|
||||
|
||||
// Retrieve the resource meta.
|
||||
const resourceMeta = resourceModel.getMeta(metakey);
|
||||
const resourceMeta = resourceModel().getMeta(metakey);
|
||||
|
||||
// Localization the fields names.
|
||||
return resourceMeta;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { camelCase, upperFirst } from 'lodash';
|
||||
import pluralize from 'pluralize';
|
||||
import * as pluralize from 'pluralize';
|
||||
|
||||
export const resourceToModelName = (resourceName: string): string => {
|
||||
return upperFirst(camelCase(pluralize.singular(resourceName)));
|
||||
|
||||
Reference in New Issue
Block a user