From 527e58b2b1b62268b39b855c88fe674f99a2e05d Mon Sep 17 00:00:00 2001 From: Claeb101 Date: Sat, 4 Mar 2023 19:43:53 -0500 Subject: [PATCH] refactor api routes --- src/call.js | 13 +++---------- src/db.js | 5 +++++ src/index.js | 15 +++++++++++++++ src/session.js | 5 +++++ 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 src/db.js create mode 100644 src/index.js create mode 100644 src/session.js diff --git a/src/call.js b/src/call.js index 5999bd5..921f8c5 100644 --- a/src/call.js +++ b/src/call.js @@ -1,8 +1,8 @@ import * as dotenv from "dotenv"; +import { Router } from "express"; dotenv.config(); import twilio from "twilio"; -import express from "express"; const accountSid = process.env.TWILIO_ACCOUNT_SID; const authToken = process.env.TWILIO_AUTH_TOKEN; @@ -11,8 +11,7 @@ const phone_number = process.env.TWILIO_PHONE_NUMBER; const client = new twilio.Twilio(accountSid, authToken); const VoiceResponse = twilio.twiml.VoiceResponse; -const app = express(); -app.use(express.urlencoded({ extended: false })); +const app = Router(); app.post("/receive", (req, res) => { // Use the Twilio Node.js SDK to build an XML response @@ -58,10 +57,4 @@ app.post("/respond", async (req, res) => { res.send(twiml.toString()); }); -// Create an HTTP server and listen for requests on port 3000 -app.listen(3000, () => { - console.log( - "Now listening on port 3000. " + - "Be sure to restart when you make code changes!" - ); -}); +export default app \ No newline at end of file diff --git a/src/db.js b/src/db.js new file mode 100644 index 0000000..570b1e9 --- /dev/null +++ b/src/db.js @@ -0,0 +1,5 @@ +import { Prisma, PrismaClient } from "@prisma/client"; + +const db = new PrismaClient() + +export {db}; \ No newline at end of file diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..669ac74 --- /dev/null +++ b/src/index.js @@ -0,0 +1,15 @@ +import express from "express"; +import call from "./call.js"; + +const app = express(); +app.use(express.urlencoded({ extended: false })); + +app.use('/call', call) + +// Create an HTTP server and listen for requests on port 3000 +app.listen(3000, () => { + console.log( + "Now listening on port 3000. " + + "Be sure to restart when you make code changes!" + ); +}); diff --git a/src/session.js b/src/session.js new file mode 100644 index 0000000..8fb8d4e --- /dev/null +++ b/src/session.js @@ -0,0 +1,5 @@ +import { db } from "./db"; + +const session = () => { + db.session.create({}) +}