Dont return couch fields
This commit is contained in:
parent
2035713b9c
commit
b44397d027
|
@ -21,17 +21,22 @@ export async function find(ctx: Ctx<void, RowActionsResponse>) {
|
|||
|
||||
if (!(await sdk.rowActions.docExists(table._id!))) {
|
||||
ctx.body = {
|
||||
tableId: table._id!,
|
||||
actions: {},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const actions = await sdk.rowActions.get(table._id!)
|
||||
ctx.body = {
|
||||
tableId: table._id!,
|
||||
...actions,
|
||||
const { actions } = await sdk.rowActions.get(table._id!)
|
||||
const result: RowActionsResponse = {
|
||||
actions: Object.entries(actions).reduce<Record<string, RowActionResponse>>(
|
||||
(acc, [key, action]) => ({
|
||||
...acc,
|
||||
[key]: { id: key, tableId: table._id!, ...action },
|
||||
}),
|
||||
{}
|
||||
),
|
||||
}
|
||||
ctx.body = result
|
||||
}
|
||||
|
||||
export async function create(
|
||||
|
@ -39,10 +44,9 @@ export async function create(
|
|||
) {
|
||||
const table = await getTable(ctx)
|
||||
|
||||
const createdAction = await sdk.rowActions.create(
|
||||
table._id!,
|
||||
ctx.request.body
|
||||
)
|
||||
const createdAction = await sdk.rowActions.create(table._id!, {
|
||||
name: ctx.request.body.name,
|
||||
})
|
||||
|
||||
ctx.body = {
|
||||
tableId: table._id!,
|
||||
|
@ -57,11 +61,9 @@ export async function update(
|
|||
const table = await getTable(ctx)
|
||||
const { actionId } = ctx.params
|
||||
|
||||
const actions = await sdk.rowActions.update(
|
||||
table._id!,
|
||||
actionId,
|
||||
ctx.request.body
|
||||
)
|
||||
const actions = await sdk.rowActions.update(table._id!, actionId, {
|
||||
name: ctx.request.body.name,
|
||||
})
|
||||
|
||||
ctx.body = {
|
||||
tableId: table._id!,
|
||||
|
|
|
@ -11,6 +11,8 @@ export function rowActionValidator() {
|
|||
return middleware.joiValidator.body(
|
||||
Joi.object({
|
||||
name: Joi.string().required(),
|
||||
id: Joi.optional(),
|
||||
tableId: Joi.optional(),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
|
@ -101,14 +101,13 @@ describe("/rowsActions", () => {
|
|||
})
|
||||
|
||||
expect(await config.api.rowAction.find(tableId)).toEqual({
|
||||
_id: `ra_${tableId}`,
|
||||
_rev: expect.stringMatching(/^1-\w+/),
|
||||
tableId: tableId,
|
||||
actions: {
|
||||
[res.id]: rowAction,
|
||||
[res.id]: {
|
||||
...rowAction,
|
||||
id: res.id,
|
||||
tableId: tableId,
|
||||
},
|
||||
},
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -120,16 +119,11 @@ describe("/rowsActions", () => {
|
|||
}
|
||||
|
||||
expect(await config.api.rowAction.find(tableId)).toEqual({
|
||||
_id: `ra_${tableId}`,
|
||||
_rev: expect.stringMatching(/^3-\w+/),
|
||||
actions: {
|
||||
[responses[0].id]: rowActions[0],
|
||||
[responses[1].id]: rowActions[1],
|
||||
[responses[2].id]: rowActions[2],
|
||||
[responses[0].id]: { ...rowActions[0], id: responses[0].id, tableId },
|
||||
[responses[1].id]: { ...rowActions[1], id: responses[1].id, tableId },
|
||||
[responses[2].id]: { ...rowActions[2], id: responses[2].id, tableId },
|
||||
},
|
||||
tableId: tableId,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -162,26 +156,20 @@ describe("/rowsActions", () => {
|
|||
await createRowAction(otherTable._id!, createRowActionRequest())
|
||||
|
||||
const response = await config.api.rowAction.find(tableId)
|
||||
expect(response).toEqual(
|
||||
expect.objectContaining({
|
||||
tableId,
|
||||
expect(response).toEqual({
|
||||
actions: {
|
||||
[rowActions[0].id]: expect.any(Object),
|
||||
[rowActions[1].id]: expect.any(Object),
|
||||
[rowActions[2].id]: expect.any(Object),
|
||||
},
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("returns empty for tables without row actions", async () => {
|
||||
const response = await config.api.rowAction.find(tableId)
|
||||
expect(response).toEqual(
|
||||
expect.objectContaining({
|
||||
tableId,
|
||||
expect(response).toEqual({
|
||||
actions: {},
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -209,7 +197,6 @@ describe("/rowsActions", () => {
|
|||
expect(res).toEqual({
|
||||
id: actionId,
|
||||
tableId,
|
||||
...actionData,
|
||||
name: updatedName,
|
||||
})
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
interface RowActionData {
|
||||
name: string
|
||||
}
|
||||
export interface CreateRowActionRequest extends RowActionData {}
|
||||
export interface UpdateRowActionRequest extends RowActionData {}
|
||||
|
||||
export interface RowActionResponse extends RowActionData {
|
||||
id: string
|
||||
|
@ -6,12 +10,5 @@ export interface RowActionResponse extends RowActionData {
|
|||
}
|
||||
|
||||
export interface RowActionsResponse {
|
||||
tableId: string
|
||||
actions: Record<string, RowActionData>
|
||||
actions: Record<string, RowActionResponse>
|
||||
}
|
||||
|
||||
interface RowActionData {
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface UpdateRowActionRequest extends RowActionData {}
|
||||
|
|
Loading…
Reference in New Issue