Browse Source

fix(nocodb): public data controller

pull/7716/head
DarkPhoenix2704 9 months ago
parent
commit
138b61b8be
  1. 31
      packages/nocodb/src/controllers/calendars-datas.controller.ts
  2. 265
      packages/nocodb/src/schema/swagger.json
  3. 42
      packages/nocodb/src/services/calendar-datas.service.ts

31
packages/nocodb/src/controllers/calendars-datas.controller.ts

@ -22,7 +22,6 @@ export class CalendarDatasController {
} }
@Get([ @Get([
'/api/v1/db/calendar-data/:orgs/:baseName/:tableName/countByDate/',
'/api/v1/db/calendar-data/:orgs/:baseName/:tableName/views/:viewName/countByDate/', '/api/v1/db/calendar-data/:orgs/:baseName/:tableName/views/:viewName/countByDate/',
]) ])
@Acl('dataList') @Acl('dataList')
@ -44,4 +43,34 @@ export class CalendarDatasController {
res.setHeader('xc-db-response', elapsedSeconds); res.setHeader('xc-db-response', elapsedSeconds);
res.json(data); res.json(data);
} }
@Get([
'/api/v1/db/public/calendar-view/:sharedViewUuid/countByDate',
'/api/v2/public/calendar-view/:sharedViewUuid/countByDate',
])
async countByDate(
@Req() req: Request,
@Param('sharedViewUuid') sharedViewUuid: string,
) {
return await this.calendarDatasService.getPublicCalendarRecordCount({
query: req.query,
password: req.headers?.['xc-password'] as string,
sharedViewUuid,
});
}
@Get([
'/api/v1/db/public/calendar-view/:sharedViewUuid',
'/api/v2/public/calendar-view/:sharedViewUuid',
])
async getPublicCalendarDataList(
@Req() req: Request,
@Param('sharedViewUuid') sharedViewUuid: string,
) {
return await this.calendarDatasService.getPublicCalendarDataList({
query: req.query,
password: req.headers?.['xc-password'] as string,
sharedViewUuid,
});
}
} }

265
packages/nocodb/src/schema/swagger.json

