This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dotenv from "dotenv"; | |
import pg from "pg"; | |
dotenv.config(); | |
console.log({ url: process.env.DATABASE_URL }); | |
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL }); | |
pool.on("error", (err) => console.error(err)); | |
export default pool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:19.4.0-alpine | |
WORKDIR /app | |
COPY package*.json ./ | |
RUN npm install | |
COPY . . | |
EXPOSE 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from "express"; | |
const userRouter = express.Router(); | |
userRouter.route("/me").get((req, res) => { | |
res.status(200).send("You are you!"); | |
}); | |
export default userRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express, { Express, Request, Response } from "express"; | |
import dotenv from "dotenv"; | |
import userRouter from "./user"; | |
dotenv.config(); | |
const app: Express = express(); | |
const port = process.env.PORT || 3000; | |
app.use(json()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"db": { | |
"connectionString": "postgresql://admin:admin1pass@localhost:5432/ecommerce" | |
}, | |
"outdir": "./schema" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE ecommerce; | |
\c ecommerce; | |
-- Create the User table | |
CREATE TABLE "User" ( | |
user_id SERIAL PRIMARY KEY, | |
email VARCHAR(255) NOT NULL, | |
created_at TIMESTAMP NOT NULL, | |
updated_at TIMESTAMP NOT NULL | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logger from "../logger"; | |
export const Graceful = (errorMessage: string) => { | |
return function captural( | |
originalMethod: Function, | |
_context: ClassMethodDecoratorContext | |
) { | |
function ReplacementMethod(this: any, ...args: any[]) { | |
try { | |
const result = originalMethod.call(this, ...args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { User } from "./DataAccessLayer"; | |
import { LogCall } from "./logCall"; | |
import { Retry } from "./retry"; | |
export type Action = "Click" | "Submit" | "Redirect"; | |
function randomIntInclusive(min: number, max: number) { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
} | |
export class MetricTracking { | |
/** | |
* This method attempts to mark a user action in the metric tracking service. It retries 3x over the course of 5 seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logger from "../logger"; | |
export const LogCall = ( | |
originalMethod: Function, | |
context: ClassMethodDecoratorContext | |
) => { | |
const methodName = String(context.name); | |
function ReplacementMethod(this: any, ...args: any[]) { | |
logger.info( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import winston, { format } from "winston"; | |
import DailyRotateFile from "winston-daily-rotate-file"; | |
const winstonLogger = winston.createLogger({ | |
format: winston.format.combine( | |
format.errors({ stack: true }), | |
format.timestamp({ | |
format: "YYYY-MM-DD HH:mm:ss+ms", | |
}), | |
format.json() |