Skip to content

Commit

Permalink
feat(app-express): pass partialFilter from body to core for data/_index
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Aug 1, 2023
1 parent fa0b961 commit 65c0a62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/app-express/api/data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const services: any = {
db,
id,
}),
index: (db: any, name: any, fields: any) =>
crocks.Async.Resolved({ ok: true, db, name, fields }),
index: (db: any, name: any, fields: any, partialFilter: any) =>
crocks.Async.Resolved({ ok: true, db, name, fields, partialFilter }),
query: (db: any, query: any) => crocks.Async.Resolved({ ok: true, db, query }),
bulkDocuments: (db: any, body: any) => crocks.Async.Resolved({ ok: true, db, results: body }),
listDocuments: (db: any, query: any) => {
Expand Down Expand Up @@ -374,7 +374,7 @@ Deno.test('data', async (t) => {
})

await t.step(
'should pass db and body name and fields to core',
'should pass db and body name fields and partialFilter to core',
async () => {
await harness
.start()
Expand All @@ -384,6 +384,7 @@ Deno.test('data', async (t) => {
body: JSON.stringify({
name: 'idx_foo',
fields: ['name'],
partialFilter: { type: 'bar' },
}),
})
.then((res) => res.json())
Expand All @@ -392,6 +393,7 @@ Deno.test('data', async (t) => {
assertEquals(body.name, 'idx_foo')
assertEquals(body.fields.length, 1)
assertEquals(body.fields[0], 'name')
assertEquals(body.partialFilter, { type: 'bar' })
})
)
.finally(async () => await harness.stop())
Expand Down
7 changes: 6 additions & 1 deletion packages/app-express/api/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export const data = (services: HyperServices) => (app: Server) => {
'/data/:db/_index',
json(),
bindCore(services),
({ data, params, body }, res) => fork(res, 201, data.index(params.db, body.name, body.fields)),
({ data, params, body }, res) =>
fork(
res,
201,
data.index(params.db, body.name, body.fields, body.partialFilter),
),
)

app.post<DbParams>(
Expand Down

0 comments on commit 65c0a62

Please sign in to comment.