mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 00:32:35 +10:00
implement button to download PDF from a public resume page
This commit is contained in:
@ -92,8 +92,13 @@ export class ResumeController {
|
||||
}
|
||||
|
||||
@Get("/public/:username/:slug")
|
||||
findOneByUsernameSlug(@Param("username") username: string, @Param("slug") slug: string) {
|
||||
return this.resumeService.findOneByUsernameSlug(username, slug);
|
||||
@UseGuards(OptionalGuard)
|
||||
findOneByUsernameSlug(
|
||||
@Param("username") username: string,
|
||||
@Param("slug") slug: string,
|
||||
@User("id") userId: string,
|
||||
) {
|
||||
return this.resumeService.findOneByUsernameSlug(username, slug, userId);
|
||||
}
|
||||
|
||||
@Patch(":id")
|
||||
@ -120,9 +125,9 @@ export class ResumeController {
|
||||
|
||||
@Get("/print/:id")
|
||||
@UseGuards(OptionalGuard, ResumeGuard)
|
||||
async printResume(@Resume() resume: ResumeDto) {
|
||||
async printResume(@User("id") userId: string | undefined, @Resume() resume: ResumeDto) {
|
||||
try {
|
||||
const url = await this.resumeService.printResume(resume);
|
||||
const url = await this.resumeService.printResume(resume, userId);
|
||||
|
||||
return { url };
|
||||
} catch (error) {
|
||||
|
||||
@ -114,13 +114,13 @@ export class ResumeService {
|
||||
return { views, downloads };
|
||||
}
|
||||
|
||||
async findOneByUsernameSlug(username: string, slug: string) {
|
||||
async findOneByUsernameSlug(username: string, slug: string, userId?: string) {
|
||||
const resume = await this.prisma.resume.findFirstOrThrow({
|
||||
where: { user: { username }, slug, visibility: "public" },
|
||||
});
|
||||
|
||||
// Update statistics: increment the number of views by 1
|
||||
await this.redis.incr(`user:${resume.userId}:resume:${resume.id}:views`);
|
||||
if (!userId) await this.redis.incr(`user:${resume.userId}:resume:${resume.id}:views`);
|
||||
|
||||
return resume;
|
||||
}
|
||||
@ -180,11 +180,11 @@ export class ResumeService {
|
||||
return this.prisma.resume.delete({ where: { userId_id: { userId, id } } });
|
||||
}
|
||||
|
||||
async printResume(resume: ResumeDto) {
|
||||
async printResume(resume: ResumeDto, userId?: string) {
|
||||
const url = await this.printerService.printResume(resume);
|
||||
|
||||
// Update statistics: increment the number of downloads by 1
|
||||
await this.redis.incr(`user:${resume.userId}:resume:${resume.id}:downloads`);
|
||||
if (!userId) await this.redis.incr(`user:${resume.userId}:resume:${resume.id}:downloads`);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user