26 lines
989 B
TypeScript
26 lines
989 B
TypeScript
import { db } from '../../db/db_index'
|
|
import { deliverySlotInfo, productInfo } from '../../db/schema'
|
|
import { eq } from 'drizzle-orm'
|
|
import { IUserSlotDbService, Slot } from '../../../../backend/src/trpc/apis/user-apis/dataAccessors/interfaces/user-slot-db-service.interface'
|
|
|
|
export class UserSlotDbService implements IUserSlotDbService {
|
|
async getActiveSlots(): Promise<Slot[]> {
|
|
return db.query.deliverySlotInfo.findMany({
|
|
where: eq(deliverySlotInfo.isActive, true),
|
|
})
|
|
}
|
|
|
|
async getProductAvailability(): Promise<Array<{ id: number; name: string; isOutOfStock: boolean; isFlashAvailable: boolean }>> {
|
|
return db
|
|
.select({
|
|
id: productInfo.id,
|
|
name: productInfo.name,
|
|
isOutOfStock: productInfo.isOutOfStock,
|
|
isFlashAvailable: productInfo.isFlashAvailable,
|
|
})
|
|
.from(productInfo)
|
|
.where(eq(productInfo.isSuspended, false))
|
|
}
|
|
}
|
|
|
|
export const userSlotDbService: IUserSlotDbService = new UserSlotDbService()
|