Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getCycleProgressChart,
getCyclesProgress,
} from '~/modules/cycle/utils';
import { startOfDay } from 'date-fns';

export const cycleQueries = {
getCycle: async (_parent: undefined, { _id }, { models }: IContext) => {
Expand All @@ -24,14 +25,16 @@ export const cycleQueries = {
...params,
orderBy: { isActive: -1, isCompleted: 1, startDate: 1 },
},
query: { teamId: params.teamId, isCompleted: false },
query: { teamId: params.teamId },
},
);

return { list, totalCount, pageInfo };
},

getCyclesActive: async (_parent: undefined, params, { models }: IContext) => {
const today = startOfDay(new Date());

if (params.taskId) {
const task = await models.Task.findOne({
_id: params.taskId,
Expand All @@ -56,12 +59,14 @@ export const cycleQueries = {

query: {
teamId: params.teamId,
isCompleted: { $ne: true },
isCompleted: false,
$or: [
{ isActive: true },
{ _id: params?.cycleId || null },
{
startDate: { $lte: new Date() },
startDate: { $lte: today },
endDate: { $gte: today },
},
{
startDate: { $gt: today },
},
],
},
Expand Down