get all accessible recipes

This commit is contained in:
Mikayla Dobson
2022-12-17 14:22:24 -06:00
parent 9a43f58ee3
commit 6c3f835b25
10 changed files with 54 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
import { IRecipe } from "../schemas";
import fs from 'fs';
import pool from "../db";
import { CollectionCtl } from "../controllers";
import now from "../util/now";
@@ -30,7 +31,24 @@ export class Recipe {
}
async getAllAccessible(id: string) {
try {
const statement = `
SELECT * FROM recipin.recipe
WHERE authoruserid = $1
OR authoruserid IN (
SELECT targetid FROM recipin.cmp_userfriendships
WHERE senderid = $1
UNION
SELECT senderid FROM recipin.cmp_userfriendships
WHERE targetid = $1
);
`
const result = await pool.query(statement, [id]);
if (result.rows.length) return result.rows;
return null;
} catch (e: any) {
throw new Error(e);
}
}
async fetchRecipesByCollection(collectionid: string) {