Skip to content

Commit

Permalink
fix: visited history list order
Browse files Browse the repository at this point in the history
  • Loading branch information
enya-yy committed Nov 22, 2023
1 parent 18aaf56 commit eea8b0c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `VisitedHisotry` ADD COLUMN `date` VARCHAR(191) NOT NULL DEFAULT '';
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ model VisitedHisotry {
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
date String @default("")
}
29 changes: 27 additions & 2 deletions server/trpc/routers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,34 @@ export const projectRouter = router({
})
if (!project)
throw new Error('Project not found')
await ctx.prisma.visitedHisotry.create({
data: {
// add or update visted history

const visitedRecord = await ctx.prisma.visitedHisotry.findFirst({
where: {
projectId: input.id,
userId: user.id,
},
})
if (visitedRecord) {
await ctx.prisma.visitedHisotry.update({
where: {
id: visitedRecord.id,
},
data: {
date: new Date().getTime().toString(),
},
})
}
else {
await ctx.prisma.visitedHisotry.create({
data: {
projectId: input.id,
userId: user.id,
date: new Date().getTime().toString(),
},
})
}

return { ...project, visibility: project.visibility.toLowerCase() }
}),
projectUpdate: protectedProcedure
Expand Down Expand Up @@ -178,6 +200,9 @@ export const projectRouter = router({
include: {
project: true,
},
orderBy: {
date: 'desc',
},
})
return visitedList
}),
Expand Down

0 comments on commit eea8b0c

Please sign in to comment.