chore: remove tests from .gitignore and add presigned URLs for course thumbnails in admin approval service
This commit is contained in:
parent
4e0191ed1f
commit
50ff78c594
4 changed files with 194 additions and 16 deletions
|
|
@ -3,6 +3,7 @@ import { config } from '../config';
|
|||
import { logger } from '../config/logger';
|
||||
import { UnauthorizedError, ValidationError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { getPresignedUrl } from '../config/minio';
|
||||
import {
|
||||
ListPendingCoursesResponse,
|
||||
GetCourseDetailForAdminResponse,
|
||||
|
|
@ -51,13 +52,22 @@ export class AdminCourseApprovalService {
|
|||
}
|
||||
});
|
||||
|
||||
const data = courses.map(course => ({
|
||||
id: course.id,
|
||||
title: course.title as { th: string; en: string },
|
||||
slug: course.slug,
|
||||
description: course.description as { th: string; en: string },
|
||||
thumbnail_url: course.thumbnail_url,
|
||||
status: course.status,
|
||||
const data = await Promise.all(courses.map(async (course) => {
|
||||
let thumbnail_presigned_url: string | null = null;
|
||||
if (course.thumbnail_url) {
|
||||
try {
|
||||
thumbnail_presigned_url = await getPresignedUrl(course.thumbnail_url, 3600);
|
||||
} catch (err) {
|
||||
logger.warn(`Failed to generate presigned URL for thumbnail: ${err}`);
|
||||
}
|
||||
}
|
||||
return {
|
||||
id: course.id,
|
||||
title: course.title as { th: string; en: string },
|
||||
slug: course.slug,
|
||||
description: course.description as { th: string; en: string },
|
||||
thumbnail_url: thumbnail_presigned_url,
|
||||
status: course.status,
|
||||
created_at: course.created_at,
|
||||
updated_at: course.updated_at,
|
||||
created_by: course.created_by,
|
||||
|
|
@ -70,11 +80,12 @@ export class AdminCourseApprovalService {
|
|||
chapters_count: course.chapters.length,
|
||||
lessons_count: course.chapters.reduce((sum, ch) => sum + ch.lessons.length, 0),
|
||||
latest_submission: course.courseApprovals[0] ? {
|
||||
id: course.courseApprovals[0].id,
|
||||
submitted_by: course.courseApprovals[0].submitted_by,
|
||||
created_at: course.courseApprovals[0].created_at,
|
||||
submitter: course.courseApprovals[0].submitter
|
||||
} : null
|
||||
id: course.courseApprovals[0].id,
|
||||
submitted_by: course.courseApprovals[0].submitted_by,
|
||||
created_at: course.courseApprovals[0].created_at,
|
||||
submitter: course.courseApprovals[0].submitter
|
||||
} : null
|
||||
};
|
||||
}));
|
||||
|
||||
return {
|
||||
|
|
@ -143,6 +154,16 @@ export class AdminCourseApprovalService {
|
|||
throw new NotFoundError('Course not found');
|
||||
}
|
||||
|
||||
// Generate presigned URL for thumbnail
|
||||
let thumbnail_presigned_url: string | null = null;
|
||||
if (course.thumbnail_url) {
|
||||
try {
|
||||
thumbnail_presigned_url = await getPresignedUrl(course.thumbnail_url, 3600);
|
||||
} catch (err) {
|
||||
logger.warn(`Failed to generate presigned URL for thumbnail: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
message: 'Course details retrieved successfully',
|
||||
|
|
@ -151,7 +172,7 @@ export class AdminCourseApprovalService {
|
|||
title: course.title as { th: string; en: string },
|
||||
slug: course.slug,
|
||||
description: course.description as { th: string; en: string },
|
||||
thumbnail_url: course.thumbnail_url,
|
||||
thumbnail_url: thumbnail_presigned_url,
|
||||
price: Number(course.price),
|
||||
is_free: course.is_free,
|
||||
have_certificate: course.have_certificate,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue