// priceHistory.ts
import { v } from "convex/values";
import { mutation, query } from "./_generated/server";
export const addPrice = mutation({
args: {
price: v.number(),
setBy: v.string(),
},
handler: async (ctx, args) => {
// check auth
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error("Not authenticated");
}
await ctx.db.insert("price_history", {
...args,
});
},
});
export const getLatestPrice = query({
handler: async (ctx) => {
return await ctx.db.query("price_history").order("desc").first();
},
});
// priceHistory.ts
import { v } from "convex/values";
import { mutation, query } from "./_generated/server";
export const addPrice = mutation({
args: {
price: v.number(),
setBy: v.string(),
},
handler: async (ctx, args) => {
// check auth
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error("Not authenticated");
}
await ctx.db.insert("price_history", {
...args,
});
},
});
export const getLatestPrice = query({
handler: async (ctx) => {
return await ctx.db.query("price_history").order("desc").first();
},
});