29 lines
773 B
TypeScript
29 lines
773 B
TypeScript
import { MemberCardProps } from ':components/MemberCard.tsx'
|
|
import { db } from ':src/db/mod.ts'
|
|
import { dbToMemberCardProps } from ':src/members/mod.ts'
|
|
import { SessionHandlers } from ':src/session/mod.ts'
|
|
import { respondApi, respondApiStream } from ':src/utils.ts'
|
|
|
|
export const handler: SessionHandlers = {
|
|
GET(_req, ctx) {
|
|
try {
|
|
const memberList = dbToMemberCardProps(db)
|
|
|
|
const params = ctx.url.searchParams
|
|
|
|
const groupParam = params.get('group')
|
|
if (groupParam) {
|
|
const list = memberList.filter(
|
|
(member) => member.groups.includes(groupParam),
|
|
) as AsyncIterableIterator<MemberCardProps>
|
|
|
|
return respondApiStream(list)
|
|
}
|
|
|
|
return respondApiStream(memberList)
|
|
} catch (error) {
|
|
return respondApi('error', error)
|
|
}
|
|
},
|
|
}
|