♻️ only show product updates if the user is an admin or the owner

This commit is contained in:
Fred KISSIE
2025-12-05 21:33:35 +01:00
parent 54c05c8345
commit 889b381e96
2 changed files with 30 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
import { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { db } from "@server/db";
import { db, roles } from "@server/db";
import { Org, orgs, userOrgs } from "@server/db";
import response from "@server/lib/response";
import HttpCode from "@server/types/HttpCode";
@@ -40,7 +40,7 @@ const listOrgsSchema = z.object({
// responses: {}
// });
type ResponseOrg = Org & { isOwner?: boolean };
type ResponseOrg = Org & { isOwner?: boolean; isAdmin?: boolean };
export type ListUserOrgsResponse = {
orgs: ResponseOrg[];
@@ -112,6 +112,7 @@ export async function listUserOrgs(
userOrgs,
and(eq(userOrgs.orgId, orgs.orgId), eq(userOrgs.userId, userId))
)
.leftJoin(roles, eq(userOrgs.orgId, roles.orgId))
.limit(limit)
.offset(offset);
@@ -128,6 +129,9 @@ export async function listUserOrgs(
if (val.userOrgs && val.userOrgs.isOwner) {
res.isOwner = val.userOrgs.isOwner;
}
if (val.roles && val.roles.isAdmin) {
res.isAdmin = val.roles.isAdmin;
}
return res;
});