mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
5 changed files with 155 additions and 0 deletions
@ -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(); |
||||
}); |
||||
}); |
@ -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; |
||||
} |
||||
} |
@ -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 {} |
@ -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(); |
||||
}); |
||||
}); |
@ -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…
Reference in new issue