Remove tableid from remove view url

This commit is contained in:
Adria Navarro 2023-07-19 18:02:15 +02:00
parent fc831db06b
commit 36b82681ff
7 changed files with 19 additions and 14 deletions

View File

@ -70,7 +70,6 @@ export enum DocumentType {
USER_FLAG = "flag", USER_FLAG = "flag",
AUTOMATION_METADATA = "meta_au", AUTOMATION_METADATA = "meta_au",
AUDIT_LOG = "al", AUDIT_LOG = "al",
VIEW = "vi",
} }
export const StaticDatabases = { export const StaticDatabases = {

View File

@ -13,8 +13,8 @@ export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
} }
export async function remove(ctx: Ctx) { export async function remove(ctx: Ctx) {
const { tableId, viewId } = ctx.params const { viewId } = ctx.params
await sdk.views.remove(tableId, viewId) await sdk.views.remove(viewId)
ctx.status = 204 ctx.status = 204
} }

View File

@ -60,7 +60,7 @@ describe("/v2/views", () => {
expect(res).toEqual({ expect(res).toEqual({
...newView, ...newView,
id: expect.stringMatching(new RegExp(`^vi_${config.table?._id!}_`)), id: expect.stringMatching(new RegExp(`${config.table?._id!}_`)),
version: 2, version: 2,
}) })
}) })
@ -97,7 +97,7 @@ describe("/v2/views", () => {
expect(await getPersistedView()).toBeDefined() expect(await getPersistedView()).toBeDefined()
await config.api.viewV2.delete(tableId, view.id) await config.api.viewV2.delete(view.id)
expect(await getPersistedView()).toBeUndefined() expect(await getPersistedView()).toBeUndefined()
}) })

View File

@ -14,7 +14,7 @@ router
viewController.v2.create viewController.v2.create
) )
.delete( .delete(
`/api/v2/views/:tableId/:viewId`, `/api/v2/views/:viewId`,
authorized(permissions.BUILDER), authorized(permissions.BUILDER),
viewController.v2.remove viewController.v2.remove
) )

View File

@ -277,5 +277,13 @@ export function getMultiIDParams(ids: string[]) {
* @returns {string} The new view ID which the view doc can be stored under. * @returns {string} The new view ID which the view doc can be stored under.
*/ */
export function generateViewID(tableId: string) { export function generateViewID(tableId: string) {
return `${DocumentType.VIEW}${SEPARATOR}${tableId}${SEPARATOR}${newid()}` return `${tableId}${SEPARATOR}${newid()}`
}
export function extractViewInfoFromId(viewId: string) {
const regex = new RegExp(`^(?<tableId>.+)${SEPARATOR}([^${SEPARATOR}]+)$`)
const res = regex.exec(viewId)
return {
tableId: res!.groups!["tableId"],
}
} }

View File

@ -38,9 +38,11 @@ export function isV2(view: View | ViewV2): view is ViewV2 {
return (view as ViewV2).version === 2 return (view as ViewV2).version === 2
} }
export async function remove(tableId: string, viewId: string): Promise<void> { export async function remove( viewId: string): Promise<void> {
const db = context.getAppDB() const db = context.getAppDB()
const {tableId}=utils.extractViewInfoFromId(viewId)
const table = await sdk.tables.getTable(tableId) const table = await sdk.tables.getTable(tableId)
const view = await get(tableId, viewId) const view = await get(tableId, viewId)
if (!view) { if (!view) {

View File

@ -31,13 +31,9 @@ export class ViewV2API extends TestAPI {
return result.body.data as ViewV2 return result.body.data as ViewV2
} }
delete = async ( delete = async (viewId: string, { expectStatus } = { expectStatus: 204 }) => {
tableId: string,
viewId: string,
{ expectStatus } = { expectStatus: 204 }
) => {
return this.request return this.request
.delete(`/api/v2/views/${tableId}/${viewId}`) .delete(`/api/v2/views/${viewId}`)
.set(this.config.defaultHeaders()) .set(this.config.defaultHeaders())
.expect(expectStatus) .expect(expectStatus)
} }