eggi-ai-db-schema-2 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +750 -0
- package/README.md +660 -0
- package/dist/config/database.d.ts +28 -0
- package/dist/config/database.d.ts.map +1 -0
- package/dist/config/database.js +72 -0
- package/dist/config/database.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/database-service.d.ts +714 -0
- package/dist/lib/database-service.d.ts.map +1 -0
- package/dist/lib/database-service.js +1394 -0
- package/dist/lib/database-service.js.map +1 -0
- package/dist/lib/db-types.d.ts +167 -0
- package/dist/lib/db-types.d.ts.map +1 -0
- package/dist/lib/db-types.js +28 -0
- package/dist/lib/db-types.js.map +1 -0
- package/dist/lib/db.d.ts +58 -0
- package/dist/lib/db.d.ts.map +1 -0
- package/dist/lib/db.js +292 -0
- package/dist/lib/db.js.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +26 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/pg-client.d.ts +50 -0
- package/dist/lib/pg-client.d.ts.map +1 -0
- package/dist/lib/pg-client.js +106 -0
- package/dist/lib/pg-client.js.map +1 -0
- package/dist/lib/schema.d.ts +298 -0
- package/dist/lib/schema.d.ts.map +1 -0
- package/dist/lib/schema.js +12 -0
- package/dist/lib/schema.js.map +1 -0
- package/dist/migration-manager.d.ts +49 -0
- package/dist/migration-manager.d.ts.map +1 -0
- package/dist/migration-manager.js +282 -0
- package/dist/migration-manager.js.map +1 -0
- package/dist/queries/minimal-connections.d.ts +31 -0
- package/dist/queries/minimal-connections.d.ts.map +1 -0
- package/dist/queries/minimal-connections.js +143 -0
- package/dist/queries/minimal-connections.js.map +1 -0
- package/dist/schema.ts +340 -0
- package/dist/seed.d.ts +8 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +40 -0
- package/dist/seed.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/types.d.ts +77 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +3 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/authenticated-user-operations.d.ts +110 -0
- package/dist/utils/authenticated-user-operations.d.ts.map +1 -0
- package/dist/utils/authenticated-user-operations.js +292 -0
- package/dist/utils/authenticated-user-operations.js.map +1 -0
- package/dist/utils/authentication-operations.d.ts +48 -0
- package/dist/utils/authentication-operations.d.ts.map +1 -0
- package/dist/utils/authentication-operations.js +172 -0
- package/dist/utils/authentication-operations.js.map +1 -0
- package/dist/utils/company-mapping-job-operations.d.ts +103 -0
- package/dist/utils/company-mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/company-mapping-job-operations.js +413 -0
- package/dist/utils/company-mapping-job-operations.js.map +1 -0
- package/dist/utils/company-sheet-upload-operations.d.ts +53 -0
- package/dist/utils/company-sheet-upload-operations.d.ts.map +1 -0
- package/dist/utils/company-sheet-upload-operations.js +135 -0
- package/dist/utils/company-sheet-upload-operations.js.map +1 -0
- package/dist/utils/contact-operations.d.ts +70 -0
- package/dist/utils/contact-operations.d.ts.map +1 -0
- package/dist/utils/contact-operations.js +294 -0
- package/dist/utils/contact-operations.js.map +1 -0
- package/dist/utils/forager-linkedin-operations.d.ts +74 -0
- package/dist/utils/forager-linkedin-operations.d.ts.map +1 -0
- package/dist/utils/forager-linkedin-operations.js +778 -0
- package/dist/utils/forager-linkedin-operations.js.map +1 -0
- package/dist/utils/ghost-genius-linkedin-operations.d.ts +23 -0
- package/dist/utils/ghost-genius-linkedin-operations.d.ts.map +1 -0
- package/dist/utils/ghost-genius-linkedin-operations.js +282 -0
- package/dist/utils/ghost-genius-linkedin-operations.js.map +1 -0
- package/dist/utils/index.d.ts +29 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +77 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/introduction-request-operations.d.ts +160 -0
- package/dist/utils/introduction-request-operations.d.ts.map +1 -0
- package/dist/utils/introduction-request-operations.js +492 -0
- package/dist/utils/introduction-request-operations.js.map +1 -0
- package/dist/utils/invitation-operations.d.ts +141 -0
- package/dist/utils/invitation-operations.d.ts.map +1 -0
- package/dist/utils/invitation-operations.js +749 -0
- package/dist/utils/invitation-operations.js.map +1 -0
- package/dist/utils/linkedin-account-operations.d.ts +45 -0
- package/dist/utils/linkedin-account-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-account-operations.js +279 -0
- package/dist/utils/linkedin-account-operations.js.map +1 -0
- package/dist/utils/linkedin-account-relationship-operations.d.ts +77 -0
- package/dist/utils/linkedin-account-relationship-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-account-relationship-operations.js +274 -0
- package/dist/utils/linkedin-account-relationship-operations.js.map +1 -0
- package/dist/utils/linkedin-data-operations.d.ts +102 -0
- package/dist/utils/linkedin-data-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-data-operations.js +613 -0
- package/dist/utils/linkedin-data-operations.js.map +1 -0
- package/dist/utils/linkedin-identifier-utils.d.ts +31 -0
- package/dist/utils/linkedin-identifier-utils.d.ts.map +1 -0
- package/dist/utils/linkedin-identifier-utils.js +63 -0
- package/dist/utils/linkedin-identifier-utils.js.map +1 -0
- package/dist/utils/linkedin-profile-cache.d.ts +131 -0
- package/dist/utils/linkedin-profile-cache.d.ts.map +1 -0
- package/dist/utils/linkedin-profile-cache.js +418 -0
- package/dist/utils/linkedin-profile-cache.js.map +1 -0
- package/dist/utils/llm-inference-job-operations.d.ts +116 -0
- package/dist/utils/llm-inference-job-operations.d.ts.map +1 -0
- package/dist/utils/llm-inference-job-operations.js +267 -0
- package/dist/utils/llm-inference-job-operations.js.map +1 -0
- package/dist/utils/mapping-job-operations.d.ts +272 -0
- package/dist/utils/mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/mapping-job-operations.js +833 -0
- package/dist/utils/mapping-job-operations.js.map +1 -0
- package/dist/utils/mapping-operations.d.ts +80 -0
- package/dist/utils/mapping-operations.d.ts.map +1 -0
- package/dist/utils/mapping-operations.js +318 -0
- package/dist/utils/mapping-operations.js.map +1 -0
- package/dist/utils/on-demand-mapping-operations.d.ts +199 -0
- package/dist/utils/on-demand-mapping-operations.d.ts.map +1 -0
- package/dist/utils/on-demand-mapping-operations.js +728 -0
- package/dist/utils/on-demand-mapping-operations.js.map +1 -0
- package/dist/utils/onboarding-operations.d.ts +53 -0
- package/dist/utils/onboarding-operations.d.ts.map +1 -0
- package/dist/utils/onboarding-operations.js +223 -0
- package/dist/utils/onboarding-operations.js.map +1 -0
- package/dist/utils/organization-assignment-job-operations.d.ts +258 -0
- package/dist/utils/organization-assignment-job-operations.d.ts.map +1 -0
- package/dist/utils/organization-assignment-job-operations.js +881 -0
- package/dist/utils/organization-assignment-job-operations.js.map +1 -0
- package/dist/utils/organization-assignment-operations.d.ts +59 -0
- package/dist/utils/organization-assignment-operations.d.ts.map +1 -0
- package/dist/utils/organization-assignment-operations.js +130 -0
- package/dist/utils/organization-assignment-operations.js.map +1 -0
- package/dist/utils/organization-operations.d.ts +284 -0
- package/dist/utils/organization-operations.d.ts.map +1 -0
- package/dist/utils/organization-operations.js +1030 -0
- package/dist/utils/organization-operations.js.map +1 -0
- package/dist/utils/organization-relationship-operations.d.ts +79 -0
- package/dist/utils/organization-relationship-operations.d.ts.map +1 -0
- package/dist/utils/organization-relationship-operations.js +294 -0
- package/dist/utils/organization-relationship-operations.js.map +1 -0
- package/dist/utils/quota-operations.d.ts +107 -0
- package/dist/utils/quota-operations.d.ts.map +1 -0
- package/dist/utils/quota-operations.js +692 -0
- package/dist/utils/quota-operations.js.map +1 -0
- package/dist/utils/recursive-mapping-job-operations.d.ts +42 -0
- package/dist/utils/recursive-mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/recursive-mapping-job-operations.js +169 -0
- package/dist/utils/recursive-mapping-job-operations.js.map +1 -0
- package/dist/utils/relationship-operations.d.ts +130 -0
- package/dist/utils/relationship-operations.d.ts.map +1 -0
- package/dist/utils/relationship-operations.js +329 -0
- package/dist/utils/relationship-operations.js.map +1 -0
- package/dist/utils/sales-pipeline-operations.d.ts +163 -0
- package/dist/utils/sales-pipeline-operations.d.ts.map +1 -0
- package/dist/utils/sales-pipeline-operations.js +725 -0
- package/dist/utils/sales-pipeline-operations.js.map +1 -0
- package/dist/utils/skills-operations.d.ts +117 -0
- package/dist/utils/skills-operations.d.ts.map +1 -0
- package/dist/utils/skills-operations.js +487 -0
- package/dist/utils/skills-operations.js.map +1 -0
- package/dist/utils/subscription-operations.d.ts +123 -0
- package/dist/utils/subscription-operations.d.ts.map +1 -0
- package/dist/utils/subscription-operations.js +391 -0
- package/dist/utils/subscription-operations.js.map +1 -0
- package/dist/utils/unipile-account-operations.d.ts +96 -0
- package/dist/utils/unipile-account-operations.d.ts.map +1 -0
- package/dist/utils/unipile-account-operations.js +255 -0
- package/dist/utils/unipile-account-operations.js.map +1 -0
- package/dist/utils/user-industry-operations.d.ts +80 -0
- package/dist/utils/user-industry-operations.d.ts.map +1 -0
- package/dist/utils/user-industry-operations.js +237 -0
- package/dist/utils/user-industry-operations.js.map +1 -0
- package/dist/utils/user-operations.d.ts +87 -0
- package/dist/utils/user-operations.d.ts.map +1 -0
- package/dist/utils/user-operations.js +212 -0
- package/dist/utils/user-operations.js.map +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,1394 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* =============================================================================
|
|
4
|
+
* DATABASE SERVICE - Clean Object-Oriented Database Management
|
|
5
|
+
* =============================================================================
|
|
6
|
+
*
|
|
7
|
+
* Provides a singleton database service that accepts connection parameters
|
|
8
|
+
* directly. No environment variables, no AWS dependencies - just clean
|
|
9
|
+
* database operations with provided connection info.
|
|
10
|
+
*
|
|
11
|
+
* @author Eggi.ai Team
|
|
12
|
+
* @version 3.0.0 - Clean architecture with input-based connections
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.DatabaseService = exports.dbService = void 0;
|
|
49
|
+
const pg_1 = require("pg");
|
|
50
|
+
// Import ALL database operations from utility files
|
|
51
|
+
const mapping_job_operations_1 = require("../utils/mapping-job-operations");
|
|
52
|
+
const llm_inference_job_operations_1 = require("../utils/llm-inference-job-operations");
|
|
53
|
+
const invitation_operations_1 = require("../utils/invitation-operations");
|
|
54
|
+
const organization_assignment_job_operations_1 = require("../utils/organization-assignment-job-operations");
|
|
55
|
+
const on_demand_mapping_operations_1 = require("../utils/on-demand-mapping-operations");
|
|
56
|
+
const linkedin_account_operations_1 = require("../utils/linkedin-account-operations");
|
|
57
|
+
const linkedin_data_operations_1 = require("../utils/linkedin-data-operations");
|
|
58
|
+
const forager_linkedin_operations_1 = require("../utils/forager-linkedin-operations");
|
|
59
|
+
const ghost_genius_linkedin_operations_1 = require("../utils/ghost-genius-linkedin-operations");
|
|
60
|
+
const linkedin_profile_cache_1 = require("../utils/linkedin-profile-cache");
|
|
61
|
+
const user_industry_operations_1 = require("../utils/user-industry-operations");
|
|
62
|
+
const authenticated_user_operations_1 = require("../utils/authenticated-user-operations");
|
|
63
|
+
const contact_operations_1 = require("../utils/contact-operations");
|
|
64
|
+
const user_operations_1 = require("../utils/user-operations");
|
|
65
|
+
const unipile_account_operations_1 = require("../utils/unipile-account-operations");
|
|
66
|
+
const linkedin_account_relationship_operations_1 = require("../utils/linkedin-account-relationship-operations");
|
|
67
|
+
const relationship_operations_1 = require("../utils/relationship-operations");
|
|
68
|
+
const minimal_connections_1 = require("../queries/minimal-connections");
|
|
69
|
+
const authentication_operations_1 = require("../utils/authentication-operations");
|
|
70
|
+
const skills_operations_1 = require("../utils/skills-operations");
|
|
71
|
+
const organization_operations_1 = require("../utils/organization-operations");
|
|
72
|
+
const mapping_operations_1 = require("../utils/mapping-operations");
|
|
73
|
+
const introduction_request_operations_1 = require("../utils/introduction-request-operations");
|
|
74
|
+
const onboarding_operations_1 = require("../utils/onboarding-operations");
|
|
75
|
+
const quota_operations_1 = require("../utils/quota-operations");
|
|
76
|
+
/**
|
|
77
|
+
* Singleton Database Service Class
|
|
78
|
+
* Manages database connections and provides type-safe query methods
|
|
79
|
+
*/
|
|
80
|
+
class DatabaseService {
|
|
81
|
+
constructor() {
|
|
82
|
+
this.dbPromise = null;
|
|
83
|
+
this.isInitialized = false;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get singleton instance of DatabaseService
|
|
87
|
+
*/
|
|
88
|
+
static getInstance() {
|
|
89
|
+
if (!DatabaseService.instance) {
|
|
90
|
+
DatabaseService.instance = new DatabaseService();
|
|
91
|
+
}
|
|
92
|
+
return DatabaseService.instance;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Build database URL from provided connection configuration
|
|
96
|
+
*/
|
|
97
|
+
buildDatabaseUrl(connectionConfig) {
|
|
98
|
+
// If complete URL is provided, use it directly
|
|
99
|
+
if (connectionConfig.databaseUrl) {
|
|
100
|
+
return connectionConfig.databaseUrl;
|
|
101
|
+
}
|
|
102
|
+
// Build URL from individual components
|
|
103
|
+
const { host = "localhost", port = 5432, database = "postgres", username = "postgres", password = "", ssl = true, } = connectionConfig;
|
|
104
|
+
// URL encode password to handle special characters
|
|
105
|
+
const encodedPassword = encodeURIComponent(password);
|
|
106
|
+
// Build connection string
|
|
107
|
+
const sslParam = ssl ? "?ssl=true&sslmode=require" : "?ssl=false";
|
|
108
|
+
const databaseUrl = `postgresql://${username}:${encodedPassword}@${host}:${port}/${database}${sslParam}&connect_timeout=30&application_name=eggi-db-service`;
|
|
109
|
+
return databaseUrl;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Initialize database connection with configuration
|
|
113
|
+
* REQUIRED: Must provide connection configuration
|
|
114
|
+
*/
|
|
115
|
+
async initialize(config) {
|
|
116
|
+
if (!this.dbPromise) {
|
|
117
|
+
console.log("🚀 DatabaseService: Starting initialization");
|
|
118
|
+
if (!config.connection) {
|
|
119
|
+
throw new Error("DatabaseService: connection configuration is required");
|
|
120
|
+
}
|
|
121
|
+
// Default pool configuration
|
|
122
|
+
const defaultPoolConfig = {
|
|
123
|
+
max: 5,
|
|
124
|
+
idleTimeoutMillis: 120000,
|
|
125
|
+
connectionTimeoutMillis: 30000,
|
|
126
|
+
};
|
|
127
|
+
// Merge pool config
|
|
128
|
+
const poolConfig = {
|
|
129
|
+
...defaultPoolConfig,
|
|
130
|
+
...config.poolConfig,
|
|
131
|
+
};
|
|
132
|
+
console.log("🔧 DatabaseService: Connection configuration", {
|
|
133
|
+
host: config.connection.host || "provided in URL",
|
|
134
|
+
poolConfig,
|
|
135
|
+
});
|
|
136
|
+
let pgPoolConfig;
|
|
137
|
+
// If connection parameters are provided directly, use them (avoids URL encoding issues)
|
|
138
|
+
if (config.connection.host && config.connection.database) {
|
|
139
|
+
console.log("🔧 Using direct connection parameters (no URL encoding)");
|
|
140
|
+
pgPoolConfig = {
|
|
141
|
+
host: config.connection.host,
|
|
142
|
+
port: config.connection.port || 5432,
|
|
143
|
+
database: config.connection.database,
|
|
144
|
+
user: config.connection.username,
|
|
145
|
+
password: config.connection.password,
|
|
146
|
+
ssl: config.connection.ssl === false ? false : { rejectUnauthorized: false },
|
|
147
|
+
...poolConfig,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// Fallback: Parse DATABASE_URL if provided
|
|
152
|
+
console.log("🔧 Using DATABASE_URL (with URL encoding)");
|
|
153
|
+
const databaseUrl = this.buildDatabaseUrl(config.connection);
|
|
154
|
+
const url = new URL(databaseUrl);
|
|
155
|
+
pgPoolConfig = {
|
|
156
|
+
host: url.hostname,
|
|
157
|
+
port: parseInt(url.port) || 5432,
|
|
158
|
+
database: url.pathname.slice(1), // Remove leading '/'
|
|
159
|
+
user: url.username,
|
|
160
|
+
password: url.password,
|
|
161
|
+
ssl: url.searchParams.get("sslmode") === "disable" || url.searchParams.get("ssl") === "false"
|
|
162
|
+
? false
|
|
163
|
+
: { rejectUnauthorized: false },
|
|
164
|
+
...poolConfig,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
// Initialize connection pool
|
|
168
|
+
const pool = new pg_1.Pool(pgPoolConfig);
|
|
169
|
+
this.dbPromise = Promise.resolve(pool);
|
|
170
|
+
await this.dbPromise;
|
|
171
|
+
this.isInitialized = true;
|
|
172
|
+
console.log("✅ DatabaseService: Initialization completed successfully");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get database instance
|
|
177
|
+
* Throws error if not initialized
|
|
178
|
+
*/
|
|
179
|
+
async getDb() {
|
|
180
|
+
if (!this.dbPromise) {
|
|
181
|
+
throw new Error("DatabaseService not initialized. Call initialize() with connection config first.");
|
|
182
|
+
}
|
|
183
|
+
return this.dbPromise;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Check if database is initialized
|
|
187
|
+
*/
|
|
188
|
+
isReady() {
|
|
189
|
+
return this.isInitialized;
|
|
190
|
+
}
|
|
191
|
+
// =============================================================================
|
|
192
|
+
// COMPREHENSIVE DATABASE OPERATIONS - ALL RDS SCHEMA FUNCTIONS
|
|
193
|
+
// =============================================================================
|
|
194
|
+
// ============================================
|
|
195
|
+
// MAPPING JOB OPERATIONS
|
|
196
|
+
// ============================================
|
|
197
|
+
async createMappingJobForLinkedInAccount(params) {
|
|
198
|
+
const db = await this.getDb();
|
|
199
|
+
return (0, mapping_job_operations_1.createMappingJobForLinkedInAccount)(db, params);
|
|
200
|
+
}
|
|
201
|
+
async createMappingJobWithLinkedInAccounts(accountsData) {
|
|
202
|
+
const db = await this.getDb();
|
|
203
|
+
return (0, mapping_job_operations_1.createMappingJobsForLinkedInAccounts)(db, accountsData);
|
|
204
|
+
}
|
|
205
|
+
async startMappingJob(mappingJobId, metadata) {
|
|
206
|
+
const db = await this.getDb();
|
|
207
|
+
return (0, mapping_job_operations_1.startMappingJob)(db, mappingJobId, metadata);
|
|
208
|
+
}
|
|
209
|
+
async completeMappingJob(mappingJobId, metadata) {
|
|
210
|
+
const db = await this.getDb();
|
|
211
|
+
return (0, mapping_job_operations_1.completeMappingJob)(db, mappingJobId, metadata);
|
|
212
|
+
}
|
|
213
|
+
async validateMappingJobCompletion(mappingJobId) {
|
|
214
|
+
const db = await this.getDb();
|
|
215
|
+
return (0, mapping_job_operations_1.validateMappingJobCompletion)(db, mappingJobId);
|
|
216
|
+
}
|
|
217
|
+
async createLlmInferenceJob(params) {
|
|
218
|
+
const db = await this.getDb();
|
|
219
|
+
return (0, llm_inference_job_operations_1.createLlmInferenceJob)(db, params);
|
|
220
|
+
}
|
|
221
|
+
async createOrganizationAssignmentJob(params) {
|
|
222
|
+
const db = await this.getDb();
|
|
223
|
+
return (0, organization_assignment_job_operations_1.createOrganizationAssignmentJob)(db, params);
|
|
224
|
+
}
|
|
225
|
+
async completeOrganizationAssignmentJob(organizationAssignmentJobId, completionMetadata) {
|
|
226
|
+
const db = await this.getDb();
|
|
227
|
+
return (0, organization_assignment_job_operations_1.completeOrganizationAssignmentJob)(db, organizationAssignmentJobId, completionMetadata);
|
|
228
|
+
}
|
|
229
|
+
async getOrganizationAssignmentJobById(organizationAssignmentJobId) {
|
|
230
|
+
const db = await this.getDb();
|
|
231
|
+
return (0, organization_assignment_job_operations_1.getOrganizationAssignmentJobById)(db, organizationAssignmentJobId);
|
|
232
|
+
}
|
|
233
|
+
async checkExportAvailability(mappingJobId, organizationId) {
|
|
234
|
+
const db = await this.getDb();
|
|
235
|
+
return (0, organization_assignment_job_operations_1.checkExportAvailability)(db, mappingJobId, organizationId);
|
|
236
|
+
}
|
|
237
|
+
async checkExportAvailabilityForLinkedInAccount(linkedinAccountId, organizationId) {
|
|
238
|
+
const db = await this.getDb();
|
|
239
|
+
return (0, organization_assignment_job_operations_1.checkExportAvailabilityForLinkedInAccount)(db, linkedinAccountId, organizationId);
|
|
240
|
+
}
|
|
241
|
+
async getExportStatusByLinkedInIdentifier(linkedinIdentifierAcoa, organizationId) {
|
|
242
|
+
const db = await this.getDb();
|
|
243
|
+
return (0, organization_assignment_job_operations_1.getExportStatusByLinkedInIdentifier)(db, linkedinIdentifierAcoa, organizationId);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get paginated exports for a user (requester)
|
|
247
|
+
* @param requesterLinkedinAccountId - LinkedIn account ID of the requester
|
|
248
|
+
* @param options - Query options (page, pageSize, sort, organizationId, status)
|
|
249
|
+
* @returns Paginated list of exports with profile and organization details
|
|
250
|
+
*/
|
|
251
|
+
async getUserExports(requesterLinkedinAccountId, options = {}) {
|
|
252
|
+
const db = await this.getDb();
|
|
253
|
+
return (0, organization_assignment_job_operations_1.getUserExports)(db, requesterLinkedinAccountId, options);
|
|
254
|
+
}
|
|
255
|
+
async getLatestOrganizationAssignmentJobForUser(userId, organizationId) {
|
|
256
|
+
const db = await this.getDb();
|
|
257
|
+
return (0, organization_assignment_job_operations_1.getLatestOrganizationAssignmentJobForUser)(db, userId, organizationId);
|
|
258
|
+
}
|
|
259
|
+
async getLatestOrganizationAssignmentJob(mappingJobId, organizationId) {
|
|
260
|
+
const db = await this.getDb();
|
|
261
|
+
return (0, organization_assignment_job_operations_1.getLatestOrganizationAssignmentJob)(db, mappingJobId, organizationId);
|
|
262
|
+
}
|
|
263
|
+
async updateOrganizationAssignmentJobMetadata(organizationAssignmentJobId, metadata) {
|
|
264
|
+
const db = await this.getDb();
|
|
265
|
+
return (0, organization_assignment_job_operations_1.updateOrganizationAssignmentJobMetadata)(db, organizationAssignmentJobId, metadata);
|
|
266
|
+
}
|
|
267
|
+
async getRelationshipScoresForMappingJob(mappingJobId, options) {
|
|
268
|
+
const db = await this.getDb();
|
|
269
|
+
return (0, mapping_job_operations_1.getRelationshipScoresForMappingJob)(db, mappingJobId, options);
|
|
270
|
+
}
|
|
271
|
+
async getEnrichedRelationshipScoresForMappingJob(mappingJobId, mainLinkedinAccountId, options) {
|
|
272
|
+
const db = await this.getDb();
|
|
273
|
+
return (0, mapping_job_operations_1.getEnrichedRelationshipScoresForMappingJob)(db, mappingJobId, mainLinkedinAccountId, options);
|
|
274
|
+
}
|
|
275
|
+
async getRelationshipScoresForAccount(linkedinAccountId, options) {
|
|
276
|
+
const db = await this.getDb();
|
|
277
|
+
return (0, relationship_operations_1.getRelationshipScoresForAccount)(db, linkedinAccountId, options);
|
|
278
|
+
}
|
|
279
|
+
async getMappingJobWithLinkedInAccount(mappingJobId) {
|
|
280
|
+
const db = await this.getDb();
|
|
281
|
+
return (0, mapping_job_operations_1.getMappingJobWithLinkedInAccount)(db, mappingJobId);
|
|
282
|
+
}
|
|
283
|
+
// ============================================
|
|
284
|
+
// ONBOARDING OPERATIONS
|
|
285
|
+
// ============================================
|
|
286
|
+
async createOnboardingJob(data) {
|
|
287
|
+
const db = await this.getDb();
|
|
288
|
+
return (0, onboarding_operations_1.createOnboardingJob)(db, data);
|
|
289
|
+
}
|
|
290
|
+
async updateOnboardingJob(onboardingJobId, updates) {
|
|
291
|
+
const db = await this.getDb();
|
|
292
|
+
return (0, onboarding_operations_1.updateOnboardingJob)(db, onboardingJobId, updates);
|
|
293
|
+
}
|
|
294
|
+
async updateOnboardingJobStep(onboardingJobId, currentStep, nextStep, metadata) {
|
|
295
|
+
const db = await this.getDb();
|
|
296
|
+
return (0, onboarding_operations_1.updateOnboardingJobStep)(db, onboardingJobId, currentStep, nextStep, metadata);
|
|
297
|
+
}
|
|
298
|
+
async completeOnboardingJob(onboardingJobId, completionMetadata) {
|
|
299
|
+
const db = await this.getDb();
|
|
300
|
+
return (0, onboarding_operations_1.completeOnboardingJob)(db, onboardingJobId, completionMetadata);
|
|
301
|
+
}
|
|
302
|
+
async getOnboardingJobByUserId(userId) {
|
|
303
|
+
const db = await this.getDb();
|
|
304
|
+
return (0, onboarding_operations_1.getOnboardingJobByUserId)(db, userId);
|
|
305
|
+
}
|
|
306
|
+
async getOnboardingJobById(onboardingJobId) {
|
|
307
|
+
const db = await this.getDb();
|
|
308
|
+
return (0, onboarding_operations_1.getOnboardingJobById)(db, onboardingJobId);
|
|
309
|
+
}
|
|
310
|
+
// ============================================
|
|
311
|
+
// ON-DEMAND MAPPING OPERATIONS
|
|
312
|
+
// ============================================
|
|
313
|
+
async createOnDemandMappingJob(data) {
|
|
314
|
+
const db = await this.getDb();
|
|
315
|
+
return (0, on_demand_mapping_operations_1.createOnDemandMappingJob)(data);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Check and increment quota for a mapping job request
|
|
319
|
+
* Returns whether the operation is allowed based on quota limits
|
|
320
|
+
*/
|
|
321
|
+
async checkAndIncrementMappingJobQuota(authenticatedUserId, organizationId, period = "daily") {
|
|
322
|
+
const db = await this.getDb();
|
|
323
|
+
return (0, quota_operations_1.checkAndIncrementQuota)(db, authenticatedUserId, organizationId, period);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Get current quota status without incrementing
|
|
327
|
+
*/
|
|
328
|
+
async getMappingJobQuotaStatus(authenticatedUserId, organizationId, period = "daily") {
|
|
329
|
+
const db = await this.getDb();
|
|
330
|
+
return (0, quota_operations_1.getQuotaStatus)(db, authenticatedUserId, organizationId, period);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get all quotas for a user across all organizations
|
|
334
|
+
* Returns quotas for all quota types (currently only mapping_jobs, but extensible)
|
|
335
|
+
*/
|
|
336
|
+
async getAllQuotasForUser(authenticatedUserId) {
|
|
337
|
+
const db = await this.getDb();
|
|
338
|
+
return (0, quota_operations_1.getAllQuotasForUser)(db, authenticatedUserId);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Initialize quota records for all organization members when subscription is activated
|
|
342
|
+
* Creates daily and monthly quota records with appropriate limits based on subscription tier
|
|
343
|
+
*/
|
|
344
|
+
async initializeQuotasForOrganization(organizationId) {
|
|
345
|
+
const db = await this.getDb();
|
|
346
|
+
return (0, quota_operations_1.initializeQuotasForOrganization)(db, organizationId);
|
|
347
|
+
}
|
|
348
|
+
async getAllOnDemandMappingJobsForUserMinimal(requesterLinkedinAccountId, limit, offset) {
|
|
349
|
+
const db = await this.getDb();
|
|
350
|
+
return (0, on_demand_mapping_operations_1.getOnDemandMappingJobsMinimal)(db, requesterLinkedinAccountId, limit || 50, offset || 0);
|
|
351
|
+
}
|
|
352
|
+
async checkMappingAvailability(targetLinkedInIdentifier) {
|
|
353
|
+
const db = await this.getDb();
|
|
354
|
+
return (0, mapping_job_operations_1.checkMappingAvailability)(db, targetLinkedInIdentifier);
|
|
355
|
+
}
|
|
356
|
+
async getOnDemandMappingJobById(jobId) {
|
|
357
|
+
return (0, on_demand_mapping_operations_1.getOnDemandMappingJobById)(jobId);
|
|
358
|
+
}
|
|
359
|
+
async getMappingJobById(mappingJobId) {
|
|
360
|
+
const db = await this.getDb();
|
|
361
|
+
return (0, mapping_job_operations_1.getMappingJobById)(db, mappingJobId);
|
|
362
|
+
}
|
|
363
|
+
async getTargetLinkedInAccountIdForOnDemandJobInOrganization(requesterLinkedinAccountId, organizationId) {
|
|
364
|
+
const db = await this.getDb();
|
|
365
|
+
return (0, on_demand_mapping_operations_1.getTargetLinkedInAccountIdForOnDemandJobInOrganization)(db, requesterLinkedinAccountId, organizationId);
|
|
366
|
+
}
|
|
367
|
+
async checkOnDemandMappingJobExists(requesterLinkedInAccountId, targetLinkedInIdentifier) {
|
|
368
|
+
return (0, on_demand_mapping_operations_1.checkOnDemandMappingJobExists)(requesterLinkedInAccountId, targetLinkedInIdentifier);
|
|
369
|
+
}
|
|
370
|
+
async updateOnDemandMappingJobId(requesterLinkedinAccountId, internalIdentifierAcoa, mappingJobId) {
|
|
371
|
+
return (0, on_demand_mapping_operations_1.updateOnDemandMappingJobId)(requesterLinkedinAccountId, internalIdentifierAcoa, mappingJobId);
|
|
372
|
+
}
|
|
373
|
+
// ============================================
|
|
374
|
+
// LINKEDIN ACCOUNT OPERATIONS (Forager-based)
|
|
375
|
+
// ============================================
|
|
376
|
+
async getLinkedInAccountsForUser(userId) {
|
|
377
|
+
const db = await this.getDb();
|
|
378
|
+
return (0, linkedin_account_operations_1.getLinkedInAccountsForUser)(db, userId);
|
|
379
|
+
}
|
|
380
|
+
// ============================================
|
|
381
|
+
// USER OPERATIONS
|
|
382
|
+
// ============================================
|
|
383
|
+
// User operations moved to dedicated user-operations.ts file
|
|
384
|
+
async getAuthenticatedUserByCognitoId(cognitoUserId) {
|
|
385
|
+
const db = await this.getDb();
|
|
386
|
+
return (0, user_operations_1.getAuthenticatedUserByCognitoId)(db, cognitoUserId);
|
|
387
|
+
}
|
|
388
|
+
async getAuthenticatedUserByUserId(userId) {
|
|
389
|
+
const db = await this.getDb();
|
|
390
|
+
return (0, user_operations_1.getAuthenticatedUserByUserId)(db, userId);
|
|
391
|
+
}
|
|
392
|
+
async getAuthenticatedUserByEmail(email) {
|
|
393
|
+
const db = await this.getDb();
|
|
394
|
+
return (0, user_operations_1.getAuthenticatedUserByEmail)(db, email);
|
|
395
|
+
}
|
|
396
|
+
async getUserByCognitoId(cognitoUserId) {
|
|
397
|
+
const db = await this.getDb();
|
|
398
|
+
return (0, user_operations_1.getUserByCognitoId)(db, cognitoUserId);
|
|
399
|
+
}
|
|
400
|
+
async getExistingUnipileAccount(cognitoUserId, platformType) {
|
|
401
|
+
const db = await this.getDb();
|
|
402
|
+
return (0, user_operations_1.getExistingUnipileAccount)(db, cognitoUserId, platformType);
|
|
403
|
+
}
|
|
404
|
+
// DEPRECATED: upsertLinkedAccount removed - use Forager-based operations instead
|
|
405
|
+
// ============================================
|
|
406
|
+
// AUTHENTICATED USER OPERATIONS
|
|
407
|
+
// ============================================
|
|
408
|
+
async findAuthenticatedUserByCognitoId(cognitoUserId) {
|
|
409
|
+
const db = await this.getDb();
|
|
410
|
+
return (0, authenticated_user_operations_1.findAuthenticatedUserByCognitoId)(db, cognitoUserId);
|
|
411
|
+
}
|
|
412
|
+
async findAuthenticatedUserById(authenticatedUserId) {
|
|
413
|
+
const db = await this.getDb();
|
|
414
|
+
return (0, authenticated_user_operations_1.findAuthenticatedUserById)(db, authenticatedUserId);
|
|
415
|
+
}
|
|
416
|
+
async findAuthenticatedUserByUserId(userId) {
|
|
417
|
+
const db = await this.getDb();
|
|
418
|
+
return (0, authenticated_user_operations_1.findAuthenticatedUserByUserId)(db, userId);
|
|
419
|
+
}
|
|
420
|
+
async updateAuthenticatedUserAdminStatus(cognitoUserId, isAdmin) {
|
|
421
|
+
const db = await this.getDb();
|
|
422
|
+
return (0, authenticated_user_operations_1.updateAuthenticatedUserAdminStatus)(db, cognitoUserId, isAdmin);
|
|
423
|
+
}
|
|
424
|
+
async getAllAdminUsers() {
|
|
425
|
+
const db = await this.getDb();
|
|
426
|
+
return (0, authenticated_user_operations_1.getAllAdminUsers)(db);
|
|
427
|
+
}
|
|
428
|
+
// ============================================
|
|
429
|
+
// LINKEDIN DATA OPERATIONS (Forager-based)
|
|
430
|
+
// ============================================
|
|
431
|
+
// ============================================
|
|
432
|
+
// LINKEDIN PROFILE CACHE OPERATIONS
|
|
433
|
+
// ============================================
|
|
434
|
+
async getCachedLinkedinProfiles(acoIdentifiers) {
|
|
435
|
+
const db = await this.getDb();
|
|
436
|
+
return (0, linkedin_profile_cache_1.getCachedLinkedInProfiles)(db, acoIdentifiers);
|
|
437
|
+
}
|
|
438
|
+
async getComprehensiveLinkedinProfile(identifier) {
|
|
439
|
+
const db = await this.getDb();
|
|
440
|
+
return (0, linkedin_profile_cache_1.getCachedLinkedInProfile)(db, identifier);
|
|
441
|
+
}
|
|
442
|
+
async getComprehensiveLinkedinProfileById(linkedinAccountId) {
|
|
443
|
+
const db = await this.getDb();
|
|
444
|
+
return (0, linkedin_profile_cache_1.getCachedLinkedInProfileById)(db, linkedinAccountId);
|
|
445
|
+
}
|
|
446
|
+
// ============================================
|
|
447
|
+
// CONTACT OPERATIONS
|
|
448
|
+
// ============================================
|
|
449
|
+
async createContactInfo(data) {
|
|
450
|
+
const db = await this.getDb();
|
|
451
|
+
return (0, contact_operations_1.createContactInfo)(db, data);
|
|
452
|
+
}
|
|
453
|
+
async upsertContactInfo(data) {
|
|
454
|
+
const db = await this.getDb();
|
|
455
|
+
return (0, contact_operations_1.upsertContactInfo)(db, data);
|
|
456
|
+
}
|
|
457
|
+
async batchCreateContactInfos(contactInfosData) {
|
|
458
|
+
const db = await this.getDb();
|
|
459
|
+
return (0, contact_operations_1.batchCreateContactInfos)(db, contactInfosData);
|
|
460
|
+
}
|
|
461
|
+
async batchUpsertContactInfos(contactInfosData) {
|
|
462
|
+
const db = await this.getDb();
|
|
463
|
+
return (0, contact_operations_1.batchUpsertContactInfos)(db, contactInfosData);
|
|
464
|
+
}
|
|
465
|
+
async getBatchUserEmails(userIds) {
|
|
466
|
+
const db = await this.getDb();
|
|
467
|
+
return (0, contact_operations_1.getBatchUserEmails)(db, userIds);
|
|
468
|
+
}
|
|
469
|
+
// ============================================
|
|
470
|
+
// UNIPILE ACCOUNT OPERATIONS
|
|
471
|
+
// ============================================
|
|
472
|
+
async createUnipileAccount(data) {
|
|
473
|
+
const db = await this.getDb();
|
|
474
|
+
return (0, unipile_account_operations_1.createUnipileAccount)(db, data);
|
|
475
|
+
}
|
|
476
|
+
async upsertUnipileAccount(data) {
|
|
477
|
+
const db = await this.getDb();
|
|
478
|
+
return (0, unipile_account_operations_1.upsertUnipileAccount)(db, data);
|
|
479
|
+
}
|
|
480
|
+
async getUserLinkedAccountStatus(cognitoUserId, activeOnly) {
|
|
481
|
+
const db = await this.getDb();
|
|
482
|
+
return (0, unipile_account_operations_1.getUserLinkedAccountStatus)(db, cognitoUserId, activeOnly);
|
|
483
|
+
}
|
|
484
|
+
async batchMarkAccountsAsSynced(accountIds, syncTime) {
|
|
485
|
+
const db = await this.getDb();
|
|
486
|
+
return (0, unipile_account_operations_1.batchMarkAccountsAsSynced)(db, accountIds, syncTime);
|
|
487
|
+
}
|
|
488
|
+
async checkAcoaAlreadyConnectedToDifferentUser(linkedinIdentifierAcoa, currentUserId) {
|
|
489
|
+
const db = await this.getDb();
|
|
490
|
+
return (0, unipile_account_operations_1.checkAcoaAlreadyConnectedToDifferentUser)(db, linkedinIdentifierAcoa, currentUserId);
|
|
491
|
+
}
|
|
492
|
+
// ============================================
|
|
493
|
+
// SOCIAL ACCOUNT RELATIONSHIP OPERATIONS
|
|
494
|
+
// ============================================
|
|
495
|
+
async upsertLinkedInAccountRelationshipScore(data) {
|
|
496
|
+
const db = await this.getDb();
|
|
497
|
+
return (0, linkedin_account_relationship_operations_1.upsertLinkedInAccountRelationshipScore)(db, data);
|
|
498
|
+
}
|
|
499
|
+
async getLinkedInAccountRelationshipScore(linkedinAccountIdA, linkedinAccountIdB, modelVersion, analysisType) {
|
|
500
|
+
const db = await this.getDb();
|
|
501
|
+
return (0, linkedin_account_relationship_operations_1.getLinkedInAccountRelationshipScore)(db, linkedinAccountIdA, linkedinAccountIdB, modelVersion, analysisType);
|
|
502
|
+
}
|
|
503
|
+
async getLinkedInRelationshipByIdWithAccountsAndUsers(relationshipId) {
|
|
504
|
+
const db = await this.getDb();
|
|
505
|
+
return (0, linkedin_account_relationship_operations_1.getLinkedInRelationshipByIdWithAccountsAndUsers)(db, relationshipId);
|
|
506
|
+
}
|
|
507
|
+
// ============================================
|
|
508
|
+
// RELATIONSHIP OPERATIONS
|
|
509
|
+
// ============================================
|
|
510
|
+
async getTopClosestConnections(cognitoUserId, modelVersion, limit, sortOrder) {
|
|
511
|
+
const db = await this.getDb();
|
|
512
|
+
return (0, relationship_operations_1.getTopClosestConnections)(db, cognitoUserId, modelVersion, limit, sortOrder);
|
|
513
|
+
}
|
|
514
|
+
// ============================================
|
|
515
|
+
// QUERY OPERATIONS
|
|
516
|
+
// ============================================
|
|
517
|
+
async getConnectionsForChromeExtension(identifier, identifierType) {
|
|
518
|
+
const db = await this.getDb();
|
|
519
|
+
return (0, minimal_connections_1.getConnectionsForChromeExtension)(db, identifier, identifierType);
|
|
520
|
+
}
|
|
521
|
+
// ============================================
|
|
522
|
+
// AUTHENTICATION OPERATIONS (Forager-based)
|
|
523
|
+
// ============================================
|
|
524
|
+
async handlePostAuthentication(cognitoUserId, userId, signupEmail) {
|
|
525
|
+
const db = await this.getDb();
|
|
526
|
+
return (0, authentication_operations_1.handlePostAuthentication)(db, cognitoUserId, userId, signupEmail);
|
|
527
|
+
}
|
|
528
|
+
// ============================================
|
|
529
|
+
// SKILLS OPERATIONS
|
|
530
|
+
// ============================================
|
|
531
|
+
async findOrCreateSkill(skillName, category) {
|
|
532
|
+
const db = await this.getDb();
|
|
533
|
+
return (0, skills_operations_1.findOrCreateSkill)(db, skillName, category);
|
|
534
|
+
}
|
|
535
|
+
async findOrCreateSkills(skillInputs) {
|
|
536
|
+
const db = await this.getDb();
|
|
537
|
+
return (0, skills_operations_1.findOrCreateSkills)(db, skillInputs);
|
|
538
|
+
}
|
|
539
|
+
async addProfileSkills(profileId, skillInputs) {
|
|
540
|
+
const db = await this.getDb();
|
|
541
|
+
return (0, skills_operations_1.addProfileSkills)(db, profileId, skillInputs);
|
|
542
|
+
}
|
|
543
|
+
async getProfileSkills(profileId) {
|
|
544
|
+
const db = await this.getDb();
|
|
545
|
+
return (0, skills_operations_1.getProfileSkills)(db, profileId);
|
|
546
|
+
}
|
|
547
|
+
async addWorkExperienceSkills(workExperienceId, skillInputs) {
|
|
548
|
+
const db = await this.getDb();
|
|
549
|
+
return (0, skills_operations_1.addWorkExperienceSkills)(db, workExperienceId, skillInputs);
|
|
550
|
+
}
|
|
551
|
+
async addEducationSkills(educationId, skillInputs) {
|
|
552
|
+
const db = await this.getDb();
|
|
553
|
+
return (0, skills_operations_1.addEducationSkills)(db, educationId, skillInputs);
|
|
554
|
+
}
|
|
555
|
+
async getEducationSkills(educationId) {
|
|
556
|
+
const db = await this.getDb();
|
|
557
|
+
return (0, skills_operations_1.getEducationSkills)(db, educationId);
|
|
558
|
+
}
|
|
559
|
+
async getWorkExperienceSkills(workExperienceId) {
|
|
560
|
+
const db = await this.getDb();
|
|
561
|
+
return (0, skills_operations_1.getWorkExperienceSkills)(db, workExperienceId);
|
|
562
|
+
}
|
|
563
|
+
async getPopularSkills(limit) {
|
|
564
|
+
const db = await this.getDb();
|
|
565
|
+
return (0, skills_operations_1.getPopularSkills)(db, limit);
|
|
566
|
+
}
|
|
567
|
+
// LinkedIn Account Operations (Forager-based - Primary)
|
|
568
|
+
async findLinkedInAccountByForagerId(foragerId) {
|
|
569
|
+
const db = await this.getDb();
|
|
570
|
+
return (0, forager_linkedin_operations_1.findLinkedInAccountByForagerId)(db, foragerId);
|
|
571
|
+
}
|
|
572
|
+
async findLinkedInAccountByPublicIdentifier(publicIdentifier) {
|
|
573
|
+
const db = await this.getDb();
|
|
574
|
+
return (0, forager_linkedin_operations_1.findLinkedInAccountByPublicIdentifier)(db, publicIdentifier);
|
|
575
|
+
}
|
|
576
|
+
async findLinkedInAccountByAnyIdentifier(identifier) {
|
|
577
|
+
const db = await this.getDb();
|
|
578
|
+
return (0, forager_linkedin_operations_1.findLinkedInAccountByAnyIdentifier)(db, identifier);
|
|
579
|
+
}
|
|
580
|
+
async findLinkedInAccountByAcoa(linkedinIdentifierAcoa) {
|
|
581
|
+
const db = await this.getDb();
|
|
582
|
+
return (0, ghost_genius_linkedin_operations_1.findLinkedInAccountByAcoa)(db, linkedinIdentifierAcoa);
|
|
583
|
+
}
|
|
584
|
+
async findOrCreateLinkedInAccountByAcoa(linkedinIdentifierAcoa, publicIdentifier, userId) {
|
|
585
|
+
const db = await this.getDb();
|
|
586
|
+
return (0, ghost_genius_linkedin_operations_1.findOrCreateLinkedInAccountByAcoa)(db, linkedinIdentifierAcoa, publicIdentifier, userId);
|
|
587
|
+
}
|
|
588
|
+
async findOrCreateLinkedInAccountByForagerId(foragerId, publicIdentifier, linkedinIdentifierAcoa, userId) {
|
|
589
|
+
const db = await this.getDb();
|
|
590
|
+
return (0, forager_linkedin_operations_1.findOrCreateLinkedInAccountByForagerId)(db, foragerId, publicIdentifier, linkedinIdentifierAcoa, userId);
|
|
591
|
+
}
|
|
592
|
+
async storeCompleteLinkedInProfileByForagerId(foragerId, profileData, userId, userWasCreated = false) {
|
|
593
|
+
const db = await this.getDb();
|
|
594
|
+
return (0, linkedin_data_operations_1.storeCompleteLinkedInProfileByForagerId)(db, foragerId, profileData, userId, userWasCreated);
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Store complete LinkedIn profile using ACoA identifier (for Ghost Genius profiles)
|
|
598
|
+
*/
|
|
599
|
+
async storeCompleteLinkedInProfileByAcoa(linkedinIdentifierAcoa, profileData, userId, userWasCreated = false) {
|
|
600
|
+
const db = await this.getDb();
|
|
601
|
+
return (0, linkedin_data_operations_1.storeCompleteLinkedInProfileByAcoa)(db, linkedinIdentifierAcoa, profileData, userId, userWasCreated);
|
|
602
|
+
}
|
|
603
|
+
async updateLinkedInAccountAcoaIdentifierByForagerId(foragerId, linkedinIdentifierAcoa) {
|
|
604
|
+
const db = await this.getDb();
|
|
605
|
+
const { updateLinkedInAccountAcoaIdentifierByForagerId } = await Promise.resolve().then(() => __importStar(require("../utils/forager-linkedin-operations")));
|
|
606
|
+
return updateLinkedInAccountAcoaIdentifierByForagerId(db, foragerId, linkedinIdentifierAcoa);
|
|
607
|
+
}
|
|
608
|
+
async updateLinkedInAccountAcoaIdentifierByForagerIdWithChangeDetection(foragerId, linkedinIdentifierAcoa) {
|
|
609
|
+
const db = await this.getDb();
|
|
610
|
+
const { updateLinkedInAccountAcoaIdentifierByForagerIdWithChangeDetection } = await Promise.resolve().then(() => __importStar(require("../utils/forager-linkedin-operations")));
|
|
611
|
+
return updateLinkedInAccountAcoaIdentifierByForagerIdWithChangeDetection(db, foragerId, linkedinIdentifierAcoa);
|
|
612
|
+
}
|
|
613
|
+
async updateLinkedInAccountProfilePictureUrl(linkedinAccountId, profilePictureUrl, profileImageHash) {
|
|
614
|
+
const db = await this.getDb();
|
|
615
|
+
const sql = profileImageHash
|
|
616
|
+
? `
|
|
617
|
+
UPDATE linkedin.accounts
|
|
618
|
+
SET profile_image_cloudfront_url = $1,
|
|
619
|
+
profile_image_hash = $2
|
|
620
|
+
WHERE id = $3
|
|
621
|
+
RETURNING id, user_id, linkedin_identifier_acoa, public_identifier, forager_id,
|
|
622
|
+
first_name, last_name, headline, summary, location,
|
|
623
|
+
profile_picture_url, profile_image_cloudfront_url, profile_image_hash,
|
|
624
|
+
follower_count, connections_count, profiles_updated_at, created_at
|
|
625
|
+
`
|
|
626
|
+
: `
|
|
627
|
+
UPDATE linkedin.accounts
|
|
628
|
+
SET profile_image_cloudfront_url = $1
|
|
629
|
+
WHERE id = $2
|
|
630
|
+
RETURNING id, user_id, linkedin_identifier_acoa, public_identifier, forager_id,
|
|
631
|
+
first_name, last_name, headline, summary, location,
|
|
632
|
+
profile_picture_url, profile_image_cloudfront_url, profile_image_hash,
|
|
633
|
+
follower_count, connections_count, profiles_updated_at, created_at
|
|
634
|
+
`;
|
|
635
|
+
const params = profileImageHash
|
|
636
|
+
? [profilePictureUrl, profileImageHash, linkedinAccountId]
|
|
637
|
+
: [profilePictureUrl, linkedinAccountId];
|
|
638
|
+
const result = await db.query(sql, params);
|
|
639
|
+
return result.rows[0];
|
|
640
|
+
}
|
|
641
|
+
async getLinkedInAccountProfileImageHash(linkedinAccountId) {
|
|
642
|
+
const db = await this.getDb();
|
|
643
|
+
const sql = `
|
|
644
|
+
SELECT profile_image_hash
|
|
645
|
+
FROM linkedin.accounts
|
|
646
|
+
WHERE id = $1
|
|
647
|
+
LIMIT 1
|
|
648
|
+
`;
|
|
649
|
+
const result = await db.query(sql, [linkedinAccountId]);
|
|
650
|
+
return result.rows[0]?.profile_image_hash || null;
|
|
651
|
+
}
|
|
652
|
+
async refreshCompleteLinkedInProfileByForagerId(foragerId, profileData, userId) {
|
|
653
|
+
const db = await this.getDb();
|
|
654
|
+
const { refreshCompleteLinkedInProfileByForagerId } = await Promise.resolve().then(() => __importStar(require("../utils/linkedin-data-operations")));
|
|
655
|
+
return refreshCompleteLinkedInProfileByForagerId(db, foragerId, profileData, userId);
|
|
656
|
+
}
|
|
657
|
+
// Authenticated User Operations (Forager-based)
|
|
658
|
+
async findAuthenticatedUserByForagerId(foragerId) {
|
|
659
|
+
const db = await this.getDb();
|
|
660
|
+
const { findAuthenticatedUserByForagerId } = await Promise.resolve().then(() => __importStar(require("../utils/authenticated-user-operations")));
|
|
661
|
+
return findAuthenticatedUserByForagerId(db, foragerId);
|
|
662
|
+
}
|
|
663
|
+
async findAuthenticatedUserByPublicIdentifier(publicIdentifier) {
|
|
664
|
+
const db = await this.getDb();
|
|
665
|
+
const { findAuthenticatedUserByPublicIdentifier } = await Promise.resolve().then(() => __importStar(require("../utils/authenticated-user-operations")));
|
|
666
|
+
return findAuthenticatedUserByPublicIdentifier(db, publicIdentifier);
|
|
667
|
+
}
|
|
668
|
+
async findAuthenticatedUserByAnyIdentifier(identifier) {
|
|
669
|
+
const db = await this.getDb();
|
|
670
|
+
const { findAuthenticatedUserByAnyIdentifier } = await Promise.resolve().then(() => __importStar(require("../utils/authenticated-user-operations")));
|
|
671
|
+
return findAuthenticatedUserByAnyIdentifier(db, identifier);
|
|
672
|
+
}
|
|
673
|
+
// Authentication Operations (Forager-based)
|
|
674
|
+
async handleLinkedInProfileFetchByForagerId(foragerId, publicIdentifier, profileData, linkedinIdentifierAcoa, providerAccountId) {
|
|
675
|
+
const db = await this.getDb();
|
|
676
|
+
const { handleLinkedInProfileFetchByForagerId } = await Promise.resolve().then(() => __importStar(require("../utils/authentication-operations")));
|
|
677
|
+
return handleLinkedInProfileFetchByForagerId(db, foragerId, publicIdentifier, profileData, linkedinIdentifierAcoa, providerAccountId);
|
|
678
|
+
}
|
|
679
|
+
async getMostRecentWorkExperience(linkedinAccountId) {
|
|
680
|
+
const db = await this.getDb();
|
|
681
|
+
return (0, linkedin_account_operations_1.getMostRecentWorkExperience)(db, linkedinAccountId);
|
|
682
|
+
}
|
|
683
|
+
// ============================================
|
|
684
|
+
// ORGANIZATION OPERATIONS
|
|
685
|
+
// ============================================
|
|
686
|
+
async getOrganizationMembershipsForUser(userId) {
|
|
687
|
+
const db = await this.getDb();
|
|
688
|
+
return (0, organization_operations_1.getOrganizationMembershipsForUser)(db, userId);
|
|
689
|
+
}
|
|
690
|
+
async getOrganizationById(organizationId) {
|
|
691
|
+
const db = await this.getDb();
|
|
692
|
+
return (0, organization_operations_1.getOrganizationById)(db, organizationId);
|
|
693
|
+
}
|
|
694
|
+
async findOrganizationByLinkedInCompanyId(linkedinCompanyId) {
|
|
695
|
+
const db = await this.getDb();
|
|
696
|
+
const { findOrganizationByLinkedInCompanyId } = await Promise.resolve().then(() => __importStar(require("../utils/organization-operations")));
|
|
697
|
+
return findOrganizationByLinkedInCompanyId(db, linkedinCompanyId);
|
|
698
|
+
}
|
|
699
|
+
async findOrganizationByLinkedInPublicIdentifier(linkedinPublicIdentifier) {
|
|
700
|
+
const db = await this.getDb();
|
|
701
|
+
const { findOrganizationByLinkedInPublicIdentifier } = await Promise.resolve().then(() => __importStar(require("../utils/organization-operations")));
|
|
702
|
+
return findOrganizationByLinkedInPublicIdentifier(db, linkedinPublicIdentifier);
|
|
703
|
+
}
|
|
704
|
+
async findOrganizationByDedupKey(dedupKey) {
|
|
705
|
+
const db = await this.getDb();
|
|
706
|
+
const { findOrganizationByDedupKey } = await Promise.resolve().then(() => __importStar(require("../utils/organization-operations")));
|
|
707
|
+
return findOrganizationByDedupKey(db, dedupKey);
|
|
708
|
+
}
|
|
709
|
+
async updateOrganizationLinkedInPublicIdentifier(organizationId, linkedinPublicIdentifier) {
|
|
710
|
+
const db = await this.getDb();
|
|
711
|
+
const { updateOrganizationLinkedInPublicIdentifier } = await Promise.resolve().then(() => __importStar(require("../utils/organization-operations")));
|
|
712
|
+
return updateOrganizationLinkedInPublicIdentifier(db, organizationId, linkedinPublicIdentifier);
|
|
713
|
+
}
|
|
714
|
+
async createCompanyMappingJob(options) {
|
|
715
|
+
const db = await this.getDb();
|
|
716
|
+
const { createCompanyMappingJob } = await Promise.resolve().then(() => __importStar(require("../utils/company-mapping-job-operations")));
|
|
717
|
+
return createCompanyMappingJob(db, options);
|
|
718
|
+
}
|
|
719
|
+
async updateCompanyMappingJobLinkedInId(companyMappingJobId, linkedinCompanyId) {
|
|
720
|
+
const db = await this.getDb();
|
|
721
|
+
const { updateCompanyMappingJobLinkedInId } = await Promise.resolve().then(() => __importStar(require("../utils/company-mapping-job-operations")));
|
|
722
|
+
return updateCompanyMappingJobLinkedInId(db, companyMappingJobId, linkedinCompanyId);
|
|
723
|
+
}
|
|
724
|
+
async updateCompanyMappingJobS3Path(companyMappingJobId, s3FilePath) {
|
|
725
|
+
const db = await this.getDb();
|
|
726
|
+
const { updateCompanyMappingJobS3Path } = await Promise.resolve().then(() => __importStar(require("../utils/company-mapping-job-operations")));
|
|
727
|
+
return updateCompanyMappingJobS3Path(db, companyMappingJobId, s3FilePath);
|
|
728
|
+
}
|
|
729
|
+
async updateCompanyMappingJobQueued(companyMappingJobId, employeesCount) {
|
|
730
|
+
const db = await this.getDb();
|
|
731
|
+
const { updateCompanyMappingJobQueued } = await Promise.resolve().then(() => __importStar(require("../utils/company-mapping-job-operations")));
|
|
732
|
+
return updateCompanyMappingJobQueued(db, companyMappingJobId, employeesCount);
|
|
733
|
+
}
|
|
734
|
+
async updateCompanyMappingJobStarted(companyMappingJobId) {
|
|
735
|
+
const db = await this.getDb();
|
|
736
|
+
const { updateCompanyMappingJobStarted } = await Promise.resolve().then(() => __importStar(require("../utils/company-mapping-job-operations")));
|
|
737
|
+
return updateCompanyMappingJobStarted(db, companyMappingJobId);
|
|
738
|
+
}
|
|
739
|
+
async updateCompanyMappingJobCompleted(companyMappingJobId, employeesCount) {
|
|
740
|
+
const db = await this.getDb();
|
|
741
|
+
const { updateCompanyMappingJobCompleted } = await Promise.resolve().then(() => __importStar(require("../utils/company-mapping-job-operations")));
|
|
742
|
+
return updateCompanyMappingJobCompleted(db, companyMappingJobId, employeesCount);
|
|
743
|
+
}
|
|
744
|
+
async getCompanyMappingJobById(companyMappingJobId) {
|
|
745
|
+
const db = await this.getDb();
|
|
746
|
+
const { getCompanyMappingJobById } = await Promise.resolve().then(() => __importStar(require("../utils/company-mapping-job-operations")));
|
|
747
|
+
return getCompanyMappingJobById(db, companyMappingJobId);
|
|
748
|
+
}
|
|
749
|
+
async updateCompanyMappingJobOrganizationId(companyMappingJobId, organizationId) {
|
|
750
|
+
const db = await this.getDb();
|
|
751
|
+
const { updateCompanyMappingJobOrganizationId } = await Promise.resolve().then(() => __importStar(require("../utils/company-mapping-job-operations")));
|
|
752
|
+
return updateCompanyMappingJobOrganizationId(db, companyMappingJobId, organizationId);
|
|
753
|
+
}
|
|
754
|
+
// =============================================================================
|
|
755
|
+
// RECURSIVE MAPPING JOB OPERATIONS
|
|
756
|
+
// =============================================================================
|
|
757
|
+
async createRecursiveMappingJob(options) {
|
|
758
|
+
const db = await this.getDb();
|
|
759
|
+
const { createRecursiveMappingJob } = await Promise.resolve().then(() => __importStar(require("../utils/recursive-mapping-job-operations")));
|
|
760
|
+
return createRecursiveMappingJob(db, options);
|
|
761
|
+
}
|
|
762
|
+
async getRecursiveMappingJobById(recursiveMappingJobId) {
|
|
763
|
+
const db = await this.getDb();
|
|
764
|
+
const { getRecursiveMappingJobById } = await Promise.resolve().then(() => __importStar(require("../utils/recursive-mapping-job-operations")));
|
|
765
|
+
return getRecursiveMappingJobById(db, recursiveMappingJobId);
|
|
766
|
+
}
|
|
767
|
+
async updateRecursiveMappingJobStarted(recursiveMappingJobId) {
|
|
768
|
+
const db = await this.getDb();
|
|
769
|
+
const { updateRecursiveMappingJobStarted } = await Promise.resolve().then(() => __importStar(require("../utils/recursive-mapping-job-operations")));
|
|
770
|
+
return updateRecursiveMappingJobStarted(db, recursiveMappingJobId);
|
|
771
|
+
}
|
|
772
|
+
async updateRecursiveMappingJobCompleted(recursiveMappingJobId, downstreamJobsCount) {
|
|
773
|
+
const db = await this.getDb();
|
|
774
|
+
const { updateRecursiveMappingJobCompleted } = await Promise.resolve().then(() => __importStar(require("../utils/recursive-mapping-job-operations")));
|
|
775
|
+
return updateRecursiveMappingJobCompleted(db, recursiveMappingJobId, downstreamJobsCount);
|
|
776
|
+
}
|
|
777
|
+
async updateOrganizationSubscriptionTier(organizationId, subscriptionTier) {
|
|
778
|
+
const db = await this.getDb();
|
|
779
|
+
const { updateOrganizationSubscriptionTier } = await Promise.resolve().then(() => __importStar(require("../utils/organization-operations")));
|
|
780
|
+
return updateOrganizationSubscriptionTier(db, organizationId, subscriptionTier);
|
|
781
|
+
}
|
|
782
|
+
// =============================================================================
|
|
783
|
+
// SUBSCRIPTION OPERATIONS
|
|
784
|
+
// =============================================================================
|
|
785
|
+
async upsertSubscription(subscriptionData) {
|
|
786
|
+
const db = await this.getDb();
|
|
787
|
+
const { upsertSubscription } = await Promise.resolve().then(() => __importStar(require("../utils/subscription-operations")));
|
|
788
|
+
return upsertSubscription(db, subscriptionData);
|
|
789
|
+
}
|
|
790
|
+
async getSubscriptionByStripeId(stripeSubscriptionId) {
|
|
791
|
+
const db = await this.getDb();
|
|
792
|
+
const { getSubscriptionByStripeId } = await Promise.resolve().then(() => __importStar(require("../utils/subscription-operations")));
|
|
793
|
+
return getSubscriptionByStripeId(db, stripeSubscriptionId);
|
|
794
|
+
}
|
|
795
|
+
async getSubscriptionByOrganizationId(organizationId) {
|
|
796
|
+
const db = await this.getDb();
|
|
797
|
+
const { getSubscriptionByOrganizationId } = await Promise.resolve().then(() => __importStar(require("../utils/subscription-operations")));
|
|
798
|
+
return getSubscriptionByOrganizationId(db, organizationId);
|
|
799
|
+
}
|
|
800
|
+
async hasOrganizationUsedFreeTrial(organizationId) {
|
|
801
|
+
const db = await this.getDb();
|
|
802
|
+
const { hasOrganizationUsedFreeTrial } = await Promise.resolve().then(() => __importStar(require("../utils/subscription-operations")));
|
|
803
|
+
return hasOrganizationUsedFreeTrial(db, organizationId);
|
|
804
|
+
}
|
|
805
|
+
async hasUserUsedFreeTrial(userId) {
|
|
806
|
+
const db = await this.getDb();
|
|
807
|
+
const { hasUserUsedFreeTrial } = await Promise.resolve().then(() => __importStar(require("../utils/subscription-operations")));
|
|
808
|
+
return hasUserUsedFreeTrial(db, userId);
|
|
809
|
+
}
|
|
810
|
+
async isStripeEventProcessed(stripeEventId) {
|
|
811
|
+
const db = await this.getDb();
|
|
812
|
+
const { isStripeEventProcessed } = await Promise.resolve().then(() => __importStar(require("../utils/subscription-operations")));
|
|
813
|
+
return isStripeEventProcessed(db, stripeEventId);
|
|
814
|
+
}
|
|
815
|
+
async updateSubscription(stripeSubscriptionId, updateData) {
|
|
816
|
+
const db = await this.getDb();
|
|
817
|
+
const { updateSubscription } = await Promise.resolve().then(() => __importStar(require("../utils/subscription-operations")));
|
|
818
|
+
return updateSubscription(db, stripeSubscriptionId, updateData);
|
|
819
|
+
}
|
|
820
|
+
async getOrganizationMembers(organizationId) {
|
|
821
|
+
const db = await this.getDb();
|
|
822
|
+
return (0, organization_operations_1.getOrganizationMembers)(db, organizationId);
|
|
823
|
+
}
|
|
824
|
+
async getOrganizationContributors(organizationId, limit = 50, offset = 0) {
|
|
825
|
+
const db = await this.getDb();
|
|
826
|
+
return (0, organization_operations_1.getOrganizationContributors)(db, organizationId, limit, offset);
|
|
827
|
+
}
|
|
828
|
+
async getOrganizationContributorsCount(organizationId) {
|
|
829
|
+
const db = await this.getDb();
|
|
830
|
+
return (0, organization_operations_1.getOrganizationContributorsCount)(db, organizationId);
|
|
831
|
+
}
|
|
832
|
+
async getOrganizationMembersCount(organizationId, contributionRole) {
|
|
833
|
+
const db = await this.getDb();
|
|
834
|
+
return (0, organization_operations_1.getOrganizationMembersCount)(db, organizationId, contributionRole);
|
|
835
|
+
}
|
|
836
|
+
async getOrganizationMembershipForUser(userId, organizationId) {
|
|
837
|
+
const db = await this.getDb();
|
|
838
|
+
return (0, organization_operations_1.getOrganizationMembershipForUser)(db, userId, organizationId);
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Get organization member by ID
|
|
842
|
+
*/
|
|
843
|
+
async getOrganizationMemberById(memberId) {
|
|
844
|
+
const db = await this.getDb();
|
|
845
|
+
const { getOrganizationMemberById } = await Promise.resolve().then(() => __importStar(require("../utils/organization-operations")));
|
|
846
|
+
return getOrganizationMemberById(db, memberId);
|
|
847
|
+
}
|
|
848
|
+
async getOrganizationContributorByUserId(organizationId, userId) {
|
|
849
|
+
const db = await this.getDb();
|
|
850
|
+
return (0, organization_operations_1.getOrganizationContributorByUserId)(db, organizationId, userId);
|
|
851
|
+
}
|
|
852
|
+
async findContributorPage(organizationId, userId, limit = 50) {
|
|
853
|
+
const db = await this.getDb();
|
|
854
|
+
return (0, organization_operations_1.findContributorPage)(db, organizationId, userId, limit);
|
|
855
|
+
}
|
|
856
|
+
async updateOrganizationMemberRole(userId, organizationId, params) {
|
|
857
|
+
const db = await this.getDb();
|
|
858
|
+
return (0, organization_operations_1.updateOrganizationMemberRole)(db, userId, organizationId, params);
|
|
859
|
+
}
|
|
860
|
+
async getOrganizationMemberRelationships(organizationId, linkedinAccountId, limit = 50) {
|
|
861
|
+
const db = await this.getDb();
|
|
862
|
+
return (0, organization_operations_1.getOrganizationMemberRelationships)(db, organizationId, linkedinAccountId, limit);
|
|
863
|
+
}
|
|
864
|
+
async getOrganizationMemberRelationshipsCount(organizationId, linkedinAccountId) {
|
|
865
|
+
const db = await this.getDb();
|
|
866
|
+
const { getOrganizationMemberRelationshipsCount } = await Promise.resolve().then(() => __importStar(require("../utils/organization-operations")));
|
|
867
|
+
return getOrganizationMemberRelationshipsCount(db, organizationId, linkedinAccountId);
|
|
868
|
+
}
|
|
869
|
+
async createOrganization(organizationData) {
|
|
870
|
+
const db = await this.getDb();
|
|
871
|
+
return (0, organization_operations_1.createOrganization)(db, organizationData);
|
|
872
|
+
}
|
|
873
|
+
async findOrCreateOrganizationMember(membershipData) {
|
|
874
|
+
const db = await this.getDb();
|
|
875
|
+
return (0, organization_operations_1.findOrCreateOrganizationMember)(db, membershipData);
|
|
876
|
+
}
|
|
877
|
+
async findPersonalWorkspaceForUser(userId) {
|
|
878
|
+
const db = await this.getDb();
|
|
879
|
+
return (0, organization_operations_1.findPersonalWorkspaceForUser)(db, userId);
|
|
880
|
+
}
|
|
881
|
+
async findOrCreateOrganizationMemberLegacy(params) {
|
|
882
|
+
const db = await this.getDb();
|
|
883
|
+
// Try to find existing member
|
|
884
|
+
const selectSql = `
|
|
885
|
+
SELECT id, organization_id, user_id, contribution_role, permissions_role, created_at
|
|
886
|
+
FROM public.organization_members
|
|
887
|
+
WHERE organization_id = $1 AND user_id = $2
|
|
888
|
+
LIMIT 1
|
|
889
|
+
`;
|
|
890
|
+
const existing = await db.query(selectSql, [params.organizationId, params.userId]);
|
|
891
|
+
if (existing.rows.length > 0) {
|
|
892
|
+
return existing.rows[0];
|
|
893
|
+
}
|
|
894
|
+
// Create new member
|
|
895
|
+
const insertSql = `
|
|
896
|
+
INSERT INTO public.organization_members (organization_id, user_id, contribution_role, permissions_role, created_at)
|
|
897
|
+
VALUES ($1, $2, $3, $4, NOW())
|
|
898
|
+
RETURNING id, organization_id, user_id, contribution_role, permissions_role, created_at
|
|
899
|
+
`;
|
|
900
|
+
const result = await db.query(insertSql, [
|
|
901
|
+
params.organizationId,
|
|
902
|
+
params.userId,
|
|
903
|
+
params.contributionRole,
|
|
904
|
+
params.permissionsRole,
|
|
905
|
+
]);
|
|
906
|
+
return result.rows[0];
|
|
907
|
+
}
|
|
908
|
+
async createOrganizationUserRelationshipAssignment(params) {
|
|
909
|
+
const db = await this.getDb();
|
|
910
|
+
const sql = `
|
|
911
|
+
INSERT INTO public.organization_user_relationships_assignments (organization_id, linkedin_relationship_id, created_at)
|
|
912
|
+
VALUES ($1, $2, NOW())
|
|
913
|
+
ON CONFLICT (organization_id, linkedin_relationship_id) DO NOTHING
|
|
914
|
+
RETURNING id, organization_id, linkedin_relationship_id, created_at
|
|
915
|
+
`;
|
|
916
|
+
const result = await db.query(sql, [params.organizationId, params.linkedinRelationshipId]);
|
|
917
|
+
// If no row was returned, it means the assignment already exists (ON CONFLICT DO NOTHING)
|
|
918
|
+
// This is not an error - it's idempotent behavior
|
|
919
|
+
if (!result.rows || result.rows.length === 0) {
|
|
920
|
+
// Return null to indicate the assignment already existed
|
|
921
|
+
return null;
|
|
922
|
+
}
|
|
923
|
+
return result.rows[0];
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Bulk create organization user relationship assignments
|
|
927
|
+
* This is more efficient and atomic than individual inserts
|
|
928
|
+
*
|
|
929
|
+
* @param params - Parameters for bulk creation
|
|
930
|
+
* @returns Object with counts of created and skipped assignments
|
|
931
|
+
*/
|
|
932
|
+
async bulkCreateOrganizationUserRelationshipAssignments(params) {
|
|
933
|
+
const db = await this.getDb();
|
|
934
|
+
if (params.linkedinRelationshipIds.length === 0) {
|
|
935
|
+
return { created: 0, skipped: 0 };
|
|
936
|
+
}
|
|
937
|
+
// Build VALUES clause for bulk insert
|
|
938
|
+
const values = [];
|
|
939
|
+
const sqlParams = [params.organizationId];
|
|
940
|
+
let paramIndex = 2;
|
|
941
|
+
params.linkedinRelationshipIds.forEach(relationshipId => {
|
|
942
|
+
values.push(`($1, $${paramIndex}, NOW())`);
|
|
943
|
+
sqlParams.push(relationshipId);
|
|
944
|
+
paramIndex++;
|
|
945
|
+
});
|
|
946
|
+
const sql = `
|
|
947
|
+
INSERT INTO public.organization_user_relationships_assignments (organization_id, linkedin_relationship_id, created_at)
|
|
948
|
+
VALUES ${values.join(", ")}
|
|
949
|
+
ON CONFLICT (organization_id, linkedin_relationship_id) DO NOTHING
|
|
950
|
+
RETURNING id, organization_id, linkedin_relationship_id, created_at
|
|
951
|
+
`;
|
|
952
|
+
const result = await db.query(sql, sqlParams);
|
|
953
|
+
const created = result.rows.length;
|
|
954
|
+
const skipped = params.linkedinRelationshipIds.length - created;
|
|
955
|
+
return { created, skipped };
|
|
956
|
+
}
|
|
957
|
+
async deleteOrganizationUserRelationshipAssignmentsByLinkedInAccount(params) {
|
|
958
|
+
const db = await this.getDb();
|
|
959
|
+
// Import the function from organization-relationship-operations
|
|
960
|
+
const { deleteOrganizationUserRelationshipAssignmentsByLinkedInAccount } = await Promise.resolve().then(() => __importStar(require("../utils/organization-relationship-operations")));
|
|
961
|
+
return deleteOrganizationUserRelationshipAssignmentsByLinkedInAccount(db, params);
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Get organization relationship assignment by ID
|
|
965
|
+
* @param assignmentId - Organization relationship assignment ID
|
|
966
|
+
* @returns Assignment data or null if not found
|
|
967
|
+
*/
|
|
968
|
+
async getOrganizationRelationshipAssignmentById(assignmentId) {
|
|
969
|
+
const db = await this.getDb();
|
|
970
|
+
const { getOrganizationRelationshipAssignmentById } = await Promise.resolve().then(() => __importStar(require("../utils/organization-relationship-operations")));
|
|
971
|
+
return getOrganizationRelationshipAssignmentById(db, assignmentId);
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Find organization member for a relationship
|
|
975
|
+
* @param organizationId - Organization ID
|
|
976
|
+
* @param linkedinRelationshipId - LinkedIn relationship ID
|
|
977
|
+
* @returns Organization member ID or null if not found
|
|
978
|
+
*/
|
|
979
|
+
async findOrganizationMemberForRelationship(organizationId, linkedinRelationshipId) {
|
|
980
|
+
const db = await this.getDb();
|
|
981
|
+
const { findOrganizationMemberForRelationship } = await Promise.resolve().then(() => __importStar(require("../utils/organization-relationship-operations")));
|
|
982
|
+
return findOrganizationMemberForRelationship(db, {
|
|
983
|
+
linkedinRelationshipId,
|
|
984
|
+
organizationId,
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Delete all relationship assignments for an organization member
|
|
989
|
+
* Uses organization_member_id for faster, more accurate lookups
|
|
990
|
+
* @param organizationMemberId - Organization member ID
|
|
991
|
+
* @param client - Optional transaction client (if provided, uses it instead of getting new connection)
|
|
992
|
+
*/
|
|
993
|
+
async deleteAssignmentsByOrganizationMember(organizationMemberId, client) {
|
|
994
|
+
const db = client || (await this.getDb());
|
|
995
|
+
const { deleteAssignmentsByOrganizationMember } = await Promise.resolve().then(() => __importStar(require("../utils/organization-assignment-operations")));
|
|
996
|
+
return deleteAssignmentsByOrganizationMember(db, organizationMemberId);
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Bulk insert relationship assignments for an organization member
|
|
1000
|
+
* Uses organization_member_id for faster, more accurate lookups
|
|
1001
|
+
* @param params - Parameters for bulk insert
|
|
1002
|
+
* @param client - Optional transaction client (if provided, uses it instead of getting new connection)
|
|
1003
|
+
*/
|
|
1004
|
+
async bulkInsertAssignmentsForOrganizationMember(params, client) {
|
|
1005
|
+
const db = client || (await this.getDb());
|
|
1006
|
+
const { bulkInsertAssignmentsForOrganizationMember } = await Promise.resolve().then(() => __importStar(require("../utils/organization-assignment-operations")));
|
|
1007
|
+
return bulkInsertAssignmentsForOrganizationMember(db, params);
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Verify relationship assignments for an organization member after commit
|
|
1011
|
+
* Uses organization_member_id for faster, more accurate lookups
|
|
1012
|
+
*/
|
|
1013
|
+
async verifyAssignmentsForOrganizationMember(params) {
|
|
1014
|
+
const db = await this.getDb();
|
|
1015
|
+
const { verifyAssignmentsForOrganizationMember } = await Promise.resolve().then(() => __importStar(require("../utils/organization-assignment-operations")));
|
|
1016
|
+
return verifyAssignmentsForOrganizationMember(db, params);
|
|
1017
|
+
}
|
|
1018
|
+
async findOrCreatePersonalWorkspace(params) {
|
|
1019
|
+
const db = await this.getDb();
|
|
1020
|
+
// Try to find existing personal workspace for this user
|
|
1021
|
+
// Updated to use workspace_type instead of subscription_tier (migration 0039)
|
|
1022
|
+
const selectSql = `
|
|
1023
|
+
SELECT id, name, workspace_type, subscription_tier, created_by_user_id, image_url, created_at
|
|
1024
|
+
FROM public.organizations
|
|
1025
|
+
WHERE created_by_user_id = $1 AND workspace_type = 'INDIVIDUALS'
|
|
1026
|
+
LIMIT 1
|
|
1027
|
+
`;
|
|
1028
|
+
const existing = await db.query(selectSql, [params.userId]);
|
|
1029
|
+
if (existing.rows.length > 0) {
|
|
1030
|
+
return existing.rows[0];
|
|
1031
|
+
}
|
|
1032
|
+
// Create new personal workspace with custom name or default
|
|
1033
|
+
// Updated to use workspace_type and subscription_tier (migration 0039)
|
|
1034
|
+
// New INDIVIDUALS workspaces default to WAITING_FOR_SUBSCRIPTION_SELECTION (not FREE_TIER)
|
|
1035
|
+
const workspaceName = params.workspaceName || "Personal Workspace";
|
|
1036
|
+
const insertOrgSql = `
|
|
1037
|
+
INSERT INTO public.organizations (name, workspace_type, subscription_tier, created_by_user_id, image_url, created_at)
|
|
1038
|
+
VALUES ($1, 'INDIVIDUALS', 'WAITING_FOR_SUBSCRIPTION_SELECTION', $2, NULL, NOW())
|
|
1039
|
+
RETURNING id, name, workspace_type, subscription_tier, created_by_user_id, image_url, created_at
|
|
1040
|
+
`;
|
|
1041
|
+
const orgResult = await db.query(insertOrgSql, [workspaceName, params.userId]);
|
|
1042
|
+
// Note: Personal workspaces always have a created_by_user_id (the user who created them)
|
|
1043
|
+
const newOrg = orgResult.rows[0];
|
|
1044
|
+
if (!newOrg) {
|
|
1045
|
+
throw new Error("Failed to create personal workspace");
|
|
1046
|
+
}
|
|
1047
|
+
// Automatically assign the user as CONTRIBUTOR + ADMIN
|
|
1048
|
+
const insertMemberSql = `
|
|
1049
|
+
INSERT INTO public.organization_members (organization_id, user_id, contribution_role, permissions_role, created_at)
|
|
1050
|
+
VALUES ($1, $2, 'CONTRIBUTOR', 'ADMIN', NOW())
|
|
1051
|
+
`;
|
|
1052
|
+
await db.query(insertMemberSql, [newOrg.id, params.userId]);
|
|
1053
|
+
return newOrg;
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Get user's personal workspace by finding the organization they are a member of with workspace_type INDIVIDUALS
|
|
1057
|
+
* Every authenticated user should have exactly one personal workspace
|
|
1058
|
+
* @param userId - The user's ID
|
|
1059
|
+
* @returns The personal workspace organization or null if not found
|
|
1060
|
+
*/
|
|
1061
|
+
async getUserPersonalWorkspace(userId) {
|
|
1062
|
+
const db = await this.getDb();
|
|
1063
|
+
// Find personal workspace by joining organization_members with organizations
|
|
1064
|
+
// Updated to use workspace_type instead of subscription_tier (migration 0039)
|
|
1065
|
+
const sql = `
|
|
1066
|
+
SELECT o.id, o.name, o.workspace_type, o.subscription_tier, o.created_by_user_id, o.image_url, o.created_at
|
|
1067
|
+
FROM public.organization_members om
|
|
1068
|
+
INNER JOIN public.organizations o ON om.organization_id = o.id
|
|
1069
|
+
WHERE om.user_id = $1 AND o.workspace_type = 'INDIVIDUALS'
|
|
1070
|
+
LIMIT 1
|
|
1071
|
+
`;
|
|
1072
|
+
const result = await db.query(sql, [userId]);
|
|
1073
|
+
if (result.rows.length === 0) {
|
|
1074
|
+
return null;
|
|
1075
|
+
}
|
|
1076
|
+
return result.rows[0];
|
|
1077
|
+
}
|
|
1078
|
+
// =============================================================================
|
|
1079
|
+
// USER OPERATIONS
|
|
1080
|
+
// =============================================================================
|
|
1081
|
+
async getUserById(userId) {
|
|
1082
|
+
const db = await this.getDb();
|
|
1083
|
+
return (0, user_operations_1.getUserById)(db, userId);
|
|
1084
|
+
}
|
|
1085
|
+
// =============================================================================
|
|
1086
|
+
// MAPPING OPERATIONS
|
|
1087
|
+
// =============================================================================
|
|
1088
|
+
async getLatestCompletedMappingJobForUser(userId) {
|
|
1089
|
+
const db = await this.getDb();
|
|
1090
|
+
return (0, mapping_operations_1.getLatestCompletedMappingJobForUser)(db, userId);
|
|
1091
|
+
}
|
|
1092
|
+
async getLatestCompletedMappingJobForLinkedInAccount(linkedinAccountId) {
|
|
1093
|
+
const db = await this.getDb();
|
|
1094
|
+
const completedJobs = await (0, mapping_job_operations_1.getCompletedMappingJobs)(db, {
|
|
1095
|
+
limit: 1,
|
|
1096
|
+
linkedinAccountId,
|
|
1097
|
+
});
|
|
1098
|
+
return completedJobs.length > 0 ? completedJobs[0] : null;
|
|
1099
|
+
}
|
|
1100
|
+
async getRelationshipsForMappingJob(jobId, maxCount = 50) {
|
|
1101
|
+
const db = await this.getDb();
|
|
1102
|
+
return (0, mapping_operations_1.getRelationshipsForMappingJob)(db, jobId, maxCount);
|
|
1103
|
+
}
|
|
1104
|
+
async getAllRelationshipsForMappingJob(jobId, maxCount = null) {
|
|
1105
|
+
const db = await this.getDb();
|
|
1106
|
+
return (0, mapping_operations_1.getAllRelationshipsForMappingJob)(db, jobId, maxCount);
|
|
1107
|
+
}
|
|
1108
|
+
async getRelationshipCountForMappingJob(jobId) {
|
|
1109
|
+
const db = await this.getDb();
|
|
1110
|
+
return (0, mapping_operations_1.getRelationshipCountForMappingJob)(db, jobId);
|
|
1111
|
+
}
|
|
1112
|
+
async getLinkedInAccountByUserId(userId) {
|
|
1113
|
+
const db = await this.getDb();
|
|
1114
|
+
return (0, mapping_operations_1.getLinkedInAccountByUserId)(db, userId);
|
|
1115
|
+
}
|
|
1116
|
+
async getUserByLinkedInAccountId(linkedinAccountId) {
|
|
1117
|
+
const db = await this.getDb();
|
|
1118
|
+
return (0, mapping_operations_1.getUserByLinkedInAccountId)(db, linkedinAccountId);
|
|
1119
|
+
}
|
|
1120
|
+
async getLinkedInAccountWithUserByForagerId(foragerId) {
|
|
1121
|
+
const db = await this.getDb();
|
|
1122
|
+
return (0, forager_linkedin_operations_1.findLinkedInAccountWithUserByForagerId)(db, foragerId);
|
|
1123
|
+
}
|
|
1124
|
+
// =============================================================================
|
|
1125
|
+
// LLM INFERENCE JOB OPERATIONS
|
|
1126
|
+
// =============================================================================
|
|
1127
|
+
async getLlmInferenceJobStatusForContributor(params) {
|
|
1128
|
+
const db = await this.getDb();
|
|
1129
|
+
return (0, llm_inference_job_operations_1.getLlmInferenceJobStatusForContributor)(db, params);
|
|
1130
|
+
}
|
|
1131
|
+
async getLlmInferenceJobStatusForMappingJob(mappingJobId) {
|
|
1132
|
+
const db = await this.getDb();
|
|
1133
|
+
return (0, llm_inference_job_operations_1.getLlmInferenceJobStatusForMappingJob)(db, mappingJobId);
|
|
1134
|
+
}
|
|
1135
|
+
async getAllLlmInferenceJobStatusesForOrganization(organizationId) {
|
|
1136
|
+
const db = await this.getDb();
|
|
1137
|
+
return (0, llm_inference_job_operations_1.getAllLlmInferenceJobStatusesForOrganization)(db, organizationId);
|
|
1138
|
+
}
|
|
1139
|
+
async getLinkedInAccountById(linkedinAccountId) {
|
|
1140
|
+
const db = await this.getDb();
|
|
1141
|
+
return (0, mapping_operations_1.getLinkedInAccountById)(db, linkedinAccountId);
|
|
1142
|
+
}
|
|
1143
|
+
// =============================================================================
|
|
1144
|
+
// USER INDUSTRY OPERATIONS (Normalized)
|
|
1145
|
+
// =============================================================================
|
|
1146
|
+
/**
|
|
1147
|
+
* Get all industries for a user
|
|
1148
|
+
* @param userId - User ID
|
|
1149
|
+
* @returns Array of industry names (lowercase)
|
|
1150
|
+
*/
|
|
1151
|
+
async getUserIndustries(userId) {
|
|
1152
|
+
const db = await this.getDb();
|
|
1153
|
+
return (0, user_industry_operations_1.getUserIndustries)(db, userId);
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Get industries for multiple users (batch query - optimized)
|
|
1157
|
+
* @param userIds - Array of user IDs
|
|
1158
|
+
* @returns Map of userId -> industry names array
|
|
1159
|
+
*/
|
|
1160
|
+
async getBatchUserIndustries(userIds) {
|
|
1161
|
+
const db = await this.getDb();
|
|
1162
|
+
return (0, user_industry_operations_1.getBatchUserIndustries)(db, userIds);
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Find or create an industry by name (always lowercase)
|
|
1166
|
+
* @param industryName - Industry name
|
|
1167
|
+
* @returns Industry ID
|
|
1168
|
+
*/
|
|
1169
|
+
async findOrCreateIndustry(industryName) {
|
|
1170
|
+
const db = await this.getDb();
|
|
1171
|
+
return (0, user_industry_operations_1.findOrCreateIndustry)(db, industryName);
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Set industries for a user (replaces existing)
|
|
1175
|
+
* @param userId - User ID
|
|
1176
|
+
* @param industryNames - Array of industry names
|
|
1177
|
+
*/
|
|
1178
|
+
async setUserIndustries(userId, industryNames) {
|
|
1179
|
+
const db = await this.getDb();
|
|
1180
|
+
return (0, user_industry_operations_1.setUserIndustries)(db, userId, industryNames);
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Add industries to a user (keeps existing)
|
|
1184
|
+
* @param userId - User ID
|
|
1185
|
+
* @param industryNames - Array of industry names to add
|
|
1186
|
+
*/
|
|
1187
|
+
async addUserIndustries(userId, industryNames) {
|
|
1188
|
+
const db = await this.getDb();
|
|
1189
|
+
return (0, user_industry_operations_1.addUserIndustries)(db, userId, industryNames);
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Remove specific industries from a user
|
|
1193
|
+
* @param userId - User ID
|
|
1194
|
+
* @param industryNames - Array of industry names to remove
|
|
1195
|
+
*/
|
|
1196
|
+
async removeUserIndustries(userId, industryNames) {
|
|
1197
|
+
const db = await this.getDb();
|
|
1198
|
+
return (0, user_industry_operations_1.removeUserIndustries)(db, userId, industryNames);
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Remove all industries from a user
|
|
1202
|
+
* @param userId - User ID
|
|
1203
|
+
*/
|
|
1204
|
+
async clearUserIndustries(userId) {
|
|
1205
|
+
const db = await this.getDb();
|
|
1206
|
+
return (0, user_industry_operations_1.clearUserIndustries)(db, userId);
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Check if a user has a specific industry
|
|
1210
|
+
* @param userId - User ID
|
|
1211
|
+
* @param industryName - Industry name to check
|
|
1212
|
+
* @returns True if user has the industry
|
|
1213
|
+
*/
|
|
1214
|
+
async userHasIndustry(userId, industryName) {
|
|
1215
|
+
const db = await this.getDb();
|
|
1216
|
+
return (0, user_industry_operations_1.userHasIndustry)(db, userId, industryName);
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Get all unique industries in the system
|
|
1220
|
+
* @param limit - Optional limit (default: 1000)
|
|
1221
|
+
* @returns Array of industry names
|
|
1222
|
+
*/
|
|
1223
|
+
async getAllIndustries(limit) {
|
|
1224
|
+
const db = await this.getDb();
|
|
1225
|
+
return (0, user_industry_operations_1.getAllIndustries)(db, limit);
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Search industries by partial name match
|
|
1229
|
+
* @param searchTerm - Search term (case-insensitive)
|
|
1230
|
+
* @param limit - Optional limit (default: 20)
|
|
1231
|
+
* @returns Array of matching industry names
|
|
1232
|
+
*/
|
|
1233
|
+
async searchIndustries(searchTerm, limit) {
|
|
1234
|
+
const db = await this.getDb();
|
|
1235
|
+
return (0, user_industry_operations_1.searchIndustries)(db, searchTerm, limit);
|
|
1236
|
+
}
|
|
1237
|
+
// =============================================================================
|
|
1238
|
+
// INVITATION OPERATIONS
|
|
1239
|
+
// =============================================================================
|
|
1240
|
+
async createInvitation(email, invitedByUserId, shadowUserId, organizationId, invitationMessage, invitedUserPermissionsRole, expiresInDays) {
|
|
1241
|
+
const db = await this.getDb();
|
|
1242
|
+
return (0, invitation_operations_1.createInvitation)(db, {
|
|
1243
|
+
email,
|
|
1244
|
+
invitedByUserId,
|
|
1245
|
+
shadowUserId,
|
|
1246
|
+
organizationId,
|
|
1247
|
+
...(invitationMessage !== undefined && { invitationMessage }),
|
|
1248
|
+
...(invitedUserPermissionsRole !== undefined && { invitedUserPermissionsRole }),
|
|
1249
|
+
...(expiresInDays !== undefined && { expiresInDays }),
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
async validateInvitationToken(token) {
|
|
1253
|
+
const db = await this.getDb();
|
|
1254
|
+
return (0, invitation_operations_1.validateInvitationToken)(db, token);
|
|
1255
|
+
}
|
|
1256
|
+
async validateInvitationEligibility(email) {
|
|
1257
|
+
const db = await this.getDb();
|
|
1258
|
+
return (0, invitation_operations_1.validateInvitationEligibility)(db, email);
|
|
1259
|
+
}
|
|
1260
|
+
async markInvitationAsUsed(token) {
|
|
1261
|
+
const db = await this.getDb();
|
|
1262
|
+
return (0, invitation_operations_1.markInvitationAsUsed)(db, token);
|
|
1263
|
+
}
|
|
1264
|
+
async revokeInvitation(invitationId) {
|
|
1265
|
+
const db = await this.getDb();
|
|
1266
|
+
return (0, invitation_operations_1.revokeInvitation)(db, invitationId);
|
|
1267
|
+
}
|
|
1268
|
+
async getInvitationById(invitationId) {
|
|
1269
|
+
const db = await this.getDb();
|
|
1270
|
+
return (0, invitation_operations_1.getInvitationById)(db, invitationId);
|
|
1271
|
+
}
|
|
1272
|
+
async getInvitationsSentByUser(invitedByUserId) {
|
|
1273
|
+
const db = await this.getDb();
|
|
1274
|
+
return (0, invitation_operations_1.getInvitationsSentByUser)(db, invitedByUserId);
|
|
1275
|
+
}
|
|
1276
|
+
async getPendingInvitationsByOrganization(organizationId) {
|
|
1277
|
+
const db = await this.getDb();
|
|
1278
|
+
return (0, invitation_operations_1.getPendingInvitationsByOrganization)(db, organizationId);
|
|
1279
|
+
}
|
|
1280
|
+
async getAllInvitationsByOrganization(organizationId) {
|
|
1281
|
+
const db = await this.getDb();
|
|
1282
|
+
return (0, invitation_operations_1.getAllInvitationsByOrganization)(db, organizationId);
|
|
1283
|
+
}
|
|
1284
|
+
async hasPendingInvitation(email, organizationId) {
|
|
1285
|
+
const db = await this.getDb();
|
|
1286
|
+
return (0, invitation_operations_1.hasPendingInvitation)(db, email, organizationId);
|
|
1287
|
+
}
|
|
1288
|
+
async hasActiveInvitationByEmail(email) {
|
|
1289
|
+
const db = await this.getDb();
|
|
1290
|
+
const { hasActiveInvitationByEmail } = await Promise.resolve().then(() => __importStar(require("../utils/invitation-operations")));
|
|
1291
|
+
return hasActiveInvitationByEmail(db, email);
|
|
1292
|
+
}
|
|
1293
|
+
async hasActiveInvitationByEmailForOrg(email, organizationId) {
|
|
1294
|
+
const db = await this.getDb();
|
|
1295
|
+
const { hasActiveInvitationByEmailForOrg } = await Promise.resolve().then(() => __importStar(require("../utils/invitation-operations")));
|
|
1296
|
+
return hasActiveInvitationByEmailForOrg(db, email, organizationId);
|
|
1297
|
+
}
|
|
1298
|
+
async isEmailUsedByAuthenticatedUser(email) {
|
|
1299
|
+
const db = await this.getDb();
|
|
1300
|
+
const { isEmailUsedByAuthenticatedUser } = await Promise.resolve().then(() => __importStar(require("../utils/invitation-operations")));
|
|
1301
|
+
return isEmailUsedByAuthenticatedUser(db, email);
|
|
1302
|
+
}
|
|
1303
|
+
async isEmailReservedByContactInfo(email) {
|
|
1304
|
+
const db = await this.getDb();
|
|
1305
|
+
const { isEmailReservedByContactInfo } = await Promise.resolve().then(() => __importStar(require("../utils/invitation-operations")));
|
|
1306
|
+
return isEmailReservedByContactInfo(db, email);
|
|
1307
|
+
}
|
|
1308
|
+
async cleanupExpiredInvitations(olderThanDays = 90) {
|
|
1309
|
+
const db = await this.getDb();
|
|
1310
|
+
return (0, invitation_operations_1.cleanupExpiredInvitations)(db, olderThanDays);
|
|
1311
|
+
}
|
|
1312
|
+
// =============================================================================
|
|
1313
|
+
// INTRODUCTION REQUEST OPERATIONS
|
|
1314
|
+
// =============================================================================
|
|
1315
|
+
async createIntroductionRequest(params) {
|
|
1316
|
+
const db = await this.getDb();
|
|
1317
|
+
return (0, introduction_request_operations_1.createIntroductionRequest)(db, params);
|
|
1318
|
+
}
|
|
1319
|
+
async getIntroductionRequestsByUser(userId, limit) {
|
|
1320
|
+
const db = await this.getDb();
|
|
1321
|
+
return (0, introduction_request_operations_1.getIntroductionRequestsByUser)(db, userId, limit);
|
|
1322
|
+
}
|
|
1323
|
+
async getIntroductionRequestById(requestId) {
|
|
1324
|
+
const db = await this.getDb();
|
|
1325
|
+
return (0, introduction_request_operations_1.getIntroductionRequestById)(db, requestId);
|
|
1326
|
+
}
|
|
1327
|
+
async hasExistingIntroductionRequest(byUserId, toRelationshipId) {
|
|
1328
|
+
const db = await this.getDb();
|
|
1329
|
+
return (0, introduction_request_operations_1.hasExistingIntroductionRequest)(db, byUserId, toRelationshipId);
|
|
1330
|
+
}
|
|
1331
|
+
async updateIntroductionRequestStatus(requestId, status) {
|
|
1332
|
+
const db = await this.getDb();
|
|
1333
|
+
return (0, introduction_request_operations_1.updateIntroductionRequestStatus)(db, requestId, status);
|
|
1334
|
+
}
|
|
1335
|
+
async markIntroductionRequestAsSeen(requestId) {
|
|
1336
|
+
const db = await this.getDb();
|
|
1337
|
+
return (0, introduction_request_operations_1.markIntroductionRequestAsSeen)(db, requestId);
|
|
1338
|
+
}
|
|
1339
|
+
async getReceivedIntroductionRequests(userId, organizationId) {
|
|
1340
|
+
const db = await this.getDb();
|
|
1341
|
+
return (0, introduction_request_operations_1.getReceivedIntroductionRequests)(db, userId, organizationId);
|
|
1342
|
+
}
|
|
1343
|
+
async getSentIntroductionRequests(userId, organizationId) {
|
|
1344
|
+
const db = await this.getDb();
|
|
1345
|
+
return (0, introduction_request_operations_1.getSentIntroductionRequests)(db, userId, organizationId);
|
|
1346
|
+
}
|
|
1347
|
+
async markReceivedIntroductionRequestsAsSeen(userId, organizationId) {
|
|
1348
|
+
const db = await this.getDb();
|
|
1349
|
+
return (0, introduction_request_operations_1.markReceivedIntroductionRequestsAsSeen)(db, userId, organizationId);
|
|
1350
|
+
}
|
|
1351
|
+
// ============================================
|
|
1352
|
+
// USER OPERATIONS
|
|
1353
|
+
// ============================================
|
|
1354
|
+
async createUser(params) {
|
|
1355
|
+
const db = await this.getDb();
|
|
1356
|
+
const sql = `
|
|
1357
|
+
INSERT INTO public.users (given_name, family_name, created_at)
|
|
1358
|
+
VALUES ($1, $2, NOW())
|
|
1359
|
+
RETURNING id, given_name, family_name, summary, embedding_summary, embedding, created_at
|
|
1360
|
+
`;
|
|
1361
|
+
const result = await db.query(sql, [params.givenName, params.familyName]);
|
|
1362
|
+
return result.rows[0];
|
|
1363
|
+
}
|
|
1364
|
+
// ============================================
|
|
1365
|
+
// AUTHENTICATED USER OPERATIONS
|
|
1366
|
+
// ============================================
|
|
1367
|
+
async createAuthenticatedUser(params) {
|
|
1368
|
+
const db = await this.getDb();
|
|
1369
|
+
return (0, authenticated_user_operations_1.createAuthenticatedUser)(db, params);
|
|
1370
|
+
}
|
|
1371
|
+
// ============================================
|
|
1372
|
+
// Company Sheet Upload Operations
|
|
1373
|
+
// ============================================
|
|
1374
|
+
async createCompanySheetUpload(data) {
|
|
1375
|
+
const db = await this.getDb();
|
|
1376
|
+
const { createCompanySheetUpload } = await Promise.resolve().then(() => __importStar(require("../utils/company-sheet-upload-operations")));
|
|
1377
|
+
return createCompanySheetUpload(db, data);
|
|
1378
|
+
}
|
|
1379
|
+
async getCompanySheetUploadById(sheetUploadId) {
|
|
1380
|
+
const db = await this.getDb();
|
|
1381
|
+
const { getCompanySheetUploadById } = await Promise.resolve().then(() => __importStar(require("../utils/company-sheet-upload-operations")));
|
|
1382
|
+
return getCompanySheetUploadById(db, sheetUploadId);
|
|
1383
|
+
}
|
|
1384
|
+
async updateCompanySheetUploadJobId(sheetUploadId, companyMappingJobId) {
|
|
1385
|
+
const db = await this.getDb();
|
|
1386
|
+
const { updateCompanySheetUploadJobId } = await Promise.resolve().then(() => __importStar(require("../utils/company-sheet-upload-operations")));
|
|
1387
|
+
return updateCompanySheetUploadJobId(db, sheetUploadId, companyMappingJobId);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
exports.DatabaseService = DatabaseService;
|
|
1391
|
+
DatabaseService.instance = null;
|
|
1392
|
+
// Export singleton instance
|
|
1393
|
+
exports.dbService = DatabaseService.getInstance();
|
|
1394
|
+
//# sourceMappingURL=database-service.js.map
|