Browse Source

wip

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
f2c0b77875
  1. 27
      packages/nocodb/src/controllers/calendars.controller.ts
  2. 5
      packages/nocodb/src/helpers/getAst.ts
  3. 42
      packages/nocodb/src/services/calendars.service.ts
  4. 39
      packages/nocodb/src/services/datas.service.ts

27
packages/nocodb/src/controllers/calendars.controller.ts

@ -1,19 +1,8 @@
import {
Body,
Controller,
Get,
HttpCode,
Param,
Patch,
Post,
Req,
UseGuards,
} from '@nestjs/common';
import { Body, Controller, Get, HttpCode, Param, Patch, Post, Req, UseGuards } from '@nestjs/common';
import { Request } from 'express';
import { ViewCreateReqType } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { CalendarsService } from '~/services/calendars.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
@Controller()
@ -25,7 +14,7 @@ export class CalendarsController {
'/api/v1/db/meta/calendars/:calendarViewId',
'/api/v2/meta/calendars/:calendarViewId',
])
@Acl('calendarViewGet')
// @Acl('calendarViewGet')
async calendarViewGet(@Param('calendarViewId') calendarViewId: string) {
return await this.calendarsService.calendarViewGet({
calendarViewId,
@ -37,7 +26,7 @@ export class CalendarsController {
'/api/v2/meta/tables/:tableId/calendars',
])
@HttpCode(200)
@Acl('calendarViewCreate')
// @Acl('calendarViewCreate')
async calendarViewCreate(
@Param('tableId') tableId: string,
@Body() body: ViewCreateReqType,
@ -60,7 +49,6 @@ export class CalendarsController {
async calendarViewUpdate(
@Param('calendarViewId') calendarViewId: string,
@Body() body,
@Req() req: Request,
) {
return await this.calendarsService.calendarViewUpdate({
@ -69,4 +57,13 @@ export class CalendarsController {
req,
});
}
@Get('/api/v1/db/data/calendars/:calendarViewId/count')
async calendarRecordCountGet(@Param('calendarViewId') calendarViewId: string, @Req() req: Request) {
return await this.calendarsService.calendarRecordCountGet({
calendarViewId,
req
});
}
}

5
packages/nocodb/src/helpers/getAst.ts

@ -13,7 +13,7 @@ import type {
Model,
} from '~/models';
import { NcError } from '~/helpers/catchError';
import { GalleryView, KanbanView, View } from '~/models';
import { CalendarView, GalleryView, KanbanView, View } from '~/models';
const getAst = async ({
query,
@ -49,6 +49,9 @@ const getAst = async ({
} else if (view && view.type === ViewTypes.KANBAN) {
const kanban = await KanbanView.get(view.id);
coverImageId = kanban.fk_cover_image_col_id;
} else if (view && view.type === ViewTypes.CALENDAR) {
const calendar = await CalendarView.get(view.id);
coverImageId = calendar.fk_cover_image_col_id;
}
if (!model.columns?.length) await model.getColumns();

42
packages/nocodb/src/services/calendars.service.ts

@ -1,16 +1,14 @@
import { Injectable } from '@nestjs/common';
import type { CalendarUpdateReqType, UserType, ViewCreateReqType } from 'nocodb-sdk';
import { AppEvents, ViewTypes } from 'nocodb-sdk';
import type {
CalendarUpdateReqType,
UserType,
ViewCreateReqType,
} from 'nocodb-sdk';
import type { NcRequest } from '~/interface/config';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError';
import { CalendarView, View } from '~/models';
import CalendarRange from '~/models/CalendarRange';
import { Model, Source } from '~/ee/models';
import NcConnectionMgrv2 from '~/ee/utils/common/NcConnectionMgrv2';
@Injectable()
export class CalendarsService {
@ -24,7 +22,7 @@ export class CalendarsService {
const calendarRanges = await CalendarRange.read(param.calendarViewId);
return {
...calendarView,
calendar_range: calendarRanges,
calendar_range: calendarRanges.ranges,
};
}
@ -83,4 +81,36 @@ export class CalendarsService {
return res;
}
async calendarRecordCountGet(param: {
calendarViewId: string;
req: any
}) {
const { query } = param.req;
console.log('query', query)
const view = await View.get(param.calendarViewId);
if (!view) {
NcError.badRequest('View not found');
}
const source = await Source.get(view.source_id);
const baseModel = await Model.getBaseModelSQL({
id: view.fk_model_id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(source),
});
const data = await baseModel.groupByAndAggregate(
'Date',
'count',
{
groupByColumnName: 'Date',
},
);
console.log(data);
return data;
}
}

39
packages/nocodb/src/services/datas.service.ts

@ -966,4 +966,43 @@ export class DatasService {
return column;
}
async getDataAggregateBy(param: {
viewId: string;
query?: any;
aggregateColumnName: string;
aggregateFunction: string;
groupByColumnName?: string;
ignoreFilters?: boolean;
sort?: {
column_name: string;
direction: 'asc' | 'desc';
};
}) {
const {viewId, query = {} } = param;
const view = await View.get(viewId)
const source = await Source.get(view.source_id);
const baseModel = await Model.getBaseModelSQL({
id: view.fk_model_id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(source),
});
const data = await baseModel.groupByAndAggregate(
param.aggregateColumnName,
param.aggregateFunction,
{
groupByColumnName: param.groupByColumnName,
sortBy: param.sort,
...query,
},
);
return new PagedResponseImpl(data, {
...query,
});
}
}

Loading…
Cancel
Save