Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fa7274a
feat: Update Schema for StockLedger
mohammedfabinsha Aug 5, 2025
d4d200c
wip: StockBalance And Reconcile
mohammedfabinsha Aug 12, 2025
22c6904
Merge branch 'master' into stockSchema
FathimaSayeeda Aug 13, 2025
e68abe9
fix: Make Order Creation a Prisma Transaction
FathimaSayeeda Aug 13, 2025
7486bfe
feat: ReserveInventory Service
FathimaSayeeda Aug 13, 2025
785fec1
fix: ReserveInventory function in Order Transaction
FathimaSayeeda Aug 13, 2025
c173767
fix: Alter Service for StockBalances of Multiple Items
FathimaSayeeda Aug 15, 2025
87e6c35
fix: Alter ReseerveInventory to take StockBalances of Multiple Items
FathimaSayeeda Aug 15, 2025
f8b2189
feat: ReleaseInventory Service
FathimaSayeeda Aug 15, 2025
72fa116
fix: ReserveInventory in CreateOrder Service
FathimaSayeeda Aug 15, 2025
6b5648c
fix: ReleaseInventory in CancelOrder Service
FathimaSayeeda Aug 15, 2025
a69208c
feat: ReleaseInventory on Order Cancellation
FathimaSayeeda Aug 29, 2025
c74395c
feat: ReleaseInventory on Payment Failure
FathimaSayeeda Aug 29, 2025
71f6b08
feat(wip): BE Stock Updates
FathimaSayeeda Sep 8, 2025
65b4488
feat: Update Stock Services
fahimalizain Sep 8, 2025
13dba30
fix: Variant Reconciliation
fahimalizain Sep 8, 2025
683880d
fix: SWR Reconciliation
fahimalizain Sep 8, 2025
6ad26c8
feat: WIP: Update Stock for Template Items
FathimaSayeeda Sep 16, 2025
4f17d2b
fix: Stock Update for Variants
FathimaSayeeda Sep 17, 2025
17f61fb
fix: Minor
FathimaSayeeda Sep 17, 2025
c7adcca
fix: Correspond StockStatus to SelectedVariant
FathimaSayeeda Sep 23, 2025
68f57f4
fix: Typing
FathimaSayeeda Sep 30, 2025
f37d635
fix: Console Logs Remove
FathimaSayeeda Sep 30, 2025
55a60bf
fix: Hook Naming
FathimaSayeeda Oct 6, 2025
0eaed3a
fix: Naming and Structure
FathimaSayeeda Oct 6, 2025
05628ee
fix: Items Folder Standardization
FathimaSayeeda Oct 6, 2025
001e321
fix: Naming and Structure - Category Service & SWR
FathimaSayeeda Oct 7, 2025
3c28deb
fix: Naming and Structure - Cart Service & SWR
FathimaSayeeda Oct 7, 2025
c3117b8
fix: Naming and Structure - Attribute Service & SWR
FathimaSayeeda Oct 7, 2025
536f394
fix: Typing
FathimaSayeeda Oct 7, 2025
311b00d
fix: Naming & Structure - Variants Service & SWR
FathimaSayeeda Oct 7, 2025
dbfadcb
fix: Naming & Structure - Wishlist Service & SWR
FathimaSayeeda Oct 7, 2025
4973e85
fix: Lint Errors
FathimaSayeeda Oct 7, 2025
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Environment Files
.env
.env.*

# compiled output
dist
Expand Down Expand Up @@ -45,4 +46,4 @@ Thumbs.db
.nx/cache

# Next.js
.next
.next
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/iron
20
1 change: 0 additions & 1 deletion libs/items/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export {
type ItemDetailsResponse,
type ItemVariantWithAttributes,
type ItemVariantWithSize,
} from './services';
Expand Down
5 changes: 3 additions & 2 deletions libs/items/src/services/attributes/add-attribute/services.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getPrismaClient } from '@vestido-ecommerce/models';

import { CreateAttributeSchema, CreateAttributeSchemaType } from './zod';
import { CreateAttributeArgs } from './types';
import { CreateAttributeSchema } from './zod';

