support on collection route
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user