mirror of https://github.com/nocodb/nocodb
Pranav C
1 year ago
10 changed files with 272 additions and 0 deletions
@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { GalleriesController } from './galleries.controller'; |
||||
import { GalleriesService } from './galleries.service'; |
||||
|
||||
describe('GalleriesController', () => { |
||||
let controller: GalleriesController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [GalleriesController], |
||||
providers: [GalleriesService], |
||||
}).compile(); |
||||
|
||||
controller = module.get<GalleriesController>(GalleriesController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,55 @@
|
||||
import { |
||||
Body, |
||||
Controller, |
||||
Get, |
||||
Param, |
||||
Patch, |
||||
Post, |
||||
UseGuards, |
||||
} from '@nestjs/common'; |
||||
import { GalleryUpdateReqType, ViewCreateReqType } from 'nocodb-sdk'; |
||||
import { |
||||
Acl, |
||||
ExtractProjectIdMiddleware, |
||||
} from '../../middlewares/extract-project-id/extract-project-id.middleware'; |
||||
import { GalleriesService } from './galleries.service'; |
||||
import { AuthGuard } from '@nestjs/passport'; |
||||
|
||||
@Controller('galleries') |
||||
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) |
||||
export class GalleriesController { |
||||
constructor(private readonly galleriesService: GalleriesService) {} |
||||
|
||||
@Get('/api/v1/db/meta/galleries/:galleryViewId') |
||||
@Acl('galleryViewGet') |
||||
async galleryViewGet(@Param('galleryViewId') galleryViewId: string) { |
||||
return await this.galleriesService.galleryViewGet({ |
||||
galleryViewId, |
||||
}); |
||||
} |
||||
|
||||
@Post('/api/v1/db/meta/tables/:tableId/galleries') |
||||
@Acl('galleryViewCreate') |
||||
async galleryViewCreate( |
||||
@Param('tableId') tableId: string, |
||||
@Body() body: ViewCreateReqType, |
||||
) { |
||||
return await this.galleriesService.galleryViewCreate({ |
||||
gallery: body, |
||||
// todo: sanitize
|
||||
tableId, |
||||
}); |
||||
} |
||||
|
||||
@Patch('/api/v1/db/meta/galleries/:galleryViewId') |
||||
@Acl('galleryViewUpdate') |
||||
async galleryViewUpdate( |
||||
@Param('galleryViewId') galleryViewId: string, |
||||
@Body() body: GalleryUpdateReqType, |
||||
) { |
||||
return await this.galleriesService.galleryViewUpdate({ |
||||
galleryViewId, |
||||
gallery: body, |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common'; |
||||
import { GalleriesService } from './galleries.service'; |
||||
import { GalleriesController } from './galleries.controller'; |
||||
|
||||
@Module({ |
||||
controllers: [GalleriesController], |
||||
providers: [GalleriesService] |
||||
}) |
||||
export class GalleriesModule {} |
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { GalleriesService } from './galleries.service'; |
||||
|
||||
describe('GalleriesService', () => { |
||||
let service: GalleriesService; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
providers: [GalleriesService], |
||||
}).compile(); |
||||
|
||||
service = module.get<GalleriesService>(GalleriesService); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(service).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,44 @@
|
||||
import { Injectable } from '@nestjs/common'; |
||||
import { GalleryUpdateReqType, ViewCreateReqType, ViewTypes } from 'nocodb-sdk'; |
||||
import { validatePayload } from '../../helpers'; |
||||
import { GalleryView, View } from '../../models'; |
||||
import { T } from 'nc-help'; |
||||
|
||||
@Injectable() |
||||
export class GalleriesService { |
||||
async galleryViewGet(param: { galleryViewId: string }) { |
||||
return await GalleryView.get(param.galleryViewId); |
||||
} |
||||
|
||||
async galleryViewCreate(param: { |
||||
tableId: string; |
||||
gallery: ViewCreateReqType; |
||||
}) { |
||||
validatePayload( |
||||
'swagger.json#/components/schemas/ViewCreateReq', |
||||
param.gallery, |
||||
); |
||||
|
||||
T.emit('evt', { evt_type: 'vtable:created', show_as: 'gallery' }); |
||||
const view = await View.insert({ |
||||
...param.gallery, |
||||
// todo: sanitize
|
||||
fk_model_id: param.tableId, |
||||
type: ViewTypes.GALLERY, |
||||
}); |
||||
return view; |
||||
} |
||||
|
||||
async galleryViewUpdate(param: { |
||||
galleryViewId: string; |
||||
gallery: GalleryUpdateReqType; |
||||
}) { |
||||
validatePayload( |
||||
'swagger.json#/components/schemas/GalleryUpdateReq', |
||||
param.gallery, |
||||
); |
||||
|
||||
T.emit('evt', { evt_type: 'view:updated', type: 'gallery' }); |
||||
return await GalleryView.update(param.galleryViewId, param.gallery); |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { GridsController } from './grids.controller'; |
||||
import { GridsService } from './grids.service'; |
||||
|
||||
describe('GridsController', () => { |
||||
let controller: GridsController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [GridsController], |
||||
providers: [GridsService], |
||||
}).compile(); |
||||
|
||||
controller = module.get<GridsController>(GridsController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,44 @@
|
||||
import { |
||||
Body, |
||||
Controller, |
||||
Param, |
||||
Patch, |
||||
Post, |
||||
UseGuards, |
||||
} from '@nestjs/common'; |
||||
import { ViewCreateReqType } from 'nocodb-sdk'; |
||||
import { |
||||
Acl, |
||||
ExtractProjectIdMiddleware, |
||||
} from '../../middlewares/extract-project-id/extract-project-id.middleware'; |
||||
import { GridsService } from './grids.service'; |
||||
import { AuthGuard } from '@nestjs/passport'; |
||||
|
||||
@Controller('grids') |
||||
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) |
||||
export class GridsController { |
||||
get '/api/v1/db/meta/tables/:tableId/grids/'() { |
||||
return this['_/api/v1/db/meta/tables/:tableId/grids/']; |
||||
} |
||||
constructor(private readonly gridsService: GridsService) {} |
||||
|
||||
@Post('/api/v1/db/meta/tables/:tableId/grids/') |
||||
@Acl('gridViewCreate') |
||||
async gridViewCreate( |
||||
@Param('tableId') tableId: string, |
||||
@Body() body: ViewCreateReqType, |
||||
) { |
||||
const view = await this.gridsService.gridViewCreate({ |
||||
grid: body, |
||||
tableId, |
||||
}); |
||||
return view; |
||||
} |
||||
@Patch('/api/v1/db/meta/grids/:viewId') |
||||
async gridViewUpdate(req, res) { |
||||
return await this.gridsService.gridViewUpdate({ |
||||
viewId: req.params.viewId, |
||||
grid: req.body, |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common'; |
||||
import { GridsService } from './grids.service'; |
||||
import { GridsController } from './grids.controller'; |
||||
|
||||
@Module({ |
||||
controllers: [GridsController], |
||||
providers: [GridsService] |
||||
}) |
||||
export class GridsModule {} |
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { GridsService } from './grids.service'; |
||||
|
||||
describe('GridsService', () => { |
||||
let service: GridsService; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
providers: [GridsService], |
||||
}).compile(); |
||||
|
||||
service = module.get<GridsService>(GridsService); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(service).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@nestjs/common'; |
||||
import { GridUpdateReqType, ViewCreateReqType, ViewTypes } from 'nocodb-sdk'; |
||||
import { validatePayload } from '../../helpers'; |
||||
import { GridView, View } from '../../models'; |
||||
import { T } from 'nc-help'; |
||||
|
||||
@Injectable() |
||||
export class GridsService { |
||||
async gridViewCreate(param: { tableId: string; grid: ViewCreateReqType }) { |
||||
validatePayload( |
||||
'swagger.json#/components/schemas/ViewCreateReq', |
||||
param.grid, |
||||
); |
||||
|
||||
const view = await View.insert({ |
||||
...param.grid, |
||||
// todo: sanitize
|
||||
fk_model_id: param.tableId, |
||||
type: ViewTypes.GRID, |
||||
}); |
||||
|
||||
T.emit('evt', { evt_type: 'vtable:created', show_as: 'grid' }); |
||||
|
||||
return view; |
||||
} |
||||
|
||||
async gridViewUpdate(param: { viewId: string; grid: GridUpdateReqType }) { |
||||
validatePayload( |
||||
'swagger.json#/components/schemas/GridUpdateReq', |
||||
param.grid, |
||||
); |
||||
T.emit('evt', { evt_type: 'view:updated', type: 'grid' }); |
||||
return await GridView.update(param.viewId, param.grid); |
||||
} |
||||
} |
Loading…
Reference in new issue