export async function createAttribute(body: CreateAttributeSchemaType) {
export async function createAttribute(body: CreateAttributeArgs) {
const prisma = getPrismaClient();

const validatedData = CreateAttributeSchema.parse(body);
Expand Down
15 changes: 7 additions & 8 deletions libs/items/src/services/attributes/add-attribute/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ItemAttribute, ItemAttributeValue } from '@prisma/client';

import { createAttribute } from './services';
import { CreateAttributeSchemaType } from './zod';

export type CreateAttributeRequest = CreateAttributeSchemaType;
export type CreateAttributeArgs = CreateAttributeSchemaType;

export type CreateAttributeResult = Awaited<ReturnType<typeof createAttribute>>;

export type CreateAttributeResponse = {
data: ItemAttribute & {
values: ItemAttributeValue[];
};
};
// export type CreateAttributeResult = ItemAttribute & {
// values: ItemAttributeValue[];
// };
4 changes: 2 additions & 2 deletions libs/items/src/services/attributes/list-attributes/service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getPrismaClient } from '@vestido-ecommerce/models';

import { ListAttributesRequest } from './types';
import { ListAttributesArgs } from './types';
import { ListAttributeRequestSchema } from './zod';

export async function listAttribute(_args: ListAttributesRequest) {
export async function listAttribute(_args: ListAttributesArgs) {
const prisma = getPrismaClient();
const args = ListAttributeRequestSchema.parse(_args ?? {});

Expand Down
4 changes: 2 additions & 2 deletions libs/items/src/services/attributes/list-attributes/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type listAttribute } from './service';
import { ListAttributeRequestSchemaType } from './zod';

export type ListAttributesRequest = ListAttributeRequestSchemaType;
export type ListAttributesResponse = Awaited<ReturnType<typeof listAttribute>>;
export type ListAttributeArgs = ListAttributeRequestSchemaType;
export type ListAttributesResult = Awaited<ReturnType<typeof listAttribute>>;
11 changes: 3 additions & 8 deletions libs/items/src/services/attributes/update-attribute/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { ItemAttribute, ItemAttributeValue } from '@prisma/client';

import { updateAttribute } from './services';
import { UpdateAttributeSchemaType } from './zod';

export type UpdateAttributeRequest = UpdateAttributeSchemaType;
export type UpdateAttributeArgs = UpdateAttributeSchemaType;

export type UpdateAttributeResponse = {
data: ItemAttribute & {
values: ItemAttributeValue[];
};
};
export type UpdateAttributeResult = Awaited<ReturnType<typeof updateAttribute>>;
5 changes: 3 additions & 2 deletions libs/items/src/services/cart/add-to-cart/services.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getPrismaClient } from '@vestido-ecommerce/models';

import { AddToCartSchema, AddToCartSchemaType } from './zod';
import { AddToCartArgs } from './types';
import { AddToCartSchema } from './zod';

