Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional phone number #37

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion packages/functions/src/routes/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { leaderboardTable, itemsTable } from "../config/db-config.js";

//Add a item
itemsRouter.post("/", async (req, res) => {
console.log("Item posted:", req.body);
try {
const {
name,
Expand All @@ -20,7 +21,9 @@ itemsRouter.post("/", async (req, res) => {
location,
date,
itemdate,
preferred_contact,
email,
phone_number,
image,
isresolved,
ishelped,
Expand All @@ -31,7 +34,7 @@ itemsRouter.post("/", async (req, res) => {
}

const item = await client.query(
`INSERT INTO ${itemsTable} (name, description, type, islost, location, date, itemdate, email, image, isresolved, ishelped) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *`,
`INSERT INTO ${itemsTable} (name, description, type, islost, location, date, itemdate, preferred_contact, email, phone_number, image, isresolved, ishelped) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING *`,
[
name,
description,
Expand All @@ -40,7 +43,9 @@ itemsRouter.post("/", async (req, res) => {
location,
date,
itemdate,
preferred_contact,
email,
phone_number,
image,
isresolved,
ishelped,
Expand Down Expand Up @@ -215,6 +220,38 @@ itemsRouter.get("/:id/email", async (req, res) => {
}
});

// Get preferred contact method associated with an item id
itemsRouter.get("/:id/contactMethod", async (req, res) => {
try {
const { id } = req.params;

const item = await client.query(
`SELECT preferred_contact FROM ${itemsTable} WHERE id=$1`,
[id]
);

res.json(item.rows[0]);
} catch (error) {
console.error(error);
}
});

// Get phone number associated with an item id
itemsRouter.get("/:id/phoneNumber", async (req, res) => {
try {
const { id } = req.params;

const item = await client.query(
`SELECT phone_number FROM ${itemsTable} WHERE id=$1`,
[id]
);

res.json(item.rows[0]);
} catch (error) {
console.error(error);
}
});

// Retrieve Items by Category
itemsRouter.get("/category/:category", async (req, res) => {
try {
Expand Down
2 changes: 2 additions & 0 deletions packages/functions/src/server/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ CREATE TABLE items (
location FLOAT[],
date VARCHAR(255),
itemDate VARCHAR(50),
preferred_contact VARCHAR(255),
email VARCHAR(255),
phone_number VARCHAR(15),
image VARCHAR(500),
islost BOOLEAN,
isResolved BOOLEAN,
Expand Down
Loading