Skip to content

Commit

Permalink
fix db tables
Browse files Browse the repository at this point in the history
  • Loading branch information
labintsev committed Dec 11, 2024
1 parent cffba96 commit f83fbdb
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 280 deletions.
28 changes: 28 additions & 0 deletions packages/nextjs/app/lib/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Choice, Question } from "./definitions";
import { sql } from "@vercel/postgres";

export async function fetchQuestions() {
try {
// Artificially delay a response for demo purposes.
// Don't do this in production :)

// console.log('Fetching revenue data...');
// await new Promise((resolve) => setTimeout(resolve, 3000));

const questions = await sql<Question>`SELECT * FROM questions`;

const choices = await sql<Choice>`SELECT * FROM choices`;

// const q_rows = questions.rows;

// todo join questions and choices

console.log("Questions fetched ", questions);
console.log("Choices fetched ", choices);

return questions.rows;
} catch (error) {
console.error("Database Error:", error);
throw new Error("Failed to fetch data.");
}
}
9 changes: 9 additions & 0 deletions packages/nextjs/app/lib/definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type Question = {
question: string;
is_active: number;
};

export type Choice = {
question_id: string;
text: string;
};
182 changes: 19 additions & 163 deletions packages/nextjs/app/seed/placeholder-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,212 +9,68 @@ const shareholders = [

const questions = [
{
id: 0,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd81a0",
question: "Do you enjoy this voting application?",
is_active: 1,
},
{
id: 1,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd81a1",
question: "Who will be Chief Executive Officer in 2025?",
is_active: 1,
},
{
id: 2,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd81a2",
question: "Do you approve this financial report?",
is_active: 1,
},
];

const question_choices = [
{
id: 0,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd8100",
question_id: questions[0].id,
choice: "Yes",
text: "Yes",
},
{
id: 1,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd8101",
question_id: questions[0].id,
choice: "No",
text: "No",
},
{
id: 2,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd8102",
question_id: questions[1].id,
choice: "Donald Duck",
text: "Donald Duck",
},
{
id: 3,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd8103",
question_id: questions[1].id,
choice: "John Smith",
text: "John Smith",
},
{
id: 4,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd8104",
question_id: questions[1].id,
choice: "Billy Bones",
text: "Billy Bones",
},
{
id: 5,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd8105",
question_id: questions[2].id,
choice: "Yes",
text: "Yes",
},
{
id: 6,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd8106",
question_id: questions[2].id,
choice: "No",
text: "No",
},
];

const shareholder_question_answers = [
{
id: 0,
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd8107",
sh_id: shareholders[0].id,
q_id: question_choices[0].id,
choice_id: question_choices[0].id,
answer_time: "2024-12-8 12-34",
},
];

const users = [
{
id: "410544b2-4001-4271-9855-fec4b6a6442a",
name: "User",
email: "user@nextmail.com",
password: "123456",
},
];

const customers = [
{
id: "d6e15727-9fe1-4961-8c5b-ea44a9bd81aa",
name: "Evil Rabbit",
email: "evil@rabbit.com",
image_url: "/customers/evil-rabbit.png",
},
{
id: "3958dc9e-712f-4377-85e9-fec4b6a6442a",
name: "Delba de Oliveira",
email: "delba@oliveira.com",
image_url: "/customers/delba-de-oliveira.png",
},
{
id: "3958dc9e-742f-4377-85e9-fec4b6a6442a",
name: "Lee Robinson",
email: "lee@robinson.com",
image_url: "/customers/lee-robinson.png",
},
{
id: "76d65c26-f784-44a2-ac19-586678f7c2f2",
name: "Michael Novotny",
email: "michael@novotny.com",
image_url: "/customers/michael-novotny.png",
},
{
id: "CC27C14A-0ACF-4F4A-A6C9-D45682C144B9",
name: "Amy Burns",
email: "amy@burns.com",
image_url: "/customers/amy-burns.png",
},
{
id: "13D07535-C59E-4157-A011-F8D2EF4E0CBB",
name: "Balazs Orban",
email: "balazs@orban.com",
image_url: "/customers/balazs-orban.png",
},
];

const invoices = [
{
customer_id: customers[0].id,
amount: 15795,
status: "pending",
date: "2022-12-06",
},
{
customer_id: customers[1].id,
amount: 20348,
status: "pending",
date: "2022-11-14",
},
{
customer_id: customers[4].id,
amount: 3040,
status: "paid",
date: "2022-10-29",
},
{
customer_id: customers[3].id,
amount: 44800,
status: "paid",
date: "2023-09-10",
},
{
customer_id: customers[5].id,
amount: 34577,
status: "pending",
date: "2023-08-05",
},
{
customer_id: customers[2].id,
amount: 54246,
status: "pending",
date: "2023-07-16",
},
{
customer_id: customers[0].id,
amount: 666,
status: "pending",
date: "2023-06-27",
},
{
customer_id: customers[3].id,
amount: 32545,
status: "paid",
date: "2023-06-09",
},
{
customer_id: customers[4].id,
amount: 1250,
status: "paid",
date: "2023-06-17",
},
{
customer_id: customers[5].id,
amount: 8546,
status: "paid",
date: "2023-06-07",
},
{
customer_id: customers[1].id,
amount: 500,
status: "paid",
date: "2023-08-19",
},
{
customer_id: customers[5].id,
amount: 8945,
status: "paid",
date: "2023-06-03",
},
{
customer_id: customers[2].id,
amount: 1000,
status: "paid",
date: "2022-06-05",
},
];

const revenue = [
{ month: "Jan", revenue: 2000 },
{ month: "Feb", revenue: 1800 },
{ month: "Mar", revenue: 2200 },
{ month: "Apr", revenue: 2500 },
{ month: "May", revenue: 2300 },
{ month: "Jun", revenue: 3200 },
{ month: "Jul", revenue: 3500 },
{ month: "Aug", revenue: 3700 },
{ month: "Sep", revenue: 2500 },
{ month: "Oct", revenue: 2800 },
{ month: "Nov", revenue: 3000 },
{ month: "Dec", revenue: 4800 },
];

export { users, customers, invoices, revenue, shareholders, questions, question_choices, shareholder_question_answers };
export { shareholders, questions, question_choices, shareholder_question_answers };
Loading

0 comments on commit f83fbdb

Please sign in to comment.