export async function addToCart(body: AddToCartSchemaType) {
export async function addToCart(body: AddToCartArgs) {
const prisma = getPrismaClient();

const validatedData = AddToCartSchema.parse(body);
Expand Down
9 changes: 3 additions & 6 deletions libs/items/src/services/cart/add-to-cart/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { CartItem } from '@prisma/client';

import { addToCart } from './services';
import { AddToCartSchemaType } from './zod';

export type AddToCartRequest = AddToCartSchemaType;
export type AddToCartArgs = AddToCartSchemaType;

export type AddToCartResponse = {
data: CartItem;
};
export type AddToCartResult = Awaited<ReturnType<typeof addToCart>>;
2 changes: 1 addition & 1 deletion libs/items/src/services/cart/get-cart/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './services';
export * from './service';
export * from './types';
10 changes: 2 additions & 8 deletions libs/items/src/services/cart/get-cart/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { CartItem, Item } from '@prisma/client';
import { listCartItems } from './service';

export type CartItemResponse = {
data: Array<
CartItem & {
item: Item;
}
>;
};
export type CartItemResult = Awaited<ReturnType<typeof listCartItems>>;
3 changes: 2 additions & 1 deletion libs/items/src/services/cart/remove-from-cart/services.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getPrismaClient } from '@vestido-ecommerce/models';

import { RemoveFromCartArgs } from './types';
import { RemoveFromCartSchema } from './zod';

export async function removeFromCart(body: unknown) {
export async function removeFromCart(body: RemoveFromCartArgs) {
const prisma = getPrismaClient();
const validatedData = RemoveFromCartSchema.parse(body);

Expand Down
9 changes: 3 additions & 6 deletions libs/items/src/services/cart/remove-from-cart/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { CartItem } from '@prisma/client';

import { removeFromCart } from './services';
import { RemoveFromCartSchemaType } from './zod';

export type RemoveFromCartRequest = RemoveFromCartSchemaType;
export type RemoveFromCartArgs = RemoveFromCartSchemaType;

export type RemoveFromCartResponse = {
data: CartItem;
};
export type RemoveFromCartResult = Awaited<ReturnType<typeof removeFromCart>>;
5 changes: 3 additions & 2 deletions libs/items/src/services/categories/create-category/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { getPrismaClient } from '@vestido-ecommerce/models';
import { VestidoError } from '@vestido-ecommerce/utils';

import { validateSlug } from '../../slug';
import { CreateCategorySchema, CreateCategorySchemaType } from './zod';
import { CreateCategoryArgs } from './types';
import { CreateCategorySchema } from './zod';

export async function createCategory(body: CreateCategorySchemaType) {
export async function createCategory(body: CreateCategoryArgs) {
const prisma = getPrismaClient();

const validatedData = CreateCategorySchema.parse(body);
Expand Down
11 changes: 3 additions & 8 deletions libs/items/src/services/categories/create-category/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Category } from '@prisma/client';

import { createCategory } from './service';
import { CreateCategorySchemaType } from './zod';

export type CreateCategoryRequest = {
data: CreateCategorySchemaType;
};
export type CreateCategoryArgs = CreateCategorySchemaType;

export type CreateCategoryResponse = {
data: Category;
};
export type CreateCategoryResult = Awaited<ReturnType<typeof createCategory>>;
6 changes: 2 additions & 4 deletions libs/items/src/services/categories/get-category/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Category } from '@prisma/client';
import { categoryDetails } from './service';

export type CategoryDetailsResponse = {
data: Category;
};
export type CategoryDetailsResult = Awaited<ReturnType<typeof categoryDetails>>;
4 changes: 2 additions & 2 deletions libs/items/src/services/categories/list-category/service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getPrismaClient } from '@vestido-ecommerce/models';

import { ListCategoryRequest } from './types';
import { ListCategoryArgs } from './types';
import { ListCategoryRequestSchema } from './zod';

export async function listCategories(_args: ListCategoryRequest) {
export async function listCategories(_args: ListCategoryArgs) {
const prisma = getPrismaClient();
const args = ListCategoryRequestSchema.parse(_args);

Expand Down
4 changes: 2 additions & 2 deletions libs/items/src/services/categories/list-category/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type listCategories } from './service';
import { ListCategoryRequestSchemaType } from './zod';

export type ListCategoryRequest = ListCategoryRequestSchemaType;
export type ListCategoriesResponse = Awaited<ReturnType<typeof listCategories>>;
export type ListCategoryArgs = ListCategoryRequestSchemaType;
export type ListCategoryResult = Awaited<ReturnType<typeof listCategories>>;
4 changes: 2 additions & 2 deletions libs/items/src/services/categories/update-category/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { getPrismaClient } from '@vestido-ecommerce/models';
import { VestidoError } from '@vestido-ecommerce/utils';

import { validateSlug } from '../../slug';
import { UpdateCategoryRequest } from './types';
import { UpdateCategoryArgs } from './types';
import { UpdateCategorySchema } from './zod';

export async function updateCategory(
categoryId: string,
data: UpdateCategoryRequest,
data: UpdateCategoryArgs,
) {
const prisma = getPrismaClient();

Expand Down
11 changes: 3 additions & 8 deletions libs/items/src/services/categories/update-category/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Category } from '@prisma/client';

import { updateCategory } from './service';
import { UpdateCategorySchemaType } from './zod';

export type UpdateCategoryRequest = {
data: UpdateCategorySchemaType;
};
export type UpdateCategoryArgs = UpdateCategorySchemaType;

export type UpdateCategoryResponse = {
data: Category;
};
export type UpdateCategoryResult = Awaited<ReturnType<typeof updateCategory>>;
1 change: 1 addition & 0 deletions libs/items/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './cart/get-cart';
export * from './cart/remove-from-cart';
export * from './categories';
export * from './items';
export * from './stocks';
export * from './variants';
export * from './wishlist/add-to-wishlist';
export * from './wishlist/get-wishlist';
Expand Down
12 changes: 4 additions & 8 deletions libs/items/src/services/items/create-item/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Item } from '@prisma/client';

import { ItemUpsertSchemaType } from '../zod';
import { createItem } from './service';

export type CreateItemArgs = ItemUpsertSchemaType;

export type CreateItemRequest = {
data: ItemUpsertSchemaType;
};
export type CreateItemResponse = {
data: Item;
};
export type CreateItemResult = Awaited<ReturnType<typeof createItem>>;
6 changes: 1 addition & 5 deletions libs/items/src/services/items/get-item/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { getItemDetails } from './service';

export type ItemDetails = NonNullable<
export type ItemDetailsResult = NonNullable<
Awaited<ReturnType<typeof getItemDetails>>
>;

export type ItemDetailsResponse = {
data: ItemDetails | null;
};
4 changes: 2 additions & 2 deletions libs/items/src/services/items/list-item/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type listItem } from './service';
import { ListItemRequestSchemaType } from './zod';
export type ListItemRequest = ListItemRequestSchemaType;
export type ListItemResponse = Awaited<ReturnType<typeof listItem>>;
export type ListItemArgs = ListItemRequestSchemaType;
export type ListItemResult = Awaited<ReturnType<typeof listItem>>;
12 changes: 4 additions & 8 deletions libs/items/src/services/items/update-item/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Item } from '@prisma/client';

