Webui / convex /settings.ts
oki692's picture
Upload folder using huggingface_hub
cfb0fa4 verified
import { v } from 'convex/values';
import { mutation, query } from './_generated/server';
export const get = query({
args: { userId: v.string() },
handler: async (ctx, { userId }) => {
const doc = await ctx.db
.query('userSettings')
.withIndex('by_userId', (q) => q.eq('userId', userId))
.first();
return doc ?? null;
}
});
export const save = mutation({
args: {
userId: v.string(),
data: v.any()
},
handler: async (ctx, { userId, data }) => {
const existing = await ctx.db
.query('userSettings')
.withIndex('by_userId', (q) => q.eq('userId', userId))
.first();
if (existing) {
await ctx.db.patch(existing._id, { data, updatedAt: Date.now() });
} else {
await ctx.db.insert('userSettings', {
userId,
data,
updatedAt: Date.now()
});
}
}
});