MCPcopy Create free account
hub / github.com/RealDevSquad/website-backend / buildQueryToFetchPaginatedDocs

Function buildQueryToFetchPaginatedDocs

utils/progresses.js:132–159  ·  view source on GitHub ↗
(queryParams)

Source from the content-addressed store, hash-verified

130 */
131
132const buildQueryToFetchPaginatedDocs = async (queryParams) => {
133 const { type, userId, taskId, orderBy, size = PROGRESSES_SIZE, page = PROGRESSES_PAGE_SIZE } = queryParams;
134 const orderByField = PROGRESS_VALID_SORT_FIELDS[0];
135 const isAscOrDsc = orderBy && PROGRESS_VALID_SORT_FIELDS[0] === orderBy ? "asc" : "desc";
136 const limit = parseInt(size, 10);
137 const offset = parseInt(page, 10) * limit;
138
139 let baseQuery;
140 if (type) {
141 baseQuery = progressesCollection.where("type", "==", type).orderBy(orderByField, isAscOrDsc);
142 } else if (userId) {
143 baseQuery = progressesCollection
144 .where("type", "==", "user")
145 .where("userId", "==", userId)
146 .orderBy(orderByField, isAscOrDsc);
147 } else {
148 baseQuery = progressesCollection
149 .where("type", "==", "task")
150 .where("taskId", "==", taskId)
151 .orderBy(orderByField, isAscOrDsc);
152 }
153
154 const totalProgress = await baseQuery.get();
155 const totalProgressCount = totalProgress.size;
156
157 baseQuery = baseQuery.limit(limit).offset(offset);
158 return { baseQuery, totalProgressCount };
159};
160
161/**
162 * Retrieves progress documents from Firestore based on the given query.

Callers 2

progresses.test.jsFile · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected