From e77b261a29d5ea89a92269e3e37ebac724740c76 Mon Sep 17 00:00:00 2001 From: Martina Date: Mon, 28 Sep 2020 21:50:11 -0700 Subject: [PATCH] fixed linking bug --- node_common/data/methods/get-slate-by-name.js | 18 ++++++++++++++++-- server.js | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/node_common/data/methods/get-slate-by-name.js b/node_common/data/methods/get-slate-by-name.js index cf26c582..daf88c97 100644 --- a/node_common/data/methods/get-slate-by-name.js +++ b/node_common/data/methods/get-slate-by-name.js @@ -1,9 +1,23 @@ import { runQuery } from "~/node_common/data/utilities"; -export default async ({ slatename, ownerId }) => { +export default async ({ slatename, ownerId, username }) => { return await runQuery({ label: "GET_SLATE_BY_NAME", queryFn: async (DB) => { + let id = ownerId; + if (username && !ownerId) { + const user = await DB.select("*") + .from("users") + .where({ username }) + .first(); + + if (!user || user.error) { + return null; + } + + id = user.id; + } + const query = await DB.select("*").from("slates").where({ slatename }); if (!query || query.error) { @@ -12,7 +26,7 @@ export default async ({ slatename, ownerId }) => { let foundSlate; for (let slate of query) { - if (slate.data.ownerId && slate.data.ownerId === ownerId) { + if (slate.data.ownerId && slate.data.ownerId === id) { foundSlate = slate; } } diff --git a/server.js b/server.js index 65ab41da..ffe082a0 100644 --- a/server.js +++ b/server.js @@ -133,6 +133,7 @@ app.prepare().then(async () => { const slate = await Data.getSlateByName({ slatename: req.params.slatename, + username: req.params.username, }); if (!slate) { @@ -185,6 +186,7 @@ app.prepare().then(async () => { const slate = await Data.getSlateByName({ slatename: req.params.slatename, + username: req.params.username, }); if (!slate) {