mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +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 { ImportModule } from '../Import/Import.module';
|
||||
import { CreditNotesApplyInvoiceModule } from '../CreditNotesApplyInvoice/CreditNotesApplyInvoice.module';
|
||||
import { ResourceModule } from '../Resource/Resource.module';
|
||||
import { ViewsModule } from '../Views/Views.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -200,7 +202,9 @@ import { CreditNotesApplyInvoiceModule } from '../CreditNotesApplyInvoice/Credit
|
||||
AttachmentsModule,
|
||||
S3Module,
|
||||
ExportModule,
|
||||
ImportModule
|
||||
ImportModule,
|
||||
ResourceModule,
|
||||
ViewsModule
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
import { FeaturesManager } from '../Features/FeaturesManager';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
||||
import { IFeatureAllItem } from '@/common/types/Features';
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { TenantUser } from '../Tenancy/TenancyModels/models/TenantUser.model';
|
||||
|
||||
interface IRoleAbility {
|
||||
subject: string;
|
||||
ability: string;
|
||||
action: string;
|
||||
}
|
||||
|
||||
interface IDashboardBootMeta {
|
||||
@@ -70,7 +70,7 @@ export class DashboardService {
|
||||
.throwIfNotFound();
|
||||
|
||||
return tenantUser.role.slug === 'admin'
|
||||
? [{ subject: 'all', ability: 'manage' }]
|
||||
? [{ subject: 'all', action: 'manage' }]
|
||||
: this.transformRoleAbility(tenantUser.role.permissions);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
IInventoryDetailsClosing,
|
||||
IInventoryDetailsNode,
|
||||
IInventoryDetailsOpening,
|
||||
IInvetoryItemDetailDOO,
|
||||
} from './InventoryItemDetails.types';
|
||||
import { I18nService } from 'nestjs-i18n';
|
||||
import { IInventoryDetailsData } from './InventoryItemDetails.types';
|
||||
@@ -33,7 +34,7 @@ export class InventoryItemDetailsTable {
|
||||
* Constructor method.
|
||||
* @param {ICashFlowStatement} report - Report statement.
|
||||
*/
|
||||
constructor(reportStatement: IInventoryDetailsData, i18n: I18nService) {
|
||||
constructor(reportStatement: IInvetoryItemDetailDOO, i18n: I18nService) {
|
||||
this.report = reportStatement;
|
||||
this.i18n = i18n;
|
||||
}
|
||||
@@ -146,6 +147,8 @@ export class InventoryItemDetailsTable {
|
||||
* @return {ITableRow}
|
||||
*/
|
||||
private itemMapper = (node: IInventoryDetailsNode): ITableRow => {
|
||||
console.log(node, 'node');
|
||||
|
||||
// @ts-ignore
|
||||
return R.compose(
|
||||
R.when(
|
||||
|
||||
@@ -25,7 +25,7 @@ export class InventoryDetailsTableInjectable {
|
||||
const inventoryDetails =
|
||||
await this.inventoryDetails.inventoryDetails(query);
|
||||
|
||||
const table = new InventoryItemDetailsTable(inventoryDetails.data, this.i18n);
|
||||
const table = new InventoryItemDetailsTable(inventoryDetails, this.i18n);
|
||||
|
||||
return {
|
||||
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 { AccountsExportable } from '../Accounts/AccountsExportable.service';
|
||||
import { AccountsModule } from '../Accounts/Accounts.module';
|
||||
import { ResourceController } from './Resource.controller';
|
||||
|
||||
@Module({
|
||||
imports: [BranchesModule, WarehousesModule, AccountsModule],
|
||||
providers: [ResourceService],
|
||||
exports: [ResourceService],
|
||||
controllers: [ResourceController]
|
||||
})
|
||||
export class ResourceModule {}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseModel } from '@/models/Model';
|
||||
import { View } from './models/View.model';
|
||||
import { ResourceService } from '../Resource/ResourceService';
|
||||
|
||||
@Injectable()
|
||||
export class GetResourceViewsService {
|
||||
constructor(private readonly resourceService: ResourceService) {}
|
||||
/**
|
||||
* Listing resource views.
|
||||
* @param {number} tenantId -
|
||||
* @param {string} resourceModel -
|
||||
*/
|
||||
public async getResourceViews(resourceName: string): Promise<View[]> {
|
||||
@@ -15,7 +14,7 @@ export class GetResourceViewsService {
|
||||
const resourceModel = this.resourceService.getResourceModel(resourceName);
|
||||
|
||||
// Default views.
|
||||
const defaultViews = resourceModel.getDefaultViews();
|
||||
const defaultViews = resourceModel().getDefaultViews();
|
||||
|
||||
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