diff --git a/packages/backend-core/src/security/roles.ts b/packages/backend-core/src/security/roles.ts index 4076be93a0..2c424a4900 100644 --- a/packages/backend-core/src/security/roles.ts +++ b/packages/backend-core/src/security/roles.ts @@ -592,7 +592,10 @@ export class AccessController { ) } - async checkScreensAccess(screens: Screen[], userRoleId: string) { + async checkScreensAccess( + screens: Screen[], + userRoleId: string + ): Promise { let accessibleScreens = [] // don't want to handle this with Promise.all as this would mean all custom roles would be // retrieved at same time, it is likely a custom role will be re-used and therefore want diff --git a/packages/server/src/api/controllers/screen.ts b/packages/server/src/api/controllers/screen.ts index ee8e0ff892..cccc0c4d77 100644 --- a/packages/server/src/api/controllers/screen.ts +++ b/packages/server/src/api/controllers/screen.ts @@ -10,13 +10,16 @@ import { updateAppPackage } from "./application" import { Plugin, ScreenProps, - BBContext, Screen, UserCtx, + FetchScreenResponse, + SaveScreenRequest, + SaveScreenResponse, + DeleteScreenResponse, } from "@budibase/types" import { builderSocket } from "../../websockets" -export async function fetch(ctx: BBContext) { +export async function fetch(ctx: UserCtx) { const db = context.getAppDB() const screens = ( @@ -37,7 +40,9 @@ export async function fetch(ctx: BBContext) { ) } -export async function save(ctx: UserCtx) { +export async function save( + ctx: UserCtx +) { const db = context.getAppDB() let screen = ctx.request.body @@ -107,7 +112,7 @@ export async function save(ctx: UserCtx) { builderSocket?.emitScreenUpdate(ctx, savedScreen) } -export async function destroy(ctx: BBContext) { +export async function destroy(ctx: UserCtx) { const db = context.getAppDB() const id = ctx.params.screenId const screen = await db.get(id) diff --git a/packages/server/src/api/controllers/script.ts b/packages/server/src/api/controllers/script.ts index 0565b30f74..ac6ac24fcc 100644 --- a/packages/server/src/api/controllers/script.ts +++ b/packages/server/src/api/controllers/script.ts @@ -14,7 +14,3 @@ export async function execute(ctx: Ctx) { throw err } } - -export async function save(ctx: Ctx) { - ctx.throw(501, "Not currently implemented") -} diff --git a/packages/server/src/api/controllers/table/index.ts b/packages/server/src/api/controllers/table/index.ts index 77c1f3923a..4b020290e9 100644 --- a/packages/server/src/api/controllers/table/index.ts +++ b/packages/server/src/api/controllers/table/index.ts @@ -19,17 +19,18 @@ import { EventType, FetchTablesResponse, FieldType, - MigrateRequest, - MigrateResponse, + MigrateTableRequest, + MigrateTableResponse, SaveTableRequest, SaveTableResponse, Table, - TableResponse, + FindTableResponse, TableSourceType, UserCtx, ValidateNewTableImportRequest, ValidateTableImportRequest, ValidateTableImportResponse, + DeleteTableResponse, } from "@budibase/types" import sdk from "../../../sdk" import { jsonFromCsvString } from "../../../utilities/csv" @@ -94,7 +95,7 @@ export async function fetch(ctx: UserCtx) { ctx.body = result } -export async function find(ctx: UserCtx) { +export async function find(ctx: UserCtx) { const tableId = ctx.params.tableId const table = await sdk.tables.getTable(tableId) @@ -137,7 +138,7 @@ export async function save(ctx: UserCtx) { builderSocket?.emitTableUpdate(ctx, cloneDeep(savedTable)) } -export async function destroy(ctx: UserCtx) { +export async function destroy(ctx: UserCtx) { const appId = ctx.appId const tableId = ctx.params.tableId await sdk.rowActions.deleteAll(tableId) @@ -223,7 +224,9 @@ export async function validateExistingTableImport( } } -export async function migrate(ctx: UserCtx) { +export async function migrate( + ctx: UserCtx +) { const { oldColumn, newColumn } = ctx.request.body let tableId = ctx.params.tableId as string const table = await sdk.tables.getTable(tableId) diff --git a/packages/server/src/api/routes/script.ts b/packages/server/src/api/routes/script.ts deleted file mode 100644 index 3780142ab5..0000000000 --- a/packages/server/src/api/routes/script.ts +++ /dev/null @@ -1,10 +0,0 @@ -import Router from "@koa/router" -import * as controller from "../controllers/script" -import authorized from "../../middleware/authorized" -import { permissions } from "@budibase/backend-core" - -const router: Router = new Router() - -router.post("/api/script", authorized(permissions.BUILDER), controller.save) - -export default router diff --git a/packages/server/src/sdk/app/tables/getters.ts b/packages/server/src/sdk/app/tables/getters.ts index 79091ea660..f32150c63d 100644 --- a/packages/server/src/sdk/app/tables/getters.ts +++ b/packages/server/src/sdk/app/tables/getters.ts @@ -9,7 +9,7 @@ import { Database, INTERNAL_TABLE_SOURCE_ID, Table, - TableResponse, + FindTableResponse, TableSourceType, TableViewsResponse, } from "@budibase/types" @@ -173,7 +173,9 @@ export async function getTables(tableIds: string[]): Promise { return await processTables(tables) } -export async function enrichViewSchemas(table: Table): Promise { +export async function enrichViewSchemas( + table: Table +): Promise { const views = [] for (const view of Object.values(table.views ?? [])) { if (sdk.views.isV2(view)) { diff --git a/packages/server/src/tests/utilities/api/table.ts b/packages/server/src/tests/utilities/api/table.ts index baaf890b52..86c9002c03 100644 --- a/packages/server/src/tests/utilities/api/table.ts +++ b/packages/server/src/tests/utilities/api/table.ts @@ -3,8 +3,8 @@ import { BulkImportResponse, CsvToJsonRequest, CsvToJsonResponse, - MigrateRequest, - MigrateResponse, + MigrateTableRequest, + MigrateTableResponse, SaveTableRequest, SaveTableResponse, Table, @@ -38,13 +38,16 @@ export class TableAPI extends TestAPI { migrate = async ( tableId: string, - data: MigrateRequest, + data: MigrateTableRequest, expectations?: Expectations - ): Promise => { - return await this._post(`/api/tables/${tableId}/migrate`, { - body: data, - expectations, - }) + ): Promise => { + return await this._post( + `/api/tables/${tableId}/migrate`, + { + body: data, + expectations, + } + ) } import = async ( diff --git a/packages/types/src/api/web/app/screen.ts b/packages/types/src/api/web/app/screen.ts index fc9eb63975..372d1ba2ea 100644 --- a/packages/types/src/api/web/app/screen.ts +++ b/packages/types/src/api/web/app/screen.ts @@ -1,4 +1,4 @@ -import { ScreenRoutingJson } from "../../../documents" +import { ScreenRoutingJson, Screen } from "../../../documents" export interface FetchScreenRoutingResponse { routes: ScreenRoutingJson @@ -6,3 +6,12 @@ export interface FetchScreenRoutingResponse { export interface FetchClientScreenRoutingResponse extends FetchScreenRoutingResponse {} + +export type FetchScreenResponse = Screen[] + +export interface SaveScreenRequest extends Screen {} +export interface SaveScreenResponse extends Screen {} + +export interface DeleteScreenResponse { + message: string +} diff --git a/packages/types/src/api/web/app/table.ts b/packages/types/src/api/web/app/table.ts index bb9329f6c1..f5d0d71560 100644 --- a/packages/types/src/api/web/app/table.ts +++ b/packages/types/src/api/web/app/table.ts @@ -3,33 +3,30 @@ import { ViewV2Enriched } from "../../../sdk" export type TableViewsResponse = { [key: string]: View | ViewV2Enriched } -export interface TableResponse extends Table { +export interface FindTableResponse extends Table { views?: TableViewsResponse } -export type FetchTablesResponse = TableResponse[] +export type FetchTablesResponse = FindTableResponse[] export interface SaveTableRequest extends TableRequest { rows?: Row[] } - export type SaveTableResponse = Table export interface BulkImportRequest { rows: Row[] identifierFields?: Array } - export interface BulkImportResponse { message: string } -export interface MigrateRequest { +export interface MigrateTableRequest { oldColumn: string newColumn: string } - -export interface MigrateResponse { +export interface MigrateTableResponse { message: string } @@ -37,12 +34,10 @@ export interface ValidateNewTableImportRequest { rows: Row[] schema: TableSchema } - export interface ValidateTableImportRequest { tableId?: string rows: Row[] } - export interface ValidateTableImportResponse { schemaValidation: { [field: string]: boolean @@ -55,5 +50,8 @@ export interface ValidateTableImportResponse { export interface CsvToJsonRequest { csvString: string } - export type CsvToJsonResponse = any[] + +export interface DeleteTableResponse { + message: string +}