Skip to content

Commit f246de9

Browse files
authored
Merge pull request #520 from impresso/develop
Release v3.1.2
2 parents c674d68 + 4094cf3 commit f246de9

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/services/images/images-v1.hooks.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
import { HookContext } from '@feathersjs/feathers'
1212
import { ImpressoApplication } from '../../types'
1313
import { Image } from '../../models/generated/schemas'
14+
import { protobuf } from 'impresso-jscommons'
15+
import { BadRequest } from '@feathersjs/errors'
1416

1517
// const { authenticate } = require('@feathersjs/authentication').hooks;
1618
const {
@@ -63,7 +65,6 @@ const updateIiifUrls = (context: HookContext<ImpressoApplication>) => {
6365
})
6466
})
6567
})
66-
console.log(context.result.data)
6768
}
6869
}
6970

@@ -111,17 +112,36 @@ const convertItemToNewImageFormat = (context: HookContext<ImpressoApplication>)
111112
context.result = newResult
112113
}
113114

115+
const deserializeFilters = (serializedFilters: string) => {
116+
if (serializedFilters == null) return []
117+
try {
118+
return protobuf.searchQuery.deserialize(serializedFilters).filters || []
119+
} catch (error) {
120+
throw new BadRequest(`Could not deserialize filters: ${(error as Error).message}`)
121+
}
122+
}
123+
124+
// parse filters
125+
const parseFiltersHook = (context: HookContext<ImpressoApplication>) => {
126+
const { filters } = context.params?.query ?? {}
127+
context.params.query.filters = deserializeFilters(filters)
128+
console.log('ooo', context.params.query.filters)
129+
}
130+
131+
const parseQ = (context: HookContext<ImpressoApplication>) => {
132+
if (context?.params?.query?.term) {
133+
context.params.query.q = context.params.query.term
134+
}
135+
}
136+
114137
export default {
115138
before: {
116139
all: [
117140
// authenticate('jwt')
118141
],
119142
find: [
120-
(context: HookContext<ImpressoApplication>) => {
121-
if (context?.params?.query?.term) {
122-
context.params.query.q = context.params.query.term
123-
}
124-
},
143+
parseFiltersHook,
144+
parseQ,
125145
validate({
126146
order_by: utils.orderBy({
127147
values: {

0 commit comments

Comments
 (0)