-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #51
- Loading branch information
Showing
10 changed files
with
240 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { NextRequest, NextResponse } from 'next/server' | ||
import { z } from 'zod' | ||
|
||
import clientPromise from '@/lib/db' | ||
import { | ||
BlockedHacker, | ||
BlockedHackerCollection, | ||
BlockedHackerSchema, | ||
} from '@/lib/db/models/BlockedHacker' | ||
import logger from '@/lib/logger' | ||
import { stringifyError } from '@/lib/utils/shared' | ||
|
||
const BodySchema = z.object({ | ||
emails: z.string().array(), | ||
decision: z.enum(['accepted', 'rejected', 'waitlisted']), | ||
}) | ||
|
||
export type ApplicationDecideRequestBody = z.infer<typeof BodySchema> | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
const body = BlockedHackerSchema.array().parse(await request.json()) | ||
|
||
const client = await clientPromise | ||
await client | ||
.db() | ||
.collection<BlockedHacker>(BlockedHackerCollection) | ||
.bulkWrite([ | ||
{ | ||
deleteMany: { filter: {} }, | ||
}, | ||
...body.map((v) => ({ | ||
insertOne: { | ||
document: v, | ||
}, | ||
})), | ||
]) | ||
|
||
return NextResponse.json({ status: 'success' }) | ||
} catch (e) { | ||
logger.error(e, request.nextUrl.pathname) | ||
return NextResponse.json({ status: 'error', message: stringifyError(e) }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
import { headers } from 'next/headers' | ||
|
||
import clientPromise from '@/lib/db' | ||
import { | ||
BlockedHacker, | ||
BlockedHackerCollection, | ||
} from '@/lib/db/models/BlockedHacker' | ||
import { getEnhancedSession } from '@/lib/utils/server' | ||
|
||
import ApplicantDataTable from './ApplicantDataTable' | ||
import { getUsers } from './utils' | ||
|
||
export default async function Applications() { | ||
const { perms } = getEnhancedSession(headers()) | ||
const client = await clientPromise | ||
const applications = ((await getUsers()) ?? []) | ||
.filter((u) => u.application) | ||
.map((u) => ({ | ||
...u.application!, | ||
email: u.email, | ||
status: u.applicationStatus ?? ('undecided' as const), | ||
})) | ||
const blockedHackers = await client | ||
.db() | ||
.collection<BlockedHacker>(BlockedHackerCollection) | ||
.find({}, { projection: { _id: 0 } }) | ||
.toArray() | ||
|
||
return <ApplicantDataTable applications={applications} perms={perms} /> | ||
return ( | ||
<ApplicantDataTable | ||
applications={applications} | ||
blockedHackers={blockedHackers} | ||
perms={perms} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.