-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add creation info for estimation aides table
- Loading branch information
Showing
7 changed files
with
84 additions
and
64 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...tions/20250122094553_add_created_date_and_creator_for_aide_estimation_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- AlterTable | ||
ALTER TABLE "estimations_aides" | ||
ADD COLUMN "created_at" TIMESTAMP(3), | ||
ADD COLUMN "user_id" TEXT; | ||
ALTER TABLE "estimations_aides" | ||
ALTER "created_at" SET DEFAULT CURRENT_TIMESTAMP; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "estimations_aides" | ||
ADD CONSTRAINT "estimations_aides_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { prismaClient } from "@/src/lib/prisma/prismaClient"; | ||
import { EstimationAide } from "@/src/lib/prisma/prismaCustomTypes"; | ||
import { projetUpdated } from "./prismaProjetQueries"; | ||
|
||
export const addAideInEstimation = async ( | ||
estimationId: number, | ||
aideId: number, | ||
userId: string, | ||
): Promise<EstimationAide> => { | ||
const response = await prismaClient.estimations_aides.upsert({ | ||
where: { | ||
estimationId_aideId: { | ||
estimationId, | ||
aideId, | ||
}, | ||
}, | ||
update: {}, | ||
create: { | ||
estimationId, | ||
aideId, | ||
user_id: userId, | ||
}, | ||
include: { | ||
aide: true, | ||
}, | ||
}); | ||
|
||
const estimation = await prismaClient.estimation.findUnique({ | ||
where: { id: estimationId }, | ||
select: { projet_id: true }, | ||
}); | ||
|
||
if (estimation) { | ||
await projetUpdated(estimation.projet_id); | ||
} | ||
|
||
return response; | ||
}; | ||
|
||
export const deleteAideInEstimation = async (estimationId: number, aideId: number): Promise<EstimationAide | null> => { | ||
const response = await prismaClient.estimations_aides.delete({ | ||
where: { | ||
estimationId_aideId: { | ||
estimationId, | ||
aideId, | ||
}, | ||
}, | ||
include: { | ||
aide: true, | ||
}, | ||
}); | ||
|
||
const estimation = await prismaClient.estimation.findUnique({ | ||
where: { id: estimationId }, | ||
select: { projet_id: true }, | ||
}); | ||
|
||
if (estimation) { | ||
await projetUpdated(estimation.projet_id); | ||
} | ||
|
||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters