Skip to content

Commit 5d57624

Browse files
committed
fix fallout of b546a4d
1 parent 3bcabeb commit 5d57624

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

src/packages/next/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@cocalc/util": "workspace:*",
6464
"@openapitools/openapi-generator-cli": "^2.13.4",
6565
"@types/express": "^4.17.13",
66-
"@types/pg": "8.11.6",
66+
"@types/pg": "^8.11.6",
6767
"@types/react": "^18.0.26",
6868
"@types/react-dom": "^18.0.10",
6969
"@vscode/vscode-languagedetection": "^1.0.22",

src/packages/server/shopping/cart/add.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ checking periodically, then blacklisting...? This isn't something of
1313
any value to a spammer so it's very unlikely to be exploited maliciously.
1414
*/
1515

16-
import { isValidUUID } from "@cocalc/util/misc";
1716
import getPool from "@cocalc/database/pool";
1817
import {
19-
ProductType,
2018
ProductDescription,
19+
ProductType,
2120
} from "@cocalc/util/db-schema/shopping-cart-items";
21+
import { isValidUUID } from "@cocalc/util/misc";
2222
import { getItem } from "./get";
2323

2424
export default async function addToCart(
2525
account_id: string,
2626
product: ProductType,
2727
description?: ProductDescription,
28-
project_id?: string
28+
project_id?: string,
2929
): Promise<number> {
3030
if (!isValidUUID(account_id)) {
3131
throw Error("account_id is invalid");
@@ -37,32 +37,32 @@ export default async function addToCart(
3737
const { rowCount } = await pool.query(
3838
`INSERT INTO shopping_cart_items (account_id, added, product, description, checked, project_id)
3939
VALUES($1, NOW(), $2, $3, true, $4)`,
40-
[account_id, product, description, project_id]
40+
[account_id, product, description, project_id],
4141
);
42-
return rowCount;
42+
return rowCount ?? 0;
4343
}
4444

4545
// Puts an item back in the cart that was removed.
4646
// - Mutates item that was actually removed and not purchased.
4747
export async function putBackInCart(
4848
account_id: string,
49-
id: number
49+
id: number,
5050
): Promise<number> {
5151
if (!isValidUUID(account_id)) {
5252
throw Error("account_id is invalid");
5353
}
5454
const pool = getPool();
5555
const { rowCount } = await pool.query(
5656
"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",
57-
[account_id, id]
57+
[account_id, id],
5858
);
59-
return rowCount;
59+
return rowCount ?? 0;
6060
}
6161

6262
// Makes copy of item that was purchased and puts it in the cart.
6363
export async function buyItAgain(
6464
account_id: string,
65-
id: number
65+
id: number,
6666
): Promise<number> {
6767
if (!isValidUUID(account_id)) {
6868
throw Error("account_id is invalid");

src/packages/server/shopping/cart/checked.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import getPool from "@cocalc/database/pool";
1212
export default async function setCheck(
1313
account_id: string,
1414
checked: boolean,
15-
id?: number
15+
id?: number,
1616
): Promise<number> {
1717
if (!isValidUUID(account_id)) {
1818
throw Error("account_id is invalid");
@@ -28,5 +28,5 @@ export default async function setCheck(
2828
}
2929

3030
const { rowCount } = await pool.query(query, params);
31-
return rowCount;
31+
return rowCount ?? 0;
3232
}

src/packages/server/shopping/cart/delete.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import getPool from "@cocalc/database/pool";
1616
// Returns number of items "deleted".
1717
export default async function deleteItem(
1818
account_id: string,
19-
id: number
19+
id: number,
2020
): Promise<number> {
2121
if (!isValidUUID(account_id)) {
2222
throw Error("account_id is invalid");
2323
}
2424
const pool = getPool();
2525
const { rowCount } = await pool.query(
2626
"DELETE FROM shopping_cart_items WHERE account_id=$1 AND id=$2 AND purchased IS NULL",
27-
[account_id, id]
27+
[account_id, id],
2828
);
29-
return rowCount;
29+
return rowCount ?? 0;
3030
}

src/packages/server/shopping/cart/edit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ export default async function editCart({
4747
query += " AND purchased IS NULL";
4848

4949
const { rowCount } = await pool.query(query, params);
50-
return rowCount;
50+
return rowCount ?? 0;
5151
}

src/packages/server/shopping/cart/recent-purchases.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default async function getRecentPurchases({
2929
const pool = getPool();
3030
const { rows } = await pool.query(
3131
`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`,
32-
[account_id, recent ?? "1 week"]
32+
[account_id, recent ?? "1 week"],
3333
);
3434
rows.sort((a, b) => -cmp(a.purchased?.time, b.purchased?.time));
3535
return rows;

src/packages/server/shopping/cart/remove.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ import getPool from "@cocalc/database/pool";
1515
// You can't remove an item more than once from a cart.
1616
export default async function removeFromCart(
1717
account_id: string,
18-
id: number
18+
id: number,
1919
): Promise<number> {
2020
if (!isValidUUID(account_id)) {
2121
throw Error("account_id is invalid");
2222
}
2323
const pool = getPool();
2424
const { rowCount } = await pool.query(
2525
"UPDATE shopping_cart_items SET removed=NOW() WHERE account_id=$1 AND id=$2 AND removed IS NULL AND purchased IS NULL",
26-
[account_id, id]
26+
[account_id, id],
2727
);
28-
return rowCount;
28+
return rowCount ?? 0;
2929
}
30-

0 commit comments

Comments
 (0)