-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): comments not working and modifying cache tool
- Loading branch information
1 parent
5d1bf13
commit 2dc5085
Showing
10 changed files
with
96 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,50 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { CommentDao } from './dao/comment.dao'; | ||
import { CommentQueryDto } from './dto'; | ||
import { CommentDto, CommentQueryDto } from './dto'; | ||
import { CACHE_MANAGER } from '@nestjs/cache-manager'; | ||
import { Cache } from 'cache-manager'; | ||
|
||
@Injectable() | ||
export class CommentsService { | ||
constructor(private commentDao: CommentDao) {} | ||
constructor( | ||
@Inject(CACHE_MANAGER) private cacheManager: Cache, | ||
private commentDao: CommentDao, | ||
) {} | ||
|
||
getComments(query: CommentQueryDto) { | ||
return this.commentDao.getComments(query); | ||
async get(query: CommentQueryDto): Promise<CommentDto[]> { | ||
if (query.listId && !query.userId && !query.commentId) { | ||
let comments = await this.cacheManager.get<CommentDto[]>( | ||
`${query.listId}-comments`, | ||
); | ||
|
||
if (comments) { | ||
return comments; | ||
} | ||
|
||
comments = await this.commentDao.getComments(query); | ||
await this.cacheManager.set(`${query.listId}-comments`, comments); | ||
|
||
return comments; | ||
} | ||
|
||
return await this.commentDao.getComments(query); | ||
} | ||
|
||
createComment(comment: string, listId: string, userId: string) { | ||
async create(comment: string, listId: string, userId: string) { | ||
await this.cacheManager.del(`${listId}-comments`); | ||
|
||
return this.commentDao.createComment(listId, userId, comment); | ||
} | ||
|
||
updateComment(comment: string, commentId: string) { | ||
async update(comment: string, commentId: string, listId: string) { | ||
await this.cacheManager.del(`${listId}-comments`); | ||
|
||
return this.commentDao.updateComment(commentId, comment); | ||
} | ||
|
||
deleteComment(commentId: string) { | ||
async delete(commentId: string, listId: string) { | ||
await this.cacheManager.del(`${listId}-comments`); | ||
|
||
return this.commentDao.deleteComment(commentId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters