From af28b7f5a8911003ace9cd32c6c9ec7452b67655 Mon Sep 17 00:00:00 2001 From: Harald Schilly Date: Wed, 10 Jul 2024 15:18:29 +0200 Subject: [PATCH] fix fallout of b546a4d268e5560 --- src/packages/next/package.json | 2 +- src/packages/pnpm-lock.yaml | 2 +- src/packages/server/shopping/cart/add.ts | 18 +++++++++--------- src/packages/server/shopping/cart/checked.ts | 4 ++-- src/packages/server/shopping/cart/delete.ts | 6 +++--- src/packages/server/shopping/cart/edit.ts | 2 +- .../server/shopping/cart/recent-purchases.ts | 2 +- src/packages/server/shopping/cart/remove.ts | 7 +++---- 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/packages/next/package.json b/src/packages/next/package.json index 73a2e1590e..5761b4b24a 100644 --- a/src/packages/next/package.json +++ b/src/packages/next/package.json @@ -63,7 +63,7 @@ "@cocalc/util": "workspace:*", "@openapitools/openapi-generator-cli": "^2.13.4", "@types/express": "^4.17.13", - "@types/pg": "8.11.6", + "@types/pg": "^8.11.6", "@types/react": "^18.0.26", "@types/react-dom": "^18.0.10", "@vscode/vscode-languagedetection": "^1.0.22", diff --git a/src/packages/pnpm-lock.yaml b/src/packages/pnpm-lock.yaml index c79c989743..edc56f1c97 100644 --- a/src/packages/pnpm-lock.yaml +++ b/src/packages/pnpm-lock.yaml @@ -1065,7 +1065,7 @@ importers: specifier: ^4.17.13 version: 4.17.15 '@types/pg': - specifier: 8.11.6 + specifier: ^8.11.6 version: 8.11.6 '@types/react': specifier: ^18.0.26 diff --git a/src/packages/server/shopping/cart/add.ts b/src/packages/server/shopping/cart/add.ts index ffb223f87f..a58b7614ea 100644 --- a/src/packages/server/shopping/cart/add.ts +++ b/src/packages/server/shopping/cart/add.ts @@ -13,19 +13,19 @@ checking periodically, then blacklisting...? This isn't something of any value to a spammer so it's very unlikely to be exploited maliciously. */ -import { isValidUUID } from "@cocalc/util/misc"; import getPool from "@cocalc/database/pool"; import { - ProductType, ProductDescription, + ProductType, } from "@cocalc/util/db-schema/shopping-cart-items"; +import { isValidUUID } from "@cocalc/util/misc"; import { getItem } from "./get"; export default async function addToCart( account_id: string, product: ProductType, description?: ProductDescription, - project_id?: string + project_id?: string, ): Promise { if (!isValidUUID(account_id)) { throw Error("account_id is invalid"); @@ -37,16 +37,16 @@ export default async function addToCart( const { rowCount } = await pool.query( `INSERT INTO shopping_cart_items (account_id, added, product, description, checked, project_id) VALUES($1, NOW(), $2, $3, true, $4)`, - [account_id, product, description, project_id] + [account_id, product, description, project_id], ); - return rowCount; + return rowCount ?? 0; } // Puts an item back in the cart that was removed. // - Mutates item that was actually removed and not purchased. export async function putBackInCart( account_id: string, - id: number + id: number, ): Promise { if (!isValidUUID(account_id)) { throw Error("account_id is invalid"); @@ -54,15 +54,15 @@ export async function putBackInCart( const pool = getPool(); const { rowCount } = await pool.query( "UPDATE shopping_cart_items SET removed=NULL, checked=TRUE WHERE account_id=$1 AND id=$2 AND removed IS NOT NULL AND purchased IS NULL", - [account_id, id] + [account_id, id], ); - return rowCount; + return rowCount ?? 0; } // Makes copy of item that was purchased and puts it in the cart. export async function buyItAgain( account_id: string, - id: number + id: number, ): Promise { if (!isValidUUID(account_id)) { throw Error("account_id is invalid"); diff --git a/src/packages/server/shopping/cart/checked.ts b/src/packages/server/shopping/cart/checked.ts index d76c42d0fc..c5140eab9d 100644 --- a/src/packages/server/shopping/cart/checked.ts +++ b/src/packages/server/shopping/cart/checked.ts @@ -12,7 +12,7 @@ import getPool from "@cocalc/database/pool"; export default async function setCheck( account_id: string, checked: boolean, - id?: number + id?: number, ): Promise { if (!isValidUUID(account_id)) { throw Error("account_id is invalid"); @@ -28,5 +28,5 @@ export default async function setCheck( } const { rowCount } = await pool.query(query, params); - return rowCount; + return rowCount ?? 0; } diff --git a/src/packages/server/shopping/cart/delete.ts b/src/packages/server/shopping/cart/delete.ts index 16cb4b9529..502b33c108 100644 --- a/src/packages/server/shopping/cart/delete.ts +++ b/src/packages/server/shopping/cart/delete.ts @@ -16,7 +16,7 @@ import getPool from "@cocalc/database/pool"; // Returns number of items "deleted". export default async function deleteItem( account_id: string, - id: number + id: number, ): Promise { if (!isValidUUID(account_id)) { throw Error("account_id is invalid"); @@ -24,7 +24,7 @@ export default async function deleteItem( const pool = getPool(); const { rowCount } = await pool.query( "DELETE FROM shopping_cart_items WHERE account_id=$1 AND id=$2 AND purchased IS NULL", - [account_id, id] + [account_id, id], ); - return rowCount; + return rowCount ?? 0; } diff --git a/src/packages/server/shopping/cart/edit.ts b/src/packages/server/shopping/cart/edit.ts index 46e79b903a..bb4c22dfb7 100644 --- a/src/packages/server/shopping/cart/edit.ts +++ b/src/packages/server/shopping/cart/edit.ts @@ -47,5 +47,5 @@ export default async function editCart({ query += " AND purchased IS NULL"; const { rowCount } = await pool.query(query, params); - return rowCount; + return rowCount ?? 0; } diff --git a/src/packages/server/shopping/cart/recent-purchases.ts b/src/packages/server/shopping/cart/recent-purchases.ts index f89994d65d..d0b3a7705f 100644 --- a/src/packages/server/shopping/cart/recent-purchases.ts +++ b/src/packages/server/shopping/cart/recent-purchases.ts @@ -29,7 +29,7 @@ export default async function getRecentPurchases({ const pool = getPool(); const { rows } = await pool.query( `SELECT * FROM shopping_cart_items WHERE account_id=$1 AND purchased IS NOT NULL AND (purchased#>>'{time}')::timestamptz >= NOW() - $2::interval AND purchased#>>'{voucher_id}' IS NULL`, - [account_id, recent ?? "1 week"] + [account_id, recent ?? "1 week"], ); rows.sort((a, b) => -cmp(a.purchased?.time, b.purchased?.time)); return rows; diff --git a/src/packages/server/shopping/cart/remove.ts b/src/packages/server/shopping/cart/remove.ts index f441b48a53..d36c89f5f2 100644 --- a/src/packages/server/shopping/cart/remove.ts +++ b/src/packages/server/shopping/cart/remove.ts @@ -15,7 +15,7 @@ import getPool from "@cocalc/database/pool"; // You can't remove an item more than once from a cart. export default async function removeFromCart( account_id: string, - id: number + id: number, ): Promise { if (!isValidUUID(account_id)) { throw Error("account_id is invalid"); @@ -23,8 +23,7 @@ export default async function removeFromCart( const pool = getPool(); const { rowCount } = await pool.query( "UPDATE shopping_cart_items SET removed=NOW() WHERE account_id=$1 AND id=$2 AND removed IS NULL AND purchased IS NULL", - [account_id, id] + [account_id, id], ); - return rowCount; + return rowCount ?? 0; } -