-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
Use it on the search option (typeahead)
Some tips, the server action (review is just rough code):
front/src/pods/embalse-search/embalse-search.repository.ts
"use server";
import { getDb } from "@/lib/mongodb";
import type { Embalse } from "./api/api.model";
export async function getEmbalsesFromDb(): Promise<Embalse[]> {
const db = getDb();
const docs = await db
.collection("embalses")
.find({}, { projection: { _id: 1, nombre: 1, slug: 1, provincia: 1 } })
.toArray();
return docs.map((doc) => ({
_id: doc.slug ?? "",
name: doc.nombre ?? "",
province: doc.provincia ?? "",
}));
}And in the embalse.api.ts
import { Embalse } from "./api.model";
import { getEmbalsesFromDb } from "../embalse-search.repository";
export const getEmbalsesCollection = async (): Promise<Embalse[]> => {
return getEmbalsesFromDb();
};Reactions are currently unavailable