@jcbuisson/express-x 1.0.22 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.mjs +24 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "1.0.22",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/index.mjs CHANGED
@@ -170,8 +170,31 @@ function expressX(app, options={}) {
170
170
 
171
171
  app.get(path, async (req, res) => {
172
172
  context.http.req = req
173
+ const query = { ...req.query }
174
+ for (const fieldName in query) {
175
+ const fieldInfo = await service.prisma.$queryRawUnsafe(`
176
+ SELECT column_name, data_type
177
+ FROM information_schema.columns
178
+ WHERE table_name = '${service.entity}' AND column_name = '${fieldName}';
179
+ `)
180
+ const fieldType = fieldInfo[0].data_type
181
+ if (fieldType === 'integer') {
182
+ query[fieldName] = parseInt(query[fieldName])
183
+ } else if (fieldType === 'numeric') {
184
+ query[fieldName] = parseFloat(query[fieldName])
185
+ } else if (fieldType === 'boolean') {
186
+ query[fieldName] = (query[fieldName] === 't') ? true : false
187
+ } else if (fieldType === 'text' || fieldType === 'character varying') {
188
+ query[fieldName] = query[fieldName]
189
+ } else {
190
+ // ?
191
+ query[fieldName] = query[fieldName]
192
+ }
193
+ }
173
194
  try {
174
- const values = await service.__find(context, req.body)
195
+ const values = await service.__find(context, {
196
+ where: query,
197
+ })
175
198
  res.json(values)
176
199
  } catch(err) {
177
200
  console.log('callErr', err)