Skip to content

Commit 91643f8

Browse files
committed
Implemented getTagById server-action in order to create dynamic metadata
1 parent d0084df commit 91643f8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/actions/tag.action.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
GetAllTagsParams,
1313
GetQuestionByTagIdParams,
1414
GetTopInteractedTagsParams,
15+
GetTagByIdParams,
1516
} from "./shared.types";
1617

1718
export async function getAllTags(params: GetAllTagsParams) {
@@ -64,6 +65,23 @@ export async function getAllTags(params: GetAllTagsParams) {
6465
}
6566
}
6667

68+
export async function getTagById(params: GetTagByIdParams) {
69+
try {
70+
connectToDatabase();
71+
72+
const { tagId } = params;
73+
74+
const tag = await Tag.findOne({
75+
_id: tagId,
76+
});
77+
78+
return tag;
79+
} catch (error) {
80+
console.log(error);
81+
throw error;
82+
}
83+
}
84+
6785
export async function getQuestionsByTagId(params: GetQuestionByTagIdParams) {
6886
try {
6987
connectToDatabase();

0 commit comments

Comments
 (0)