user route for getting friendships

This commit is contained in:
Mikayla Dobson
2022-11-23 11:20:44 -06:00
parent d2d38bf7dd
commit d984ea64eb
15 changed files with 112 additions and 13 deletions

View File

@@ -1,7 +1,9 @@
import { IUser } from "../schemas";
import fs from "fs";
import pgPromise from "pg-promise";
import pool from '../db';
import now from "../util/now";
import { appRoot } from "..";
const pgp = pgPromise({ capSQL: true });
export class User {
@@ -91,4 +93,15 @@ export class User {
throw new Error(error);
}
}
async getFriends(id: string) {
try {
const sql = fs.readFileSync(appRoot + '/db/sql/friendships.sql').toString();
const result = await pool.query(sql, [id]);
if (result.rows.length) return result.rows;
return null;
} catch (e: any) {
throw new Error(e);
}
}
}