mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
6 changed files with 108 additions and 1 deletions
@ -0,0 +1,20 @@ |
|||||||
|
import { Test, TestingModule } from '@nestjs/testing'; |
||||||
|
import { GridColumnsController } from './grid-columns.controller'; |
||||||
|
import { GridColumnsService } from './grid-columns.service'; |
||||||
|
|
||||||
|
describe('GridColumnsController', () => { |
||||||
|
let controller: GridColumnsController; |
||||||
|
|
||||||
|
beforeEach(async () => { |
||||||
|
const module: TestingModule = await Test.createTestingModule({ |
||||||
|
controllers: [GridColumnsController], |
||||||
|
providers: [GridColumnsService], |
||||||
|
}).compile(); |
||||||
|
|
||||||
|
controller = module.get<GridColumnsController>(GridColumnsController); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should be defined', () => { |
||||||
|
expect(controller).toBeDefined(); |
||||||
|
}); |
||||||
|
}); |
@ -0,0 +1,33 @@ |
|||||||
|
import { Body, Controller, Get, Param, Patch, UseGuards } from '@nestjs/common'; |
||||||
|
import { GridColumnReqType } from 'nocodb-sdk'; |
||||||
|
import { |
||||||
|
Acl, |
||||||
|
ExtractProjectIdMiddleware, |
||||||
|
} from '../../middlewares/extract-project-id/extract-project-id.middleware'; |
||||||
|
import { GridColumnsService } from './grid-columns.service'; |
||||||
|
import { AuthGuard } from '@nestjs/passport'; |
||||||
|
|
||||||
|
@Controller('grid-columns') |
||||||
|
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) |
||||||
|
export class GridColumnsController { |
||||||
|
constructor(private readonly gridColumnsService: GridColumnsService) {} |
||||||
|
|
||||||
|
@Get('/api/v1/db/meta/grids/:gridViewId/grid-columns') |
||||||
|
@Acl('columnList') |
||||||
|
async columnList(@Param('gridViewId') gridViewId: string) { |
||||||
|
return await this.gridColumnsService.columnList({ |
||||||
|
gridViewId, |
||||||
|
}); |
||||||
|
} |
||||||
|
@Patch('/api/v1/db/meta/grid-columns/:gridViewColumnId') |
||||||
|
@Acl('gridColumnUpdate') |
||||||
|
async gridColumnUpdate( |
||||||
|
@Param('gridViewColumnId') gridViewColumnId: string, |
||||||
|
@Body() body: GridColumnReqType, |
||||||
|
) { |
||||||
|
return this.gridColumnsService.gridColumnUpdate({ |
||||||
|
gridViewColumnId, |
||||||
|
grid: body, |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
import { Module } from '@nestjs/common'; |
||||||
|
import { GridColumnsService } from './grid-columns.service'; |
||||||
|
import { GridColumnsController } from './grid-columns.controller'; |
||||||
|
|
||||||
|
@Module({ |
||||||
|
controllers: [GridColumnsController], |
||||||
|
providers: [GridColumnsService] |
||||||
|
}) |
||||||
|
export class GridColumnsModule {} |
@ -0,0 +1,18 @@ |
|||||||
|
import { Test, TestingModule } from '@nestjs/testing'; |
||||||
|
import { GridColumnsService } from './grid-columns.service'; |
||||||
|
|
||||||
|
describe('GridColumnsService', () => { |
||||||
|
let service: GridColumnsService; |
||||||
|
|
||||||
|
beforeEach(async () => { |
||||||
|
const module: TestingModule = await Test.createTestingModule({ |
||||||
|
providers: [GridColumnsService], |
||||||
|
}).compile(); |
||||||
|
|
||||||
|
service = module.get<GridColumnsService>(GridColumnsService); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should be defined', () => { |
||||||
|
expect(service).toBeDefined(); |
||||||
|
}); |
||||||
|
}); |
@ -0,0 +1,26 @@ |
|||||||
|
import { Injectable } from '@nestjs/common'; |
||||||
|
import { GridColumnReqType } from 'nocodb-sdk'; |
||||||
|
import { validatePayload } from '../../helpers'; |
||||||
|
import { GridViewColumn } from '../../models'; |
||||||
|
import { T } from 'nc-help'; |
||||||
|
|
||||||
|
@Injectable() |
||||||
|
export class GridColumnsService { |
||||||
|
|
||||||
|
async columnList(param: { gridViewId: string }) { |
||||||
|
return await GridViewColumn.list(param.gridViewId); |
||||||
|
} |
||||||
|
|
||||||
|
async gridColumnUpdate(param: { |
||||||
|
gridViewColumnId: string; |
||||||
|
grid: GridColumnReqType; |
||||||
|
}) { |
||||||
|
validatePayload( |
||||||
|
'swagger.json#/components/schemas/GridColumnReq', |
||||||
|
param.grid, |
||||||
|
); |
||||||
|
|
||||||
|
T.emit('evt', { evt_type: 'gridViewColumn:updated' }); |
||||||
|
return await GridViewColumn.update(param.gridViewColumnId, param.grid); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue