From 4e63296a653af2ddbc6a382c500a9b31f0ed0d45 Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Sat, 12 Apr 2025 00:27:48 +0000 Subject: [PATCH] Refactor: Replace organization ID with customer ID in data models and access methods. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/55bdac1c-eb79-41e7-a716-be82bfbdddcd.jpg --- server/storage.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/storage.ts b/server/storage.ts index 1f88189..3b2a6d4 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -342,9 +342,9 @@ export class MemStorage implements IStorage { return this.domainsMap.get(parseInt(id)); } - async getDomainsByOrganization(organizationId: string): Promise { + async getDomainsByCustomer(customerId: string): Promise { return Array.from(this.domainsMap.values()) - .filter(domain => domain.organizationId === organizationId); + .filter(domain => domain.customerId === customerId); } async getAllDomains(): Promise { @@ -358,7 +358,7 @@ export class MemStorage implements IStorage { const newDomain: Domain = { id: numId.toString(), name: domain.name, - organizationId: domain.organizationId!, + customerId: domain.customerId, providerId: domain.providerId || "1", // Default to the first provider if not specified isActive: domain.isActive ?? true, lastUpdated, @@ -502,9 +502,15 @@ export class MemStorage implements IStorage { .find(apiToken => apiToken.token === token); } - async getApiTokensByOrganization(organizationId: string): Promise { + async getApiTokensByCustomer(customerId: string): Promise { + // Get all token-customer access records for this customer + const customerAccess = Array.from(this.apiTokenCustomerAccessMap.values()) + .filter(access => access.customerId === customerId); + + // Get the tokens with access to this customer + const tokenIds = customerAccess.map(access => access.tokenId); return Array.from(this.apiTokensMap.values()) - .filter(token => token.organizationId === organizationId); + .filter(token => tokenIds.includes(token.id)); } async createApiToken(token: any): Promise { @@ -568,7 +574,7 @@ export class MemStorage implements IStorage { id: numId.toString(), name: token.name || "Unnamed Token", token: token.token || "test_token_" + numId, - organizationId: token.organizationId || "1", + customerId: token.customerId || "1", permissions: permissions, role: token.role || 'readonly', createdBy: token.createdBy || "1",