mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
refactor(nestjs): resource meta endpoint
This commit is contained in:
@@ -83,6 +83,8 @@ import { S3Module } from '../S3/S3.module';
|
|||||||
import { ExportModule } from '../Export/Export.module';
|
import { ExportModule } from '../Export/Export.module';
|
||||||
import { ImportModule } from '../Import/Import.module';
|
import { ImportModule } from '../Import/Import.module';
|
||||||
import { CreditNotesApplyInvoiceModule } from '../CreditNotesApplyInvoice/CreditNotesApplyInvoice.module';
|
import { CreditNotesApplyInvoiceModule } from '../CreditNotesApplyInvoice/CreditNotesApplyInvoice.module';
|
||||||
|
import { ResourceModule } from '../Resource/Resource.module';
|
||||||
|
import { ViewsModule } from '../Views/Views.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -200,7 +202,9 @@ import { CreditNotesApplyInvoiceModule } from '../CreditNotesApplyInvoice/Credit
|
|||||||
AttachmentsModule,
|
AttachmentsModule,
|
||||||
S3Module,
|
S3Module,
|
||||||
ExportModule,
|
ExportModule,
|
||||||
ImportModule
|
ImportModule,
|
||||||
|
ResourceModule,
|
||||||
|
ViewsModule
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [
|
providers: [
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
|
import { Inject } from '@nestjs/common';
|
||||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||||
import { FeaturesManager } from '../Features/FeaturesManager';
|
import { FeaturesManager } from '../Features/FeaturesManager';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
||||||
import { IFeatureAllItem } from '@/common/types/Features';
|
import { IFeatureAllItem } from '@/common/types/Features';
|
||||||
import { Inject } from '@nestjs/common';
|
|
||||||
import { TenantUser } from '../Tenancy/TenancyModels/models/TenantUser.model';
|
import { TenantUser } from '../Tenancy/TenancyModels/models/TenantUser.model';
|
||||||
|
|
||||||
interface IRoleAbility {
|
interface IRoleAbility {
|
||||||
subject: string;
|
subject: string;
|
||||||
ability: string;
|
action: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IDashboardBootMeta {
|
interface IDashboardBootMeta {
|
||||||
@@ -70,7 +70,7 @@ export class DashboardService {
|
|||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
return tenantUser.role.slug === 'admin'
|
return tenantUser.role.slug === 'admin'
|
||||||
? [{ subject: 'all', ability: 'manage' }]
|
? [{ subject: 'all', action: 'manage' }]
|
||||||
: this.transformRoleAbility(tenantUser.role.permissions);
|
: this.transformRoleAbility(tenantUser.role.permissions);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
IInventoryDetailsClosing,
|
IInventoryDetailsClosing,
|
||||||
IInventoryDetailsNode,
|
IInventoryDetailsNode,
|
||||||
IInventoryDetailsOpening,
|
IInventoryDetailsOpening,
|
||||||
|
IInvetoryItemDetailDOO,
|
||||||
} from './InventoryItemDetails.types';
|
} from './InventoryItemDetails.types';
|
||||||
import { I18nService } from 'nestjs-i18n';
|
import { I18nService } from 'nestjs-i18n';
|
||||||
import { IInventoryDetailsData } from './InventoryItemDetails.types';
|
import { IInventoryDetailsData } from './InventoryItemDetails.types';
|
||||||
@@ -33,7 +34,7 @@ export class InventoryItemDetailsTable {
|
|||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {ICashFlowStatement} report - Report statement.
|
* @param {ICashFlowStatement} report - Report statement.
|
||||||
*/
|
*/
|
||||||
constructor(reportStatement: IInventoryDetailsData, i18n: I18nService) {
|
constructor(reportStatement: IInvetoryItemDetailDOO, i18n: I18nService) {
|
||||||
this.report = reportStatement;
|
this.report = reportStatement;
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
}
|
}
|
||||||
@@ -146,6 +147,8 @@ export class InventoryItemDetailsTable {
|
|||||||
* @return {ITableRow}
|
* @return {ITableRow}
|
||||||
*/
|
*/
|
||||||
private itemMapper = (node: IInventoryDetailsNode): ITableRow => {
|
private itemMapper = (node: IInventoryDetailsNode): ITableRow => {
|
||||||
|
console.log(node, 'node');
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return R.compose(
|
return R.compose(
|
||||||
R.when(
|
R.when(
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export class InventoryDetailsTableInjectable {
|
|||||||
const inventoryDetails =
|
const inventoryDetails =
|
||||||
await this.inventoryDetails.inventoryDetails(query);
|
await this.inventoryDetails.inventoryDetails(query);
|
||||||
|
|
||||||
const table = new InventoryItemDetailsTable(inventoryDetails.data, this.i18n);
|
const table = new InventoryItemDetailsTable(inventoryDetails, this.i18n);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
table: {
|
table: {
|
||||||
|
|||||||
21
packages/server/src/modules/Resource/Resource.controller.ts
Normal file
21
packages/server/src/modules/Resource/Resource.controller.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { Controller, Get, Param } from '@nestjs/common';
|
||||||
|
import { GetResourceViewsService } from '../Views/GetResourceViews.service';
|
||||||
|
import { ResourceService } from './ResourceService';
|
||||||
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@Controller('resources')
|
||||||
|
@ApiTags('resources')
|
||||||
|
export class ResourceController {
|
||||||
|
constructor(private readonly resourcesService: ResourceService) {}
|
||||||
|
|
||||||
|
@Get('/:resourceModel/meta')
|
||||||
|
@ApiResponse({ status: 200, description: 'Retrieves the resource meta' })
|
||||||
|
@ApiOperation({ summary: 'Retrieves the resource meta' })
|
||||||
|
getResourceMeta(@Param('resourceModel') resourceModel: string) {
|
||||||
|
const resourceMeta = this.resourcesService.getResourceMeta(resourceModel);
|
||||||
|
|
||||||
|
return {
|
||||||
|
resourceMeta,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,12 @@ import { BranchesModule } from '../Branches/Branches.module';
|
|||||||
import { WarehousesModule } from '../Warehouses/Warehouses.module';
|
import { WarehousesModule } from '../Warehouses/Warehouses.module';
|
||||||
import { AccountsExportable } from '../Accounts/AccountsExportable.service';
|
import { AccountsExportable } from '../Accounts/AccountsExportable.service';
|
||||||
import { AccountsModule } from '../Accounts/Accounts.module';
|
import { AccountsModule } from '../Accounts/Accounts.module';
|
||||||
|
import { ResourceController } from './Resource.controller';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [BranchesModule, WarehousesModule, AccountsModule],
|
imports: [BranchesModule, WarehousesModule, AccountsModule],
|
||||||
providers: [ResourceService],
|
providers: [ResourceService],
|
||||||
exports: [ResourceService],
|
exports: [ResourceService],
|
||||||
|
controllers: [ResourceController]
|
||||||
})
|
})
|
||||||
export class ResourceModule {}
|
export class ResourceModule {}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { BaseModel } from '@/models/Model';
|
|
||||||
import { View } from './models/View.model';
|
import { View } from './models/View.model';
|
||||||
|
import { ResourceService } from '../Resource/ResourceService';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GetResourceViewsService {
|
export class GetResourceViewsService {
|
||||||
constructor(private readonly resourceService: ResourceService) {}
|
constructor(private readonly resourceService: ResourceService) {}
|
||||||
/**
|
/**
|
||||||
* Listing resource views.
|
* Listing resource views.
|
||||||
* @param {number} tenantId -
|
|
||||||
* @param {string} resourceModel -
|
* @param {string} resourceModel -
|
||||||
*/
|
*/
|
||||||
public async getResourceViews(resourceName: string): Promise<View[]> {
|
public async getResourceViews(resourceName: string): Promise<View[]> {
|
||||||
@@ -15,7 +14,7 @@ export class GetResourceViewsService {
|
|||||||
const resourceModel = this.resourceService.getResourceModel(resourceName);
|
const resourceModel = this.resourceService.getResourceModel(resourceName);
|
||||||
|
|
||||||
// Default views.
|
// Default views.
|
||||||
const defaultViews = resourceModel.getDefaultViews();
|
const defaultViews = resourceModel().getDefaultViews();
|
||||||
|
|
||||||
return defaultViews;
|
return defaultViews;
|
||||||
}
|
}
|
||||||
|
|||||||
20
packages/server/src/modules/Views/Views.controller.ts
Normal file
20
packages/server/src/modules/Views/Views.controller.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Controller, Get, Param } from '@nestjs/common';
|
||||||
|
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { GetResourceViewsService } from './GetResourceViews.service';
|
||||||
|
|
||||||
|
@Controller('views')
|
||||||
|
@ApiTags('views')
|
||||||
|
export class ViewsController {
|
||||||
|
constructor(
|
||||||
|
private readonly getResourceViewsService: GetResourceViewsService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Get('/resource/:resourceModel')
|
||||||
|
@ApiResponse({ status: 200, description: 'Specific resource views' })
|
||||||
|
@ApiOperation({ summary: 'Get the given resource views' })
|
||||||
|
async getResourceViews(@Param('resourceModel') resourceModel: string) {
|
||||||
|
const views =
|
||||||
|
await this.getResourceViewsService.getResourceViews(resourceModel);
|
||||||
|
return { views };
|
||||||
|
}
|
||||||
|
}
|
||||||
11
packages/server/src/modules/Views/Views.module.ts
Normal file
11
packages/server/src/modules/Views/Views.module.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { GetResourceViewsService } from './GetResourceViews.service';
|
||||||
|
import { ViewsController } from './Views.controller';
|
||||||
|
import { ResourceModule } from '../Resource/Resource.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [ResourceModule],
|
||||||
|
controllers: [ViewsController],
|
||||||
|
providers: [GetResourceViewsService],
|
||||||
|
})
|
||||||
|
export class ViewsModule {}
|
||||||
Reference in New Issue
Block a user