mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 23:54:02 +00:00
feat(bot): add self-hosted scheduled dispatch support
Co-authored-by: claw <stanislavkalishin+claw@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { and, asc, eq } from 'drizzle-orm'
|
||||
import { and, asc, eq, lte } from 'drizzle-orm'
|
||||
|
||||
import { createDbClient, schema } from '@household/db'
|
||||
import { instantFromDatabaseValue, instantToDate, nowInstant } from '@household/domain'
|
||||
@@ -129,6 +129,26 @@ export function createDbScheduledDispatchRepository(databaseUrl: string): {
|
||||
return rows.map(mapScheduledDispatch)
|
||||
},
|
||||
|
||||
async listDueScheduledDispatches(input) {
|
||||
const filters = [
|
||||
eq(schema.scheduledDispatches.status, 'scheduled'),
|
||||
lte(schema.scheduledDispatches.dueAt, instantToDate(input.dueBefore))
|
||||
]
|
||||
|
||||
if (input.provider) {
|
||||
filters.push(eq(schema.scheduledDispatches.provider, input.provider))
|
||||
}
|
||||
|
||||
const rows = await db
|
||||
.select(scheduledDispatchSelect())
|
||||
.from(schema.scheduledDispatches)
|
||||
.where(and(...filters))
|
||||
.orderBy(asc(schema.scheduledDispatches.dueAt), asc(schema.scheduledDispatches.createdAt))
|
||||
.limit(input.limit)
|
||||
|
||||
return rows.map(mapScheduledDispatch)
|
||||
},
|
||||
|
||||
async updateScheduledDispatch(input) {
|
||||
const updates: Record<string, unknown> = {
|
||||
updatedAt: instantToDate(input.updatedAt)
|
||||
|
||||
Reference in New Issue
Block a user