From 9137b5e1e64f2df09f58191a7b4d18f57cd74871 Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Thu, 26 Mar 2026 00:49:47 +0530 Subject: [PATCH] enh --- apps/backend/src/dbService.ts | 220 +------------------------- apps/backend/src/postgresImporter.ts | 221 +++++++++++++++++++++++++++ 2 files changed, 228 insertions(+), 213 deletions(-) create mode 100644 apps/backend/src/postgresImporter.ts diff --git a/apps/backend/src/dbService.ts b/apps/backend/src/dbService.ts index 8615e8e..49f4478 100644 --- a/apps/backend/src/dbService.ts +++ b/apps/backend/src/dbService.ts @@ -1,221 +1,15 @@ // Database Service - Central export for all database-related imports -// This file re-exports everything from postgresService to provide a clean abstraction layer -// Implementation is the responsibility of postgresService package +// This file re-exports everything from postgresImporter to provide a clean abstraction layer -import { getOrderDetails as getOrderDetailsFromDb } from 'postgresService' import type { AdminOrderDetails } from '@packages/shared' +import { getOrderDetails } from '@/src/postgresImporter' -// Re-export database connection -export { db } from 'postgresService' +// Re-export everything from postgresImporter +export * from '@/src/postgresImporter' -// Re-export all schema exports -export * from 'postgresService' - -// Re-export methods from postgresService (implementation lives there) - -export { - // Banner methods - getBanners, - getBannerById, - createBanner, - updateBanner, - deleteBanner, - // Complaint methods - getComplaints, - resolveComplaint, - // Constants methods - getAllConstants, - upsertConstants, - // Coupon methods - getAllCoupons, - getCouponById, - invalidateCoupon, - validateCoupon, - getReservedCoupons, - getUsersForCoupon, - createCouponWithRelations, - updateCouponWithRelations, - generateCancellationCoupon, - createReservedCouponWithProducts, - createCouponForUser, - checkUsersExist, - checkCouponExists, - checkReservedCouponExists, - getOrderWithUser, - // Store methods - getAllStores, - getStoreById, - createStore, - updateStore, - deleteStore, - // Staff-user methods - getStaffUserByName, - getAllStaff, - getAllUsers, - getUserWithDetails, - updateUserSuspensionStatus, - checkStaffUserExists, - checkStaffRoleExists, - createStaffUser, - getAllRoles, - // User methods - createUserByMobile, - getUserByMobile, - getUnresolvedComplaintsCount, - getAllUsersWithFilters, - getOrderCountsByUserIds, - getLastOrdersByUserIds, - getSuspensionStatusesByUserIds, - getUserBasicInfo, - getUserSuspensionStatus, - getUserOrders, - getOrderStatusesByOrderIds, - getItemCountsByOrderIds, - upsertUserSuspension, - searchUsers, - getAllNotifCreds, - getAllUnloggedTokens, - getNotifTokensByUserIds, - getUserIncidentsWithRelations, - createUserIncident, - // Vendor-snippets methods - checkVendorSnippetExists, - getVendorSnippetById, - getVendorSnippetByCode, - getAllVendorSnippets, - createVendorSnippet, - updateVendorSnippet, - deleteVendorSnippet, - getProductsByIds, - getVendorSlotById, - getVendorOrdersBySlotId, - getOrderItemsByOrderIds, - getOrderStatusByOrderIds, - updateVendorOrderItemPackaging, - getVendorOrders, - // Product methods - getAllProducts, - getProductById, - deleteProduct, - createProduct, - updateProduct, - toggleProductOutOfStock, - updateSlotProducts, - getSlotProductIds, - getSlotsProductIds, - getAllUnits, - getAllProductTags, - getProductReviews, - respondToReview, - getAllProductGroups, - createProductGroup, - updateProductGroup, - deleteProductGroup, - addProductToGroup, - removeProductFromGroup, - updateProductPrices, - // Slots methods - getActiveSlotsWithProducts, - getActiveSlots, - getSlotsAfterDate, - getSlotByIdWithRelations, - createSlotWithRelations, - updateSlotWithRelations, - deleteSlotById, - updateSlotCapacity, - getSlotDeliverySequence, - updateSlotDeliverySequence, - // User address methods - getUserDefaultAddress, - getUserAddresses, - getUserAddressById, - clearUserDefaultAddress, - createUserAddress, - updateUserAddress, - deleteUserAddress, - hasOngoingOrdersForAddress, - getUserActiveBanners, - getUserCartItemsWithProducts, - getUserProductById, - getUserCartItemByUserProduct, - incrementUserCartItemQuantity, - insertUserCartItem, - updateUserCartItemQuantity, - deleteUserCartItem, - clearUserCart, - getUserComplaints, - createUserComplaint, - getUserStoreSummaries, - getUserStoreDetail, - getUserProductDetailById, - getUserProductReviews, - getUserProductByIdBasic, - createUserProductReview, - getUserActiveSlotsList, - getUserProductAvailability, - getUserPaymentOrderById, - getUserPaymentByOrderId, - getUserPaymentByMerchantOrderId, - updateUserPaymentSuccess, - updateUserOrderPaymentStatus, - markUserPaymentFailed, - getUserAuthByEmail, - getUserAuthByMobile, - getUserAuthById, - getUserAuthCreds, - getUserAuthDetails, - createUserAuthWithCreds, - createUserAuthWithMobile, - upsertUserAuthPassword, - deleteUserAuthAccount, - getUserActiveCouponsWithRelations, - getUserAllCouponsWithRelations, - getUserReservedCouponByCode, - redeemUserReservedCoupon, - getUserProfileById, - getUserProfileDetailById, - getUserWithCreds, - getUserNotifCred, - upsertUserNotifCred, - deleteUserUnloggedToken, - getUserUnloggedToken, - upsertUserUnloggedToken, - // Order methods - updateOrderNotes, - updateOrderPackaged, - updateOrderDelivered, - updateOrderItemPackaging, - removeDeliveryCharge, - getSlotOrders, - updateAddressCoords, - getAllOrders, - rebalanceSlots, - cancelOrder, - deleteOrderById, - // User Order helpers - validateAndGetUserCoupon, - applyDiscountToUserOrder, - getUserAddressByIdAndUser, - getOrderProductById, - checkUserSuspended, - getUserSlotCapacityStatus, - placeUserOrderTransaction, - deleteUserCartItemsForOrder, - recordUserCouponUsage, - getUserOrdersWithRelations, - getUserOrderCount, - getUserOrderByIdWithRelations, - getUserCouponUsageForOrder, - getUserOrderBasic, - cancelUserOrderTransaction, - updateUserOrderNotes, - getUserRecentlyDeliveredOrderIds, - getUserProductIdsFromOrders, - getUserProductsForRecentOrders, -} from 'postgresService' - -export async function getOrderDetails(orderId: number): Promise { - return getOrderDetailsFromDb(orderId) +// Re-export getOrderDetails with the correct signature +export async function getOrderDetailsWrapper(orderId: number): Promise { + return getOrderDetails(orderId) } // Re-export all types from shared package diff --git a/apps/backend/src/postgresImporter.ts b/apps/backend/src/postgresImporter.ts new file mode 100644 index 0000000..5dee723 --- /dev/null +++ b/apps/backend/src/postgresImporter.ts @@ -0,0 +1,221 @@ +// Postgres Importer - Intermediate layer to avoid direct postgresService imports in dbService +// This file re-exports everything from postgresService + +// Re-export database connection +export { db } from 'postgresService' + +// Re-export all schema exports +export * from 'postgresService' + +// Re-export all helper methods from postgresService +export { + // Admin - Banner + getBanners, + getBannerById, + createBanner, + updateBanner, + deleteBanner, + // Admin - Complaint + getComplaints, + resolveComplaint, + // Admin - Constants + getAllConstants, + upsertConstants, + // Admin - Coupon + getAllCoupons, + getCouponById, + invalidateCoupon, + validateCoupon, + getReservedCoupons, + getUsersForCoupon, + createCouponWithRelations, + updateCouponWithRelations, + generateCancellationCoupon, + createReservedCouponWithProducts, + createCouponForUser, + checkUsersExist, + checkCouponExists, + checkReservedCouponExists, + getOrderWithUser, + // Admin - Order + updateOrderNotes, + getOrderDetails, + updateOrderPackaged, + updateOrderDelivered, + updateOrderItemPackaging, + removeDeliveryCharge, + getSlotOrders, + updateAddressCoords, + getAllOrders, + rebalanceSlots, + cancelOrder, + deleteOrderById, + // Admin - Product + getAllProducts, + getProductById, + deleteProduct, + createProduct, + updateProduct, + toggleProductOutOfStock, + updateSlotProducts, + getSlotProductIds, + getSlotsProductIds, + getAllUnits, + getAllProductTags, + getProductReviews, + respondToReview, + getAllProductGroups, + createProductGroup, + updateProductGroup, + deleteProductGroup, + addProductToGroup, + removeProductFromGroup, + updateProductPrices, + // Admin - Slots + getActiveSlotsWithProducts, + getActiveSlots, + getSlotsAfterDate, + getSlotByIdWithRelations, + createSlotWithRelations, + updateSlotWithRelations, + deleteSlotById, + updateSlotCapacity, + getSlotDeliverySequence, + updateSlotDeliverySequence, + // Admin - Staff User + getStaffUserByName, + getAllStaff, + getAllUsers, + getUserWithDetails, + updateUserSuspensionStatus, + checkStaffUserExists, + checkStaffRoleExists, + createStaffUser, + getAllRoles, + // Admin - Store + getAllStores, + getStoreById, + createStore, + updateStore, + deleteStore, + // Admin - User + createUserByMobile, + getUserByMobile, + getUnresolvedComplaintsCount, + getAllUsersWithFilters, + getOrderCountsByUserIds, + getLastOrdersByUserIds, + getSuspensionStatusesByUserIds, + getUserBasicInfo, + getUserSuspensionStatus, + getUserOrders, + getOrderStatusesByOrderIds, + getItemCountsByOrderIds, + upsertUserSuspension, + searchUsers, + getAllNotifCreds, + getAllUnloggedTokens, + getNotifTokensByUserIds, + getUserIncidentsWithRelations, + createUserIncident, + // Admin - Vendor Snippets + checkVendorSnippetExists, + getVendorSnippetById, + getVendorSnippetByCode, + getAllVendorSnippets, + createVendorSnippet, + updateVendorSnippet, + deleteVendorSnippet, + getProductsByIds, + getVendorSlotById, + getVendorOrdersBySlotId, + getOrderItemsByOrderIds, + getOrderStatusByOrderIds, + updateVendorOrderItemPackaging, + getVendorOrders, + // User - Address + getUserDefaultAddress, + getUserAddresses, + getUserAddressById, + clearUserDefaultAddress, + createUserAddress, + updateUserAddress, + deleteUserAddress, + hasOngoingOrdersForAddress, + // User - Banners + getUserActiveBanners, + // User - Cart + getUserCartItemsWithProducts, + getUserProductById, + getUserCartItemByUserProduct, + incrementUserCartItemQuantity, + insertUserCartItem, + updateUserCartItemQuantity, + deleteUserCartItem, + clearUserCart, + // User - Complaint + getUserComplaints, + createUserComplaint, + // User - Stores + getUserStoreSummaries, + getUserStoreDetail, + // User - Product + getUserProductDetailById, + getUserProductReviews, + getUserProductByIdBasic, + createUserProductReview, + // User - Slots + getUserActiveSlotsList, + getUserProductAvailability, + // User - Payments + getUserPaymentOrderById, + getUserPaymentByOrderId, + getUserPaymentByMerchantOrderId, + updateUserPaymentSuccess, + updateUserOrderPaymentStatus, + markUserPaymentFailed, + // User - Auth + getUserAuthByEmail, + getUserAuthByMobile, + getUserAuthById, + getUserAuthCreds, + getUserAuthDetails, + createUserAuthWithCreds, + createUserAuthWithMobile, + upsertUserAuthPassword, + deleteUserAuthAccount, + // User - Coupon + getUserActiveCouponsWithRelations, + getUserAllCouponsWithRelations, + getUserReservedCouponByCode, + redeemUserReservedCoupon, + // User - Profile + getUserProfileById, + getUserProfileDetailById, + getUserWithCreds, + getUserNotifCred, + upsertUserNotifCred, + deleteUserUnloggedToken, + getUserUnloggedToken, + upsertUserUnloggedToken, + // User - Order + validateAndGetUserCoupon, + applyDiscountToUserOrder, + getUserAddressByIdAndUser, + getOrderProductById, + checkUserSuspended, + getUserSlotCapacityStatus, + placeUserOrderTransaction, + deleteUserCartItemsForOrder, + recordUserCouponUsage, + getUserOrdersWithRelations, + getUserOrderCount, + getUserOrderByIdWithRelations, + getUserCouponUsageForOrder, + getUserOrderBasic, + cancelUserOrderTransaction, + updateUserOrderNotes, + getUserRecentlyDeliveredOrderIds, + getUserProductIdsFromOrders, + getUserProductsForRecentOrders, +} from 'postgresService'