Skip to content

Commit

Permalink
fix(goal): use max operator for new goal scopeId
Browse files Browse the repository at this point in the history
  • Loading branch information
awinogradov committed Jun 20, 2023
1 parent e550f89 commit 69975d1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const createGoal = async (activityId: string, input: GoalCommon) => {
${activityId},
${input.state.id},
${input.priority},
count(*) + 1
max("scopeId") + 1
FROM "Goal" WHERE "projectId" = ${input.parent.id};
`;

Expand Down Expand Up @@ -113,7 +113,7 @@ export const createGoal = async (activityId: string, input: GoalCommon) => {
export const changeGoalProject = async (id: string, newProjectId: string) => {
await prisma.$executeRaw`
UPDATE "Goal"
SET "projectId" = ${newProjectId}, "scopeId" = (SELECT count(*) + 1 FROM "Goal" WHERE "projectId" = ${newProjectId})
SET "projectId" = ${newProjectId}, "scopeId" = (SELECT max("scopeId") + 1 FROM "Goal" WHERE "projectId" = ${newProjectId})
WHERE "id" = ${id};
`;

Expand Down

0 comments on commit 69975d1

Please sign in to comment.