@@ -114,6 +114,7 @@ export class AdminService {
114114 repoUrl : submission . project . repoUrl ,
115115 screenshotUrl : submission . project . screenshotUrl ,
116116 nowHackatimeHours : submission . project . nowHackatimeHours ,
117+ nowHackatimeProjects : submission . project . nowHackatimeProjects ,
117118 } ,
118119 submission : {
119120 description : submission . description ,
@@ -186,6 +187,7 @@ export class AdminService {
186187 repoUrl : true ,
187188 screenshotUrl : true ,
188189 nowHackatimeHours : true ,
190+ nowHackatimeProjects : true ,
189191 airtableRecId : true ,
190192 isLocked : true ,
191193 createdAt : true ,
@@ -236,4 +238,156 @@ export class AdminService {
236238
237239 return updatedProject ;
238240 }
241+
242+ async approveEditRequest ( requestId : number , adminUserId : number ) {
243+ const editRequest = await this . prisma . editRequest . findUnique ( {
244+ where : { requestId } ,
245+ include : {
246+ project : true ,
247+ user : true ,
248+ } ,
249+ } ) ;
250+
251+ if ( ! editRequest ) {
252+ throw new NotFoundException ( 'Edit request not found' ) ;
253+ }
254+
255+ if ( editRequest . status !== 'pending' ) {
256+ throw new ForbiddenException ( 'Edit request has already been processed' ) ;
257+ }
258+
259+ // Calculate hackatime hours if hackatime projects are being updated
260+ let calculatedHours = editRequest . project . nowHackatimeHours ;
261+ if ( ( editRequest . requestedData as any ) . nowHackatimeProjects ) {
262+ // For now, we'll set a placeholder value. In a real implementation,
263+ // you would fetch hours from the hackatime API based on project names
264+ calculatedHours = ( ( editRequest . requestedData as any ) . nowHackatimeProjects as string [ ] ) . length * 10 ; // Placeholder calculation
265+ }
266+
267+ // Update the project with the requested data
268+ const updateData : any = { } ;
269+ if ( ( editRequest . requestedData as any ) . projectTitle !== undefined ) {
270+ updateData . projectTitle = ( editRequest . requestedData as any ) . projectTitle ;
271+ }
272+ if ( ( editRequest . requestedData as any ) . description !== undefined ) {
273+ updateData . description = ( editRequest . requestedData as any ) . description ;
274+ }
275+ if ( ( editRequest . requestedData as any ) . playableUrl !== undefined ) {
276+ updateData . playableUrl = ( editRequest . requestedData as any ) . playableUrl ;
277+ }
278+ if ( ( editRequest . requestedData as any ) . repoUrl !== undefined ) {
279+ updateData . repoUrl = ( editRequest . requestedData as any ) . repoUrl ;
280+ }
281+ if ( ( editRequest . requestedData as any ) . screenshotUrl !== undefined ) {
282+ updateData . screenshotUrl = ( editRequest . requestedData as any ) . screenshotUrl ;
283+ }
284+ if ( ( editRequest . requestedData as any ) . airtableRecId !== undefined ) {
285+ updateData . airtableRecId = ( editRequest . requestedData as any ) . airtableRecId ;
286+ }
287+ if ( ( editRequest . requestedData as any ) . nowHackatimeProjects !== undefined ) {
288+ updateData . nowHackatimeProjects = ( editRequest . requestedData as any ) . nowHackatimeProjects ;
289+ updateData . nowHackatimeHours = calculatedHours ;
290+ }
291+
292+ // Update the project
293+ const updatedProject = await this . prisma . project . update ( {
294+ where : { projectId : editRequest . projectId } ,
295+ data : updateData ,
296+ } ) ;
297+
298+ // Update the edit request status
299+ const updatedEditRequest = await this . prisma . editRequest . update ( {
300+ where : { requestId } ,
301+ data : {
302+ status : 'approved' ,
303+ reviewedBy : adminUserId ,
304+ reviewedAt : new Date ( ) ,
305+ } ,
306+ include : {
307+ user : {
308+ select : {
309+ userId : true ,
310+ firstName : true ,
311+ lastName : true ,
312+ email : true ,
313+ } ,
314+ } ,
315+ project : {
316+ select : {
317+ projectId : true ,
318+ projectTitle : true ,
319+ projectType : true ,
320+ } ,
321+ } ,
322+ reviewer : {
323+ select : {
324+ userId : true ,
325+ firstName : true ,
326+ lastName : true ,
327+ email : true ,
328+ } ,
329+ } ,
330+ } ,
331+ } ) ;
332+
333+ return {
334+ message : 'Edit request approved successfully.' ,
335+ editRequest : updatedEditRequest ,
336+ project : updatedProject ,
337+ } ;
338+ }
339+
340+ async rejectEditRequest ( requestId : number , reason : string , adminUserId : number ) {
341+ const editRequest = await this . prisma . editRequest . findUnique ( {
342+ where : { requestId } ,
343+ } ) ;
344+
345+ if ( ! editRequest ) {
346+ throw new NotFoundException ( 'Edit request not found' ) ;
347+ }
348+
349+ if ( editRequest . status !== 'pending' ) {
350+ throw new ForbiddenException ( 'Edit request has already been processed' ) ;
351+ }
352+
353+ const updatedEditRequest = await this . prisma . editRequest . update ( {
354+ where : { requestId } ,
355+ data : {
356+ status : 'rejected' ,
357+ reason,
358+ reviewedBy : adminUserId ,
359+ reviewedAt : new Date ( ) ,
360+ } ,
361+ include : {
362+ user : {
363+ select : {
364+ userId : true ,
365+ firstName : true ,
366+ lastName : true ,
367+ email : true ,
368+ } ,
369+ } ,
370+ project : {
371+ select : {
372+ projectId : true ,
373+ projectTitle : true ,
374+ projectType : true ,
375+ } ,
376+ } ,
377+ reviewer : {
378+ select : {
379+ userId : true ,
380+ firstName : true ,
381+ lastName : true ,
382+ email : true ,
383+ } ,
384+ } ,
385+ } ,
386+ } ) ;
387+
388+ return {
389+ message : 'Edit request rejected successfully.' ,
390+ editRequest : updatedEditRequest ,
391+ } ;
392+ }
239393}
0 commit comments