dates
This commit is contained in:
2
convex/_generated/api.d.ts
vendored
2
convex/_generated/api.d.ts
vendored
@@ -14,6 +14,7 @@ import type * as analysisSections from "../analysisSections.js";
|
||||
import type * as auth from "../auth.js";
|
||||
import type * as dataSources from "../dataSources.js";
|
||||
import type * as http from "../http.js";
|
||||
import type * as logs from "../logs.js";
|
||||
import type * as opportunities from "../opportunities.js";
|
||||
import type * as projects from "../projects.js";
|
||||
import type * as searchJobs from "../searchJobs.js";
|
||||
@@ -33,6 +34,7 @@ declare const fullApi: ApiFromModules<{
|
||||
auth: typeof auth;
|
||||
dataSources: typeof dataSources;
|
||||
http: typeof http;
|
||||
logs: typeof logs;
|
||||
opportunities: typeof opportunities;
|
||||
projects: typeof projects;
|
||||
searchJobs: typeof searchJobs;
|
||||
|
||||
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);
|
||||
},
|
||||
});
|
||||
@@ -221,6 +221,24 @@ const schema = defineSchema({
|
||||
})
|
||||
.index("by_project_status", ["projectId", "status"])
|
||||
.index("by_project_createdAt", ["projectId", "createdAt"]),
|
||||
logs: defineTable({
|
||||
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")),
|
||||
userId: v.optional(v.id("users")),
|
||||
createdAt: v.number(),
|
||||
})
|
||||
.index("by_createdAt", ["createdAt"])
|
||||
.index("by_project_createdAt", ["projectId", "createdAt"]),
|
||||
});
|
||||
|
||||
export default schema;
|
||||
|
||||
Reference in New Issue
Block a user