@@ -2,7 +2,7 @@ import { groq } from "next-sanity";
22import { readClient , writeClient } from "./lib/client" ;
33import { buildQuery } from "./utils" ;
44
5- import type { GetResourcesParams } from "@/types" ;
5+ import type { DocTypeParams , GetResourcesParams } from "@/types" ;
66
77/**
88 * Fetch a list of resources based on search criteria.
@@ -11,26 +11,27 @@ import type { GetResourcesParams } from "@/types";
1111 * @param {string } params.query - The search query to filter resources by title or content.
1212 * @param {string | undefined } params.category - The category to filter resources by.
1313 * @param {number } params.page - The page number for paginated results.
14+ * @param {string } params.type - The type of resource to fetch.
1415 * @returns {Promise<Object[] | undefined> } A promise that resolves to an array of resource objects if found, or undefined if an error occurred.
1516 *
1617 * @throws {Error } Throws an error if there was an issue fetching the resources.
1718 */
1819export const getResources = async (
1920 params : GetResourcesParams
2021) : Promise < Object [ ] | undefined | any > => {
21- const { query, category, page } : GetResourcesParams = params ;
22+ const { query, category, page, type } : GetResourcesParams = params ;
2223
2324 try {
2425 const resources = await readClient . fetch (
2526 groq `${ buildQuery ( {
26- type : "resource" ,
27+ type,
2728 query,
2829 category,
29- page : page ,
30+ page,
3031 } ) } {
3132 _id,
3233 title,
33- downloadLink ,
34+ link ,
3435 "image": poster.asset->url,
3536 views,
3637 slug,
@@ -58,18 +59,22 @@ export const getResources = async (
5859 *
5960 * @throws {Error } Throws an error if there was an issue fetching the playlist.
6061 */
61- export const getResourcesPlaylist = async ( ) : Promise <
62- Object [ ] | undefined | any
63- > => {
62+ export const getResourcesPlaylist = async (
63+ params : DocTypeParams
64+ ) : Promise < Object [ ] | undefined | any > => {
65+ const { type } : DocTypeParams = params ;
66+
6467 try {
6568 const resources = await readClient . fetch (
66- groq `*[_type == "resourcePlaylist"]{
69+ groq `*[_type == "${
70+ type === "video" ? "videoPlaylist" : "resourcePlaylist"
71+ } "]{
6772 _id,
6873 title,
6974 resources[0...6]->{
7075 title,
7176 _id,
72- downloadLink ,
77+ link ,
7378 "image": poster.asset->url,
7479 views,
7580 category
@@ -101,7 +106,7 @@ export const getResourceById = async ({
101106 groq `*[_type == "resource" && _id == "${ id } "]{
102107 _id,
103108 title,
104- downloadLink ,
109+ link ,
105110 "image": poster.asset->url,
106111 views,
107112 slug,
@@ -129,7 +134,7 @@ export const getResourceById = async ({
129134 *
130135 * @throws {Error } Throws an error if there was an issue incrementing the download count.
131136 */
132- export const incrementDownloadsById = async ( {
137+ export const newInteractById = async ( {
133138 id,
134139} : {
135140 id : string ;
@@ -145,9 +150,9 @@ export const incrementDownloadsById = async ({
145150 throw new Error ( `Resource with ID ${ id } not found.` ) ;
146151 }
147152
148- const views = resource [ 0 ] . views + 1 ;
153+ const updatedValue = resource [ 0 ] . views + 1 ;
149154
150- await writeClient . patch ( id ) . set ( { views } ) . commit ( ) ;
155+ await writeClient . patch ( id ) . inc ( { views : updatedValue } ) ;
151156 } catch ( error ) {
152157 console . error ( error ) ;
153158 }
0 commit comments