dates
This commit is contained in:
32
convex/logs.ts
Normal file
32
convex/logs.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { mutation } from "./_generated/server";
|
||||
import { v } from "convex/values";
|
||||
import { getAuthUserId } from "@convex-dev/auth/server";
|
||||
|
||||
export const createLog = mutation({
|
||||
args: {
|
||||
level: v.union(
|
||||
v.literal("debug"),
|
||||
v.literal("info"),
|
||||
v.literal("warn"),
|
||||
v.literal("error")
|
||||
),
|
||||
message: v.string(),
|
||||
labels: v.array(v.string()),
|
||||
payload: v.optional(v.any()),
|
||||
source: v.optional(v.string()),
|
||||
requestId: v.optional(v.string()),
|
||||
projectId: v.optional(v.id("projects")),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const userId = await getAuthUserId(ctx);
|
||||
const base = {
|
||||
...args,
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
if (userId) {
|
||||
await ctx.db.insert("logs", { ...base, userId });
|
||||
return;
|
||||
}
|
||||
await ctx.db.insert("logs", base);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user