|
|
@ -71,18 +71,20 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|
|
|
const userId = ctx.session?.user?.id;
|
|
|
|
const userId = ctx.session?.user?.id;
|
|
|
|
|
|
|
|
|
|
|
|
return await ctx.prisma.$transaction(async (tx) => {
|
|
|
|
return await ctx.prisma.$transaction(async (tx) => {
|
|
|
|
const questionToUpdate = await tx.questionsQuestion.findUnique({
|
|
|
|
const [questionToUpdate, questionEncounterCreated] = await Promise.all([
|
|
|
|
where: {
|
|
|
|
tx.questionsQuestion.findUnique({
|
|
|
|
id: input.questionId,
|
|
|
|
where: {
|
|
|
|
},
|
|
|
|
id: input.questionId,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
tx.questionsQuestionEncounter.create({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
...input,
|
|
|
|
|
|
|
|
userId,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
const questionEncounterCreated = await tx.questionsQuestionEncounter.create({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
...input,
|
|
|
|
|
|
|
|
userId,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (questionToUpdate === null) {
|
|
|
|
if (questionToUpdate === null) {
|
|
|
|
throw new TRPCError({
|
|
|
|
throw new TRPCError({
|
|
|
@ -131,20 +133,22 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await ctx.prisma.$transaction(async (tx) => {
|
|
|
|
return await ctx.prisma.$transaction(async (tx) => {
|
|
|
|
const questionToUpdate = await tx.questionsQuestion.findUnique({
|
|
|
|
const [questionToUpdate, questionEncounterUpdated] = await Promise.all([
|
|
|
|
where: {
|
|
|
|
tx.questionsQuestion.findUnique({
|
|
|
|
id: questionEncounterToUpdate.questionId,
|
|
|
|
where: {
|
|
|
|
},
|
|
|
|
id: questionEncounterToUpdate.questionId,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
tx.prisma.questionsQuestionEncounter.update({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
...input,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
id: input.id,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
const questionEncounterUpdated = await ctx.prisma.questionsQuestionEncounter.update({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
...input,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
id: input.id,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (questionToUpdate!.lastSeenAt === questionEncounterToUpdate.seenAt) {
|
|
|
|
if (questionToUpdate!.lastSeenAt === questionEncounterToUpdate.seenAt) {
|
|
|
|
const latestEncounter = await ctx.prisma.questionsQuestionEncounter.findFirst({
|
|
|
|
const latestEncounter = await ctx.prisma.questionsQuestionEncounter.findFirst({
|
|
|
@ -194,17 +198,18 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await ctx.prisma.$transaction(async (tx) => {
|
|
|
|
return await ctx.prisma.$transaction(async (tx) => {
|
|
|
|
const questionToUpdate = await tx.questionsQuestion.findUnique({
|
|
|
|
const [questionToUpdate, questionEncounterDeleted] = await Promise.all([
|
|
|
|
where: {
|
|
|
|
tx.questionsQuestion.findUnique({
|
|
|
|
id: questionEncounterToDelete.questionId,
|
|
|
|
where: {
|
|
|
|
},
|
|
|
|
id: questionEncounterToDelete.questionId,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
}),
|
|
|
|
const questionEncounterDeleted = await ctx.prisma.questionsQuestionEncounter.delete({
|
|
|
|
tx.prisma.questionsQuestionEncounter.delete({
|
|
|
|
where: {
|
|
|
|
where: {
|
|
|
|
id: input.id,
|
|
|
|
id: input.id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
if (questionToUpdate!.lastSeenAt === questionEncounterToDelete.seenAt) {
|
|
|
|
if (questionToUpdate!.lastSeenAt === questionEncounterToDelete.seenAt) {
|
|
|
|
const latestEncounter = await ctx.prisma.questionsQuestionEncounter.findFirst({
|
|
|
|
const latestEncounter = await ctx.prisma.questionsQuestionEncounter.findFirst({
|
|
|
|