export const getOrCreate = action({
args: {
location_id: v.string(),
},
handler: async (ctx, { location_id }) => {
const location: null | any = await ctx.runQuery(internal.locations.get, {
location_id,
});
if (location) {
return location;
}
const combinedObj = await fetchLocationWithPhotos(location_id);
await ctx.runMutation(internal.locations.create, {
combinedObj,
location_id,
});
return {
...combinedObj,
location_id,
};
},
});
export const get = internalQuery({
args: {
location_id: v.string(),
},
handler: async (ctx, { location_id }) => {
return await ctx.db
.query("locations")
.filter((q) => q.eq(q.field("location_id"), location_id))
.unique();
},
});
export const create = internalMutation({
args: {
location_id: v.string(),
combinedObj: v.any(),
},
handler: async (ctx, { location_id, combinedObj }) => {
return await ctx.db.insert("locations", {
location_id,
...combinedObj,
});
},
});
export const getOrCreate = action({
args: {
location_id: v.string(),
},
handler: async (ctx, { location_id }) => {
const location: null | any = await ctx.runQuery(internal.locations.get, {
location_id,
});
if (location) {
return location;
}
const combinedObj = await fetchLocationWithPhotos(location_id);
await ctx.runMutation(internal.locations.create, {
combinedObj,
location_id,
});
return {
...combinedObj,
location_id,
};
},
});
export const get = internalQuery({
args: {
location_id: v.string(),
},
handler: async (ctx, { location_id }) => {
return await ctx.db
.query("locations")
.filter((q) => q.eq(q.field("location_id"), location_id))
.unique();
},
});
export const create = internalMutation({
args: {
location_id: v.string(),
combinedObj: v.any(),
},
handler: async (ctx, { location_id, combinedObj }) => {
return await ctx.db.insert("locations", {
location_id,
...combinedObj,
});
},
});