File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
src/routes/api/admin/guilds/[guild]/tickets Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ const { pools } = require ( '../../../../../../lib/threads' ) ;
2+ const { export : pool } = pools ;
3+
4+ module . exports . get = fastify => ( {
5+ handler : async ( req , res ) => {
6+ /** @type {import('client') } */
7+ const client = req . routeOptions . config . client ;
8+ const guildId = req . params . guild ;
9+ const ticketId = req . params . ticket ;
10+ const ticket = await client . prisma . ticket . findUnique ( {
11+ include : {
12+ archivedChannels : true ,
13+ archivedMessages : true ,
14+ archivedRoles : true ,
15+ archivedUsers : true ,
16+ feedback : true ,
17+ questionAnswers : true ,
18+ } ,
19+ where : {
20+ guildId, // ! prevent unauthorised access
21+ id : ticketId ,
22+ } ,
23+ } ) ;
24+
25+ if ( ! ticket ) return res . status ( 404 ) . send ( new Error ( 'Not Found' ) ) ;
26+
27+ res . header ( 'Content-Type' , 'application/json' ) ; // exportTicket returns stringified JSON
28+ return await pool . queue ( w => w . exportTicket ( ticket ) ) ;
29+ } ,
30+ onRequest : [ fastify . authenticate , fastify . isAdmin ] ,
31+ } ) ;
Original file line number Diff line number Diff line change 1+ const { pools } = require ( '../../../../../../lib/threads' ) ;
2+ const { crypto } = pools ;
3+
4+ module . exports . get = fastify => ( {
5+ handler : async req => {
6+ /** @type {import('client') } */
7+ const client = req . routeOptions . config . client ;
8+ const { query } = req ;
9+ // TODO: advanced filters
10+ const tickets = await client . prisma . ticket . findMany ( {
11+ orderBy : { createdAt : 'asc' } ,
12+ where : {
13+ createdAt : { gte : query . since && new Date ( ( Number ( query . since ) * 1000 ) || query . since ) } ,
14+ guildId : req . params . guild ,
15+ } ,
16+ } ) ;
17+ return Promise . all (
18+ tickets . map ( async ticket => {
19+ ticket . closedReason &&= await crypto . queue ( w => w . decrypt ( ticket . closedReason ) ) ;
20+ ticket . topic &&= await crypto . queue ( w => w . decrypt ( ticket . topic ) ) ;
21+ return ticket ;
22+ } ) ,
23+ ) ;
24+ } ,
25+ onRequest : [ fastify . authenticate , fastify . isAdmin ] ,
26+ } ) ;
27+
You can’t perform that action at this time.
0 commit comments