feat: wire convex data foundations
This commit is contained in:
73
convex/outreach.ts
Normal file
73
convex/outreach.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { v } from "convex/values";
|
||||
|
||||
import { normalizeListLimit } from "./domain";
|
||||
import { mutation, query } from "./_generated/server";
|
||||
|
||||
const strategy = v.union(
|
||||
v.literal("call_first"),
|
||||
v.literal("email_first"),
|
||||
v.literal("defer"),
|
||||
v.literal("do_not_contact"),
|
||||
);
|
||||
|
||||
export const create = mutation({
|
||||
args: {
|
||||
leadId: v.id("leads"),
|
||||
auditId: v.optional(v.id("audits")),
|
||||
strategy,
|
||||
phoneScript: v.optional(v.string()),
|
||||
emailSubject: v.optional(v.string()),
|
||||
emailBody: v.optional(v.string()),
|
||||
followUpDraft: v.optional(v.string()),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const now = Date.now();
|
||||
|
||||
return await ctx.db.insert("outreachRecords", {
|
||||
...args,
|
||||
approvalStatus: "draft",
|
||||
sendStatus: "not_sent",
|
||||
responseStatus: "none",
|
||||
salesStatus: "follow_up_planned",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const list = query({
|
||||
args: {
|
||||
leadId: v.optional(v.id("leads")),
|
||||
approvalStatus: v.optional(
|
||||
v.union(v.literal("draft"), v.literal("approved"), v.literal("rejected")),
|
||||
),
|
||||
limit: v.optional(v.number()),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const limit = normalizeListLimit(args.limit);
|
||||
|
||||
if (args.leadId) {
|
||||
const leadId = args.leadId;
|
||||
|
||||
return await ctx.db
|
||||
.query("outreachRecords")
|
||||
.withIndex("by_leadId", (q) => q.eq("leadId", leadId))
|
||||
.order("desc")
|
||||
.take(limit);
|
||||
}
|
||||
|
||||
if (args.approvalStatus) {
|
||||
const approvalStatus = args.approvalStatus;
|
||||
|
||||
return await ctx.db
|
||||
.query("outreachRecords")
|
||||
.withIndex("by_approvalStatus", (q) =>
|
||||
q.eq("approvalStatus", approvalStatus),
|
||||
)
|
||||
.order("desc")
|
||||
.take(limit);
|
||||
}
|
||||
|
||||
return await ctx.db.query("outreachRecords").order("desc").take(limit);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user