Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions packages/backend/convex/tenants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,8 @@ export const create = mutation({
export const getGeneral = query({
args: {},
handler: async (ctx) => {
const user = await getUser(ctx);
const membership = await ctx.db
.query("accountMembers")
.withIndex("by_user", (q) => q.eq("userId", user._id))
.first();
if (!membership) return null;

const tenant = await ctx.db
.query("tenants")
.withIndex("by_account", (q) => q.eq("accountId", membership.accountId))
.first();
const tenantId = await getTenantIdFromJwt(ctx);
const tenant = await ctx.db.get(tenantId);
if (!tenant) return null;

return {
Expand All @@ -99,20 +90,9 @@ export const updateGeneral = mutation({
description: v.optional(v.string()),
},
handler: async (ctx, args) => {
const user = await getUser(ctx);
const membership = await ctx.db
.query("accountMembers")
.withIndex("by_user", (q) => q.eq("userId", user._id))
.first();
if (!membership) throw new Error("No account found");

const tenant = await ctx.db
.query("tenants")
.withIndex("by_account", (q) => q.eq("accountId", membership.accountId))
.first();
if (!tenant) throw new Error("Tenant not found");
const tenantId = await getTenantIdFromJwt(ctx);

await ctx.db.patch(tenant._id, {
await ctx.db.patch(tenantId, {
name: args.name,
description: args.description ?? "",
updatedAt: Date.now(),
Expand Down