simplesearch now accepts empty querystring correctly
This commit is contained in:
@@ -4,6 +4,7 @@ import UpdateEmployeeValidator from 'App/Validators/UpdateEmployeeValidator'
|
|||||||
import CreateEmployeeValidator from 'App/Validators/CreateEmployeeValidator'
|
import CreateEmployeeValidator from 'App/Validators/CreateEmployeeValidator'
|
||||||
|
|
||||||
import Database from '@ioc:Adonis/Lucid/Database'
|
import Database from '@ioc:Adonis/Lucid/Database'
|
||||||
|
import Logger from '@ioc:Adonis/Core/Logger'
|
||||||
|
|
||||||
type ResultShow = {
|
type ResultShow = {
|
||||||
id: number,
|
id: number,
|
||||||
@@ -34,7 +35,7 @@ export default class EmployeesController {
|
|||||||
employees.from('employees')
|
employees.from('employees')
|
||||||
employees.select(select)
|
employees.select(select)
|
||||||
|
|
||||||
if(simpleSearch) {
|
if(simpleSearch && simpleSearch.query !== '') {
|
||||||
simpleSearch.columns.forEach(column => {
|
simpleSearch.columns.forEach(column => {
|
||||||
employees.orWhere(column, 'like', `%${simpleSearch.query}%`)
|
employees.orWhere(column, 'like', `%${simpleSearch.query}%`)
|
||||||
})
|
})
|
||||||
@@ -158,7 +159,7 @@ export default class EmployeesController {
|
|||||||
private async simpleSearch(qs : string): Promise<{query: string, columns: string[]} | false>{
|
private async simpleSearch(qs : string): Promise<{query: string, columns: string[]} | false>{
|
||||||
if (!qs) return false
|
if (!qs) return false
|
||||||
|
|
||||||
const regex = /([\w@.]+)(?:\((\w+(?:,\w+)*)\))*/i
|
const regex = /([\w@.]*)(?:\((\w+(?:,\w+)*)\))*/i
|
||||||
const columns = await Database.connection().columnsInfo('employees')
|
const columns = await Database.connection().columnsInfo('employees')
|
||||||
|
|
||||||
const match = qs.match(regex) ?? []
|
const match = qs.match(regex) ?? []
|
||||||
|
|||||||
Reference in New Issue
Block a user