Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions front/src/lib/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ const globalForMongo = globalThis as typeof globalThis & {
};

//crea el cliente solo si no existe ya (singleton)
function getClient(): MongoClient {
async function getClient(): Promise<MongoClient> {
if (!globalForMongo._mongoClient) {
globalForMongo._mongoClient = new MongoClient(connectionString);
await globalForMongo._mongoClient.connect();
}

return globalForMongo._mongoClient;
}
//lo que exportamo devuelve la instancia de Db lista para hacer queries
export function getDb(): Db {
return getClient().db();
export async function getDb(): Promise<Db> {
const client = await getClient();
return client.db();
}
5 changes: 4 additions & 1 deletion front/src/pods/embalse-search/embalse-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useState, useEffect } from "react";
import { useCombobox } from "downshift";
import { useRouter } from "next/navigation";
import { SearchIcon } from "./components/search-icon";
import { Embalse, getEmbalsesCollection } from "./api";
import { EmbalseSearchModel } from "./embalse-search.model";
Expand All @@ -12,6 +13,7 @@ const mapEmbalseToSearch = (embalse: Embalse): EmbalseSearchModel => ({
});

export const EmbalseSearch: React.FC = () => {
const router = useRouter();
const [embalses, setEmbalses] = useState<Embalse[]>([]);
const [filteredEmbalses, setFilteredEmbalses] = useState<
EmbalseSearchModel[]
Expand Down Expand Up @@ -47,7 +49,8 @@ export const EmbalseSearch: React.FC = () => {
},
onSelectedItemChange: ({ selectedItem }) => {
if (selectedItem) {
console.log("Embalse seleccionado: ", selectedItem);
//console.log("Embalse seleccionado: ", selectedItem);
router.push(`/embalse/${selectedItem.slug}`);
}
},
});
Expand Down
2 changes: 1 addition & 1 deletion front/src/pods/embalse/embalse.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Embalse } from "db-model";

export async function getEmbalseBySlug(slug: string): Promise<Embalse | null> {
//conecta con BD y trae datos en base al slug
const db = getDb();
const db = await getDb();
const doc = await db.collection("embalses").findOne({ slug });

if (!doc) {
Expand Down
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"axios": "^1.10.0",
"cheerio": "^1.1.2",
"downshift": "^9.2.0",
"playwright": "^1.54.2"
}
}