feat: add monitor order with updatedAt
This commit is contained in:
parent
d9d234551a
commit
625374cafe
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Monitor" ADD COLUMN "updatedAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
@ -261,6 +261,7 @@ model Monitor {
|
||||
/// [CommonPayload]
|
||||
payload Json @db.Json
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
||||
updatedAt DateTime @default(now()) @updatedAt @db.Timestamptz(6)
|
||||
|
||||
workspace Workspace @relation(fields: [workspaceId], references: [id])
|
||||
|
||||
|
@ -20,6 +20,7 @@ export const MonitorModelSchema = z.object({
|
||||
*/
|
||||
payload: jsonSchema,
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
})
|
||||
|
||||
export interface CompleteMonitor extends z.infer<typeof MonitorModelSchema> {
|
||||
|
@ -45,6 +45,9 @@ export const monitorRouter = router({
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: 'desc',
|
||||
},
|
||||
});
|
||||
|
||||
return monitors as MonitorInfoWithNotificationIds[];
|
||||
@ -426,6 +429,60 @@ export const monitorRouter = router({
|
||||
|
||||
return list;
|
||||
}),
|
||||
clearEvents: workspaceOwnerProcedure
|
||||
.meta(
|
||||
buildMonitorOpenapi({
|
||||
method: 'DELETE',
|
||||
path: '/clearEvents',
|
||||
})
|
||||
)
|
||||
.input(
|
||||
z.object({
|
||||
monitorId: z.string().cuid2(),
|
||||
})
|
||||
)
|
||||
.output(z.number())
|
||||
.mutation(async ({ input }) => {
|
||||
const { workspaceId, monitorId } = input;
|
||||
|
||||
const { count } = await prisma.monitorEvent.deleteMany({
|
||||
where: {
|
||||
monitor: {
|
||||
id: monitorId,
|
||||
workspaceId,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return count;
|
||||
}),
|
||||
clearData: workspaceOwnerProcedure
|
||||
.meta(
|
||||
buildMonitorOpenapi({
|
||||
method: 'DELETE',
|
||||
path: '/clearData',
|
||||
})
|
||||
)
|
||||
.input(
|
||||
z.object({
|
||||
monitorId: z.string().cuid2(),
|
||||
})
|
||||
)
|
||||
.output(z.number())
|
||||
.mutation(async ({ input }) => {
|
||||
const { workspaceId, monitorId } = input;
|
||||
|
||||
const { count } = await prisma.monitorData.deleteMany({
|
||||
where: {
|
||||
monitor: {
|
||||
id: monitorId,
|
||||
workspaceId,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return count;
|
||||
}),
|
||||
getStatus: workspaceProcedure
|
||||
.meta(
|
||||
buildMonitorOpenapi({
|
||||
|
Loading…
Reference in New Issue
Block a user