Skip to content
Merged
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
47 changes: 47 additions & 0 deletions src/api/functions/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// TODO: (store) Create a function to check if a given product and variant are sellable to a given user
// If it is sellable, return the price ID to create a stripe checkout session for

import { type DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { type Redis } from "api/types.js";

// If not, return null.
export type CheckItemSellableInputs = {
userId: string; // This is generally their Illinois email
productId: string;
variantId: string;
dynamoClient: DynamoDBClient;
redisClient: Redis;
};

export type CheckItemSellableOutputs = null | string;

export async function checkItemSellable({
userId,
productId,
variantId,
dynamoClient,
redisClient,
}: CheckItemSellableInputs): Promise<CheckItemSellableOutputs> {
// In a transaction:
// First, check if there is stock.
// If there is stock, check that the user is still under their limit.
// If there is, check if they are a paid member.
// If paid member return member_price_id for the variant request, if not return the nonmember_price_id
return null;
}

export type CreateCheckoutSessionInputs = {
priceId: string;
username: string;
stripeApiKey: string;
};

export type CreateCheckoutSessionOutputs = string;

export async function createCheckoutSession({
priceId,
}: CreateCheckoutSessionInputs): Promise<CreateCheckoutSessionOutputs> {
// Check stripe modules createCheckoutSession function
// initatior string should be "acm-store"
return "";
}
3 changes: 3 additions & 0 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export type GenericConfigType = {
UserInfoTable: string;
SigInfoTableName: string;
EntraHostedDomainName: string;
StoreInventoryTableName: string;
// TODO: (store) add other tables
};

type EnvironmentConfigType = {
Expand Down Expand Up @@ -106,6 +108,7 @@ const genericConfig: GenericConfigType = {
UserInfoTable: "infra-core-api-user-info",
SigInfoTableName: "infra-core-api-sigs",
EntraHostedDomainName: "acmillinois.onmicrosoft.com",
StoreInventoryTableName: "infra-core-api-store-inventory"
} as const;

const environmentConfig: EnvironmentConfigType = {
Expand Down
19 changes: 19 additions & 0 deletions terraform/modules/dynamo/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,22 @@ resource "aws_dynamodb_table" "sig_info" {
projection_type = "KEYS_ONLY"
}
}

resource "aws_dynamodb_table" "store_inventory" {
billing_mode = "PAY_PER_REQUEST"
name = "${var.ProjectId}-store-inventory"
deletion_protection_enabled = true
hash_key = "productId"
range_key = "variantId"
point_in_time_recovery {
enabled = true
}
attribute {
name = "productId"
type = "S"
}
attribute {
name = "variantId"
type = "S"
}
}
Loading