@ -9915,6 +9915,99 @@
} }
} }
}, },
"/api/v1/db/public/calendar-view/{sharedViewUuid}/countByDate": {
"parameters": [
{
"schema": {
"type": "string",
"example": "24a6d0bb-e45d-4b1a-bfef-f492d870de9f"
},
"name": "sharedViewUuid",
"in": "path",
"required": true,
"description": "Shared View UUID"
},
{
"schema": {
"type": "string"
},
"in": "header",
"name": "xc-password",
"description": "Shared view password"
}
],
"get": {
"summary": "Count of Records in Dates in Calendar View",
"operationId": "public-calendar-count",
"parameters": [
{
"schema": {
"type": "string"
},
"name": "from_date",
"in": "query",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "to_date",
"in": "query",
"required": true
},
{
"schema": {
"type": "array"
},
"in": "query",
"name": "sort"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "where"
},
{
"schema": {
"type": "integer",
"minimum": 1
},
"in": "query",
"name": "limit"
},
{
"schema": {
"type": "integer",
"minimum": 0
},
"in": "query",
"name": "offset"
},
{
"$ref": "#/components/parameters/xc-auth"
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"tags": [
"Public"
]
}
},
"/api/v1/db/data/{orgs}/{baseName}/{tableName}/views/{viewName}": { "/api/v1/db/data/{orgs}/{baseName}/{tableName}/views/{viewName}": {
"parameters": [ "parameters": [
{ {
@ -10253,101 +10346,6 @@
} }
} }
}, },
"/api/v1/db/data/{orgs}/{baseName}/{tableName}/views/{viewName}/countByDate/" : {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true,
"description": "Organisation Name. Currently `noco` will be used."
},
{
"schema": {
"type": "string"
},
"name": "baseName",
"in": "path",
"required": true,
"description": "Base Name"
},
{
"schema": {
"type": "string"
},
"name": "tableName",
"in": "path",
"required": true,
"description": "Table Name"
},
{
"schema": {
"type": "string"
},
"name": "viewName",
"in": "path",
"required": true
}
],
"get": {
"summary": "Count of Records in Dates in Calendar View",
"operationId": "db-view-row-calendar-count",
"description": "Get the count of table view rows grouped by the dates",
"tags": [
"DB View Row"
],
"parameters": [
{
"schema": {
"type": "array"
},
"in": "query",
"name": "sort"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "where"
},
{
"schema": {
"type": "integer",
"minimum": 1
},
"in": "query",
"name": "limit"
},
{
"schema": {
"type": "integer",
"minimum": 0
},
"in": "query",
"name": "offset"
},
{
"$ref": "#/components/parameters/xc-auth"
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
}
}
},
"/api/v1/db/data/{orgs}/{baseName}/{tableName}/views/{viewName}/groupby": { "/api/v1/db/data/{orgs}/{baseName}/{tableName}/views/{viewName}/groupby": {
"parameters": [ "parameters": [
{ {
@ -12317,83 +12315,6 @@
"description": "List Shared View Grouped Data" "description": "List Shared View Grouped Data"
} }
}, },
"/api/v1/db/public/shared-view/{sharedViewUuid}/countByDate": {
"parameters": [
{
"schema": {
"type": "string",
"example": "24a6d0bb-e45d-4b1a-bfef-f492d870de9f"
},
"name": "sharedViewUuid",
"in": "path",
"required": true,
"description": "Shared View UUID"
},
{
"schema": {
"type": "string"
},
"in": "header",
"name": "xc-password",
"description": "Shared view password"
}
],
"get": {
"summary": "Count of Records in Dates in Calendar View",
"operationId": "public-calendar-count",
"parameters": [
{
"schema": {
"type": "array"
},
"in": "query",
"name": "sort"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "where"
},
{
"schema": {
"type": "integer",
"minimum": 1
},
"in": "query",
"name": "limit"
},
{
"schema": {
"type": "integer",
"minimum": 0
},
"in": "query",
"name": "offset"
},
{
"$ref": "#/components/parameters/xc-auth"
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
},
"tags": [
"Public"
]
}
},
"/api/v1/db/public/shared-view/{sharedViewUuid}/rows": { "/api/v1/db/public/shared-view/{sharedViewUuid}/rows": {
"parameters": [ "parameters": [
{ {

42
packages/nocodb/src/services/calendar-datas.service.ts

@ -1,5 +1,5 @@
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { ViewTypes } from 'nocodb-sdk'; import { ErrorMessages, ViewTypes } from 'nocodb-sdk';
import { nocoExecute } from 'nc-help'; import { nocoExecute } from 'nc-help';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import type { CalendarRangeType, FilterType } from 'nocodb-sdk'; import type { CalendarRangeType, FilterType } from 'nocodb-sdk';
@ -98,6 +98,46 @@ export class CalendarDatasService {
}); });
} }
async getPublicCalendarRecordCount(param: {
password: string;
query: any;
sharedViewUuid: string;
}) {
const { sharedViewUuid, password, query = {} } = param;
const view = await View.getByUUID(sharedViewUuid);
if (!view) NcError.notFound('Not found');
if (view.type !== ViewTypes.CALENDAR) {
NcError.notFound('Not found');
}
if (view.password && view.password !== password) {
return NcError.forbidden(ErrorMessages.INVALID_SHARED_VIEW_PASSWORD);
}
return this.getCalendarRecordCount({ viewId: view.id, query });
}
async getPublicCalendarDataList(param: {
password: string;
query: any;
sharedViewUuid: string;
}) {
const { sharedViewUuid, password, query = {} } = param;
const view = await View.getByUUID(sharedViewUuid);
if (!view) NcError.notFound('Not found');
if (view.type !== ViewTypes.CALENDAR) {
NcError.notFound('Not found');
}
if (view.password && view.password !== password) {
return NcError.forbidden(ErrorMessages.INVALID_SHARED_VIEW_PASSWORD);
}
return this.getCalendarDataList({ viewId: view.id, query });
}
async getCalendarRecordCount(param: { viewId: string; query: any }) { async getCalendarRecordCount(param: { viewId: string; query: any }) {
const { viewId, query } = param; const { viewId, query } = param;
const from_date = query.from_date; const from_date = query.from_date;

Loading…
Cancel
Save