mirror of
https://github.com/KevinMidboe/planetposen-backend.git
synced 2025-10-29 08:20:12 +00:00
Resolved prettier & eslint issues
This commit is contained in:
@@ -8,7 +8,7 @@ const password = configuration.get("database", "password");
|
||||
const host = configuration.get("database", "host");
|
||||
const dbName = configuration.get("database", "database");
|
||||
|
||||
let postgresDB = new PostgresDatabase(user, password, host, dbName);
|
||||
const postgresDB = new PostgresDatabase(user, password, host, dbName);
|
||||
|
||||
postgresDB.connect();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class StripeApi {
|
||||
});
|
||||
}
|
||||
|
||||
createProduct(cart) {
|
||||
createProduct() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import cookie from "cookie";
|
||||
import type { Request, Response, NextFunction } from "express";
|
||||
import type { Request, Response } from "express";
|
||||
|
||||
const cookieOptions = {
|
||||
path: "/",
|
||||
|
||||
@@ -109,7 +109,7 @@ async function addSku(req: Request, res: Response) {
|
||||
const skus = await productRepository.getSkus(product_id);
|
||||
|
||||
if (!skus.find((sku) => sku.default_price === true)) {
|
||||
const setDefaultResponse = await productRepository.setSkuDefaultPrice(
|
||||
await productRepository.setSkuDefaultPrice(
|
||||
product_id,
|
||||
skus[skus.length - 1].sku_id
|
||||
);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import Stripe from "stripe";
|
||||
|
||||
import logger from "../../logger";
|
||||
import Configuration from "../../config/configuration";
|
||||
import StripeApi from "../../stripe/stripeApi";
|
||||
import StripeRepository from "../../stripe/stripeRepository";
|
||||
import OrderRepository from "../../order";
|
||||
import CustomerRepository from "../../customer";
|
||||
|
||||
import Stripe from "stripe";
|
||||
|
||||
import type { Request, Response, NextFunction } from "express";
|
||||
import type { IOrder, ILineItem } from "../../interfaces/IOrder";
|
||||
import type ICustomer from "../../interfaces/ICustomer";
|
||||
@@ -22,29 +23,62 @@ async function create(req, res) {
|
||||
const clientId = req?.planetId;
|
||||
const { order_id, customer_no } = req.body;
|
||||
|
||||
logger.info("Creating stripe payment intent", {
|
||||
client_id: clientId,
|
||||
order_id,
|
||||
customer_no,
|
||||
});
|
||||
|
||||
if (!order_id || !customer_no) {
|
||||
logger.warning("Missing order_id and/or customer_id");
|
||||
|
||||
return res.status(400).send({
|
||||
success: false,
|
||||
message: "Missing order_id and/or customer_id",
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const order: IOrder = await orderRepository.getOrder(order_id);
|
||||
const customer: ICustomer = await customerRepository.getCustomer(customer_no);
|
||||
const customer: ICustomer = await customerRepository.getCustomer(
|
||||
customer_no
|
||||
);
|
||||
|
||||
const sum = order.lineItems?.reduce(
|
||||
(total, lineItem: ILineItem) => total + lineItem.quantity * lineItem.price,
|
||||
(total, lineItem: ILineItem) =>
|
||||
total + lineItem.quantity * lineItem.price,
|
||||
0
|
||||
);
|
||||
|
||||
stripeRepository
|
||||
.createPayment(clientId, sum, order_id, customer)
|
||||
.then((clientSecret) =>
|
||||
.then((clientSecret) => {
|
||||
logger.info("New stripe payment", {
|
||||
client_id: clientId,
|
||||
client_secret: clientSecret,
|
||||
});
|
||||
|
||||
res.send({
|
||||
success: true,
|
||||
clientSecret,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
res.statusCode = error?.statusCode || 500;
|
||||
logger.error("Error creating stripe payment intent", {
|
||||
error,
|
||||
client_id: clientId,
|
||||
customer_no,
|
||||
order_id,
|
||||
});
|
||||
|
||||
res.send({
|
||||
success: false,
|
||||
message:
|
||||
error?.message ||
|
||||
"Unexcepted error while creating stripe payment intent",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function updatePayment(req: Request, res: Response) {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// import * as global from "../types/global";
|
||||
import path from "path";
|
||||
import express from "express";
|
||||
import { createServer } from "http";
|
||||
|
||||
@@ -29,8 +27,6 @@ app.use(setupCORS);
|
||||
app.use(setupHeaders);
|
||||
app.use(getOrSetCookieForClient);
|
||||
|
||||
// parse application/json
|
||||
|
||||
const router = express.Router();
|
||||
router.use(express.json());
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import cookie from "cookie";
|
||||
import { ClientRequest } from "http";
|
||||
import { WebSocketServer, Websocket, Request } from "ws";
|
||||
import WSCart from "../cart/WSCart";
|
||||
import CartSession from "../cart/CartSession";
|
||||
@@ -26,9 +25,9 @@ function setupCartWebsocketServer(server) {
|
||||
// setInterval(() => cartSession.listCarts(), 3000);
|
||||
setInterval(() => cartSession.removeIfNotAlive(), 1000);
|
||||
|
||||
wss.on("connection", (ws, req) => {
|
||||
wss.on("connection", (ws: Websocket, req: Request) => {
|
||||
const sessionId = generateUUID();
|
||||
let clientId =
|
||||
const clientId =
|
||||
getCookieValue(req.headers.cookie, "planetId") ||
|
||||
getHeaderValue(req.url, "planetId");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user