mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
11 changed files with 413 additions and 1 deletions
@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { FiltersController } from './filters.controller'; |
||||
import { FiltersService } from './filters.service'; |
||||
|
||||
describe('FiltersController', () => { |
||||
let controller: FiltersController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [FiltersController], |
||||
providers: [FiltersService], |
||||
}).compile(); |
||||
|
||||
controller = module.get<FiltersController>(FiltersController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,127 @@
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common'; |
||||
import { AuthGuard } from '@nestjs/passport'; |
||||
import { PagedResponseImpl } from '../../helpers/PagedResponse'; |
||||
import { |
||||
ExtractProjectIdMiddleware, |
||||
UseAclMiddleware, |
||||
} from '../../middlewares/extract-project-id/extract-project-id.middleware'; |
||||
import { FiltersService } from './filters.service'; |
||||
|
||||
@Controller() |
||||
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) |
||||
export class FiltersController { |
||||
constructor(private readonly filtersService: FiltersService) {} |
||||
|
||||
@Get('/api/v1/db/meta/views/:viewId/filters') |
||||
@UseAclMiddleware({ |
||||
permissionName: 'filterList', |
||||
}) |
||||
async filterList(@Param('viewId') viewId: string) { |
||||
return new PagedResponseImpl( |
||||
await this.filtersService.filterList({ |
||||
viewId, |
||||
}), |
||||
); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
export async function filterGet(req: Request, res: Response) { |
||||
res.json(await filterService.filterGet({ filterId: req.params.filterId })); |
||||
} |
||||
|
||||
|
||||
export async function filterChildrenRead(req: Request, res: Response) { |
||||
res.json( |
||||
new PagedResponseImpl( |
||||
await filterService.filterChildrenList({ |
||||
filterId: req.params.filterParentId, |
||||
}) |
||||
) |
||||
); |
||||
} |
||||
|
||||
export async function filterCreate(req: Request<any, any, FilterReqType>, res) { |
||||
const filter = await filterService.filterCreate({ |
||||
filter: req.body, |
||||
viewId: req.params.viewId, |
||||
}); |
||||
res.json(filter); |
||||
} |
||||
|
||||
export async function filterUpdate(req, res) { |
||||
const filter = await filterService.filterUpdate({ |
||||
filterId: req.params.filterId, |
||||
filter: req.body, |
||||
}); |
||||
res.json(filter); |
||||
} |
||||
|
||||
export async function filterDelete(req: Request, res: Response) { |
||||
const filter = await filterService.filterDelete({ |
||||
filterId: req.params.filterId, |
||||
}); |
||||
res.json(filter); |
||||
} |
||||
|
||||
export async function hookFilterList(req: Request, res: Response) { |
||||
res.json( |
||||
new PagedResponseImpl( |
||||
await filterService.hookFilterList({ |
||||
hookId: req.params.hookId, |
||||
}) |
||||
) |
||||
); |
||||
} |
||||
|
||||
export async function hookFilterCreate( |
||||
req: Request<any, any, FilterReqType>, |
||||
res |
||||
) { |
||||
const filter = await filterService.hookFilterCreate({ |
||||
filter: req.body, |
||||
hookId: req.params.hookId, |
||||
}); |
||||
res.json(filter); |
||||
} |
||||
|
||||
const router = Router({ mergeParams: true }); |
||||
|
||||
router.post( |
||||
'/api/v1/db/meta/views/:viewId/filters', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(filterCreate, 'filterCreate') |
||||
); |
||||
|
||||
router.get( |
||||
'/api/v1/db/meta/hooks/:hookId/filters', |
||||
ncMetaAclMw(hookFilterList, 'filterList') |
||||
); |
||||
router.post( |
||||
'/api/v1/db/meta/hooks/:hookId/filters', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(hookFilterCreate, 'filterCreate') |
||||
); |
||||
|
||||
router.get( |
||||
'/api/v1/db/meta/filters/:filterId', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(filterGet, 'filterGet') |
||||
); |
||||
router.patch( |
||||
'/api/v1/db/meta/filters/:filterId', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(filterUpdate, 'filterUpdate') |
||||
); |
||||
router.delete( |
||||
'/api/v1/db/meta/filters/:filterId', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(filterDelete, 'filterDelete') |
||||
); |
||||
router.get( |
||||
'/api/v1/db/meta/filters/:filterParentId/children', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(filterChildrenRead, 'filterChildrenRead') |
||||
); |
||||
export default router; |
||||
* */ |
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common'; |
||||
import { FiltersService } from './filters.service'; |
||||
import { FiltersController } from './filters.controller'; |
||||
|
||||
@Module({ |
||||
controllers: [FiltersController], |
||||
providers: [FiltersService] |
||||
}) |
||||
export class FiltersModule {} |
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { FiltersService } from './filters.service'; |
||||
|
||||
describe('FiltersService', () => { |
||||
let service: FiltersService; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
providers: [FiltersService], |
||||
}).compile(); |
||||
|
||||
service = module.get<FiltersService>(FiltersService); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(service).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,69 @@
|
||||
import { Injectable } from '@nestjs/common'; |
||||
import { FilterReqType } from 'nocodb-sdk'; |
||||
import { validatePayload } from '../../helpers'; |
||||
import { Filter } from '../../models'; |
||||
import { T } from 'nc-help'; |
||||
|
||||
@Injectable() |
||||
export class FiltersService { |
||||
async hookFilterCreate(param: { filter: FilterReqType; hookId: any }) { |
||||
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); |
||||
|
||||
const filter = await Filter.insert({ |
||||
...param.filter, |
||||
fk_hook_id: param.hookId, |
||||
}); |
||||
|
||||
T.emit('evt', { evt_type: 'hookFilter:created' }); |
||||
return filter; |
||||
} |
||||
|
||||
async hookFilterList(param: { hookId: any }) { |
||||
return Filter.rootFilterListByHook({ hookId: param.hookId }); |
||||
} |
||||
|
||||
async filterDelete(param: { filterId: string }) { |
||||
await Filter.delete(param.filterId); |
||||
T.emit('evt', { evt_type: 'filter:deleted' }); |
||||
return true; |
||||
} |
||||
|
||||
async filterCreate(param: { filter: FilterReqType; viewId: string }) { |
||||
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); |
||||
|
||||
const filter = await Filter.insert({ |
||||
...param.filter, |
||||
fk_view_id: param.viewId, |
||||
}); |
||||
|
||||
T.emit('evt', { evt_type: 'filter:created' }); |
||||
|
||||
return filter; |
||||
} |
||||
async filterUpdate(param: { filter: FilterReqType; filterId: string }) { |
||||
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); |
||||
|
||||
// todo: type correction
|
||||
const filter = await Filter.update(param.filterId, param.filter as Filter); |
||||
|
||||
T.emit('evt', { evt_type: 'filter:updated' }); |
||||
|
||||
return filter; |
||||
} |
||||
|
||||
async filterChildrenList(param: { filterId: any }) { |
||||
return Filter.parentFilterList({ |
||||
parentId: param.filterId, |
||||
}); |
||||
} |
||||
|
||||
async filterGet(param: { filterId: string }) { |
||||
const filter = await Filter.get(param.filterId); |
||||
return filter; |
||||
} |
||||
|
||||
async filterList(param: { viewId: string }) { |
||||
const filter = await Filter.rootFilterList({ viewId: param.viewId }); |
||||
return filter; |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { SortsController } from './sorts.controller'; |
||||
import { SortsService } from './sorts.service'; |
||||
|
||||
describe('SortsController', () => { |
||||
let controller: SortsController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [SortsController], |
||||
providers: [SortsService], |
||||
}).compile(); |
||||
|
||||
controller = module.get<SortsController>(SortsController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,79 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common'; |
||||
import { PagedResponseImpl } from '../../helpers/PagedResponse'; |
||||
import { SortsService } from './sorts.service'; |
||||
|
||||
@Controller('sorts') |
||||
export class SortsController { |
||||
constructor(private readonly sortsService: SortsService) {} |
||||
|
||||
@Get('/api/v1/db/meta/views/:viewId/sorts/') |
||||
async sortList(@Param('viewId') viewId: string) { |
||||
return; |
||||
new PagedResponseImpl( |
||||
await this.sortsService.sortList({ |
||||
viewId, |
||||
}), |
||||
); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
|
||||
|
||||
export async function sortCreate(req: Request<any, any, SortReqType>, res) { |
||||
const sort = await sortService.sortCreate({ |
||||
sort: req.body, |
||||
viewId: req.params.viewId, |
||||
}); |
||||
res.json(sort); |
||||
} |
||||
|
||||
export async function sortUpdate(req, res) { |
||||
const sort = await sortService.sortUpdate({ |
||||
sortId: req.params.sortId, |
||||
sort: req.body, |
||||
}); |
||||
res.json(sort); |
||||
} |
||||
|
||||
export async function sortDelete(req: Request, res: Response) { |
||||
const sort = await sortService.sortDelete({ |
||||
sortId: req.params.sortId, |
||||
}); |
||||
res.json(sort); |
||||
} |
||||
|
||||
export async function sortGet(req: Request, res: Response) { |
||||
const sort = await sortService.sortGet({ |
||||
sortId: req.params.sortId, |
||||
}); |
||||
res.json(sort); |
||||
} |
||||
|
||||
const router = Router({ mergeParams: true }); |
||||
|
||||
router.post( |
||||
'/api/v1/db/meta/views/:viewId/sorts/', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(sortCreate, 'sortCreate') |
||||
); |
||||
|
||||
router.get( |
||||
'/api/v1/db/meta/sorts/:sortId', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(sortGet, 'sortGet') |
||||
); |
||||
|
||||
router.patch( |
||||
'/api/v1/db/meta/sorts/:sortId', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(sortUpdate, 'sortUpdate') |
||||
); |
||||
router.delete( |
||||
'/api/v1/db/meta/sorts/:sortId', |
||||
metaApiMetrics, |
||||
ncMetaAclMw(sortDelete, 'sortDelete') |
||||
); |
||||
export default router; |
||||
|
||||
* */ |
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common'; |
||||
import { SortsService } from './sorts.service'; |
||||
import { SortsController } from './sorts.controller'; |
||||
|
||||
@Module({ |
||||
controllers: [SortsController], |
||||
providers: [SortsService] |
||||
}) |
||||
export class SortsModule {} |
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { SortsService } from './sorts.service'; |
||||
|
||||
describe('SortsService', () => { |
||||
let service: SortsService; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
providers: [SortsService], |
||||
}).compile(); |
||||
|
||||
service = module.get<SortsService>(SortsService); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(service).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,41 @@
|
||||
import { Injectable } from '@nestjs/common'; |
||||
import { SortReqType } from 'nocodb-sdk'; |
||||
import { validatePayload } from '../../helpers'; |
||||
import { Sort } from '../../models'; |
||||
import { T } from 'nc-help'; |
||||
|
||||
@Injectable() |
||||
export class SortsService { |
||||
async sortGet(param: { sortId: string }) { |
||||
return Sort.get(param.sortId); |
||||
} |
||||
|
||||
async sortDelete(param: { sortId: string }) { |
||||
await Sort.delete(param.sortId); |
||||
T.emit('evt', { evt_type: 'sort:deleted' }); |
||||
return true; |
||||
} |
||||
|
||||
async sortUpdate(param: { sortId: any; sort: SortReqType }) { |
||||
validatePayload('swagger.json#/components/schemas/SortReq', param.sort); |
||||
|
||||
const sort = await Sort.update(param.sortId, param.sort); |
||||
T.emit('evt', { evt_type: 'sort:updated' }); |
||||
return sort; |
||||
} |
||||
|
||||
async sortCreate(param: { viewId: any; sort: SortReqType }) { |
||||
validatePayload('swagger.json#/components/schemas/SortReq', param.sort); |
||||
|
||||
const sort = await Sort.insert({ |
||||
...param.sort, |
||||
fk_view_id: param.viewId, |
||||
} as Sort); |
||||
T.emit('evt', { evt_type: 'sort:created' }); |
||||
return sort; |
||||
} |
||||
|
||||
async sortList(param: { viewId: string }) { |
||||
return Sort.list({ viewId: param.viewId }); |
||||
} |
||||
} |
Loading…
Reference in new issue