feat: add user search functionality

- Implemented `GET /users/search` endpoint in the backend to enable user search by username or display name.
- Added `search` method in `UsersService` and `UsersRepository`.
- Updated frontend `UserService` to support the new search API.
This commit is contained in:
Mathis HERRIOT
2026-01-29 15:47:03 +01:00
parent 2c18fd1c1a
commit f852835c59
4 changed files with 39 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
import { Injectable } from "@nestjs/common";
import { and, eq, lte, sql } from "drizzle-orm";
import { and, count, eq, ilike, or, sql } from "drizzle-orm";
import { DatabaseService } from "../../database/database.service";
import { contents, favorites, users } from "../../database/schemas";
@@ -97,6 +97,21 @@ export class UsersRepository {
return result[0] || null;
}
async search(query: string) {
return this.databaseService.db
.select({
uuid: users.uuid,
username: users.username,
displayName: users.displayName,
avatarUrl: users.avatarUrl,
})
.from(users)
.where(
or(ilike(users.username, `%${query}%`), ilike(users.displayName, `%${query}%`)),
)
.limit(10);
}
async findOne(uuid: string) {
const result = await this.databaseService.db
.select()