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