Browse Source

feat: map view apis

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 1 year ago
parent
commit
772d5deb1f
  1. 3
      packages/nocodb-nest/src/app.module.ts
  2. 20
      packages/nocodb-nest/src/modules/maps/maps.controller.spec.ts
  3. 53
      packages/nocodb-nest/src/modules/maps/maps.controller.ts
  4. 9
      packages/nocodb-nest/src/modules/maps/maps.module.ts
  5. 18
      packages/nocodb-nest/src/modules/maps/maps.service.spec.ts
  6. 33
      packages/nocodb-nest/src/modules/maps/maps.service.ts

3
packages/nocodb-nest/src/app.module.ts

@ -24,9 +24,10 @@ import { KanbansModule } from './modules/kanbans/kanbans.module';
import { GalleriesModule } from './modules/galleries/galleries.module';
import { FormColumnsModule } from './modules/form-columns/form-columns.module';
import { GridColumnsModule } from './modules/grid-columns/grid-columns.module';
import { MapsModule } from './modules/maps/maps.module';
@Module({
imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule, GridsModule, KanbansModule, GalleriesModule, FormColumnsModule, GridColumnsModule],
imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule, GridsModule, KanbansModule, GalleriesModule, FormColumnsModule, GridColumnsModule, MapsModule],
controllers: [],
providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware],
exports: [Connection, MetaService],

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

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

53
packages/nocodb-nest/src/modules/maps/maps.controller.ts

@ -0,0 +1,53 @@
import {
Body,
Controller,
Get,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
import { MapUpdateReqType, ViewCreateReqType } from 'nocodb-sdk';
import {
Acl,
ExtractProjectIdMiddleware,
} from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { MapsService } from './maps.service';
import { AuthGuard } from '@nestjs/passport';
@Controller('maps')
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class MapsController {
constructor(private readonly mapsService: MapsService) {}
@Get('/api/v1/db/meta/maps/:mapViewId')
@Acl('mapViewGet')
async mapViewGet(@Param('mapViewId') mapViewId: string) {
return await this.mapsService.mapViewGet({ mapViewId });
}
@Post('/api/v1/db/meta/tables/:tableId/maps')
@Acl('mapViewCreate')
async mapViewCreate(
@Param('tableId') tableId: string,
@Body() body: ViewCreateReqType,
) {
const view = await this.mapsService.mapViewCreate({
tableId,
map: body,
});
return view;
}
@Patch('/api/v1/db/meta/maps/:mapViewId')
@Acl('mapViewUpdate')
async mapViewUpdate(
@Param('mapViewId') mapViewId: string,
@Body() body: MapUpdateReqType,
) {
return await this.mapsService.mapViewUpdate({
mapViewId: mapViewId,
map: body,
});
}
}

9
packages/nocodb-nest/src/modules/maps/maps.module.ts

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { MapsService } from './maps.service';
import { MapsController } from './maps.controller';
@Module({
controllers: [MapsController],
providers: [MapsService]
})
export class MapsModule {}

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

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

33
packages/nocodb-nest/src/modules/maps/maps.service.ts

@ -0,0 +1,33 @@
import { Injectable } from '@nestjs/common';
import { T } from 'nc-help';
import { MapUpdateReqType, ViewCreateReqType, ViewTypes } from 'nocodb-sdk';
import { validatePayload } from '../../helpers';
import { MapView, View } from '../../models';
@Injectable()
export class MapsService {
async mapViewGet(param: { mapViewId: string }) {
return await MapView.get(param.mapViewId);
}
async mapViewCreate(param: { tableId: string; map: ViewCreateReqType }) {
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
param.map,
);
const view = await View.insert({
...param.map,
// todo: sanitize
fk_model_id: param.tableId,
type: ViewTypes.MAP,
});
T.emit('evt', { evt_type: 'vtable:created', show_as: 'map' });
return view;
}
async mapViewUpdate(param: { mapViewId: string; map: MapUpdateReqType }) {
validatePayload('swagger.json#/components/schemas/MapUpdateReq', param.map);
T.emit('evt', { evt_type: 'view:updated', type: 'map' });
return await MapView.update(param.mapViewId, param.map);
}
}
Loading…
Cancel
Save