fix(partner): scope auto-claim to owned workspaces and guard against active subs
This commit is contained in:
@@ -147,6 +147,20 @@ export const getFirstUnlinkedSlotByLicenseKey = async (
|
||||
});
|
||||
};
|
||||
|
||||
export const getAllActivePartnerSubsByWorkspaceIds = async (
|
||||
db: dbClient,
|
||||
workspacePublicIds: string[],
|
||||
) => {
|
||||
if (workspacePublicIds.length === 0) return [];
|
||||
return await db.query.subscription.findMany({
|
||||
where: and(
|
||||
inArray(subscription.referenceId, workspacePublicIds),
|
||||
isNotNull(subscription.partnerLicenseKey),
|
||||
inArray(subscription.status, ["active", "trialing"]),
|
||||
),
|
||||
});
|
||||
};
|
||||
|
||||
export const getFirstActivePartnerSubByWorkspaceIds = async (
|
||||
db: dbClient,
|
||||
workspacePublicIds: string[],
|
||||
|
||||
@@ -315,6 +315,16 @@ export const getAllByUserId = async (db: dbClient, userId: string) => {
|
||||
return result.filter((member) => !member.workspace.deletedAt);
|
||||
};
|
||||
|
||||
export const getAllOwnedByUserId = async (db: dbClient, userId: string) => {
|
||||
return await db.query.workspaces.findMany({
|
||||
columns: {
|
||||
publicId: true,
|
||||
plan: true,
|
||||
},
|
||||
where: and(eq(workspaces.createdBy, userId), isNull(workspaces.deletedAt)),
|
||||
});
|
||||
};
|
||||
|
||||
export const getMemberByPublicId = (db: dbClient, memberPublicId: string) => {
|
||||
return db.query.workspaceMembers.findFirst({
|
||||
columns: {
|
||||
|
||||
Reference in New Issue
Block a user