( data: InputTypeApproveIntroComment, )
| 289 | } |
| 290 | }; |
| 291 | const approveIntroCommentHandler = async ( |
| 292 | data: InputTypeApproveIntroComment, |
| 293 | ): Promise<ReturnTypeApproveIntroComment> => { |
| 294 | const session = await getServerSession(authOptions); |
| 295 | const { content_comment_ids, approved, adminPassword, currentPath } = data; |
| 296 | |
| 297 | if (adminPassword) { |
| 298 | if (adminPassword !== process.env.ADMIN_SECRET) { |
| 299 | return { error: 'Unauthorized' }; |
| 300 | } |
| 301 | } else if (!session || !session.user || session.user.role !== ROLES.ADMIN) { |
| 302 | return { error: 'Unauthorized ' }; |
| 303 | } |
| 304 | |
| 305 | const [contentId, commentId] = content_comment_ids.split(';'); |
| 306 | try { |
| 307 | const existingComment = await prisma.comment.findUnique({ |
| 308 | where: { id: parseInt(commentId, 10) }, |
| 309 | }); |
| 310 | |
| 311 | if (!existingComment) { |
| 312 | return { error: 'Comment not found.' }; |
| 313 | } |
| 314 | |
| 315 | const introData = parseIntroComment(existingComment.content); |
| 316 | |
| 317 | if ( |
| 318 | !introData || |
| 319 | introData.length === 0 || |
| 320 | existingComment.commentType !== CommentType.INTRO |
| 321 | ) { |
| 322 | return { |
| 323 | error: |
| 324 | 'Comment is not an intro comment or can not be parsed. Plese check that last segment has end time include.', |
| 325 | }; |
| 326 | } |
| 327 | // Update the comment but if its admin we need to check if the comment is approved |
| 328 | const updObj = { |
| 329 | approved, |
| 330 | }; |
| 331 | let updatedComment = null; |
| 332 | await prisma.$transaction(async (prisma) => { |
| 333 | updatedComment = await prisma.comment.update({ |
| 334 | where: { id: parseInt(commentId, 10) }, |
| 335 | data: updObj, |
| 336 | }); |
| 337 | await prisma.videoMetadata.update({ |
| 338 | where: { |
| 339 | contentId: Number(contentId), |
| 340 | }, |
| 341 | data: { |
| 342 | segments: introData, |
| 343 | }, |
| 344 | }); |
| 345 | }); |
| 346 | if (currentPath) { |
| 347 | revalidatePath(currentPath); |
| 348 | } |
nothing calls this directly
no test coverage detected