EmployeesController.index now support selection of specific rows and never tranfers the password(hash)!
This commit is contained in:
@@ -25,12 +25,14 @@ export default class EmployeesController {
|
||||
|
||||
const limit: number = request.qs().limit ?? 10
|
||||
const page: number = request.qs().page ?? 1
|
||||
const select: string[] = await this.select(request.qs().select ?? '')
|
||||
const sortBy = await this.sortBy(request.qs().sort_by)
|
||||
|
||||
const simpleSearch = await this.simpleSearch(request.qs().simple_search)
|
||||
|
||||
const employees = Database.query()
|
||||
employees.from('employees')
|
||||
employees.select(select)
|
||||
|
||||
if(simpleSearch) {
|
||||
simpleSearch.columns.forEach(column => {
|
||||
@@ -177,4 +179,14 @@ export default class EmployeesController {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private async select(qs: string): Promise<string[]> {
|
||||
const columns = await Database.connection().columnsInfo('employees')
|
||||
|
||||
let arr = qs.split(',').filter(item => item !== 'password' && item !== '' && columns.hasOwnProperty(item))
|
||||
|
||||
if(arr.length === 0) arr = ['id', 'last_name', 'first_name', 'email', 'mobile', 'phone', 'role']
|
||||
|
||||
return arr
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,11 @@ const corsConfig: CorsConfig = {
|
||||
| one of the above values.
|
||||
|
|
||||
*/
|
||||
origin: 'http://localhost:3000',
|
||||
origin:
|
||||
[
|
||||
'http://localhost:3000',
|
||||
'http://localhost:5000'
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user