Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goal update method returned error by update criteria state #1280

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/hooks/useCommentResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions src/schema/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof goalCommentSchema>;
32 changes: 22 additions & 10 deletions trpc/router/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -676,6 +680,7 @@ export const goal = router({
participants: { include: { user: true, ghost: true } },
activity: { include: { user: true, ghost: true } },
project: true,
goalAsCriteria: true,
},
}),
]);
Expand All @@ -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
? {
Expand Down
Loading