EmployeesController.index now support selection of specific rows and never tranfers the password(hash)!

This commit is contained in:
Sockenklaus
2021-11-07 02:21:48 +01:00
parent b0f695d253
commit 9c8f96783b
2 changed files with 17 additions and 1 deletions

View File

@@ -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
}
}

View File

@@ -44,7 +44,11 @@ const corsConfig: CorsConfig = {
| one of the above values.
|
*/
origin: 'http://localhost:3000',
origin:
[
'http://localhost:3000',
'http://localhost:5000'
],
/*
|--------------------------------------------------------------------------