diff --git a/src/hooks/useCommentResource.ts b/src/hooks/useCommentResource.ts index fa3bd6b00..7923182a6 100644 --- a/src/hooks/useCommentResource.ts +++ b/src/hooks/useCommentResource.ts @@ -11,11 +11,12 @@ export const useCommentResource = () => { const create = (cb: (params: Comment) => void) => - async ({ goalId, stateId, description }: GoalCommentSchema) => { + async ({ goalId, stateId, description, stateType }: GoalCommentSchema) => { const promise = createMutation.mutateAsync({ goalId, stateId, description, + stateType, }); const [data] = await notifyPromise(promise, 'commentCreate'); diff --git a/src/schema/goal.ts b/src/schema/goal.ts index 8f2162938..db83d6802 100644 --- a/src/schema/goal.ts +++ b/src/schema/goal.ts @@ -200,6 +200,9 @@ export const goalCommentSchema = z.object({ message: tr("Comments's description must be longer than 1 symbol"), }), stateId: z.string().optional(), + stateType: z + .enum([StateType.Canceled, StateType.Completed, StateType.Failed, StateType.InProgress, StateType.NotStarted]) + .optional(), }); export type GoalCommentSchema = z.infer; diff --git a/trpc/router/goal.ts b/trpc/router/goal.ts index 3601c6882..020ab0477 100644 --- a/trpc/router/goal.ts +++ b/trpc/router/goal.ts @@ -525,11 +525,13 @@ export const goal = router({ data: history.map((record) => ({ ...record, activityId: ctx.session.user.activityId })), }, }, - goalAsCriteria: { - update: { - isDone: input.state.type === StateType.Completed, - }, - }, + goalAsCriteria: actualGoal.goalAsCriteria + ? { + update: { + isDone: input.state.type === StateType.Completed, + }, + } + : undefined, }, include: { ...goalDeepQuery, @@ -651,11 +653,13 @@ export const goal = router({ activityId: ctx.session.user.activityId, }, }, - goalAsCriteria: { - update: { - isDone: input.state.type === StateType.Completed, - }, - }, + goalAsCriteria: actualGoal.goalAsCriteria + ? { + update: { + isDone: input.state.type === StateType.Completed, + }, + } + : undefined, }, }); } catch (error: any) { @@ -676,6 +680,7 @@ export const goal = router({ participants: { include: { user: true, ghost: true } }, activity: { include: { user: true, ghost: true } }, project: true, + goalAsCriteria: true, }, }), ]); @@ -694,6 +699,13 @@ export const goal = router({ data: { id: input.goalId, stateId: _isEditable ? input.stateId : actualGoal.stateId, + goalAsCriteria: actualGoal.goalAsCriteria + ? { + update: { + isDone: _isEditable && input.stateType && input.stateType === StateType.Completed, + }, + } + : undefined, history: _isEditable && input.stateId && input.stateId !== actualGoal.stateId ? {