Browse Source

feat: view column apis - module

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
cc0122d513
  1. 20
      packages/nocodb-nest/src/modules/view-columns/view-columns.controller.spec.ts
  2. 58
      packages/nocodb-nest/src/modules/view-columns/view-columns.controller.ts
  3. 9
      packages/nocodb-nest/src/modules/view-columns/view-columns.module.ts
  4. 18
      packages/nocodb-nest/src/modules/view-columns/view-columns.service.spec.ts
  5. 50
      packages/nocodb-nest/src/modules/view-columns/view-columns.service.ts

20
packages/nocodb-nest/src/modules/view-columns/view-columns.controller.spec.ts

@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ViewColumnsController } from './view-columns.controller';
import { ViewColumnsService } from './view-columns.service';
describe('ViewColumnsController', () => {
let controller: ViewColumnsController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ViewColumnsController],
providers: [ViewColumnsService],
}).compile();
controller = module.get<ViewColumnsController>(ViewColumnsController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

58
packages/nocodb-nest/src/modules/view-columns/view-columns.controller.ts

@ -0,0 +1,58 @@
import {
Body,
Controller,
Get,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
import { ColumnReqType, ViewColumnReqType } from 'nocodb-sdk';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
import {
Acl,
ExtractProjectIdMiddleware,
} from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { ViewColumnsService } from './view-columns.service';
import { AuthGuard } from '@nestjs/passport';
@Controller('view-columns')
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class ViewColumnsController {
constructor(private readonly viewColumnsService: ViewColumnsService) {}
@Get('/api/v1/db/meta/views/:viewId/columns/')
@Acl('columnList')
async columnList(@Param('viewId') viewId: string) {
return;
new PagedResponseImpl(await this.viewColumnsService.columnList({ viewId }));
}
@Post('/api/v1/db/meta/views/:viewId/columns/')
@Acl('columnAdd')
async columnAdd(
@Param('viewId') viewId: string,
@Body() body: ViewColumnReqType,
) {
const viewColumn = await this.viewColumnsService.columnAdd({
viewId,
column: body,
});
return viewColumn;
}
@Patch('/api/v1/db/meta/views/:viewId/columns/:columnId')
@Acl('columnUpdate')
async columnUpdate(
@Param('viewId') viewId: string,
@Param('columnId') columnId: string,
@Body() body: ViewColumnReqType,
) {
const result = await this.viewColumnsService.columnUpdate({
viewId,
columnId,
column: body,
});
return result;
}
}

9
packages/nocodb-nest/src/modules/view-columns/view-columns.module.ts

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ViewColumnsService } from './view-columns.service';
import { ViewColumnsController } from './view-columns.controller';
@Module({
controllers: [ViewColumnsController],
providers: [ViewColumnsService]
})
export class ViewColumnsModule {}

18
packages/nocodb-nest/src/modules/view-columns/view-columns.service.spec.ts

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ViewColumnsService } from './view-columns.service';
describe('ViewColumnsService', () => {
let service: ViewColumnsService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ViewColumnsService],
}).compile();
service = module.get<ViewColumnsService>(ViewColumnsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

50
packages/nocodb-nest/src/modules/view-columns/view-columns.service.ts

@ -0,0 +1,50 @@
import { Injectable } from '@nestjs/common';
import { ViewColumnReqType, ViewColumnUpdateReqType } from 'nocodb-sdk';
import { validatePayload } from '../../helpers';
import { View } from '../../models';
import { T } from 'nc-help';
@Injectable()
export class ViewColumnsService {
async columnList(param: { viewId: string }) {
return await View.getColumns(param.viewId);
}
async columnAdd(param: { viewId: string; column: ViewColumnReqType }) {
validatePayload(
'swagger.json#/components/schemas/ViewColumnReq',
param.column,
);
const viewColumn = await View.insertOrUpdateColumn(
param.viewId,
param.column.fk_column_id,
{
order: param.column.order,
show: param.column.show,
},
);
T.emit('evt', { evt_type: 'viewColumn:inserted' });
return viewColumn;
}
async columnUpdate(param: {
viewId: string;
columnId: string;
column: ViewColumnUpdateReqType;
}) {
validatePayload(
'swagger.json#/components/schemas/ViewColumnUpdateReq',
param.column,
);
const result = await View.updateColumn(
param.viewId,
param.columnId,
param.column,
);
T.emit('evt', { evt_type: 'viewColumn:updated' });
return result;
}
}
Loading…
Cancel
Save