import { ItemUpsertSchemaType } from '../zod';
import { updateItem } from './service';

export type UpdateItemArgs = ItemUpsertSchemaType;

export type UpdateItemRequest = {
data: ItemUpsertSchemaType;
};
export type UpdateItemResponse = {
data: Item;
};
export type UpdateItemResult = Awaited<ReturnType<typeof updateItem>>;
1 change: 1 addition & 0 deletions libs/items/src/services/items/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const ItemVariantWithSizeSchema = z.object({
stockStatus: z
.nativeEnum(StockStatus)
.default('AVAILABLE' satisfies StockStatus),
stockBalance: z.number().nullish(),
});

export type ItemVariantWithSize = z.infer<typeof ItemVariantWithSizeSchema>;
Expand Down
2 changes: 2 additions & 0 deletions libs/items/src/services/stocks/get-stock-balance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './service';
export * from './types';
89 changes: 89 additions & 0 deletions libs/items/src/services/stocks/get-stock-balance/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import type { PrismaTransactionalClient } from '@vestido-ecommerce/models';
import { PrismaClient } from '@vestido-ecommerce/models';
import { VestidoError } from '@vestido-ecommerce/utils';

import { getStockStatus } from '../get-stock-status';
import { StockBalanceRow } from './types';
import { GetStockBalanceInputSchemaType } from './zod';

type StockBalanceResult = {
itemId: string;
itemVariantId: string | null;
stockBalance: number;
stockStatus: 'OUT_OF_STOCK' | 'LIMITED_STOCK' | 'AVAILABLE';
_stockBalanceRow: StockBalanceRow;
};

export async function getStockBalances(
prisma: PrismaClient | PrismaTransactionalClient,
items: GetStockBalanceInputSchemaType[],
): Promise<Record<string, StockBalanceResult>> {
const itemIdsOnly = items
.filter((i) => !i.itemVariantId)
.map((i) => i.itemId);
const variantIdsOnly = items
.filter((i) => !!i.itemVariantId)
.map((i) => i.itemVariantId!);

const rows: StockBalanceRow[] = [];
if (itemIdsOnly.length > 0) {
rows.push(
...((await prisma.$queryRawUnsafe(
`
SELECT
"id" AS "itemId",
NULL AS "itemVariantId",
"stockBalance" AS balance,
"hasVariants"
FROM "Item"
WHERE "id" = ANY($1::uuid[])
FOR UPDATE
`,
itemIdsOnly,
)) as StockBalanceRow[]),
);

const templateRows = rows.filter((r) => r.hasVariants);
if (templateRows.length > 0) {
throw new VestidoError({
message: `Some items have variants. Please specify itemVariantId instead of itemId.`,
name: 'TemplateItemCannotHaveStockBalance',
httpStatus: 400,
context: {
itemIds: templateRows.map((r) => r.itemId),
},
});
}
}

if (variantIdsOnly.length > 0) {
rows.push(
...((await prisma.$queryRawUnsafe(
`
SELECT "itemId",
"id" AS "itemVariantId",
"stockBalance" AS balance
FROM "ItemVariant"
WHERE "id" = ANY($1::uuid[])
FOR UPDATE
`,
variantIdsOnly,
)) as StockBalanceRow[]),
);
}

const result: Record<string, StockBalanceResult> = {};

for (const row of rows) {
const key = row.itemVariantId ?? row.itemId;
result[key] = {
itemId: row.itemId,
itemVariantId: row.itemVariantId,
stockBalance: row.balance,
stockStatus: getStockStatus(row.balance),
_stockBalanceRow: row,
};
}

return result;
}
Loading
Loading