Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const getProductsForAttach = async ({
version,
});

const archivedProducts = products.filter((prod) => prod.archived);
if (archivedProducts.length > 0) {
throw new RecaseError({
message: `Cannot attach archived product${archivedProducts.length > 1 ? "s" : ""}: ${archivedProducts.map((p) => p.id).join(", ")}`,
code: ErrCode.InvalidRequest,
});
}

if (notNullish(product_ids)) {
const freeTrialProds = products.filter((prod) =>
notNullish(prod.free_trial),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const handleGetPricingTable = createRoute({
const { customer_id: customerId } = c.req.valid("query");

const [products, customer] = await Promise.all([
ProductService.listFull({ db, orgId: org.id, env }),
ProductService.listFull({ db, orgId: org.id, env, archived: false }),
(async () => {
if (!customerId) {
return undefined;
Expand Down
4 changes: 2 additions & 2 deletions server/src/internal/product/actions/createProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const createProduct = async ({
id: data.id,
});

// 1. If existing product, throw error
if (existing) throw new ProductAlreadyExistsError({ productId: data.id });
// 1. If existing non-archived product, throw error
if (existing && !existing.archived) throw new ProductAlreadyExistsError({ productId: data.id });

await validateDefaultFlag({
ctx,
Expand Down
21 changes: 12 additions & 9 deletions server/src/internal/products/ProductService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ export class ProductService {
internalFeatureId: string;
}) {
const fullProducts = (await db.query.products.findMany({
where: exists(
db
.select()
.from(entitlements)
.where(
and(
eq(entitlements.internal_product_id, products.internal_id),
eq(entitlements.internal_feature_id, internalFeatureId),
where: and(
ne(products.archived, true),
exists(
db
.select()
.from(entitlements)
.where(
and(
eq(entitlements.internal_product_id, products.internal_id),
eq(entitlements.internal_feature_id, internalFeatureId),
),
),
),
),
),
with: {
entitlements: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const handleCreatePlan = createRoute({
id: body.id,
});

// 1. If existing product, throw error
if (existing) throw new ProductAlreadyExistsError({ productId: body.id });
// 1. If existing non-archived product, throw error
if (existing && !existing.archived) throw new ProductAlreadyExistsError({ productId: body.id });

await validateDefaultFlag({
ctx,
Expand Down