-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomerModel.js
42 lines (35 loc) · 927 Bytes
/
customerModel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { initDBConnection } from "../../db/db-connection.js";
let db;
export function initDb() {
db = initDBConnection();
}
export const itemsByCategory = async () => {
const { rows: items } = await db.query(
`SELECT
C.ID,
C.CATEGORY_NAME as categoryName ,
C.DESCRIPTION,
(
SELECT json_agg(json_build_object(
'id', ID,
'itemName', ITEM_NAME,
'price', PRICE
))
FROM ITEM
WHERE
CATEGORY_ID = C.ID AND ACTIVE IS TRUE
) AS ITEMS
FROM CATEGORY C
ORDER BY C.ID ASC;`
);
return items;
};
// FOR CONTACT PAGE
// post query
export const postMessage = async (user) => {
const insertQuery = `INSERT INTO
message(name, email, phone_number, message)
VALUES($1, $2, $3, $4) RETURNING *`;
const values = [user.name, user.email, user.phoneNumber, user.message];
return await db.query(insertQuery, values);
};