Fix Convex validator to accept null for optional string fields
Rust serializes Option<String>::None as null, not undefined. Updated reportUsbPolicyStatus mutation to accept both null and undefined for error and currentPolicy fields. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
20b63f4ad6
commit
5846c299ce
1 changed files with 8 additions and 4 deletions
|
|
@ -70,10 +70,14 @@ export const reportUsbPolicyStatus = mutation({
|
||||||
args: {
|
args: {
|
||||||
machineToken: v.string(),
|
machineToken: v.string(),
|
||||||
status: v.string(),
|
status: v.string(),
|
||||||
error: v.optional(v.string()),
|
// Rust envia null para Option<String>::None, entao precisamos aceitar null tambem
|
||||||
currentPolicy: v.optional(v.string()),
|
error: v.optional(v.union(v.string(), v.null())),
|
||||||
|
currentPolicy: v.optional(v.union(v.string(), v.null())),
|
||||||
},
|
},
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
|
// Converte null para undefined para uso interno
|
||||||
|
const errorValue = args.error ?? undefined
|
||||||
|
const currentPolicyValue = args.currentPolicy ?? undefined
|
||||||
const tokenHash = hashToken(args.machineToken)
|
const tokenHash = hashToken(args.machineToken)
|
||||||
|
|
||||||
const tokenRecord = await ctx.db
|
const tokenRecord = await ctx.db
|
||||||
|
|
@ -102,7 +106,7 @@ export const reportUsbPolicyStatus = mutation({
|
||||||
|
|
||||||
await ctx.db.patch(machine._id, {
|
await ctx.db.patch(machine._id, {
|
||||||
usbPolicyStatus: args.status,
|
usbPolicyStatus: args.status,
|
||||||
usbPolicyError: args.error,
|
usbPolicyError: errorValue,
|
||||||
usbPolicyReportedAt: now,
|
usbPolicyReportedAt: now,
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
})
|
})
|
||||||
|
|
@ -116,7 +120,7 @@ export const reportUsbPolicyStatus = mutation({
|
||||||
if (latestEvent && latestEvent.status === "PENDING") {
|
if (latestEvent && latestEvent.status === "PENDING") {
|
||||||
await ctx.db.patch(latestEvent._id, {
|
await ctx.db.patch(latestEvent._id, {
|
||||||
status: args.status,
|
status: args.status,
|
||||||
error: args.error,
|
error: errorValue,
|
||||||
appliedAt: args.status === "APPLIED" ? now : undefined,
|
appliedAt: args.status === "APPLIED" ? now : undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue