Arno Kaimbacher
e0ff71b117
All checks were successful
CI Pipeline / japa-tests (push) Successful in 47s
- additional validation rules like 'uniqueArray' - additional Lucid models like BaseModel.ts for filling attributes, Title.ts, Description.ts - npm updates for @adonisjs/core
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
|
import Person from 'App/Models/Person';
|
|
// import Dataset from 'App/Models/Dataset';
|
|
|
|
// node ace make:controller Author
|
|
export default class AuthorsController {
|
|
public async index({}: HttpContextContract) {
|
|
// select * from gba.persons
|
|
// where exists (select * from gba.documents inner join gba.link_documents_persons on "documents"."id" = "link_documents_persons"."document_id"
|
|
// where ("link_documents_persons"."role" = 'author') and ("persons"."id" = "link_documents_persons"."person_id"));
|
|
const authors = await Person.query()
|
|
.whereHas('datasets', (dQuery) => {
|
|
dQuery.wherePivot('role', 'author');
|
|
})
|
|
.withCount('datasets', (query) => {
|
|
query.as('datasets_count');
|
|
});
|
|
|
|
return authors;
|
|
}
|
|
|
|
public async persons({ request }: HttpContextContract) {
|
|
const authors = Person.query().where('status', true);
|
|
|
|
if (request.input('filter')) {
|
|
// users = users.whereRaw('name like %?%', [request.input('search')])
|
|
const searchTerm = request.input('filter');
|
|
authors.whereILike('first_name', `%${searchTerm}%`).orWhereILike('last_name', `%${searchTerm}%`);
|
|
// .orWhere('email', 'like', `%${searchTerm}%`);
|
|
}
|
|
|
|
let persons = await authors;
|
|
return persons;
|
|
}
|
|
}
|