enh
This commit is contained in:
parent
588cbe00f3
commit
1b62c6add4
5 changed files with 10 additions and 66 deletions
|
|
@ -73,7 +73,6 @@ export {
|
|||
updateSkuDeals,
|
||||
replaceProductTags,
|
||||
mergeSkus,
|
||||
toggleSkuOutOfStock,
|
||||
updateSlotProducts,
|
||||
getSlotProductIds,
|
||||
getSlotsProductIds,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import {
|
|||
getAllProducts as getAllProductsInDb,
|
||||
getProductById as getProductByIdInDb,
|
||||
deleteProduct as deleteProductInDb,
|
||||
toggleProductOutOfStock as toggleProductOutOfStockInDb,
|
||||
updateSlotProducts as updateSlotProductsInDb,
|
||||
getSlotProductIds as getSlotProductIdsInDb,
|
||||
getSlotsProductIds as getSlotsProductIdsInDb,
|
||||
|
|
@ -21,11 +20,9 @@ import {
|
|||
checkProductExistsByName,
|
||||
checkUnitExists,
|
||||
createProduct as createProductInDb,
|
||||
createSpecialDealsForProduct,
|
||||
replaceProductTags,
|
||||
getProductImagesById,
|
||||
updateProduct as updateProductInDb,
|
||||
updateProductDeals,
|
||||
checkProductTagExistsByName,
|
||||
createProductTag as createProductTagInDb,
|
||||
updateProductTag as updateProductTagInDb,
|
||||
|
|
@ -44,7 +41,6 @@ import type {
|
|||
AdminProductListResponse,
|
||||
AdminProductResponse,
|
||||
AdminDeleteProductResult,
|
||||
AdminToggleOutOfStockResult,
|
||||
AdminUpdateSlotProductsResult,
|
||||
AdminSlotProductIdsResult,
|
||||
AdminSlotsProductIdsResult,
|
||||
|
|
@ -187,46 +183,6 @@ export const productRouter = router({
|
|||
}
|
||||
}),
|
||||
|
||||
toggleOutOfStock: protectedProcedure
|
||||
.input(z.object({
|
||||
id: z.number(),
|
||||
}))
|
||||
.mutation(async ({ input }): Promise<AdminToggleOutOfStockResult> => {
|
||||
const { id } = input;
|
||||
|
||||
const updatedProduct = await toggleProductOutOfStockInDb(id)
|
||||
|
||||
/*
|
||||
// Old implementation - direct DB queries:
|
||||
const product = await db.query.productInfo.findFirst({
|
||||
where: eq(productInfo.id, id),
|
||||
});
|
||||
|
||||
if (!product) {
|
||||
throw new ApiError("Product not found", 404);
|
||||
}
|
||||
|
||||
const [updatedProduct] = await db
|
||||
.update(productInfo)
|
||||
.set({
|
||||
isOutOfStock: !product.isOutOfStock,
|
||||
})
|
||||
.where(eq(productInfo.id, id))
|
||||
.returning();
|
||||
*/
|
||||
|
||||
if (!updatedProduct) {
|
||||
throw new ApiError('Product not found', 404)
|
||||
}
|
||||
|
||||
await scheduleStoreInitialization()
|
||||
|
||||
return {
|
||||
product: updatedProduct,
|
||||
message: `Product marked as ${updatedProduct.isOutOfStock ? 'out of stock' : 'in stock'}`,
|
||||
}
|
||||
}),
|
||||
|
||||
createProduct: protectedProcedure
|
||||
.input(z.object({
|
||||
name: z.string().min(1, 'Name is required'),
|
||||
|
|
@ -386,16 +342,16 @@ export const productRouter = router({
|
|||
updateSlotProducts: protectedProcedure
|
||||
.input(z.object({
|
||||
slotId: z.string(),
|
||||
productIds: z.array(z.string()),
|
||||
skuIds: z.array(z.string()),
|
||||
}))
|
||||
.mutation(async ({ input }): Promise<AdminUpdateSlotProductsResult> => {
|
||||
const { slotId, productIds } = input;
|
||||
const { slotId, skuIds } = input;
|
||||
|
||||
if (!Array.isArray(productIds)) {
|
||||
throw new ApiError("productIds must be an array", 400);
|
||||
if (!Array.isArray(skuIds)) {
|
||||
throw new ApiError("skuIds must be an array", 400);
|
||||
}
|
||||
|
||||
const result = await updateSlotProductsInDb(slotId, productIds)
|
||||
const result = await updateSlotProductsInDb(slotId, skuIds)
|
||||
|
||||
/*
|
||||
// Old implementation - direct DB queries:
|
||||
|
|
@ -460,7 +416,7 @@ export const productRouter = router({
|
|||
.query(async ({ input }): Promise<AdminSlotProductIdsResult> => {
|
||||
const { slotId } = input;
|
||||
|
||||
const productIds = await getSlotProductIdsInDb(slotId)
|
||||
const skuIds = await getSlotProductIdsInDb(slotId)
|
||||
|
||||
/*
|
||||
// Old implementation - direct DB queries:
|
||||
|
|
@ -474,12 +430,7 @@ export const productRouter = router({
|
|||
const productIds = associations.map(assoc => assoc.productId);
|
||||
|
||||
return {
|
||||
productIds,
|
||||
};
|
||||
*/
|
||||
|
||||
return {
|
||||
productIds,
|
||||
skuIds,
|
||||
}
|
||||
}),
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,6 @@ export {
|
|||
updateSkuDeals,
|
||||
replaceProductTags,
|
||||
mergeSkus,
|
||||
toggleSkuOutOfStock,
|
||||
updateSlotProducts,
|
||||
getSlotProductIds,
|
||||
getSlotsProductIds,
|
||||
|
|
|
|||
|
|
@ -370,7 +370,6 @@ export async function updateProduct(id: number, input: any): Promise<AdminProduc
|
|||
}
|
||||
}
|
||||
|
||||
export async function toggleSkuOutOfStock(id: number): Promise<AdminSku | null> {
|
||||
const product = await db.query.productSkus.findFirst({
|
||||
where: eq(productSkus.id, id),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -466,7 +466,8 @@ export interface AdminSpecialDeal {
|
|||
}
|
||||
|
||||
export interface AdminProductWithDetails extends AdminProduct {
|
||||
unit: AdminUnit;
|
||||
store: Store | null;
|
||||
skus: AdminSku[];
|
||||
deals: AdminSpecialDeal[];
|
||||
tags: AdminProductTagInfo[];
|
||||
}
|
||||
|
|
@ -484,11 +485,6 @@ export interface AdminDeleteProductResult {
|
|||
message: string;
|
||||
}
|
||||
|
||||
export interface AdminToggleOutOfStockResult {
|
||||
product: AdminProduct;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface AdminUpdateSlotProductsResult {
|
||||
message: string;
|
||||
added: number;
|
||||
|
|
@ -496,7 +492,7 @@ export interface AdminUpdateSlotProductsResult {
|
|||
}
|
||||
|
||||
export interface AdminSlotProductIdsResult {
|
||||
productIds: number[];
|
||||
skuIds: number[];
|
||||
}
|
||||
|
||||
export type AdminSlotsProductIdsResult = Record<number, number[]>;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue