From 502428052c079cc04d3d3063d99bb603fc3db626 Mon Sep 17 00:00:00 2001 From: xyzuan Date: Wed, 11 Dec 2024 20:12:12 +0700 Subject: [PATCH] feat(blog): Delete redis key when comment / reaction --- src/api/controller/blog/commentBlog.ts | 3 +++ src/api/controller/blog/reactionBlog.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/api/controller/blog/commentBlog.ts b/src/api/controller/blog/commentBlog.ts index f1afa02..82a7a89 100644 --- a/src/api/controller/blog/commentBlog.ts +++ b/src/api/controller/blog/commentBlog.ts @@ -4,6 +4,7 @@ import { BadRequestException } from "@constants/exceptions"; import { rateLimit } from "elysia-rate-limit"; import { createElysia } from "@libs/elysia"; import blogModel from "@models/blog.model"; +import { redis } from "@libs/redisClient"; export default createElysia() .use(blogModel) @@ -26,6 +27,8 @@ export default createElysia() throw new BadRequestException("Blog not found."); } + await redis.del(`blog.${blog.slug}`); + return { status: 200, data: await prismaClient.blogComment.create({ diff --git a/src/api/controller/blog/reactionBlog.ts b/src/api/controller/blog/reactionBlog.ts index a13f36d..70e1bc2 100644 --- a/src/api/controller/blog/reactionBlog.ts +++ b/src/api/controller/blog/reactionBlog.ts @@ -3,6 +3,7 @@ import { prismaClient } from "@libs/prismaDatabase"; import { BadRequestException } from "@constants/exceptions"; import { createElysia } from "@libs/elysia"; import blogModel from "@models/blog.model"; +import { redis } from "@libs/redisClient"; export default createElysia() .use(blogModel) @@ -20,6 +21,8 @@ export default createElysia() throw new BadRequestException("Blog not found."); } + await redis.del(`blog.${blog.slug}`); + const existingReaction = await prismaClient.blogReaction.findFirst({ where: { blogId: blog.id,