Skip to content

Commit cfedde9

Browse files
committed
chore: show correct err msg for deleted tileh
1 parent 06aa505 commit cfedde9

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

packages/backend/src/apps/tiles/__tests__/actions/create-row.itest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,14 @@ describe('tiles create row action', () => {
8383
$.user = viewer
8484
await expect(createRowAction.run($)).rejects.toThrow(StepError)
8585
})
86+
87+
it('should throw correct error if Tile deleted', async () => {
88+
$.user = editor
89+
await TableMetadata.query()
90+
.patch({
91+
deletedAt: new Date().toISOString(),
92+
})
93+
.where({ id: $.step.parameters.tableId })
94+
await expect(createRowAction.run($)).rejects.toThrow(StepError)
95+
})
8696
})

packages/backend/src/apps/tiles/actions/create-row/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ const action: IRawAction = {
9797
await TableCollaborator.hasAccess($.user?.id, tableId, 'editor', $)
9898

9999
const table = await TableMetadata.query().findById(tableId)
100+
if (!table) {
101+
throw new StepError(
102+
'Tile not found',
103+
'Tile may have been deleted. Please check your tile.',
104+
$.step.position,
105+
'tiles',
106+
)
107+
}
100108

101109
/**
102110
* convert array to object

packages/backend/src/apps/tiles/dynamic-data/list-columns.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ const dynamicData: IDynamicData = {
2626
.$relatedQuery('tables')
2727
.findById($.step.parameters.tableId as string)
2828
.whereIn('role', ['owner', 'editor'])
29-
.throwIfNotFound()
29+
.throwIfNotFound({
30+
message: 'Tile may have been deleted. Please check your tile.',
31+
})
3032
const columns = await tile
3133
.$relatedQuery('columns')
3234
.orderBy('position', 'asc')
@@ -38,14 +40,17 @@ const dynamicData: IDynamicData = {
3840
name: name,
3941
})),
4042
}
41-
} catch (e) {
42-
logger.error('Tiles dynamic data: list columns error', {
43-
userId: $.user?.id,
44-
tableId: $.step.parameters.tableId,
45-
flowId: $.flow?.id,
46-
stepId: $.step?.id,
47-
})
48-
throw new Error('Unable to fetch columns')
43+
} catch (err) {
44+
logger.error(
45+
err.data.message ?? 'Tiles dynamic data: list columns error',
46+
{
47+
userId: $.user?.id,
48+
tableId: $.step.parameters.tableId,
49+
flowId: $.flow?.id,
50+
stepId: $.step?.id,
51+
},
52+
)
53+
throw new Error(err.data.message ?? 'Unable to fetch columns')
4954
}
5055
},
5156
}

packages/backend/src/graphql/__tests__/mutations/tiles/delete-table.itest.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it } from 'vitest'
33

44
import { ForbiddenError } from '@/errors/graphql-errors'
55
import deleteTable from '@/graphql/mutations/tiles/delete-table'
6+
import TableCollaborator from '@/models/table-collaborators'
67
import TableMetadata from '@/models/table-metadata'
78
import User from '@/models/user'
89
import Context from '@/types/express/context'
@@ -35,7 +36,7 @@ describe('delete table mutation', () => {
3536
})
3637
})
3738

38-
it('should delete table and columns', async () => {
39+
it('should delete table, columns and collaborators', async () => {
3940
const success = await deleteTable(
4041
null,
4142
{ input: { id: dummyTable.id } },
@@ -46,9 +47,13 @@ describe('delete table mutation', () => {
4647
.resultSize()
4748

4849
const deletedTable = await TableMetadata.query().findById(dummyTable.id)
50+
const tableCollaborators = await TableCollaborator.query().where({
51+
table_id: dummyTable.id,
52+
})
4953
expect(success).toBe(true)
5054
expect(deletedTable).toBeUndefined()
5155
expect(tableColumnCount).toBe(0)
56+
expect(tableCollaborators.length).toBe(0)
5257
})
5358

5459
it('should throw an error if table is not found', async () => {

packages/backend/src/graphql/mutations/tiles/delete-table.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const deleteTable: MutationResolvers['deleteTable'] = async (
2020
.throwIfNotFound()
2121

2222
await table.$relatedQuery('columns', trx).delete()
23+
await TableCollaborator.query().where({ table_id: params.input.id }).patch({
24+
deletedAt: new Date().toISOString(),
25+
})
2326
await table.$query(trx).delete()
2427
})
2528

0 commit comments

Comments
 (0)