@@ -241,6 +241,94 @@ export const threadInfo = async function(req: Request, res: Response) {
241241 }
242242} ;
243243
244+ /*
245+ return msg: {
246+ list: [
247+ {
248+ threadInfo,
249+ threadAuthor,
250+ },
251+ {
252+ threadInfo,
253+ threadAuthor,
254+ },
255+ {
256+ threadInfo,
257+ threadAuthor,
258+ },
259+ ]
260+ }
261+ */
262+ export const threadGetTop3 = async function ( req :Request , res : Response ) {
263+ try {
264+ verifyJWT ( req . header ( "Authorization" ) ) ;
265+
266+ let { fid } = req . params ;
267+ let topArr : Array < Thread > = [ ] ;
268+ let threadTop1 = await prisma . threads ( {
269+ where : {
270+ top : 1 ,
271+ forum : {
272+ id : fid
273+ }
274+ } ,
275+ orderBy : "lastDate_DESC"
276+ } )
277+ if ( threadTop1 . length > 0 ) {
278+ topArr . push ( threadTop1 [ 0 ] ) ;
279+ } else {
280+ topArr . push ( null ) ;
281+ }
282+ let threadMostPost = await prisma . threads ( {
283+ where : {
284+ top : 0 ,
285+ forum : {
286+ id : fid
287+ } ,
288+ active : true
289+ } ,
290+ orderBy : "postCount_DESC"
291+ } )
292+ if ( threadMostPost . length > 0 ) {
293+ topArr . push ( threadMostPost [ 0 ] ) ;
294+ } else {
295+ topArr . push ( null ) ;
296+ }
297+ let threadNewUpdate = await prisma . threads ( {
298+ where : {
299+ top : 0 ,
300+ forum : {
301+ id : fid
302+ } ,
303+ active : true ,
304+ } ,
305+ orderBy : "updatedAt_DESC"
306+ } )
307+ if ( threadNewUpdate . length > 1 ) {
308+ if ( topArr [ 1 ] !== null && threadNewUpdate [ 0 ] . id === topArr [ 1 ] . id ) {
309+ topArr . push ( threadNewUpdate [ 1 ] ) ;
310+ } else {
311+ topArr . push ( threadNewUpdate [ 0 ] ) ;
312+ }
313+ } else {
314+ topArr . push ( null ) ;
315+ }
316+
317+ const resultArr = await Promise . all (
318+ topArr . map ( async item => {
319+ return item ? {
320+ thread : item ,
321+ user : filterUserInfo (
322+ await prisma . thread ( { id : item . id } ) . user ( )
323+ )
324+ } : null ;
325+ } )
326+ ) ;
327+ res . json ( { code : 1 , msg : { list : resultArr } } ) ;
328+ } catch ( e ) {
329+ res . json ( { code : - 1 , msg : e . message } ) ;
330+ }
331+ }
244332export const threadCreate = async function ( req : Request , res : Response ) {
245333 try {
246334 const {
@@ -713,6 +801,7 @@ export const threadTop = async function(req: Request, res: Response) {
713801 }
714802} ;
715803
804+
716805export const threadClose = async function ( req : Request , res : Response ) {
717806 try {
718807 const authObj = verifyJWT ( req . header ( "Authorization" ) ) ;
0 commit comments