mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 14:43:24 +00:00
feat: add a search modal using the database (wip)
This commit is contained in:
17
app/controllers/searches_controller.ts
Normal file
17
app/controllers/searches_controller.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { HttpContext } from '@adonisjs/core/http';
|
||||
import db from '@adonisjs/lucid/services/db';
|
||||
|
||||
export default class SearchesController {
|
||||
async search({ request, auth }: HttpContext) {
|
||||
const term = request.qs()?.term;
|
||||
if (!term) {
|
||||
return console.warn('qs term null');
|
||||
}
|
||||
|
||||
const { rows } = await db.rawQuery('SELECT * FROM search_text(?, ?)', [
|
||||
term,
|
||||
auth.user!.id,
|
||||
]);
|
||||
return { results: rows };
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import vine from '@vinejs/vine';
|
||||
|
||||
export const searchValidator = vine.compile(
|
||||
vine.object({
|
||||
searchTerm: vine.string().trim().minLength(1).maxLength(254),
|
||||
links: vine.boolean(),
|
||||
collections: vine.boolean(),
|
||||
})
|
||||
);
|
||||
Reference in New Issue
Block a user