support on collection route

This commit is contained in:
Mikayla Dobson
2022-11-19 12:02:28 -06:00
parent c6156e237e
commit bf16841b95
5 changed files with 59 additions and 6 deletions

View File

@@ -7,7 +7,8 @@ export class Collection {
const statement = `SELECT * FROM recipin.collection WHERE id = $1`;
const values = [id];
const result = await pool.query(statement, values);
return result;
if (result.rows.length) return result.rows[0];
return null;
} catch (e: any) {
throw new Error(e);
}
@@ -18,18 +19,26 @@ export class Collection {
try {
const statement = `SELECT * FROM recipin.collection`;
const result = await pool.query(statement);
return result;
if (result.rows.length) return result.rows;
return null;
} catch (e: any) {
throw new Error(e);
}
}
async post(data: ICollection) {
const { name, active, ismaincollection, ownerid } = data;
try {
const statement = `
INSERT INTO recipin.collection
()
(name, active, ismaincollection, ownerid)
VALUES ($1, $2, $3, $4)
RETURNING *;
`
const values = [name, active, ismaincollection, ownerid];
const result = await pool.query(statement, values);
if (result.rows.length) return result.rows;
return null;
} catch (e: any) {
throw new Error(e);
}