Files
comroots-backend/src/loaders/createApplicationStatusLoader.ts
T
2026-06-24 14:10:53 +02:00

15 lines
627 B
TypeScript

import orm from '@src/type-orm.source'
import DataLoader from 'dataloader'
export const createApplicationStatusLoader = () =>
new DataLoader<{ offerId: number, userId: number }, String | null>(async (keys) => {
const applications: { id: number, offerId: number, userId: number, status: string }[] = await orm.createQueryBuilder()
.select('*')
.from('offer_application', 'oa')
.orWhere(keys)
.execute()
return keys.map(key => {
const application = applications.find(a => a.offerId == key.offerId && a.userId == key.userId)
return application ? application.status : null
})
})