[offers][fix] Fix generate analysis API by deleting analysis if exists before creating

pull/380/head
BryannYeap 3 years ago
parent c12c318a0b
commit 0edcfb7af3

@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE "OffersAnalysis" DROP CONSTRAINT "OffersAnalysis_offerId_fkey";
-- DropForeignKey
ALTER TABLE "OffersAnalysis" DROP CONSTRAINT "OffersAnalysis_profileId_fkey";
-- AddForeignKey
ALTER TABLE "OffersAnalysis" ADD CONSTRAINT "OffersAnalysis_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "OffersProfile"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "OffersAnalysis" ADD CONSTRAINT "OffersAnalysis_offerId_fkey" FOREIGN KEY ("offerId") REFERENCES "OffersOffer"("id") ON DELETE CASCADE ON UPDATE CASCADE;

@ -358,10 +358,10 @@ model OffersFullTime {
model OffersAnalysis {
id String @id @default(cuid())
profile OffersProfile @relation(fields: [profileId], references: [id])
profile OffersProfile @relation(fields: [profileId], references: [id], onDelete: Cascade)
profileId String @unique
overallHighestOffer OffersOffer @relation("HighestOverallOffer", fields: [offerId], references: [id])
overallHighestOffer OffersOffer @relation("HighestOverallOffer", fields: [offerId], references: [id], onDelete: Cascade)
offerId String @unique
// OVERALL

@ -71,6 +71,12 @@ export const offersAnalysisRouter = createRouter().query('generate', {
profileId: z.string(),
}),
async resolve({ ctx, input }) {
await ctx.prisma.offersAnalysis.deleteMany({
where: {
profileId: input.profileId,
},
});
const offers = await ctx.prisma.offersOffer.findMany({
include: {
OffersFullTime: {

Loading…
Cancel
Save