freshyo/apps/backend/src/sqliteImporter.ts
2026-08-15 10:34:28 +05:30

295 lines
6.9 KiB
TypeScript

// SQLite Importer - Intermediate layer to avoid direct db_helper_sqlite imports in dbService
// This file re-exports everything from sqliteService
// Re-export database connection
import type { D1Database } from '@cloudflare/workers-types'
import { db, initDb as initDbBase } from 'sqliteService'
export { db }
let dbInitialized = false
export const initDb = (database: D1Database) => {
if (dbInitialized) return
initDbBase(database)
dbInitialized = true
}
// Re-export all schema exports
export * from 'sqliteService'
// Re-export all helper methods from sqliteService
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,
checkProductExistsByName,
checkUnitExists,
getProductImagesById,
createSpecialDealsForSku,
updateSkuDeals,
replaceProductTags,
replaceTagProducts,
mergeSkus,
updateSlotProducts,
getSlotsProductIds,
getAllUnits,
getAllProductTags,
getAllProductTagInfos,
getProductTagInfoById,
createProductTag,
getProductTagById,
updateProductTag,
deleteProductTag,
checkProductTagExistsByName,
getProductReviews,
respondToReview,
getAllProductGroups,
createProductGroup,
updateProductGroup,
deleteProductGroup,
addProductToGroup,
removeProductFromGroup,
updateProductPrices,
// Merge duplicate products into multi-SKU products
mergeDuplicateProducts,
// Admin - Slots
getActiveSlotsWithProducts,
getActiveSlots,
getSlotsAfterDate,
getSlotByIdWithRelations,
createSlotWithRelations,
updateSlotWithRelations,
deleteSlotById,
updateSlotCapacity,
getSlotDeliverySequence,
updateSlotDeliverySequence,
staleSlotsCleanup,
// Admin - Staff User
getStaffUserByName,
getStaffUserById,
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 - Complaint
getUserComplaints,
createUserComplaint,
// User - Stores
getUserStoreSummaries,
getUserStoreDetail,
// User - Product
getUserProductDetailById,
getUserProductReviews,
getUserProductByIdBasic,
createUserProductReview,
getAllProductsWithUnits,
type ProductSummaryData,
// User - Slots
getUserActiveSlotsList,
getUserProductAvailability,
// User - Payments
getUserPaymentOrderById,
getUserPaymentByOrderId,
getUserPaymentByMerchantOrderId,
updateUserPaymentSuccess,
updateUserOrderPaymentStatus,
markUserPaymentFailed,
// User - Auth
getUserAuthByEmail,
getUserAuthByMobile,
getUserAuthById,
getUserAuthCreds,
getUserAuthDetails,
isUserSuspended,
createUserAuthWithCreds,
createUserAuthWithMobile,
upsertUserAuthPassword,
deleteUserAuthAccount,
// UV API helpers
createUserWithProfile,
getUserDetailsByUserId,
updateUserProfile,
// 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,
// Store Helpers
getAllBannersForCache,
getAllProductsForCache,
getAvailabilityForCache,
getAllStoresForCache,
getAllDeliverySlotsForCache,
getAllSpecialDealsForCache,
getAllProductTagsForCache,
getAllTagsForCache,
getAllTagProductMappings,
getAllSlotsWithProductsForCache,
getAllUserNegativityScores,
getUserNegativityScore,
type BannerData,
type ProductBasicData,
type StoreBasicData,
type DeliverySlotData,
type SpecialDealData,
type ProductTagData,
type TagBasicData,
type TagProductMapping,
type SlotWithProductsData,
type UserNegativityData,
// Automated Jobs
toggleKeyVal,
getAllKeyValStore,
// Post-order handler helpers
getOrdersByIdsWithFullData,
getOrderByIdWithFullData,
type OrderWithFullData,
type OrderWithCancellationData,
// Common API helpers
getSuspendedSkuIds,
getNextDeliveryDateWithCapacity,
getStoresSummary,
healthCheck,
// Delete orders helper
deleteOrdersWithRelations,
// Seed helpers
seedUnits,
seedStaffRoles,
seedStaffPermissions,
seedRolePermissions,
seedKeyValStore,
type UnitSeedData,
type RolePermissionAssignment,
type KeyValSeedData,
type StaffRoleName,
type StaffPermissionName,
// Upload URL Helpers
createUploadUrlStatus,
claimUploadUrlStatus,
} from 'sqliteService'