Skip to content

Commit f687358

Browse files
committed
add exact type while querying the user or task type
1 parent e69d2e1 commit f687358

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

utils/progresses.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const getProgressDateTimestamp = () => {
3232
const buildQueryForPostingProgress = ({ type, userId, taskId }) => {
3333
const query =
3434
type === "user"
35-
? progressesCollection.where("userId", "==", userId)
36-
: progressesCollection.where("taskId", "==", taskId);
35+
? progressesCollection.where("type", "==", "user").where("userId", "==", userId)
36+
: progressesCollection.where("type", "==", "task").where("taskId", "==", taskId);
3737
return query;
3838
};
3939

@@ -136,9 +136,9 @@ const buildRangeProgressQuery = (queryParams) => {
136136
const { userId, taskId, startDate, endDate } = queryParams;
137137
let query = progressesCollection;
138138
if (userId) {
139-
query = query.where("userId", "==", userId);
139+
query = query.where("type", "==", "user").where("userId", "==", userId);
140140
} else if (taskId) {
141-
query = query.where("taskId", "==", taskId);
141+
query = query.where("type", "==", "task").where("taskId", "==", taskId);
142142
} else {
143143
throw new Error("Either userId or taskId is required.");
144144
}
@@ -191,14 +191,15 @@ const buildQueryToSearchProgressByDay = (pathParams) => {
191191
const { userId, taskId, date } = pathParams;
192192
let query = progressesCollection;
193193
if (userId) {
194-
query = query.where("userId", "==", userId);
194+
query = query.where("type", "==", "user").where("userId", "==", userId);
195195
} else {
196-
query = query.where("taskId", "==", taskId);
196+
query = query.where("type", "==", "task").where("taskId", "==", taskId);
197197
}
198198
const dateTimeStamp = new Date(date).setUTCHours(0, 0, 0, 0);
199199
query = query.where("date", "==", dateTimeStamp).limit(1);
200200
return query;
201201
};
202+
202203
module.exports = {
203204
getProgressDateTimestamp,
204205
buildQueryForPostingProgress,

0 commit comments

Comments
 (0)