adaptic-backend 1.0.340 → 1.0.341
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/Account.cjs +2543 -2265
- package/Account.d.ts +19 -2
- package/Action.cjs +1116 -838
- package/Action.d.ts +19 -2
- package/Alert.cjs +2626 -2348
- package/Alert.d.ts +19 -2
- package/Allocation.cjs +2578 -2300
- package/Allocation.d.ts +19 -2
- package/AlpacaAccount.cjs +2383 -2105
- package/AlpacaAccount.d.ts +19 -2
- package/Asset.cjs +1813 -1535
- package/Asset.d.ts +19 -2
- package/Authenticator.cjs +2568 -2290
- package/Authenticator.d.ts +19 -2
- package/Customer.cjs +2495 -2217
- package/Customer.d.ts +19 -2
- package/EconomicEvent.cjs +645 -367
- package/EconomicEvent.d.ts +19 -2
- package/MarketSentiment.cjs +618 -340
- package/MarketSentiment.d.ts +19 -2
- package/NewsArticle.cjs +1933 -1655
- package/NewsArticle.d.ts +19 -2
- package/NewsArticleAssetSentiment.cjs +1842 -1564
- package/NewsArticleAssetSentiment.d.ts +19 -2
- package/ScheduledOptionOrder.cjs +594 -316
- package/ScheduledOptionOrder.d.ts +19 -2
- package/Session.cjs +2570 -2292
- package/Session.d.ts +19 -2
- package/Trade.cjs +1073 -795
- package/Trade.d.ts +19 -2
- package/User.cjs +2288 -2010
- package/User.d.ts +19 -2
- package/VerificationToken.cjs +606 -328
- package/VerificationToken.d.ts +19 -2
- package/esm/Account.d.ts +19 -2
- package/esm/Account.d.ts.map +1 -1
- package/esm/Account.js.map +1 -1
- package/esm/Account.mjs +2534 -2263
- package/esm/Action.d.ts +19 -2
- package/esm/Action.d.ts.map +1 -1
- package/esm/Action.js.map +1 -1
- package/esm/Action.mjs +1107 -836
- package/esm/Alert.d.ts +19 -2
- package/esm/Alert.d.ts.map +1 -1
- package/esm/Alert.js.map +1 -1
- package/esm/Alert.mjs +2617 -2346
- package/esm/Allocation.d.ts +19 -2
- package/esm/Allocation.d.ts.map +1 -1
- package/esm/Allocation.js.map +1 -1
- package/esm/Allocation.mjs +2569 -2298
- package/esm/AlpacaAccount.d.ts +19 -2
- package/esm/AlpacaAccount.d.ts.map +1 -1
- package/esm/AlpacaAccount.js.map +1 -1
- package/esm/AlpacaAccount.mjs +2374 -2103
- package/esm/Asset.d.ts +19 -2
- package/esm/Asset.d.ts.map +1 -1
- package/esm/Asset.js.map +1 -1
- package/esm/Asset.mjs +1804 -1533
- package/esm/Authenticator.d.ts +19 -2
- package/esm/Authenticator.d.ts.map +1 -1
- package/esm/Authenticator.js.map +1 -1
- package/esm/Authenticator.mjs +2559 -2288
- package/esm/Customer.d.ts +19 -2
- package/esm/Customer.d.ts.map +1 -1
- package/esm/Customer.js.map +1 -1
- package/esm/Customer.mjs +2486 -2215
- package/esm/EconomicEvent.d.ts +19 -2
- package/esm/EconomicEvent.d.ts.map +1 -1
- package/esm/EconomicEvent.js.map +1 -1
- package/esm/EconomicEvent.mjs +636 -365
- package/esm/MarketSentiment.d.ts +19 -2
- package/esm/MarketSentiment.d.ts.map +1 -1
- package/esm/MarketSentiment.js.map +1 -1
- package/esm/MarketSentiment.mjs +609 -338
- package/esm/NewsArticle.d.ts +19 -2
- package/esm/NewsArticle.d.ts.map +1 -1
- package/esm/NewsArticle.js.map +1 -1
- package/esm/NewsArticle.mjs +1924 -1653
- package/esm/NewsArticleAssetSentiment.d.ts +19 -2
- package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
- package/esm/NewsArticleAssetSentiment.js.map +1 -1
- package/esm/NewsArticleAssetSentiment.mjs +1833 -1562
- package/esm/ScheduledOptionOrder.d.ts +19 -2
- package/esm/ScheduledOptionOrder.d.ts.map +1 -1
- package/esm/ScheduledOptionOrder.js.map +1 -1
- package/esm/ScheduledOptionOrder.mjs +585 -314
- package/esm/Session.d.ts +19 -2
- package/esm/Session.d.ts.map +1 -1
- package/esm/Session.js.map +1 -1
- package/esm/Session.mjs +2561 -2290
- package/esm/Trade.d.ts +19 -2
- package/esm/Trade.d.ts.map +1 -1
- package/esm/Trade.js.map +1 -1
- package/esm/Trade.mjs +1064 -793
- package/esm/User.d.ts +19 -2
- package/esm/User.d.ts.map +1 -1
- package/esm/User.js.map +1 -1
- package/esm/User.mjs +2279 -2008
- package/esm/VerificationToken.d.ts +19 -2
- package/esm/VerificationToken.d.ts.map +1 -1
- package/esm/VerificationToken.js.map +1 -1
- package/esm/VerificationToken.mjs +597 -326
- package/esm/prismaClient.d.ts +4 -5
- package/esm/prismaClient.d.ts.map +1 -1
- package/esm/prismaClient.js.map +1 -1
- package/esm/prismaClient.mjs +13 -11
- package/package.json +1 -1
- package/prismaClient.cjs +13 -11
- package/prismaClient.d.ts +4 -5
- package/server.cjs +37 -5
package/User.cjs
CHANGED
@@ -126,183 +126,731 @@ exports.User = {
|
|
126
126
|
* @param client - Apollo Client instance.
|
127
127
|
* @returns The created User or null.
|
128
128
|
*/
|
129
|
+
/**
|
130
|
+
* Create a new User record.
|
131
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
132
|
+
* @param props - Properties for the new record.
|
133
|
+
* @param globalClient - Apollo Client instance.
|
134
|
+
* @returns The created User or null.
|
135
|
+
*/
|
129
136
|
async create(props, globalClient) {
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
?
|
160
|
-
|
137
|
+
var _a, _b, _c, _d, _e;
|
138
|
+
// Maximum number of retries for database connection issues
|
139
|
+
const MAX_RETRIES = 3;
|
140
|
+
let retryCount = 0;
|
141
|
+
let lastError = null;
|
142
|
+
// Retry loop to handle potential database connection issues
|
143
|
+
while (retryCount < MAX_RETRIES) {
|
144
|
+
try {
|
145
|
+
const [modules, client] = await Promise.all([
|
146
|
+
(0, client_1.getApolloModules)(),
|
147
|
+
globalClient
|
148
|
+
? Promise.resolve(globalClient)
|
149
|
+
: client_1.client
|
150
|
+
]);
|
151
|
+
const { gql, ApolloError } = modules;
|
152
|
+
const CREATE_ONE_USER = gql `
|
153
|
+
mutation createOneUser($data: UserCreateInput!) {
|
154
|
+
createOneUser(data: $data) {
|
155
|
+
${selectionSet}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
`;
|
159
|
+
const variables = {
|
160
|
+
data: {
|
161
|
+
name: props.name !== undefined ? props.name : undefined,
|
162
|
+
email: props.email !== undefined ? props.email : undefined,
|
163
|
+
emailVerified: props.emailVerified !== undefined ? props.emailVerified : undefined,
|
164
|
+
image: props.image !== undefined ? props.image : undefined,
|
165
|
+
role: props.role !== undefined ? props.role : undefined,
|
166
|
+
bio: props.bio !== undefined ? props.bio : undefined,
|
167
|
+
jobTitle: props.jobTitle !== undefined ? props.jobTitle : undefined,
|
168
|
+
currentAccount: props.currentAccount !== undefined ? props.currentAccount : undefined,
|
169
|
+
plan: props.plan !== undefined ? props.plan : undefined,
|
170
|
+
openaiAPIKey: props.openaiAPIKey !== undefined ? props.openaiAPIKey : undefined,
|
171
|
+
openaiModel: props.openaiModel !== undefined ? props.openaiModel : undefined,
|
172
|
+
customer: props.customer ?
|
173
|
+
typeof props.customer === 'object' && Object.keys(props.customer).length === 1 && Object.keys(props.customer)[0] === 'id'
|
174
|
+
? { connect: {
|
175
|
+
id: props.customer.id
|
176
|
+
}
|
177
|
+
}
|
178
|
+
: { connectOrCreate: {
|
179
|
+
where: {
|
180
|
+
id: props.customer.id !== undefined ? props.customer.id : undefined,
|
181
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? props.customer.stripeCustomerId : undefined,
|
182
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? props.customer.stripeSubscriptionId : undefined,
|
183
|
+
authUserId: props.customer.authUserId !== undefined ? {
|
184
|
+
equals: props.customer.authUserId
|
185
|
+
} : undefined,
|
186
|
+
name: props.customer.name !== undefined ? {
|
187
|
+
equals: props.customer.name
|
188
|
+
} : undefined,
|
189
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? {
|
190
|
+
equals: props.customer.stripePriceId
|
191
|
+
} : undefined,
|
192
|
+
},
|
193
|
+
create: {
|
194
|
+
authUserId: props.customer.authUserId !== undefined ? props.customer.authUserId : undefined,
|
195
|
+
name: props.customer.name !== undefined ? props.customer.name : undefined,
|
196
|
+
plan: props.customer.plan !== undefined ? props.customer.plan : undefined,
|
197
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? props.customer.stripeCustomerId : undefined,
|
198
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? props.customer.stripeSubscriptionId : undefined,
|
199
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? props.customer.stripePriceId : undefined,
|
200
|
+
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? props.customer.stripeCurrentPeriodEnd : undefined,
|
201
|
+
},
|
202
|
+
}
|
203
|
+
} : undefined,
|
204
|
+
accounts: props.accounts ?
|
205
|
+
Array.isArray(props.accounts) && props.accounts.length > 0 && props.accounts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
206
|
+
connect: props.accounts.map((item) => ({
|
207
|
+
id: item.id
|
208
|
+
}))
|
161
209
|
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
210
|
+
: { connectOrCreate: props.accounts.map((item) => ({
|
211
|
+
where: {
|
212
|
+
id: item.id !== undefined ? item.id : undefined,
|
213
|
+
userId: item.userId !== undefined ? {
|
214
|
+
equals: item.userId
|
215
|
+
} : undefined,
|
216
|
+
providerAccountId: item.providerAccountId !== undefined ? {
|
217
|
+
equals: item.providerAccountId
|
218
|
+
} : undefined,
|
219
|
+
},
|
220
|
+
create: {
|
221
|
+
type: item.type !== undefined ? item.type : undefined,
|
222
|
+
provider: item.provider !== undefined ? item.provider : undefined,
|
223
|
+
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
224
|
+
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
225
|
+
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
226
|
+
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
227
|
+
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
228
|
+
scope: item.scope !== undefined ? item.scope : undefined,
|
229
|
+
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
230
|
+
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
231
|
+
},
|
232
|
+
}))
|
233
|
+
} : undefined,
|
234
|
+
sessions: props.sessions ?
|
235
|
+
Array.isArray(props.sessions) && props.sessions.length > 0 && props.sessions.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
236
|
+
connect: props.sessions.map((item) => ({
|
237
|
+
id: item.id
|
238
|
+
}))
|
239
|
+
}
|
240
|
+
: { connectOrCreate: props.sessions.map((item) => ({
|
241
|
+
where: {
|
242
|
+
id: item.id !== undefined ? item.id : undefined,
|
243
|
+
userId: item.userId !== undefined ? {
|
244
|
+
equals: item.userId
|
245
|
+
} : undefined,
|
246
|
+
},
|
247
|
+
create: {
|
248
|
+
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
249
|
+
expires: item.expires !== undefined ? item.expires : undefined,
|
250
|
+
},
|
251
|
+
}))
|
252
|
+
} : undefined,
|
253
|
+
authenticators: props.authenticators ?
|
254
|
+
Array.isArray(props.authenticators) && props.authenticators.length > 0 && props.authenticators.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
255
|
+
connect: props.authenticators.map((item) => ({
|
256
|
+
id: item.id
|
257
|
+
}))
|
187
258
|
}
|
259
|
+
: { connectOrCreate: props.authenticators.map((item) => ({
|
260
|
+
where: {
|
261
|
+
id: item.id !== undefined ? item.id : undefined,
|
262
|
+
userId: item.userId !== undefined ? {
|
263
|
+
equals: item.userId
|
264
|
+
} : undefined,
|
265
|
+
},
|
266
|
+
create: {
|
267
|
+
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
268
|
+
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
269
|
+
counter: item.counter !== undefined ? item.counter : undefined,
|
270
|
+
},
|
271
|
+
}))
|
272
|
+
} : undefined,
|
273
|
+
alpacaAccounts: props.alpacaAccounts ?
|
274
|
+
Array.isArray(props.alpacaAccounts) && props.alpacaAccounts.length > 0 && props.alpacaAccounts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
275
|
+
connect: props.alpacaAccounts.map((item) => ({
|
276
|
+
id: item.id
|
277
|
+
}))
|
278
|
+
}
|
279
|
+
: { connectOrCreate: props.alpacaAccounts.map((item) => ({
|
280
|
+
where: {
|
281
|
+
id: item.id !== undefined ? item.id : undefined,
|
282
|
+
userId: item.userId !== undefined ? {
|
283
|
+
equals: item.userId
|
284
|
+
} : undefined,
|
285
|
+
},
|
286
|
+
create: {
|
287
|
+
type: item.type !== undefined ? item.type : undefined,
|
288
|
+
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
289
|
+
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
290
|
+
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
291
|
+
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
292
|
+
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
293
|
+
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
294
|
+
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
295
|
+
set: item.cryptoTradingPairs
|
296
|
+
} : undefined,
|
297
|
+
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
298
|
+
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
299
|
+
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
300
|
+
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
301
|
+
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
302
|
+
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
303
|
+
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
304
|
+
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
305
|
+
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
306
|
+
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
307
|
+
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
308
|
+
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
309
|
+
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
310
|
+
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
311
|
+
allocation: item.allocation ?
|
312
|
+
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
313
|
+
? { connect: {
|
314
|
+
id: item.allocation.id
|
315
|
+
}
|
316
|
+
}
|
317
|
+
: { connectOrCreate: {
|
318
|
+
where: {
|
319
|
+
id: item.allocation.id !== undefined ? item.allocation.id : undefined,
|
320
|
+
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? item.allocation.alpacaAccountId : undefined,
|
321
|
+
},
|
322
|
+
create: {
|
323
|
+
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
324
|
+
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
325
|
+
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
326
|
+
},
|
327
|
+
}
|
328
|
+
} : undefined,
|
329
|
+
alerts: item.alerts ?
|
330
|
+
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
331
|
+
connect: item.alerts.map((item) => ({
|
332
|
+
id: item.id
|
333
|
+
}))
|
334
|
+
}
|
335
|
+
: { connectOrCreate: item.alerts.map((item) => ({
|
336
|
+
where: {
|
337
|
+
id: item.id !== undefined ? item.id : undefined,
|
338
|
+
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
339
|
+
equals: item.alpacaAccountId
|
340
|
+
} : undefined,
|
341
|
+
},
|
342
|
+
create: {
|
343
|
+
message: item.message !== undefined ? item.message : undefined,
|
344
|
+
type: item.type !== undefined ? item.type : undefined,
|
345
|
+
isRead: item.isRead !== undefined ? item.isRead : undefined,
|
346
|
+
},
|
347
|
+
}))
|
348
|
+
} : undefined,
|
349
|
+
},
|
350
|
+
}))
|
351
|
+
} : undefined,
|
352
|
+
},
|
353
|
+
};
|
354
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
355
|
+
const response = await client.mutate({
|
356
|
+
mutation: CREATE_ONE_USER,
|
357
|
+
variables: filteredVariables,
|
358
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
359
|
+
fetchPolicy: 'no-cache'
|
360
|
+
});
|
361
|
+
if (response.errors && response.errors.length > 0)
|
362
|
+
throw new Error(response.errors[0].message);
|
363
|
+
if (response && response.data && response.data.createOneUser) {
|
364
|
+
return response.data.createOneUser;
|
365
|
+
}
|
366
|
+
else {
|
367
|
+
return null;
|
368
|
+
}
|
369
|
+
}
|
370
|
+
catch (error) {
|
371
|
+
lastError = error;
|
372
|
+
// Check if this is a database connection error that we should retry
|
373
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
374
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
375
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
376
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
377
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
378
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
379
|
+
retryCount++;
|
380
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
381
|
+
console.warn("Database connection error, retrying...");
|
382
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
383
|
+
continue;
|
384
|
+
}
|
385
|
+
// Log the error and rethrow
|
386
|
+
console.error("Database error occurred:", error);
|
387
|
+
throw error;
|
388
|
+
}
|
389
|
+
}
|
390
|
+
// If we exhausted retries, throw the last error
|
391
|
+
throw lastError;
|
392
|
+
},
|
393
|
+
/**
|
394
|
+
* Create multiple User records.
|
395
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
396
|
+
* @param props - Array of User objects for the new records.
|
397
|
+
* @param globalClient - Apollo Client instance.
|
398
|
+
* @returns The count of created records or null.
|
399
|
+
*/
|
400
|
+
async createMany(props, globalClient) {
|
401
|
+
var _a, _b, _c, _d, _e;
|
402
|
+
// Maximum number of retries for database connection issues
|
403
|
+
const MAX_RETRIES = 3;
|
404
|
+
let retryCount = 0;
|
405
|
+
let lastError = null;
|
406
|
+
// Retry loop to handle potential database connection issues
|
407
|
+
while (retryCount < MAX_RETRIES) {
|
408
|
+
try {
|
409
|
+
const [modules, client] = await Promise.all([
|
410
|
+
(0, client_1.getApolloModules)(),
|
411
|
+
globalClient
|
412
|
+
? Promise.resolve(globalClient)
|
413
|
+
: client_1.client
|
414
|
+
]);
|
415
|
+
const { gql, ApolloError } = modules;
|
416
|
+
const CREATE_MANY_USER = gql `
|
417
|
+
mutation createManyUser($data: [UserCreateManyInput!]!) {
|
418
|
+
createManyUser(data: $data) {
|
419
|
+
count
|
420
|
+
}
|
421
|
+
}`;
|
422
|
+
const variables = {
|
423
|
+
data: props.map(prop => ({
|
424
|
+
name: prop.name !== undefined ? prop.name : undefined,
|
425
|
+
email: prop.email !== undefined ? prop.email : undefined,
|
426
|
+
emailVerified: prop.emailVerified !== undefined ? prop.emailVerified : undefined,
|
427
|
+
image: prop.image !== undefined ? prop.image : undefined,
|
428
|
+
role: prop.role !== undefined ? prop.role : undefined,
|
429
|
+
bio: prop.bio !== undefined ? prop.bio : undefined,
|
430
|
+
jobTitle: prop.jobTitle !== undefined ? prop.jobTitle : undefined,
|
431
|
+
currentAccount: prop.currentAccount !== undefined ? prop.currentAccount : undefined,
|
432
|
+
customerId: prop.customerId !== undefined ? prop.customerId : undefined,
|
433
|
+
plan: prop.plan !== undefined ? prop.plan : undefined,
|
434
|
+
openaiAPIKey: prop.openaiAPIKey !== undefined ? prop.openaiAPIKey : undefined,
|
435
|
+
openaiModel: prop.openaiModel !== undefined ? prop.openaiModel : undefined,
|
436
|
+
})),
|
437
|
+
};
|
438
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
439
|
+
const response = await client.mutate({
|
440
|
+
mutation: CREATE_MANY_USER,
|
441
|
+
variables: filteredVariables,
|
442
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
443
|
+
fetchPolicy: 'no-cache'
|
444
|
+
});
|
445
|
+
if (response.errors && response.errors.length > 0)
|
446
|
+
throw new Error(response.errors[0].message);
|
447
|
+
if (response && response.data && response.data.createManyUser) {
|
448
|
+
return response.data.createManyUser;
|
449
|
+
}
|
450
|
+
else {
|
451
|
+
return null;
|
452
|
+
}
|
453
|
+
}
|
454
|
+
catch (error) {
|
455
|
+
lastError = error;
|
456
|
+
// Check if this is a database connection error that we should retry
|
457
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
458
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
459
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
460
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
461
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
462
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
463
|
+
retryCount++;
|
464
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
465
|
+
console.warn("Database connection error, retrying...");
|
466
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
467
|
+
continue;
|
468
|
+
}
|
469
|
+
// Log the error and rethrow
|
470
|
+
console.error("Database error occurred:", error);
|
471
|
+
throw error;
|
472
|
+
}
|
473
|
+
}
|
474
|
+
// If we exhausted retries, throw the last error
|
475
|
+
throw lastError;
|
476
|
+
},
|
477
|
+
/**
|
478
|
+
* Update a single User record.
|
479
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
480
|
+
* @param props - Properties to update.
|
481
|
+
* @param globalClient - Apollo Client instance.
|
482
|
+
* @returns The updated User or null.
|
483
|
+
*/
|
484
|
+
async update(props, globalClient) {
|
485
|
+
var _a, _b, _c, _d, _e;
|
486
|
+
// Maximum number of retries for database connection issues
|
487
|
+
const MAX_RETRIES = 3;
|
488
|
+
let retryCount = 0;
|
489
|
+
let lastError = null;
|
490
|
+
// Retry loop to handle potential database connection issues
|
491
|
+
while (retryCount < MAX_RETRIES) {
|
492
|
+
try {
|
493
|
+
const [modules, client] = await Promise.all([
|
494
|
+
(0, client_1.getApolloModules)(),
|
495
|
+
globalClient
|
496
|
+
? Promise.resolve(globalClient)
|
497
|
+
: client_1.client
|
498
|
+
]);
|
499
|
+
const { gql, ApolloError } = modules;
|
500
|
+
const UPDATE_ONE_USER = gql `
|
501
|
+
mutation updateOneUser($data: UserUpdateInput!, $where: UserWhereUniqueInput!) {
|
502
|
+
updateOneUser(data: $data, where: $where) {
|
503
|
+
${selectionSet}
|
504
|
+
}
|
505
|
+
}`;
|
506
|
+
const variables = {
|
507
|
+
where: {
|
508
|
+
id: props.id !== undefined ? props.id : undefined,
|
509
|
+
email: props.email !== undefined ? props.email : undefined,
|
510
|
+
name: props.name !== undefined ? {
|
511
|
+
equals: props.name
|
188
512
|
} : undefined,
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
}))
|
194
|
-
}
|
195
|
-
: { connectOrCreate: props.accounts.map((item) => ({
|
196
|
-
where: {
|
197
|
-
id: item.id !== undefined ? item.id : undefined,
|
198
|
-
userId: item.userId !== undefined ? {
|
199
|
-
equals: item.userId
|
200
|
-
} : undefined,
|
201
|
-
providerAccountId: item.providerAccountId !== undefined ? {
|
202
|
-
equals: item.providerAccountId
|
203
|
-
} : undefined,
|
204
|
-
},
|
205
|
-
create: {
|
206
|
-
type: item.type !== undefined ? item.type : undefined,
|
207
|
-
provider: item.provider !== undefined ? item.provider : undefined,
|
208
|
-
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
209
|
-
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
210
|
-
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
211
|
-
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
212
|
-
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
213
|
-
scope: item.scope !== undefined ? item.scope : undefined,
|
214
|
-
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
215
|
-
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
216
|
-
},
|
217
|
-
}))
|
513
|
+
},
|
514
|
+
data: {
|
515
|
+
id: props.id !== undefined ? {
|
516
|
+
set: props.id
|
218
517
|
} : undefined,
|
219
|
-
|
220
|
-
|
221
|
-
connect: props.sessions.map((item) => ({
|
222
|
-
id: item.id
|
223
|
-
}))
|
224
|
-
}
|
225
|
-
: { connectOrCreate: props.sessions.map((item) => ({
|
226
|
-
where: {
|
227
|
-
id: item.id !== undefined ? item.id : undefined,
|
228
|
-
userId: item.userId !== undefined ? {
|
229
|
-
equals: item.userId
|
230
|
-
} : undefined,
|
231
|
-
},
|
232
|
-
create: {
|
233
|
-
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
234
|
-
expires: item.expires !== undefined ? item.expires : undefined,
|
235
|
-
},
|
236
|
-
}))
|
518
|
+
name: props.name !== undefined ? {
|
519
|
+
set: props.name
|
237
520
|
} : undefined,
|
238
|
-
|
239
|
-
|
240
|
-
connect: props.authenticators.map((item) => ({
|
241
|
-
id: item.id
|
242
|
-
}))
|
243
|
-
}
|
244
|
-
: { connectOrCreate: props.authenticators.map((item) => ({
|
245
|
-
where: {
|
246
|
-
id: item.id !== undefined ? item.id : undefined,
|
247
|
-
userId: item.userId !== undefined ? {
|
248
|
-
equals: item.userId
|
249
|
-
} : undefined,
|
250
|
-
},
|
251
|
-
create: {
|
252
|
-
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
253
|
-
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
254
|
-
counter: item.counter !== undefined ? item.counter : undefined,
|
255
|
-
},
|
256
|
-
}))
|
521
|
+
email: props.email !== undefined ? {
|
522
|
+
set: props.email
|
257
523
|
} : undefined,
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
:
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
524
|
+
emailVerified: props.emailVerified !== undefined ? {
|
525
|
+
set: props.emailVerified
|
526
|
+
} : undefined,
|
527
|
+
image: props.image !== undefined ? {
|
528
|
+
set: props.image
|
529
|
+
} : undefined,
|
530
|
+
createdAt: props.createdAt !== undefined ? {
|
531
|
+
set: props.createdAt
|
532
|
+
} : undefined,
|
533
|
+
updatedAt: props.updatedAt !== undefined ? {
|
534
|
+
set: props.updatedAt
|
535
|
+
} : undefined,
|
536
|
+
role: props.role !== undefined ? {
|
537
|
+
set: props.role
|
538
|
+
} : undefined,
|
539
|
+
bio: props.bio !== undefined ? {
|
540
|
+
set: props.bio
|
541
|
+
} : undefined,
|
542
|
+
jobTitle: props.jobTitle !== undefined ? {
|
543
|
+
set: props.jobTitle
|
544
|
+
} : undefined,
|
545
|
+
currentAccount: props.currentAccount !== undefined ? {
|
546
|
+
set: props.currentAccount
|
547
|
+
} : undefined,
|
548
|
+
plan: props.plan !== undefined ? {
|
549
|
+
set: props.plan
|
550
|
+
} : undefined,
|
551
|
+
openaiAPIKey: props.openaiAPIKey !== undefined ? {
|
552
|
+
set: props.openaiAPIKey
|
553
|
+
} : undefined,
|
554
|
+
openaiModel: props.openaiModel !== undefined ? {
|
555
|
+
set: props.openaiModel
|
556
|
+
} : undefined,
|
557
|
+
customer: props.customer ?
|
558
|
+
typeof props.customer === 'object' && Object.keys(props.customer).length === 1 && (Object.keys(props.customer)[0] === 'id' || Object.keys(props.customer)[0] === 'symbol')
|
559
|
+
? {
|
560
|
+
connect: {
|
561
|
+
id: props.customer.id
|
562
|
+
}
|
563
|
+
} : { upsert: {
|
564
|
+
where: {
|
565
|
+
id: props.customer.id !== undefined ? {
|
566
|
+
equals: props.customer.id
|
567
|
+
} : undefined,
|
568
|
+
authUserId: props.customer.authUserId !== undefined ? {
|
569
|
+
equals: props.customer.authUserId
|
570
|
+
} : undefined,
|
571
|
+
name: props.customer.name !== undefined ? {
|
572
|
+
equals: props.customer.name
|
573
|
+
} : undefined,
|
574
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? {
|
575
|
+
equals: props.customer.stripeCustomerId
|
576
|
+
} : undefined,
|
577
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? {
|
578
|
+
equals: props.customer.stripeSubscriptionId
|
579
|
+
} : undefined,
|
580
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? {
|
581
|
+
equals: props.customer.stripePriceId
|
582
|
+
} : undefined,
|
583
|
+
},
|
584
|
+
update: {
|
585
|
+
authUserId: props.customer.authUserId !== undefined ? {
|
586
|
+
set: props.customer.authUserId
|
587
|
+
} : undefined,
|
588
|
+
name: props.customer.name !== undefined ? {
|
589
|
+
set: props.customer.name
|
590
|
+
} : undefined,
|
591
|
+
plan: props.customer.plan !== undefined ? {
|
592
|
+
set: props.customer.plan
|
593
|
+
} : undefined,
|
594
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? {
|
595
|
+
set: props.customer.stripeCustomerId
|
596
|
+
} : undefined,
|
597
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? {
|
598
|
+
set: props.customer.stripeSubscriptionId
|
599
|
+
} : undefined,
|
600
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? {
|
601
|
+
set: props.customer.stripePriceId
|
602
|
+
} : undefined,
|
603
|
+
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? {
|
604
|
+
set: props.customer.stripeCurrentPeriodEnd
|
605
|
+
} : undefined,
|
606
|
+
},
|
607
|
+
create: {
|
608
|
+
authUserId: props.customer.authUserId !== undefined ? props.customer.authUserId : undefined,
|
609
|
+
name: props.customer.name !== undefined ? props.customer.name : undefined,
|
610
|
+
plan: props.customer.plan !== undefined ? props.customer.plan : undefined,
|
611
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? props.customer.stripeCustomerId : undefined,
|
612
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? props.customer.stripeSubscriptionId : undefined,
|
613
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? props.customer.stripePriceId : undefined,
|
614
|
+
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? props.customer.stripeCurrentPeriodEnd : undefined,
|
615
|
+
},
|
616
|
+
}
|
617
|
+
} : undefined,
|
618
|
+
accounts: props.accounts ?
|
619
|
+
Array.isArray(props.accounts) && props.accounts.length > 0 && props.accounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
620
|
+
connect: props.accounts.map((item) => ({
|
621
|
+
id: item.id
|
622
|
+
}))
|
623
|
+
} : { upsert: props.accounts.map((item) => ({
|
624
|
+
where: {
|
625
|
+
id: item.id !== undefined ? item.id : undefined,
|
626
|
+
userId: item.userId !== undefined ? {
|
627
|
+
equals: item.userId
|
628
|
+
} : undefined,
|
629
|
+
providerAccountId: item.providerAccountId !== undefined ? {
|
630
|
+
equals: item.providerAccountId
|
631
|
+
} : undefined,
|
632
|
+
},
|
633
|
+
update: {
|
634
|
+
id: item.id !== undefined ? {
|
635
|
+
set: item.id
|
636
|
+
} : undefined,
|
637
|
+
type: item.type !== undefined ? {
|
638
|
+
set: item.type
|
639
|
+
} : undefined,
|
640
|
+
provider: item.provider !== undefined ? {
|
641
|
+
set: item.provider
|
642
|
+
} : undefined,
|
643
|
+
providerAccountId: item.providerAccountId !== undefined ? {
|
644
|
+
set: item.providerAccountId
|
645
|
+
} : undefined,
|
646
|
+
refresh_token: item.refresh_token !== undefined ? {
|
647
|
+
set: item.refresh_token
|
648
|
+
} : undefined,
|
649
|
+
access_token: item.access_token !== undefined ? {
|
650
|
+
set: item.access_token
|
651
|
+
} : undefined,
|
652
|
+
expires_at: item.expires_at !== undefined ? {
|
653
|
+
set: item.expires_at
|
654
|
+
} : undefined,
|
655
|
+
token_type: item.token_type !== undefined ? {
|
656
|
+
set: item.token_type
|
657
|
+
} : undefined,
|
658
|
+
scope: item.scope !== undefined ? {
|
659
|
+
set: item.scope
|
660
|
+
} : undefined,
|
661
|
+
id_token: item.id_token !== undefined ? {
|
662
|
+
set: item.id_token
|
663
|
+
} : undefined,
|
664
|
+
session_state: item.session_state !== undefined ? {
|
665
|
+
set: item.session_state
|
666
|
+
} : undefined,
|
667
|
+
},
|
668
|
+
create: {
|
669
|
+
type: item.type !== undefined ? item.type : undefined,
|
670
|
+
provider: item.provider !== undefined ? item.provider : undefined,
|
671
|
+
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
672
|
+
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
673
|
+
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
674
|
+
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
675
|
+
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
676
|
+
scope: item.scope !== undefined ? item.scope : undefined,
|
677
|
+
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
678
|
+
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
679
|
+
},
|
680
|
+
}))
|
681
|
+
} : undefined,
|
682
|
+
sessions: props.sessions ?
|
683
|
+
Array.isArray(props.sessions) && props.sessions.length > 0 && props.sessions.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
684
|
+
connect: props.sessions.map((item) => ({
|
685
|
+
id: item.id
|
686
|
+
}))
|
687
|
+
} : { upsert: props.sessions.map((item) => ({
|
688
|
+
where: {
|
689
|
+
id: item.id !== undefined ? item.id : undefined,
|
690
|
+
userId: item.userId !== undefined ? {
|
691
|
+
equals: item.userId
|
692
|
+
} : undefined,
|
693
|
+
},
|
694
|
+
update: {
|
695
|
+
id: item.id !== undefined ? {
|
696
|
+
set: item.id
|
697
|
+
} : undefined,
|
698
|
+
sessionToken: item.sessionToken !== undefined ? {
|
699
|
+
set: item.sessionToken
|
700
|
+
} : undefined,
|
701
|
+
expires: item.expires !== undefined ? {
|
702
|
+
set: item.expires
|
703
|
+
} : undefined,
|
704
|
+
},
|
705
|
+
create: {
|
706
|
+
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
707
|
+
expires: item.expires !== undefined ? item.expires : undefined,
|
708
|
+
},
|
709
|
+
}))
|
710
|
+
} : undefined,
|
711
|
+
authenticators: props.authenticators ?
|
712
|
+
Array.isArray(props.authenticators) && props.authenticators.length > 0 && props.authenticators.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
713
|
+
connect: props.authenticators.map((item) => ({
|
714
|
+
id: item.id
|
715
|
+
}))
|
716
|
+
} : { upsert: props.authenticators.map((item) => ({
|
717
|
+
where: {
|
718
|
+
id: item.id !== undefined ? item.id : undefined,
|
719
|
+
userId: item.userId !== undefined ? {
|
720
|
+
equals: item.userId
|
721
|
+
} : undefined,
|
722
|
+
},
|
723
|
+
update: {
|
724
|
+
id: item.id !== undefined ? {
|
725
|
+
set: item.id
|
726
|
+
} : undefined,
|
727
|
+
credentialID: item.credentialID !== undefined ? {
|
728
|
+
set: item.credentialID
|
729
|
+
} : undefined,
|
730
|
+
publicKey: item.publicKey !== undefined ? {
|
731
|
+
set: item.publicKey
|
732
|
+
} : undefined,
|
733
|
+
counter: item.counter !== undefined ? {
|
734
|
+
set: item.counter
|
735
|
+
} : undefined,
|
736
|
+
},
|
737
|
+
create: {
|
738
|
+
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
739
|
+
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
740
|
+
counter: item.counter !== undefined ? item.counter : undefined,
|
741
|
+
},
|
742
|
+
}))
|
743
|
+
} : undefined,
|
744
|
+
alpacaAccounts: props.alpacaAccounts ?
|
745
|
+
Array.isArray(props.alpacaAccounts) && props.alpacaAccounts.length > 0 && props.alpacaAccounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
746
|
+
connect: props.alpacaAccounts.map((item) => ({
|
747
|
+
id: item.id
|
748
|
+
}))
|
749
|
+
} : { upsert: props.alpacaAccounts.map((item) => ({
|
750
|
+
where: {
|
751
|
+
id: item.id !== undefined ? item.id : undefined,
|
752
|
+
userId: item.userId !== undefined ? {
|
753
|
+
equals: item.userId
|
754
|
+
} : undefined,
|
755
|
+
},
|
756
|
+
update: {
|
757
|
+
id: item.id !== undefined ? {
|
758
|
+
set: item.id
|
759
|
+
} : undefined,
|
760
|
+
type: item.type !== undefined ? {
|
761
|
+
set: item.type
|
762
|
+
} : undefined,
|
763
|
+
APIKey: item.APIKey !== undefined ? {
|
764
|
+
set: item.APIKey
|
765
|
+
} : undefined,
|
766
|
+
APISecret: item.APISecret !== undefined ? {
|
767
|
+
set: item.APISecret
|
768
|
+
} : undefined,
|
769
|
+
configuration: item.configuration !== undefined ? {
|
770
|
+
set: item.configuration
|
771
|
+
} : undefined,
|
772
|
+
marketOpen: item.marketOpen !== undefined ? {
|
773
|
+
set: item.marketOpen
|
774
|
+
} : undefined,
|
775
|
+
realTime: item.realTime !== undefined ? {
|
776
|
+
set: item.realTime
|
777
|
+
} : undefined,
|
778
|
+
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? {
|
779
|
+
set: item.cryptoTradingEnabled
|
780
|
+
} : undefined,
|
781
|
+
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
782
|
+
set: item.cryptoTradingPairs
|
783
|
+
} : undefined,
|
784
|
+
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? {
|
785
|
+
set: item.cryptoTradeAllocationPct
|
786
|
+
} : undefined,
|
787
|
+
tradeAllocationPct: item.tradeAllocationPct !== undefined ? {
|
788
|
+
set: item.tradeAllocationPct
|
789
|
+
} : undefined,
|
790
|
+
minPercentageChange: item.minPercentageChange !== undefined ? {
|
791
|
+
set: item.minPercentageChange
|
792
|
+
} : undefined,
|
793
|
+
volumeThreshold: item.volumeThreshold !== undefined ? {
|
794
|
+
set: item.volumeThreshold
|
795
|
+
} : undefined,
|
796
|
+
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? {
|
797
|
+
set: item.enablePortfolioTrailingStop
|
798
|
+
} : undefined,
|
799
|
+
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? {
|
800
|
+
set: item.portfolioTrailPercent
|
801
|
+
} : undefined,
|
802
|
+
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? {
|
803
|
+
set: item.portfolioProfitThresholdPercent
|
804
|
+
} : undefined,
|
805
|
+
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? {
|
806
|
+
set: item.reducedPortfolioTrailPercent
|
807
|
+
} : undefined,
|
808
|
+
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? {
|
809
|
+
set: item.defaultTrailingStopPercentage100
|
810
|
+
} : undefined,
|
811
|
+
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? {
|
812
|
+
set: item.firstTrailReductionThreshold100
|
813
|
+
} : undefined,
|
814
|
+
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? {
|
815
|
+
set: item.secondTrailReductionThreshold100
|
816
|
+
} : undefined,
|
817
|
+
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? {
|
818
|
+
set: item.firstReducedTrailPercentage100
|
819
|
+
} : undefined,
|
820
|
+
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? {
|
821
|
+
set: item.secondReducedTrailPercentage100
|
822
|
+
} : undefined,
|
823
|
+
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? {
|
824
|
+
set: item.minimumPriceChangePercent100
|
825
|
+
} : undefined,
|
826
|
+
allocation: item.allocation ?
|
827
|
+
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && (Object.keys(item.allocation)[0] === 'id' || Object.keys(item.allocation)[0] === 'symbol')
|
828
|
+
? {
|
829
|
+
connect: {
|
830
|
+
id: item.allocation.id
|
831
|
+
}
|
832
|
+
} : { upsert: {
|
303
833
|
where: {
|
304
|
-
id: item.allocation.id !== undefined ?
|
305
|
-
|
834
|
+
id: item.allocation.id !== undefined ? {
|
835
|
+
equals: item.allocation.id
|
836
|
+
} : undefined,
|
837
|
+
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? {
|
838
|
+
equals: item.allocation.alpacaAccountId
|
839
|
+
} : undefined,
|
840
|
+
},
|
841
|
+
update: {
|
842
|
+
id: item.allocation.id !== undefined ? {
|
843
|
+
set: item.allocation.id
|
844
|
+
} : undefined,
|
845
|
+
stocks: item.allocation.stocks !== undefined ? {
|
846
|
+
set: item.allocation.stocks
|
847
|
+
} : undefined,
|
848
|
+
crypto: item.allocation.crypto !== undefined ? {
|
849
|
+
set: item.allocation.crypto
|
850
|
+
} : undefined,
|
851
|
+
etfs: item.allocation.etfs !== undefined ? {
|
852
|
+
set: item.allocation.etfs
|
853
|
+
} : undefined,
|
306
854
|
},
|
307
855
|
create: {
|
308
856
|
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
@@ -311,19 +859,32 @@ exports.User = {
|
|
311
859
|
},
|
312
860
|
}
|
313
861
|
} : undefined,
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
: { connectOrCreate: item.alerts.map((item) => ({
|
862
|
+
alerts: item.alerts ?
|
863
|
+
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
864
|
+
connect: item.alerts.map((item) => ({
|
865
|
+
id: item.id
|
866
|
+
}))
|
867
|
+
} : { upsert: item.alerts.map((item) => ({
|
321
868
|
where: {
|
322
869
|
id: item.id !== undefined ? item.id : undefined,
|
323
870
|
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
324
871
|
equals: item.alpacaAccountId
|
325
872
|
} : undefined,
|
326
873
|
},
|
874
|
+
update: {
|
875
|
+
id: item.id !== undefined ? {
|
876
|
+
set: item.id
|
877
|
+
} : undefined,
|
878
|
+
message: item.message !== undefined ? {
|
879
|
+
set: item.message
|
880
|
+
} : undefined,
|
881
|
+
type: item.type !== undefined ? {
|
882
|
+
set: item.type
|
883
|
+
} : undefined,
|
884
|
+
isRead: item.isRead !== undefined ? {
|
885
|
+
set: item.isRead
|
886
|
+
} : undefined,
|
887
|
+
},
|
327
888
|
create: {
|
328
889
|
message: item.message !== undefined ? item.message : undefined,
|
329
890
|
type: item.type !== undefined ? item.type : undefined,
|
@@ -331,765 +892,1201 @@ exports.User = {
|
|
331
892
|
},
|
332
893
|
}))
|
333
894
|
} : undefined,
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
895
|
+
},
|
896
|
+
create: {
|
897
|
+
type: item.type !== undefined ? item.type : undefined,
|
898
|
+
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
899
|
+
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
900
|
+
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
901
|
+
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
902
|
+
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
903
|
+
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
904
|
+
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
905
|
+
set: item.cryptoTradingPairs
|
906
|
+
} : undefined,
|
907
|
+
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
908
|
+
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
909
|
+
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
910
|
+
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
911
|
+
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
912
|
+
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
913
|
+
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
914
|
+
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
915
|
+
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
916
|
+
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
917
|
+
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
918
|
+
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
919
|
+
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
920
|
+
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
921
|
+
allocation: item.allocation ?
|
922
|
+
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
923
|
+
? { connect: {
|
924
|
+
id: item.allocation.id
|
925
|
+
}
|
926
|
+
}
|
927
|
+
: { connectOrCreate: {
|
928
|
+
where: {
|
929
|
+
id: item.allocation.id !== undefined ? item.allocation.id : undefined,
|
930
|
+
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? item.allocation.alpacaAccountId : undefined,
|
931
|
+
},
|
932
|
+
create: {
|
933
|
+
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
934
|
+
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
935
|
+
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
936
|
+
},
|
937
|
+
}
|
938
|
+
} : undefined,
|
939
|
+
alerts: item.alerts ?
|
940
|
+
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
941
|
+
connect: item.alerts.map((item) => ({
|
942
|
+
id: item.id
|
943
|
+
}))
|
944
|
+
}
|
945
|
+
: { connectOrCreate: item.alerts.map((item) => ({
|
946
|
+
where: {
|
947
|
+
id: item.id !== undefined ? item.id : undefined,
|
948
|
+
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
949
|
+
equals: item.alpacaAccountId
|
950
|
+
} : undefined,
|
951
|
+
},
|
952
|
+
create: {
|
953
|
+
message: item.message !== undefined ? item.message : undefined,
|
954
|
+
type: item.type !== undefined ? item.type : undefined,
|
955
|
+
isRead: item.isRead !== undefined ? item.isRead : undefined,
|
956
|
+
},
|
957
|
+
}))
|
958
|
+
} : undefined,
|
959
|
+
},
|
960
|
+
}))
|
961
|
+
} : undefined,
|
962
|
+
},
|
963
|
+
};
|
964
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
965
|
+
const response = await client.mutate({
|
966
|
+
mutation: UPDATE_ONE_USER,
|
967
|
+
variables: filteredVariables,
|
968
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
969
|
+
fetchPolicy: 'no-cache'
|
970
|
+
});
|
971
|
+
if (response.errors && response.errors.length > 0)
|
972
|
+
throw new Error(response.errors[0].message);
|
973
|
+
if (response && response.data && response.data.updateOneUser) {
|
974
|
+
return response.data.updateOneUser;
|
975
|
+
}
|
976
|
+
else {
|
977
|
+
return null;
|
978
|
+
}
|
346
979
|
}
|
347
|
-
|
348
|
-
|
980
|
+
catch (error) {
|
981
|
+
lastError = error;
|
982
|
+
// Check if this is a database connection error that we should retry
|
983
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
984
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
985
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
986
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
987
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
988
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
989
|
+
retryCount++;
|
990
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
991
|
+
console.warn("Database connection error, retrying...");
|
992
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
993
|
+
continue;
|
994
|
+
}
|
995
|
+
// Log the error and rethrow
|
996
|
+
console.error("Database error occurred:", error);
|
997
|
+
throw error;
|
349
998
|
}
|
350
999
|
}
|
351
|
-
|
352
|
-
|
353
|
-
throw error;
|
354
|
-
}
|
1000
|
+
// If we exhausted retries, throw the last error
|
1001
|
+
throw lastError;
|
355
1002
|
},
|
356
1003
|
/**
|
357
|
-
*
|
358
|
-
*
|
1004
|
+
* Upsert a single User record.
|
1005
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
1006
|
+
* @param props - Properties to update.
|
359
1007
|
* @param globalClient - Apollo Client instance.
|
360
|
-
* @returns The
|
1008
|
+
* @returns The updated User or null.
|
361
1009
|
*/
|
362
|
-
async
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
1010
|
+
async upsert(props, globalClient) {
|
1011
|
+
var _a, _b, _c, _d, _e;
|
1012
|
+
// Maximum number of retries for database connection issues
|
1013
|
+
const MAX_RETRIES = 3;
|
1014
|
+
let retryCount = 0;
|
1015
|
+
let lastError = null;
|
1016
|
+
// Retry loop to handle potential database connection issues
|
1017
|
+
while (retryCount < MAX_RETRIES) {
|
1018
|
+
try {
|
1019
|
+
const [modules, client] = await Promise.all([
|
1020
|
+
(0, client_1.getApolloModules)(),
|
1021
|
+
globalClient
|
1022
|
+
? Promise.resolve(globalClient)
|
1023
|
+
: client_1.client
|
1024
|
+
]);
|
1025
|
+
const { gql, ApolloError } = modules;
|
1026
|
+
const UPSERT_ONE_USER = gql `
|
1027
|
+
mutation upsertOneUser($where: UserWhereUniqueInput!, $create: UserCreateInput!, $update: UserUpdateInput!) {
|
1028
|
+
upsertOneUser(where: $where, create: $create, update: $update) {
|
1029
|
+
${selectionSet}
|
1030
|
+
}
|
1031
|
+
}`;
|
1032
|
+
const variables = {
|
1033
|
+
where: {
|
1034
|
+
id: props.id !== undefined ? props.id : undefined,
|
1035
|
+
email: props.email !== undefined ? props.email : undefined,
|
1036
|
+
name: props.name !== undefined ? {
|
1037
|
+
equals: props.name
|
1038
|
+
} : undefined,
|
1039
|
+
},
|
1040
|
+
create: {
|
1041
|
+
name: props.name !== undefined ? props.name : undefined,
|
1042
|
+
email: props.email !== undefined ? props.email : undefined,
|
1043
|
+
emailVerified: props.emailVerified !== undefined ? props.emailVerified : undefined,
|
1044
|
+
image: props.image !== undefined ? props.image : undefined,
|
1045
|
+
role: props.role !== undefined ? props.role : undefined,
|
1046
|
+
bio: props.bio !== undefined ? props.bio : undefined,
|
1047
|
+
jobTitle: props.jobTitle !== undefined ? props.jobTitle : undefined,
|
1048
|
+
currentAccount: props.currentAccount !== undefined ? props.currentAccount : undefined,
|
1049
|
+
plan: props.plan !== undefined ? props.plan : undefined,
|
1050
|
+
openaiAPIKey: props.openaiAPIKey !== undefined ? props.openaiAPIKey : undefined,
|
1051
|
+
openaiModel: props.openaiModel !== undefined ? props.openaiModel : undefined,
|
1052
|
+
customer: props.customer ?
|
1053
|
+
typeof props.customer === 'object' && Object.keys(props.customer).length === 1 && Object.keys(props.customer)[0] === 'id'
|
1054
|
+
? { connect: {
|
1055
|
+
id: props.customer.id
|
1056
|
+
}
|
1057
|
+
}
|
1058
|
+
: { connectOrCreate: {
|
1059
|
+
where: {
|
1060
|
+
id: props.customer.id !== undefined ? props.customer.id : undefined,
|
1061
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? props.customer.stripeCustomerId : undefined,
|
1062
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? props.customer.stripeSubscriptionId : undefined,
|
1063
|
+
authUserId: props.customer.authUserId !== undefined ? {
|
1064
|
+
equals: props.customer.authUserId
|
1065
|
+
} : undefined,
|
1066
|
+
name: props.customer.name !== undefined ? {
|
1067
|
+
equals: props.customer.name
|
1068
|
+
} : undefined,
|
1069
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? {
|
1070
|
+
equals: props.customer.stripePriceId
|
1071
|
+
} : undefined,
|
1072
|
+
},
|
1073
|
+
create: {
|
1074
|
+
authUserId: props.customer.authUserId !== undefined ? props.customer.authUserId : undefined,
|
1075
|
+
name: props.customer.name !== undefined ? props.customer.name : undefined,
|
1076
|
+
plan: props.customer.plan !== undefined ? props.customer.plan : undefined,
|
1077
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? props.customer.stripeCustomerId : undefined,
|
1078
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? props.customer.stripeSubscriptionId : undefined,
|
1079
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? props.customer.stripePriceId : undefined,
|
1080
|
+
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? props.customer.stripeCurrentPeriodEnd : undefined,
|
1081
|
+
},
|
1082
|
+
}
|
1083
|
+
} : undefined,
|
1084
|
+
accounts: props.accounts ?
|
1085
|
+
Array.isArray(props.accounts) && props.accounts.length > 0 && props.accounts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1086
|
+
connect: props.accounts.map((item) => ({
|
1087
|
+
id: item.id
|
1088
|
+
}))
|
1089
|
+
}
|
1090
|
+
: { connectOrCreate: props.accounts.map((item) => ({
|
1091
|
+
where: {
|
1092
|
+
id: item.id !== undefined ? item.id : undefined,
|
1093
|
+
userId: item.userId !== undefined ? {
|
1094
|
+
equals: item.userId
|
1095
|
+
} : undefined,
|
1096
|
+
providerAccountId: item.providerAccountId !== undefined ? {
|
1097
|
+
equals: item.providerAccountId
|
1098
|
+
} : undefined,
|
1099
|
+
},
|
1100
|
+
create: {
|
1101
|
+
type: item.type !== undefined ? item.type : undefined,
|
1102
|
+
provider: item.provider !== undefined ? item.provider : undefined,
|
1103
|
+
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
1104
|
+
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
1105
|
+
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
1106
|
+
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
1107
|
+
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
1108
|
+
scope: item.scope !== undefined ? item.scope : undefined,
|
1109
|
+
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
1110
|
+
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
1111
|
+
},
|
1112
|
+
}))
|
1113
|
+
} : undefined,
|
1114
|
+
sessions: props.sessions ?
|
1115
|
+
Array.isArray(props.sessions) && props.sessions.length > 0 && props.sessions.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1116
|
+
connect: props.sessions.map((item) => ({
|
1117
|
+
id: item.id
|
1118
|
+
}))
|
1119
|
+
}
|
1120
|
+
: { connectOrCreate: props.sessions.map((item) => ({
|
1121
|
+
where: {
|
1122
|
+
id: item.id !== undefined ? item.id : undefined,
|
1123
|
+
userId: item.userId !== undefined ? {
|
1124
|
+
equals: item.userId
|
1125
|
+
} : undefined,
|
1126
|
+
},
|
1127
|
+
create: {
|
1128
|
+
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
1129
|
+
expires: item.expires !== undefined ? item.expires : undefined,
|
1130
|
+
},
|
1131
|
+
}))
|
1132
|
+
} : undefined,
|
1133
|
+
authenticators: props.authenticators ?
|
1134
|
+
Array.isArray(props.authenticators) && props.authenticators.length > 0 && props.authenticators.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1135
|
+
connect: props.authenticators.map((item) => ({
|
1136
|
+
id: item.id
|
1137
|
+
}))
|
1138
|
+
}
|
1139
|
+
: { connectOrCreate: props.authenticators.map((item) => ({
|
1140
|
+
where: {
|
1141
|
+
id: item.id !== undefined ? item.id : undefined,
|
1142
|
+
userId: item.userId !== undefined ? {
|
1143
|
+
equals: item.userId
|
1144
|
+
} : undefined,
|
1145
|
+
},
|
1146
|
+
create: {
|
1147
|
+
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
1148
|
+
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
1149
|
+
counter: item.counter !== undefined ? item.counter : undefined,
|
1150
|
+
},
|
1151
|
+
}))
|
1152
|
+
} : undefined,
|
1153
|
+
alpacaAccounts: props.alpacaAccounts ?
|
1154
|
+
Array.isArray(props.alpacaAccounts) && props.alpacaAccounts.length > 0 && props.alpacaAccounts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1155
|
+
connect: props.alpacaAccounts.map((item) => ({
|
1156
|
+
id: item.id
|
1157
|
+
}))
|
1158
|
+
}
|
1159
|
+
: { connectOrCreate: props.alpacaAccounts.map((item) => ({
|
1160
|
+
where: {
|
1161
|
+
id: item.id !== undefined ? item.id : undefined,
|
1162
|
+
userId: item.userId !== undefined ? {
|
1163
|
+
equals: item.userId
|
1164
|
+
} : undefined,
|
1165
|
+
},
|
1166
|
+
create: {
|
1167
|
+
type: item.type !== undefined ? item.type : undefined,
|
1168
|
+
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
1169
|
+
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
1170
|
+
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
1171
|
+
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
1172
|
+
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
1173
|
+
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
1174
|
+
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
1175
|
+
set: item.cryptoTradingPairs
|
1176
|
+
} : undefined,
|
1177
|
+
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
1178
|
+
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
1179
|
+
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
1180
|
+
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
1181
|
+
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
1182
|
+
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
1183
|
+
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
1184
|
+
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
1185
|
+
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
1186
|
+
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
1187
|
+
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
1188
|
+
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
1189
|
+
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
1190
|
+
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
1191
|
+
allocation: item.allocation ?
|
1192
|
+
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
1193
|
+
? { connect: {
|
1194
|
+
id: item.allocation.id
|
1195
|
+
}
|
1196
|
+
}
|
1197
|
+
: { connectOrCreate: {
|
1198
|
+
where: {
|
1199
|
+
id: item.allocation.id !== undefined ? item.allocation.id : undefined,
|
1200
|
+
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? item.allocation.alpacaAccountId : undefined,
|
1201
|
+
},
|
1202
|
+
create: {
|
1203
|
+
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
1204
|
+
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
1205
|
+
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
1206
|
+
},
|
1207
|
+
}
|
1208
|
+
} : undefined,
|
1209
|
+
alerts: item.alerts ?
|
1210
|
+
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1211
|
+
connect: item.alerts.map((item) => ({
|
1212
|
+
id: item.id
|
1213
|
+
}))
|
1214
|
+
}
|
1215
|
+
: { connectOrCreate: item.alerts.map((item) => ({
|
1216
|
+
where: {
|
1217
|
+
id: item.id !== undefined ? item.id : undefined,
|
1218
|
+
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
1219
|
+
equals: item.alpacaAccountId
|
1220
|
+
} : undefined,
|
1221
|
+
},
|
1222
|
+
create: {
|
1223
|
+
message: item.message !== undefined ? item.message : undefined,
|
1224
|
+
type: item.type !== undefined ? item.type : undefined,
|
1225
|
+
isRead: item.isRead !== undefined ? item.isRead : undefined,
|
1226
|
+
},
|
1227
|
+
}))
|
1228
|
+
} : undefined,
|
1229
|
+
},
|
1230
|
+
}))
|
1231
|
+
} : undefined,
|
1232
|
+
},
|
1233
|
+
update: {
|
1234
|
+
name: props.name !== undefined ? {
|
1235
|
+
set: props.name
|
1236
|
+
} : undefined,
|
1237
|
+
email: props.email !== undefined ? {
|
1238
|
+
set: props.email
|
1239
|
+
} : undefined,
|
1240
|
+
emailVerified: props.emailVerified !== undefined ? {
|
1241
|
+
set: props.emailVerified
|
1242
|
+
} : undefined,
|
1243
|
+
image: props.image !== undefined ? {
|
1244
|
+
set: props.image
|
1245
|
+
} : undefined,
|
1246
|
+
role: props.role !== undefined ? {
|
1247
|
+
set: props.role
|
1248
|
+
} : undefined,
|
1249
|
+
bio: props.bio !== undefined ? {
|
1250
|
+
set: props.bio
|
1251
|
+
} : undefined,
|
1252
|
+
jobTitle: props.jobTitle !== undefined ? {
|
1253
|
+
set: props.jobTitle
|
1254
|
+
} : undefined,
|
1255
|
+
currentAccount: props.currentAccount !== undefined ? {
|
1256
|
+
set: props.currentAccount
|
1257
|
+
} : undefined,
|
1258
|
+
plan: props.plan !== undefined ? {
|
1259
|
+
set: props.plan
|
1260
|
+
} : undefined,
|
1261
|
+
openaiAPIKey: props.openaiAPIKey !== undefined ? {
|
1262
|
+
set: props.openaiAPIKey
|
1263
|
+
} : undefined,
|
1264
|
+
openaiModel: props.openaiModel !== undefined ? {
|
1265
|
+
set: props.openaiModel
|
1266
|
+
} : undefined,
|
1267
|
+
customer: props.customer ?
|
1268
|
+
typeof props.customer === 'object' && Object.keys(props.customer).length === 1 && (Object.keys(props.customer)[0] === 'id' || Object.keys(props.customer)[0] === 'symbol')
|
1269
|
+
? {
|
1270
|
+
connect: {
|
1271
|
+
id: props.customer.id
|
1272
|
+
}
|
1273
|
+
} : { upsert: {
|
1274
|
+
where: {
|
1275
|
+
id: props.customer.id !== undefined ? {
|
1276
|
+
equals: props.customer.id
|
1277
|
+
} : undefined,
|
1278
|
+
authUserId: props.customer.authUserId !== undefined ? {
|
1279
|
+
equals: props.customer.authUserId
|
1280
|
+
} : undefined,
|
1281
|
+
name: props.customer.name !== undefined ? {
|
1282
|
+
equals: props.customer.name
|
1283
|
+
} : undefined,
|
1284
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? {
|
1285
|
+
equals: props.customer.stripeCustomerId
|
1286
|
+
} : undefined,
|
1287
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? {
|
1288
|
+
equals: props.customer.stripeSubscriptionId
|
1289
|
+
} : undefined,
|
1290
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? {
|
1291
|
+
equals: props.customer.stripePriceId
|
1292
|
+
} : undefined,
|
1293
|
+
},
|
1294
|
+
update: {
|
1295
|
+
authUserId: props.customer.authUserId !== undefined ? {
|
1296
|
+
set: props.customer.authUserId
|
1297
|
+
} : undefined,
|
1298
|
+
name: props.customer.name !== undefined ? {
|
1299
|
+
set: props.customer.name
|
1300
|
+
} : undefined,
|
1301
|
+
plan: props.customer.plan !== undefined ? {
|
1302
|
+
set: props.customer.plan
|
1303
|
+
} : undefined,
|
1304
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? {
|
1305
|
+
set: props.customer.stripeCustomerId
|
1306
|
+
} : undefined,
|
1307
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? {
|
1308
|
+
set: props.customer.stripeSubscriptionId
|
1309
|
+
} : undefined,
|
1310
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? {
|
1311
|
+
set: props.customer.stripePriceId
|
1312
|
+
} : undefined,
|
1313
|
+
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? {
|
1314
|
+
set: props.customer.stripeCurrentPeriodEnd
|
1315
|
+
} : undefined,
|
1316
|
+
},
|
1317
|
+
create: {
|
1318
|
+
authUserId: props.customer.authUserId !== undefined ? props.customer.authUserId : undefined,
|
1319
|
+
name: props.customer.name !== undefined ? props.customer.name : undefined,
|
1320
|
+
plan: props.customer.plan !== undefined ? props.customer.plan : undefined,
|
1321
|
+
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? props.customer.stripeCustomerId : undefined,
|
1322
|
+
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? props.customer.stripeSubscriptionId : undefined,
|
1323
|
+
stripePriceId: props.customer.stripePriceId !== undefined ? props.customer.stripePriceId : undefined,
|
1324
|
+
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? props.customer.stripeCurrentPeriodEnd : undefined,
|
1325
|
+
},
|
1326
|
+
}
|
1327
|
+
} : undefined,
|
1328
|
+
accounts: props.accounts ?
|
1329
|
+
Array.isArray(props.accounts) && props.accounts.length > 0 && props.accounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1330
|
+
connect: props.accounts.map((item) => ({
|
1331
|
+
id: item.id
|
1332
|
+
}))
|
1333
|
+
} : { upsert: props.accounts.map((item) => ({
|
1334
|
+
where: {
|
1335
|
+
id: item.id !== undefined ? item.id : undefined,
|
1336
|
+
userId: item.userId !== undefined ? {
|
1337
|
+
equals: item.userId
|
1338
|
+
} : undefined,
|
1339
|
+
providerAccountId: item.providerAccountId !== undefined ? {
|
1340
|
+
equals: item.providerAccountId
|
1341
|
+
} : undefined,
|
1342
|
+
},
|
1343
|
+
update: {
|
1344
|
+
id: item.id !== undefined ? {
|
1345
|
+
set: item.id
|
1346
|
+
} : undefined,
|
1347
|
+
type: item.type !== undefined ? {
|
1348
|
+
set: item.type
|
1349
|
+
} : undefined,
|
1350
|
+
provider: item.provider !== undefined ? {
|
1351
|
+
set: item.provider
|
1352
|
+
} : undefined,
|
1353
|
+
providerAccountId: item.providerAccountId !== undefined ? {
|
1354
|
+
set: item.providerAccountId
|
1355
|
+
} : undefined,
|
1356
|
+
refresh_token: item.refresh_token !== undefined ? {
|
1357
|
+
set: item.refresh_token
|
1358
|
+
} : undefined,
|
1359
|
+
access_token: item.access_token !== undefined ? {
|
1360
|
+
set: item.access_token
|
1361
|
+
} : undefined,
|
1362
|
+
expires_at: item.expires_at !== undefined ? {
|
1363
|
+
set: item.expires_at
|
1364
|
+
} : undefined,
|
1365
|
+
token_type: item.token_type !== undefined ? {
|
1366
|
+
set: item.token_type
|
1367
|
+
} : undefined,
|
1368
|
+
scope: item.scope !== undefined ? {
|
1369
|
+
set: item.scope
|
1370
|
+
} : undefined,
|
1371
|
+
id_token: item.id_token !== undefined ? {
|
1372
|
+
set: item.id_token
|
1373
|
+
} : undefined,
|
1374
|
+
session_state: item.session_state !== undefined ? {
|
1375
|
+
set: item.session_state
|
1376
|
+
} : undefined,
|
1377
|
+
},
|
1378
|
+
create: {
|
1379
|
+
type: item.type !== undefined ? item.type : undefined,
|
1380
|
+
provider: item.provider !== undefined ? item.provider : undefined,
|
1381
|
+
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
1382
|
+
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
1383
|
+
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
1384
|
+
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
1385
|
+
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
1386
|
+
scope: item.scope !== undefined ? item.scope : undefined,
|
1387
|
+
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
1388
|
+
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
1389
|
+
},
|
1390
|
+
}))
|
1391
|
+
} : undefined,
|
1392
|
+
sessions: props.sessions ?
|
1393
|
+
Array.isArray(props.sessions) && props.sessions.length > 0 && props.sessions.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1394
|
+
connect: props.sessions.map((item) => ({
|
1395
|
+
id: item.id
|
1396
|
+
}))
|
1397
|
+
} : { upsert: props.sessions.map((item) => ({
|
1398
|
+
where: {
|
1399
|
+
id: item.id !== undefined ? item.id : undefined,
|
1400
|
+
userId: item.userId !== undefined ? {
|
1401
|
+
equals: item.userId
|
1402
|
+
} : undefined,
|
1403
|
+
},
|
1404
|
+
update: {
|
1405
|
+
id: item.id !== undefined ? {
|
1406
|
+
set: item.id
|
1407
|
+
} : undefined,
|
1408
|
+
sessionToken: item.sessionToken !== undefined ? {
|
1409
|
+
set: item.sessionToken
|
1410
|
+
} : undefined,
|
1411
|
+
expires: item.expires !== undefined ? {
|
1412
|
+
set: item.expires
|
1413
|
+
} : undefined,
|
1414
|
+
},
|
1415
|
+
create: {
|
1416
|
+
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
1417
|
+
expires: item.expires !== undefined ? item.expires : undefined,
|
1418
|
+
},
|
1419
|
+
}))
|
1420
|
+
} : undefined,
|
1421
|
+
authenticators: props.authenticators ?
|
1422
|
+
Array.isArray(props.authenticators) && props.authenticators.length > 0 && props.authenticators.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1423
|
+
connect: props.authenticators.map((item) => ({
|
1424
|
+
id: item.id
|
1425
|
+
}))
|
1426
|
+
} : { upsert: props.authenticators.map((item) => ({
|
1427
|
+
where: {
|
1428
|
+
id: item.id !== undefined ? item.id : undefined,
|
1429
|
+
userId: item.userId !== undefined ? {
|
1430
|
+
equals: item.userId
|
1431
|
+
} : undefined,
|
1432
|
+
},
|
1433
|
+
update: {
|
1434
|
+
id: item.id !== undefined ? {
|
1435
|
+
set: item.id
|
1436
|
+
} : undefined,
|
1437
|
+
credentialID: item.credentialID !== undefined ? {
|
1438
|
+
set: item.credentialID
|
1439
|
+
} : undefined,
|
1440
|
+
publicKey: item.publicKey !== undefined ? {
|
1441
|
+
set: item.publicKey
|
1442
|
+
} : undefined,
|
1443
|
+
counter: item.counter !== undefined ? {
|
1444
|
+
set: item.counter
|
1445
|
+
} : undefined,
|
1446
|
+
},
|
1447
|
+
create: {
|
1448
|
+
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
1449
|
+
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
1450
|
+
counter: item.counter !== undefined ? item.counter : undefined,
|
1451
|
+
},
|
1452
|
+
}))
|
1453
|
+
} : undefined,
|
1454
|
+
alpacaAccounts: props.alpacaAccounts ?
|
1455
|
+
Array.isArray(props.alpacaAccounts) && props.alpacaAccounts.length > 0 && props.alpacaAccounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1456
|
+
connect: props.alpacaAccounts.map((item) => ({
|
1457
|
+
id: item.id
|
1458
|
+
}))
|
1459
|
+
} : { upsert: props.alpacaAccounts.map((item) => ({
|
1460
|
+
where: {
|
1461
|
+
id: item.id !== undefined ? item.id : undefined,
|
1462
|
+
userId: item.userId !== undefined ? {
|
1463
|
+
equals: item.userId
|
1464
|
+
} : undefined,
|
1465
|
+
},
|
1466
|
+
update: {
|
1467
|
+
id: item.id !== undefined ? {
|
1468
|
+
set: item.id
|
1469
|
+
} : undefined,
|
1470
|
+
type: item.type !== undefined ? {
|
1471
|
+
set: item.type
|
1472
|
+
} : undefined,
|
1473
|
+
APIKey: item.APIKey !== undefined ? {
|
1474
|
+
set: item.APIKey
|
1475
|
+
} : undefined,
|
1476
|
+
APISecret: item.APISecret !== undefined ? {
|
1477
|
+
set: item.APISecret
|
1478
|
+
} : undefined,
|
1479
|
+
configuration: item.configuration !== undefined ? {
|
1480
|
+
set: item.configuration
|
1481
|
+
} : undefined,
|
1482
|
+
marketOpen: item.marketOpen !== undefined ? {
|
1483
|
+
set: item.marketOpen
|
1484
|
+
} : undefined,
|
1485
|
+
realTime: item.realTime !== undefined ? {
|
1486
|
+
set: item.realTime
|
1487
|
+
} : undefined,
|
1488
|
+
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? {
|
1489
|
+
set: item.cryptoTradingEnabled
|
1490
|
+
} : undefined,
|
1491
|
+
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
1492
|
+
set: item.cryptoTradingPairs
|
1493
|
+
} : undefined,
|
1494
|
+
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? {
|
1495
|
+
set: item.cryptoTradeAllocationPct
|
1496
|
+
} : undefined,
|
1497
|
+
tradeAllocationPct: item.tradeAllocationPct !== undefined ? {
|
1498
|
+
set: item.tradeAllocationPct
|
1499
|
+
} : undefined,
|
1500
|
+
minPercentageChange: item.minPercentageChange !== undefined ? {
|
1501
|
+
set: item.minPercentageChange
|
1502
|
+
} : undefined,
|
1503
|
+
volumeThreshold: item.volumeThreshold !== undefined ? {
|
1504
|
+
set: item.volumeThreshold
|
1505
|
+
} : undefined,
|
1506
|
+
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? {
|
1507
|
+
set: item.enablePortfolioTrailingStop
|
1508
|
+
} : undefined,
|
1509
|
+
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? {
|
1510
|
+
set: item.portfolioTrailPercent
|
1511
|
+
} : undefined,
|
1512
|
+
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? {
|
1513
|
+
set: item.portfolioProfitThresholdPercent
|
1514
|
+
} : undefined,
|
1515
|
+
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? {
|
1516
|
+
set: item.reducedPortfolioTrailPercent
|
1517
|
+
} : undefined,
|
1518
|
+
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? {
|
1519
|
+
set: item.defaultTrailingStopPercentage100
|
1520
|
+
} : undefined,
|
1521
|
+
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? {
|
1522
|
+
set: item.firstTrailReductionThreshold100
|
1523
|
+
} : undefined,
|
1524
|
+
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? {
|
1525
|
+
set: item.secondTrailReductionThreshold100
|
1526
|
+
} : undefined,
|
1527
|
+
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? {
|
1528
|
+
set: item.firstReducedTrailPercentage100
|
1529
|
+
} : undefined,
|
1530
|
+
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? {
|
1531
|
+
set: item.secondReducedTrailPercentage100
|
1532
|
+
} : undefined,
|
1533
|
+
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? {
|
1534
|
+
set: item.minimumPriceChangePercent100
|
1535
|
+
} : undefined,
|
1536
|
+
allocation: item.allocation ?
|
1537
|
+
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && (Object.keys(item.allocation)[0] === 'id' || Object.keys(item.allocation)[0] === 'symbol')
|
1538
|
+
? {
|
1539
|
+
connect: {
|
1540
|
+
id: item.allocation.id
|
1541
|
+
}
|
1542
|
+
} : { upsert: {
|
1543
|
+
where: {
|
1544
|
+
id: item.allocation.id !== undefined ? {
|
1545
|
+
equals: item.allocation.id
|
1546
|
+
} : undefined,
|
1547
|
+
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? {
|
1548
|
+
equals: item.allocation.alpacaAccountId
|
1549
|
+
} : undefined,
|
1550
|
+
},
|
1551
|
+
update: {
|
1552
|
+
id: item.allocation.id !== undefined ? {
|
1553
|
+
set: item.allocation.id
|
1554
|
+
} : undefined,
|
1555
|
+
stocks: item.allocation.stocks !== undefined ? {
|
1556
|
+
set: item.allocation.stocks
|
1557
|
+
} : undefined,
|
1558
|
+
crypto: item.allocation.crypto !== undefined ? {
|
1559
|
+
set: item.allocation.crypto
|
1560
|
+
} : undefined,
|
1561
|
+
etfs: item.allocation.etfs !== undefined ? {
|
1562
|
+
set: item.allocation.etfs
|
1563
|
+
} : undefined,
|
1564
|
+
},
|
1565
|
+
create: {
|
1566
|
+
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
1567
|
+
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
1568
|
+
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
1569
|
+
},
|
1570
|
+
}
|
1571
|
+
} : undefined,
|
1572
|
+
alerts: item.alerts ?
|
1573
|
+
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1574
|
+
connect: item.alerts.map((item) => ({
|
1575
|
+
id: item.id
|
1576
|
+
}))
|
1577
|
+
} : { upsert: item.alerts.map((item) => ({
|
1578
|
+
where: {
|
1579
|
+
id: item.id !== undefined ? item.id : undefined,
|
1580
|
+
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
1581
|
+
equals: item.alpacaAccountId
|
1582
|
+
} : undefined,
|
1583
|
+
},
|
1584
|
+
update: {
|
1585
|
+
id: item.id !== undefined ? {
|
1586
|
+
set: item.id
|
1587
|
+
} : undefined,
|
1588
|
+
message: item.message !== undefined ? {
|
1589
|
+
set: item.message
|
1590
|
+
} : undefined,
|
1591
|
+
type: item.type !== undefined ? {
|
1592
|
+
set: item.type
|
1593
|
+
} : undefined,
|
1594
|
+
isRead: item.isRead !== undefined ? {
|
1595
|
+
set: item.isRead
|
1596
|
+
} : undefined,
|
1597
|
+
},
|
1598
|
+
create: {
|
1599
|
+
message: item.message !== undefined ? item.message : undefined,
|
1600
|
+
type: item.type !== undefined ? item.type : undefined,
|
1601
|
+
isRead: item.isRead !== undefined ? item.isRead : undefined,
|
1602
|
+
},
|
1603
|
+
}))
|
1604
|
+
} : undefined,
|
1605
|
+
},
|
1606
|
+
create: {
|
1607
|
+
type: item.type !== undefined ? item.type : undefined,
|
1608
|
+
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
1609
|
+
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
1610
|
+
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
1611
|
+
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
1612
|
+
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
1613
|
+
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
1614
|
+
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
1615
|
+
set: item.cryptoTradingPairs
|
1616
|
+
} : undefined,
|
1617
|
+
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
1618
|
+
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
1619
|
+
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
1620
|
+
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
1621
|
+
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
1622
|
+
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
1623
|
+
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
1624
|
+
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
1625
|
+
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
1626
|
+
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
1627
|
+
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
1628
|
+
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
1629
|
+
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
1630
|
+
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
1631
|
+
allocation: item.allocation ?
|
1632
|
+
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
1633
|
+
? { connect: {
|
1634
|
+
id: item.allocation.id
|
1635
|
+
}
|
1636
|
+
}
|
1637
|
+
: { connectOrCreate: {
|
1638
|
+
where: {
|
1639
|
+
id: item.allocation.id !== undefined ? item.allocation.id : undefined,
|
1640
|
+
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? item.allocation.alpacaAccountId : undefined,
|
1641
|
+
},
|
1642
|
+
create: {
|
1643
|
+
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
1644
|
+
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
1645
|
+
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
1646
|
+
},
|
1647
|
+
}
|
1648
|
+
} : undefined,
|
1649
|
+
alerts: item.alerts ?
|
1650
|
+
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1651
|
+
connect: item.alerts.map((item) => ({
|
1652
|
+
id: item.id
|
1653
|
+
}))
|
1654
|
+
}
|
1655
|
+
: { connectOrCreate: item.alerts.map((item) => ({
|
1656
|
+
where: {
|
1657
|
+
id: item.id !== undefined ? item.id : undefined,
|
1658
|
+
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
1659
|
+
equals: item.alpacaAccountId
|
1660
|
+
} : undefined,
|
1661
|
+
},
|
1662
|
+
create: {
|
1663
|
+
message: item.message !== undefined ? item.message : undefined,
|
1664
|
+
type: item.type !== undefined ? item.type : undefined,
|
1665
|
+
isRead: item.isRead !== undefined ? item.isRead : undefined,
|
1666
|
+
},
|
1667
|
+
}))
|
1668
|
+
} : undefined,
|
1669
|
+
},
|
1670
|
+
}))
|
1671
|
+
} : undefined,
|
1672
|
+
},
|
1673
|
+
};
|
1674
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
1675
|
+
const response = await client.mutate({
|
1676
|
+
mutation: UPSERT_ONE_USER,
|
1677
|
+
variables: filteredVariables,
|
1678
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
1679
|
+
fetchPolicy: 'no-cache'
|
1680
|
+
});
|
1681
|
+
if (response.errors && response.errors.length > 0)
|
1682
|
+
throw new Error(response.errors[0].message);
|
1683
|
+
if (response && response.data && response.data.upsertOneUser) {
|
1684
|
+
return response.data.upsertOneUser;
|
1685
|
+
}
|
1686
|
+
else {
|
1687
|
+
return null;
|
1688
|
+
}
|
399
1689
|
}
|
400
|
-
|
401
|
-
|
1690
|
+
catch (error) {
|
1691
|
+
lastError = error;
|
1692
|
+
// Check if this is a database connection error that we should retry
|
1693
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
1694
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
1695
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
1696
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
1697
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
1698
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
1699
|
+
retryCount++;
|
1700
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
1701
|
+
console.warn("Database connection error, retrying...");
|
1702
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
1703
|
+
continue;
|
1704
|
+
}
|
1705
|
+
// Log the error and rethrow
|
1706
|
+
console.error("Database error occurred:", error);
|
1707
|
+
throw error;
|
402
1708
|
}
|
403
1709
|
}
|
404
|
-
|
405
|
-
|
406
|
-
throw error;
|
407
|
-
}
|
1710
|
+
// If we exhausted retries, throw the last error
|
1711
|
+
throw lastError;
|
408
1712
|
},
|
409
1713
|
/**
|
410
|
-
* Update
|
411
|
-
*
|
1714
|
+
* Update multiple User records.
|
1715
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
1716
|
+
* @param props - Array of User objects for the updated records.
|
412
1717
|
* @param globalClient - Apollo Client instance.
|
413
|
-
* @returns The
|
1718
|
+
* @returns The count of created records or null.
|
414
1719
|
*/
|
415
|
-
async
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
? {
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
counter: item.counter !== undefined ? item.counter : undefined,
|
664
|
-
},
|
665
|
-
}))
|
666
|
-
} : undefined,
|
667
|
-
alpacaAccounts: props.alpacaAccounts ?
|
668
|
-
Array.isArray(props.alpacaAccounts) && props.alpacaAccounts.length > 0 && props.alpacaAccounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
669
|
-
connect: props.alpacaAccounts.map((item) => ({
|
670
|
-
id: item.id
|
671
|
-
}))
|
672
|
-
} : { upsert: props.alpacaAccounts.map((item) => ({
|
673
|
-
where: {
|
674
|
-
id: item.id !== undefined ? item.id : undefined,
|
675
|
-
userId: item.userId !== undefined ? {
|
676
|
-
equals: item.userId
|
677
|
-
} : undefined,
|
678
|
-
},
|
679
|
-
update: {
|
680
|
-
id: item.id !== undefined ? {
|
681
|
-
set: item.id
|
682
|
-
} : undefined,
|
683
|
-
type: item.type !== undefined ? {
|
684
|
-
set: item.type
|
685
|
-
} : undefined,
|
686
|
-
APIKey: item.APIKey !== undefined ? {
|
687
|
-
set: item.APIKey
|
688
|
-
} : undefined,
|
689
|
-
APISecret: item.APISecret !== undefined ? {
|
690
|
-
set: item.APISecret
|
691
|
-
} : undefined,
|
692
|
-
configuration: item.configuration !== undefined ? {
|
693
|
-
set: item.configuration
|
694
|
-
} : undefined,
|
695
|
-
marketOpen: item.marketOpen !== undefined ? {
|
696
|
-
set: item.marketOpen
|
697
|
-
} : undefined,
|
698
|
-
realTime: item.realTime !== undefined ? {
|
699
|
-
set: item.realTime
|
700
|
-
} : undefined,
|
701
|
-
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? {
|
702
|
-
set: item.cryptoTradingEnabled
|
703
|
-
} : undefined,
|
704
|
-
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
705
|
-
set: item.cryptoTradingPairs
|
706
|
-
} : undefined,
|
707
|
-
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? {
|
708
|
-
set: item.cryptoTradeAllocationPct
|
709
|
-
} : undefined,
|
710
|
-
tradeAllocationPct: item.tradeAllocationPct !== undefined ? {
|
711
|
-
set: item.tradeAllocationPct
|
712
|
-
} : undefined,
|
713
|
-
minPercentageChange: item.minPercentageChange !== undefined ? {
|
714
|
-
set: item.minPercentageChange
|
715
|
-
} : undefined,
|
716
|
-
volumeThreshold: item.volumeThreshold !== undefined ? {
|
717
|
-
set: item.volumeThreshold
|
718
|
-
} : undefined,
|
719
|
-
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? {
|
720
|
-
set: item.enablePortfolioTrailingStop
|
721
|
-
} : undefined,
|
722
|
-
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? {
|
723
|
-
set: item.portfolioTrailPercent
|
724
|
-
} : undefined,
|
725
|
-
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? {
|
726
|
-
set: item.portfolioProfitThresholdPercent
|
727
|
-
} : undefined,
|
728
|
-
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? {
|
729
|
-
set: item.reducedPortfolioTrailPercent
|
730
|
-
} : undefined,
|
731
|
-
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? {
|
732
|
-
set: item.defaultTrailingStopPercentage100
|
733
|
-
} : undefined,
|
734
|
-
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? {
|
735
|
-
set: item.firstTrailReductionThreshold100
|
736
|
-
} : undefined,
|
737
|
-
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? {
|
738
|
-
set: item.secondTrailReductionThreshold100
|
739
|
-
} : undefined,
|
740
|
-
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? {
|
741
|
-
set: item.firstReducedTrailPercentage100
|
742
|
-
} : undefined,
|
743
|
-
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? {
|
744
|
-
set: item.secondReducedTrailPercentage100
|
745
|
-
} : undefined,
|
746
|
-
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? {
|
747
|
-
set: item.minimumPriceChangePercent100
|
748
|
-
} : undefined,
|
749
|
-
allocation: item.allocation ?
|
750
|
-
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && (Object.keys(item.allocation)[0] === 'id' || Object.keys(item.allocation)[0] === 'symbol')
|
751
|
-
? {
|
752
|
-
connect: {
|
753
|
-
id: item.allocation.id
|
754
|
-
}
|
755
|
-
} : { upsert: {
|
756
|
-
where: {
|
757
|
-
id: item.allocation.id !== undefined ? {
|
758
|
-
equals: item.allocation.id
|
759
|
-
} : undefined,
|
760
|
-
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? {
|
761
|
-
equals: item.allocation.alpacaAccountId
|
762
|
-
} : undefined,
|
763
|
-
},
|
764
|
-
update: {
|
765
|
-
id: item.allocation.id !== undefined ? {
|
766
|
-
set: item.allocation.id
|
767
|
-
} : undefined,
|
768
|
-
stocks: item.allocation.stocks !== undefined ? {
|
769
|
-
set: item.allocation.stocks
|
770
|
-
} : undefined,
|
771
|
-
crypto: item.allocation.crypto !== undefined ? {
|
772
|
-
set: item.allocation.crypto
|
773
|
-
} : undefined,
|
774
|
-
etfs: item.allocation.etfs !== undefined ? {
|
775
|
-
set: item.allocation.etfs
|
776
|
-
} : undefined,
|
777
|
-
},
|
778
|
-
create: {
|
779
|
-
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
780
|
-
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
781
|
-
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
782
|
-
},
|
783
|
-
}
|
784
|
-
} : undefined,
|
785
|
-
alerts: item.alerts ?
|
786
|
-
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
787
|
-
connect: item.alerts.map((item) => ({
|
788
|
-
id: item.id
|
789
|
-
}))
|
790
|
-
} : { upsert: item.alerts.map((item) => ({
|
791
|
-
where: {
|
792
|
-
id: item.id !== undefined ? item.id : undefined,
|
793
|
-
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
794
|
-
equals: item.alpacaAccountId
|
795
|
-
} : undefined,
|
796
|
-
},
|
797
|
-
update: {
|
798
|
-
id: item.id !== undefined ? {
|
799
|
-
set: item.id
|
800
|
-
} : undefined,
|
801
|
-
message: item.message !== undefined ? {
|
802
|
-
set: item.message
|
803
|
-
} : undefined,
|
804
|
-
type: item.type !== undefined ? {
|
805
|
-
set: item.type
|
806
|
-
} : undefined,
|
807
|
-
isRead: item.isRead !== undefined ? {
|
808
|
-
set: item.isRead
|
809
|
-
} : undefined,
|
810
|
-
},
|
811
|
-
create: {
|
812
|
-
message: item.message !== undefined ? item.message : undefined,
|
813
|
-
type: item.type !== undefined ? item.type : undefined,
|
814
|
-
isRead: item.isRead !== undefined ? item.isRead : undefined,
|
815
|
-
},
|
816
|
-
}))
|
817
|
-
} : undefined,
|
818
|
-
},
|
819
|
-
create: {
|
820
|
-
type: item.type !== undefined ? item.type : undefined,
|
821
|
-
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
822
|
-
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
823
|
-
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
824
|
-
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
825
|
-
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
826
|
-
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
827
|
-
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
828
|
-
set: item.cryptoTradingPairs
|
829
|
-
} : undefined,
|
830
|
-
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
831
|
-
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
832
|
-
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
833
|
-
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
834
|
-
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
835
|
-
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
836
|
-
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
837
|
-
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
838
|
-
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
839
|
-
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
840
|
-
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
841
|
-
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
842
|
-
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
843
|
-
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
844
|
-
allocation: item.allocation ?
|
845
|
-
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
846
|
-
? { connect: {
|
847
|
-
id: item.allocation.id
|
848
|
-
}
|
849
|
-
}
|
850
|
-
: { connectOrCreate: {
|
851
|
-
where: {
|
852
|
-
id: item.allocation.id !== undefined ? item.allocation.id : undefined,
|
853
|
-
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? item.allocation.alpacaAccountId : undefined,
|
854
|
-
},
|
855
|
-
create: {
|
856
|
-
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
857
|
-
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
858
|
-
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
859
|
-
},
|
860
|
-
}
|
1720
|
+
async updateMany(props, globalClient) {
|
1721
|
+
var _a, _b, _c, _d, _e;
|
1722
|
+
// Maximum number of retries for database connection issues
|
1723
|
+
const MAX_RETRIES = 3;
|
1724
|
+
let retryCount = 0;
|
1725
|
+
let lastError = null;
|
1726
|
+
// Retry loop to handle potential database connection issues
|
1727
|
+
while (retryCount < MAX_RETRIES) {
|
1728
|
+
try {
|
1729
|
+
const [modules, client] = await Promise.all([
|
1730
|
+
(0, client_1.getApolloModules)(),
|
1731
|
+
globalClient
|
1732
|
+
? Promise.resolve(globalClient)
|
1733
|
+
: client_1.client
|
1734
|
+
]);
|
1735
|
+
const { gql, ApolloError } = modules;
|
1736
|
+
const UPDATE_MANY_USER = gql `
|
1737
|
+
mutation updateManyUser($data: [UserCreateManyInput!]!) {
|
1738
|
+
updateManyUser(data: $data) {
|
1739
|
+
count
|
1740
|
+
}
|
1741
|
+
}`;
|
1742
|
+
const variables = props.map(prop => ({
|
1743
|
+
where: {
|
1744
|
+
id: prop.id !== undefined ? prop.id : undefined,
|
1745
|
+
email: prop.email !== undefined ? prop.email : undefined,
|
1746
|
+
name: prop.name !== undefined ? {
|
1747
|
+
equals: prop.name
|
1748
|
+
} : undefined,
|
1749
|
+
},
|
1750
|
+
data: {
|
1751
|
+
id: prop.id !== undefined ? {
|
1752
|
+
set: prop.id
|
1753
|
+
} : undefined,
|
1754
|
+
name: prop.name !== undefined ? {
|
1755
|
+
set: prop.name
|
1756
|
+
} : undefined,
|
1757
|
+
email: prop.email !== undefined ? {
|
1758
|
+
set: prop.email
|
1759
|
+
} : undefined,
|
1760
|
+
emailVerified: prop.emailVerified !== undefined ? {
|
1761
|
+
set: prop.emailVerified
|
1762
|
+
} : undefined,
|
1763
|
+
image: prop.image !== undefined ? {
|
1764
|
+
set: prop.image
|
1765
|
+
} : undefined,
|
1766
|
+
createdAt: prop.createdAt !== undefined ? {
|
1767
|
+
set: prop.createdAt
|
1768
|
+
} : undefined,
|
1769
|
+
updatedAt: prop.updatedAt !== undefined ? {
|
1770
|
+
set: prop.updatedAt
|
1771
|
+
} : undefined,
|
1772
|
+
role: prop.role !== undefined ? {
|
1773
|
+
set: prop.role
|
1774
|
+
} : undefined,
|
1775
|
+
bio: prop.bio !== undefined ? {
|
1776
|
+
set: prop.bio
|
1777
|
+
} : undefined,
|
1778
|
+
jobTitle: prop.jobTitle !== undefined ? {
|
1779
|
+
set: prop.jobTitle
|
1780
|
+
} : undefined,
|
1781
|
+
currentAccount: prop.currentAccount !== undefined ? {
|
1782
|
+
set: prop.currentAccount
|
1783
|
+
} : undefined,
|
1784
|
+
plan: prop.plan !== undefined ? {
|
1785
|
+
set: prop.plan
|
1786
|
+
} : undefined,
|
1787
|
+
openaiAPIKey: prop.openaiAPIKey !== undefined ? {
|
1788
|
+
set: prop.openaiAPIKey
|
1789
|
+
} : undefined,
|
1790
|
+
openaiModel: prop.openaiModel !== undefined ? {
|
1791
|
+
set: prop.openaiModel
|
1792
|
+
} : undefined,
|
1793
|
+
customer: prop.customer ?
|
1794
|
+
typeof prop.customer === 'object' && Object.keys(prop.customer).length === 1 && (Object.keys(prop.customer)[0] === 'id' || Object.keys(prop.customer)[0] === 'symbol')
|
1795
|
+
? {
|
1796
|
+
connect: {
|
1797
|
+
id: prop.customer.id
|
1798
|
+
}
|
1799
|
+
} : { upsert: {
|
1800
|
+
where: {
|
1801
|
+
id: prop.customer.id !== undefined ? {
|
1802
|
+
equals: prop.customer.id
|
1803
|
+
} : undefined,
|
1804
|
+
authUserId: prop.customer.authUserId !== undefined ? {
|
1805
|
+
equals: prop.customer.authUserId
|
1806
|
+
} : undefined,
|
1807
|
+
name: prop.customer.name !== undefined ? {
|
1808
|
+
equals: prop.customer.name
|
1809
|
+
} : undefined,
|
1810
|
+
stripeCustomerId: prop.customer.stripeCustomerId !== undefined ? {
|
1811
|
+
equals: prop.customer.stripeCustomerId
|
1812
|
+
} : undefined,
|
1813
|
+
stripeSubscriptionId: prop.customer.stripeSubscriptionId !== undefined ? {
|
1814
|
+
equals: prop.customer.stripeSubscriptionId
|
1815
|
+
} : undefined,
|
1816
|
+
stripePriceId: prop.customer.stripePriceId !== undefined ? {
|
1817
|
+
equals: prop.customer.stripePriceId
|
1818
|
+
} : undefined,
|
1819
|
+
},
|
1820
|
+
update: {
|
1821
|
+
authUserId: prop.customer.authUserId !== undefined ? {
|
1822
|
+
set: prop.customer.authUserId
|
1823
|
+
} : undefined,
|
1824
|
+
name: prop.customer.name !== undefined ? {
|
1825
|
+
set: prop.customer.name
|
1826
|
+
} : undefined,
|
1827
|
+
plan: prop.customer.plan !== undefined ? {
|
1828
|
+
set: prop.customer.plan
|
1829
|
+
} : undefined,
|
1830
|
+
stripeCustomerId: prop.customer.stripeCustomerId !== undefined ? {
|
1831
|
+
set: prop.customer.stripeCustomerId
|
1832
|
+
} : undefined,
|
1833
|
+
stripeSubscriptionId: prop.customer.stripeSubscriptionId !== undefined ? {
|
1834
|
+
set: prop.customer.stripeSubscriptionId
|
1835
|
+
} : undefined,
|
1836
|
+
stripePriceId: prop.customer.stripePriceId !== undefined ? {
|
1837
|
+
set: prop.customer.stripePriceId
|
1838
|
+
} : undefined,
|
1839
|
+
stripeCurrentPeriodEnd: prop.customer.stripeCurrentPeriodEnd !== undefined ? {
|
1840
|
+
set: prop.customer.stripeCurrentPeriodEnd
|
1841
|
+
} : undefined,
|
1842
|
+
},
|
1843
|
+
create: {
|
1844
|
+
authUserId: prop.customer.authUserId !== undefined ? prop.customer.authUserId : undefined,
|
1845
|
+
name: prop.customer.name !== undefined ? prop.customer.name : undefined,
|
1846
|
+
plan: prop.customer.plan !== undefined ? prop.customer.plan : undefined,
|
1847
|
+
stripeCustomerId: prop.customer.stripeCustomerId !== undefined ? prop.customer.stripeCustomerId : undefined,
|
1848
|
+
stripeSubscriptionId: prop.customer.stripeSubscriptionId !== undefined ? prop.customer.stripeSubscriptionId : undefined,
|
1849
|
+
stripePriceId: prop.customer.stripePriceId !== undefined ? prop.customer.stripePriceId : undefined,
|
1850
|
+
stripeCurrentPeriodEnd: prop.customer.stripeCurrentPeriodEnd !== undefined ? prop.customer.stripeCurrentPeriodEnd : undefined,
|
1851
|
+
},
|
1852
|
+
}
|
1853
|
+
} : undefined,
|
1854
|
+
accounts: prop.accounts ?
|
1855
|
+
Array.isArray(prop.accounts) && prop.accounts.length > 0 && prop.accounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1856
|
+
connect: prop.accounts.map((item) => ({
|
1857
|
+
id: item.id
|
1858
|
+
}))
|
1859
|
+
} : { upsert: prop.accounts.map((item) => ({
|
1860
|
+
where: {
|
1861
|
+
id: item.id !== undefined ? item.id : undefined,
|
1862
|
+
userId: item.userId !== undefined ? {
|
1863
|
+
equals: item.userId
|
1864
|
+
} : undefined,
|
1865
|
+
providerAccountId: item.providerAccountId !== undefined ? {
|
1866
|
+
equals: item.providerAccountId
|
1867
|
+
} : undefined,
|
1868
|
+
},
|
1869
|
+
update: {
|
1870
|
+
id: item.id !== undefined ? {
|
1871
|
+
set: item.id
|
1872
|
+
} : undefined,
|
1873
|
+
type: item.type !== undefined ? {
|
1874
|
+
set: item.type
|
1875
|
+
} : undefined,
|
1876
|
+
provider: item.provider !== undefined ? {
|
1877
|
+
set: item.provider
|
1878
|
+
} : undefined,
|
1879
|
+
providerAccountId: item.providerAccountId !== undefined ? {
|
1880
|
+
set: item.providerAccountId
|
1881
|
+
} : undefined,
|
1882
|
+
refresh_token: item.refresh_token !== undefined ? {
|
1883
|
+
set: item.refresh_token
|
1884
|
+
} : undefined,
|
1885
|
+
access_token: item.access_token !== undefined ? {
|
1886
|
+
set: item.access_token
|
1887
|
+
} : undefined,
|
1888
|
+
expires_at: item.expires_at !== undefined ? {
|
1889
|
+
set: item.expires_at
|
1890
|
+
} : undefined,
|
1891
|
+
token_type: item.token_type !== undefined ? {
|
1892
|
+
set: item.token_type
|
1893
|
+
} : undefined,
|
1894
|
+
scope: item.scope !== undefined ? {
|
1895
|
+
set: item.scope
|
1896
|
+
} : undefined,
|
1897
|
+
id_token: item.id_token !== undefined ? {
|
1898
|
+
set: item.id_token
|
1899
|
+
} : undefined,
|
1900
|
+
session_state: item.session_state !== undefined ? {
|
1901
|
+
set: item.session_state
|
1902
|
+
} : undefined,
|
1903
|
+
},
|
1904
|
+
create: {
|
1905
|
+
type: item.type !== undefined ? item.type : undefined,
|
1906
|
+
provider: item.provider !== undefined ? item.provider : undefined,
|
1907
|
+
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
1908
|
+
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
1909
|
+
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
1910
|
+
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
1911
|
+
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
1912
|
+
scope: item.scope !== undefined ? item.scope : undefined,
|
1913
|
+
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
1914
|
+
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
1915
|
+
},
|
1916
|
+
}))
|
1917
|
+
} : undefined,
|
1918
|
+
sessions: prop.sessions ?
|
1919
|
+
Array.isArray(prop.sessions) && prop.sessions.length > 0 && prop.sessions.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1920
|
+
connect: prop.sessions.map((item) => ({
|
1921
|
+
id: item.id
|
1922
|
+
}))
|
1923
|
+
} : { upsert: prop.sessions.map((item) => ({
|
1924
|
+
where: {
|
1925
|
+
id: item.id !== undefined ? item.id : undefined,
|
1926
|
+
userId: item.userId !== undefined ? {
|
1927
|
+
equals: item.userId
|
1928
|
+
} : undefined,
|
1929
|
+
},
|
1930
|
+
update: {
|
1931
|
+
id: item.id !== undefined ? {
|
1932
|
+
set: item.id
|
1933
|
+
} : undefined,
|
1934
|
+
sessionToken: item.sessionToken !== undefined ? {
|
1935
|
+
set: item.sessionToken
|
1936
|
+
} : undefined,
|
1937
|
+
expires: item.expires !== undefined ? {
|
1938
|
+
set: item.expires
|
1939
|
+
} : undefined,
|
1940
|
+
},
|
1941
|
+
create: {
|
1942
|
+
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
1943
|
+
expires: item.expires !== undefined ? item.expires : undefined,
|
1944
|
+
},
|
1945
|
+
}))
|
1946
|
+
} : undefined,
|
1947
|
+
authenticators: prop.authenticators ?
|
1948
|
+
Array.isArray(prop.authenticators) && prop.authenticators.length > 0 && prop.authenticators.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1949
|
+
connect: prop.authenticators.map((item) => ({
|
1950
|
+
id: item.id
|
1951
|
+
}))
|
1952
|
+
} : { upsert: prop.authenticators.map((item) => ({
|
1953
|
+
where: {
|
1954
|
+
id: item.id !== undefined ? item.id : undefined,
|
1955
|
+
userId: item.userId !== undefined ? {
|
1956
|
+
equals: item.userId
|
1957
|
+
} : undefined,
|
1958
|
+
},
|
1959
|
+
update: {
|
1960
|
+
id: item.id !== undefined ? {
|
1961
|
+
set: item.id
|
1962
|
+
} : undefined,
|
1963
|
+
credentialID: item.credentialID !== undefined ? {
|
1964
|
+
set: item.credentialID
|
1965
|
+
} : undefined,
|
1966
|
+
publicKey: item.publicKey !== undefined ? {
|
1967
|
+
set: item.publicKey
|
861
1968
|
} : undefined,
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
:
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
equals: props.customer.stripePriceId
|
963
|
-
} : undefined,
|
964
|
-
},
|
965
|
-
create: {
|
966
|
-
authUserId: props.customer.authUserId !== undefined ? props.customer.authUserId : undefined,
|
967
|
-
name: props.customer.name !== undefined ? props.customer.name : undefined,
|
968
|
-
plan: props.customer.plan !== undefined ? props.customer.plan : undefined,
|
969
|
-
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? props.customer.stripeCustomerId : undefined,
|
970
|
-
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? props.customer.stripeSubscriptionId : undefined,
|
971
|
-
stripePriceId: props.customer.stripePriceId !== undefined ? props.customer.stripePriceId : undefined,
|
972
|
-
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? props.customer.stripeCurrentPeriodEnd : undefined,
|
973
|
-
},
|
974
|
-
}
|
975
|
-
} : undefined,
|
976
|
-
accounts: props.accounts ?
|
977
|
-
Array.isArray(props.accounts) && props.accounts.length > 0 && props.accounts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
978
|
-
connect: props.accounts.map((item) => ({
|
979
|
-
id: item.id
|
980
|
-
}))
|
981
|
-
}
|
982
|
-
: { connectOrCreate: props.accounts.map((item) => ({
|
983
|
-
where: {
|
984
|
-
id: item.id !== undefined ? item.id : undefined,
|
985
|
-
userId: item.userId !== undefined ? {
|
986
|
-
equals: item.userId
|
987
|
-
} : undefined,
|
988
|
-
providerAccountId: item.providerAccountId !== undefined ? {
|
989
|
-
equals: item.providerAccountId
|
990
|
-
} : undefined,
|
991
|
-
},
|
992
|
-
create: {
|
993
|
-
type: item.type !== undefined ? item.type : undefined,
|
994
|
-
provider: item.provider !== undefined ? item.provider : undefined,
|
995
|
-
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
996
|
-
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
997
|
-
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
998
|
-
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
999
|
-
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
1000
|
-
scope: item.scope !== undefined ? item.scope : undefined,
|
1001
|
-
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
1002
|
-
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
1003
|
-
},
|
1004
|
-
}))
|
1005
|
-
} : undefined,
|
1006
|
-
sessions: props.sessions ?
|
1007
|
-
Array.isArray(props.sessions) && props.sessions.length > 0 && props.sessions.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1008
|
-
connect: props.sessions.map((item) => ({
|
1009
|
-
id: item.id
|
1010
|
-
}))
|
1011
|
-
}
|
1012
|
-
: { connectOrCreate: props.sessions.map((item) => ({
|
1013
|
-
where: {
|
1014
|
-
id: item.id !== undefined ? item.id : undefined,
|
1015
|
-
userId: item.userId !== undefined ? {
|
1016
|
-
equals: item.userId
|
1017
|
-
} : undefined,
|
1018
|
-
},
|
1019
|
-
create: {
|
1020
|
-
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
1021
|
-
expires: item.expires !== undefined ? item.expires : undefined,
|
1022
|
-
},
|
1023
|
-
}))
|
1024
|
-
} : undefined,
|
1025
|
-
authenticators: props.authenticators ?
|
1026
|
-
Array.isArray(props.authenticators) && props.authenticators.length > 0 && props.authenticators.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1027
|
-
connect: props.authenticators.map((item) => ({
|
1028
|
-
id: item.id
|
1029
|
-
}))
|
1030
|
-
}
|
1031
|
-
: { connectOrCreate: props.authenticators.map((item) => ({
|
1032
|
-
where: {
|
1033
|
-
id: item.id !== undefined ? item.id : undefined,
|
1034
|
-
userId: item.userId !== undefined ? {
|
1035
|
-
equals: item.userId
|
1036
|
-
} : undefined,
|
1037
|
-
},
|
1038
|
-
create: {
|
1039
|
-
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
1040
|
-
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
1041
|
-
counter: item.counter !== undefined ? item.counter : undefined,
|
1042
|
-
},
|
1043
|
-
}))
|
1044
|
-
} : undefined,
|
1045
|
-
alpacaAccounts: props.alpacaAccounts ?
|
1046
|
-
Array.isArray(props.alpacaAccounts) && props.alpacaAccounts.length > 0 && props.alpacaAccounts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
1047
|
-
connect: props.alpacaAccounts.map((item) => ({
|
1048
|
-
id: item.id
|
1049
|
-
}))
|
1050
|
-
}
|
1051
|
-
: { connectOrCreate: props.alpacaAccounts.map((item) => ({
|
1052
|
-
where: {
|
1053
|
-
id: item.id !== undefined ? item.id : undefined,
|
1054
|
-
userId: item.userId !== undefined ? {
|
1055
|
-
equals: item.userId
|
1056
|
-
} : undefined,
|
1057
|
-
},
|
1058
|
-
create: {
|
1059
|
-
type: item.type !== undefined ? item.type : undefined,
|
1060
|
-
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
1061
|
-
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
1062
|
-
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
1063
|
-
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
1064
|
-
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
1065
|
-
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
1066
|
-
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
1067
|
-
set: item.cryptoTradingPairs
|
1068
|
-
} : undefined,
|
1069
|
-
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
1070
|
-
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
1071
|
-
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
1072
|
-
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
1073
|
-
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
1074
|
-
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
1075
|
-
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
1076
|
-
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
1077
|
-
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
1078
|
-
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
1079
|
-
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
1080
|
-
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
1081
|
-
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
1082
|
-
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
1083
|
-
allocation: item.allocation ?
|
1084
|
-
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
1085
|
-
? { connect: {
|
1086
|
-
id: item.allocation.id
|
1087
|
-
}
|
1088
|
-
}
|
1089
|
-
: { connectOrCreate: {
|
1969
|
+
counter: item.counter !== undefined ? {
|
1970
|
+
set: item.counter
|
1971
|
+
} : undefined,
|
1972
|
+
},
|
1973
|
+
create: {
|
1974
|
+
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
1975
|
+
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
1976
|
+
counter: item.counter !== undefined ? item.counter : undefined,
|
1977
|
+
},
|
1978
|
+
}))
|
1979
|
+
} : undefined,
|
1980
|
+
alpacaAccounts: prop.alpacaAccounts ?
|
1981
|
+
Array.isArray(prop.alpacaAccounts) && prop.alpacaAccounts.length > 0 && prop.alpacaAccounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1982
|
+
connect: prop.alpacaAccounts.map((item) => ({
|
1983
|
+
id: item.id
|
1984
|
+
}))
|
1985
|
+
} : { upsert: prop.alpacaAccounts.map((item) => ({
|
1986
|
+
where: {
|
1987
|
+
id: item.id !== undefined ? item.id : undefined,
|
1988
|
+
userId: item.userId !== undefined ? {
|
1989
|
+
equals: item.userId
|
1990
|
+
} : undefined,
|
1991
|
+
},
|
1992
|
+
update: {
|
1993
|
+
id: item.id !== undefined ? {
|
1994
|
+
set: item.id
|
1995
|
+
} : undefined,
|
1996
|
+
type: item.type !== undefined ? {
|
1997
|
+
set: item.type
|
1998
|
+
} : undefined,
|
1999
|
+
APIKey: item.APIKey !== undefined ? {
|
2000
|
+
set: item.APIKey
|
2001
|
+
} : undefined,
|
2002
|
+
APISecret: item.APISecret !== undefined ? {
|
2003
|
+
set: item.APISecret
|
2004
|
+
} : undefined,
|
2005
|
+
configuration: item.configuration !== undefined ? {
|
2006
|
+
set: item.configuration
|
2007
|
+
} : undefined,
|
2008
|
+
marketOpen: item.marketOpen !== undefined ? {
|
2009
|
+
set: item.marketOpen
|
2010
|
+
} : undefined,
|
2011
|
+
realTime: item.realTime !== undefined ? {
|
2012
|
+
set: item.realTime
|
2013
|
+
} : undefined,
|
2014
|
+
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? {
|
2015
|
+
set: item.cryptoTradingEnabled
|
2016
|
+
} : undefined,
|
2017
|
+
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
2018
|
+
set: item.cryptoTradingPairs
|
2019
|
+
} : undefined,
|
2020
|
+
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? {
|
2021
|
+
set: item.cryptoTradeAllocationPct
|
2022
|
+
} : undefined,
|
2023
|
+
tradeAllocationPct: item.tradeAllocationPct !== undefined ? {
|
2024
|
+
set: item.tradeAllocationPct
|
2025
|
+
} : undefined,
|
2026
|
+
minPercentageChange: item.minPercentageChange !== undefined ? {
|
2027
|
+
set: item.minPercentageChange
|
2028
|
+
} : undefined,
|
2029
|
+
volumeThreshold: item.volumeThreshold !== undefined ? {
|
2030
|
+
set: item.volumeThreshold
|
2031
|
+
} : undefined,
|
2032
|
+
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? {
|
2033
|
+
set: item.enablePortfolioTrailingStop
|
2034
|
+
} : undefined,
|
2035
|
+
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? {
|
2036
|
+
set: item.portfolioTrailPercent
|
2037
|
+
} : undefined,
|
2038
|
+
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? {
|
2039
|
+
set: item.portfolioProfitThresholdPercent
|
2040
|
+
} : undefined,
|
2041
|
+
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? {
|
2042
|
+
set: item.reducedPortfolioTrailPercent
|
2043
|
+
} : undefined,
|
2044
|
+
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? {
|
2045
|
+
set: item.defaultTrailingStopPercentage100
|
2046
|
+
} : undefined,
|
2047
|
+
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? {
|
2048
|
+
set: item.firstTrailReductionThreshold100
|
2049
|
+
} : undefined,
|
2050
|
+
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? {
|
2051
|
+
set: item.secondTrailReductionThreshold100
|
2052
|
+
} : undefined,
|
2053
|
+
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? {
|
2054
|
+
set: item.firstReducedTrailPercentage100
|
2055
|
+
} : undefined,
|
2056
|
+
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? {
|
2057
|
+
set: item.secondReducedTrailPercentage100
|
2058
|
+
} : undefined,
|
2059
|
+
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? {
|
2060
|
+
set: item.minimumPriceChangePercent100
|
2061
|
+
} : undefined,
|
2062
|
+
allocation: item.allocation ?
|
2063
|
+
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && (Object.keys(item.allocation)[0] === 'id' || Object.keys(item.allocation)[0] === 'symbol')
|
2064
|
+
? {
|
2065
|
+
connect: {
|
2066
|
+
id: item.allocation.id
|
2067
|
+
}
|
2068
|
+
} : { upsert: {
|
1090
2069
|
where: {
|
1091
|
-
id: item.allocation.id !== undefined ?
|
1092
|
-
|
2070
|
+
id: item.allocation.id !== undefined ? {
|
2071
|
+
equals: item.allocation.id
|
2072
|
+
} : undefined,
|
2073
|
+
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? {
|
2074
|
+
equals: item.allocation.alpacaAccountId
|
2075
|
+
} : undefined,
|
2076
|
+
},
|
2077
|
+
update: {
|
2078
|
+
id: item.allocation.id !== undefined ? {
|
2079
|
+
set: item.allocation.id
|
2080
|
+
} : undefined,
|
2081
|
+
stocks: item.allocation.stocks !== undefined ? {
|
2082
|
+
set: item.allocation.stocks
|
2083
|
+
} : undefined,
|
2084
|
+
crypto: item.allocation.crypto !== undefined ? {
|
2085
|
+
set: item.allocation.crypto
|
2086
|
+
} : undefined,
|
2087
|
+
etfs: item.allocation.etfs !== undefined ? {
|
2088
|
+
set: item.allocation.etfs
|
2089
|
+
} : undefined,
|
1093
2090
|
},
|
1094
2091
|
create: {
|
1095
2092
|
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
@@ -1098,19 +2095,32 @@ exports.User = {
|
|
1098
2095
|
},
|
1099
2096
|
}
|
1100
2097
|
} : undefined,
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
: { connectOrCreate: item.alerts.map((item) => ({
|
2098
|
+
alerts: item.alerts ?
|
2099
|
+
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
2100
|
+
connect: item.alerts.map((item) => ({
|
2101
|
+
id: item.id
|
2102
|
+
}))
|
2103
|
+
} : { upsert: item.alerts.map((item) => ({
|
1108
2104
|
where: {
|
1109
2105
|
id: item.id !== undefined ? item.id : undefined,
|
1110
2106
|
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
1111
2107
|
equals: item.alpacaAccountId
|
1112
2108
|
} : undefined,
|
1113
2109
|
},
|
2110
|
+
update: {
|
2111
|
+
id: item.id !== undefined ? {
|
2112
|
+
set: item.id
|
2113
|
+
} : undefined,
|
2114
|
+
message: item.message !== undefined ? {
|
2115
|
+
set: item.message
|
2116
|
+
} : undefined,
|
2117
|
+
type: item.type !== undefined ? {
|
2118
|
+
set: item.type
|
2119
|
+
} : undefined,
|
2120
|
+
isRead: item.isRead !== undefined ? {
|
2121
|
+
set: item.isRead
|
2122
|
+
} : undefined,
|
2123
|
+
},
|
1114
2124
|
create: {
|
1115
2125
|
message: item.message !== undefined ? item.message : undefined,
|
1116
2126
|
type: item.type !== undefined ? item.type : undefined,
|
@@ -1118,1142 +2128,410 @@ exports.User = {
|
|
1118
2128
|
},
|
1119
2129
|
}))
|
1120
2130
|
} : undefined,
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
emailVerified: props.emailVerified !== undefined ? {
|
1133
|
-
set: props.emailVerified
|
1134
|
-
} : undefined,
|
1135
|
-
image: props.image !== undefined ? {
|
1136
|
-
set: props.image
|
1137
|
-
} : undefined,
|
1138
|
-
role: props.role !== undefined ? {
|
1139
|
-
set: props.role
|
1140
|
-
} : undefined,
|
1141
|
-
bio: props.bio !== undefined ? {
|
1142
|
-
set: props.bio
|
1143
|
-
} : undefined,
|
1144
|
-
jobTitle: props.jobTitle !== undefined ? {
|
1145
|
-
set: props.jobTitle
|
1146
|
-
} : undefined,
|
1147
|
-
currentAccount: props.currentAccount !== undefined ? {
|
1148
|
-
set: props.currentAccount
|
1149
|
-
} : undefined,
|
1150
|
-
plan: props.plan !== undefined ? {
|
1151
|
-
set: props.plan
|
1152
|
-
} : undefined,
|
1153
|
-
openaiAPIKey: props.openaiAPIKey !== undefined ? {
|
1154
|
-
set: props.openaiAPIKey
|
1155
|
-
} : undefined,
|
1156
|
-
openaiModel: props.openaiModel !== undefined ? {
|
1157
|
-
set: props.openaiModel
|
1158
|
-
} : undefined,
|
1159
|
-
customer: props.customer ?
|
1160
|
-
typeof props.customer === 'object' && Object.keys(props.customer).length === 1 && (Object.keys(props.customer)[0] === 'id' || Object.keys(props.customer)[0] === 'symbol')
|
1161
|
-
? {
|
1162
|
-
connect: {
|
1163
|
-
id: props.customer.id
|
1164
|
-
}
|
1165
|
-
} : { upsert: {
|
1166
|
-
where: {
|
1167
|
-
id: props.customer.id !== undefined ? {
|
1168
|
-
equals: props.customer.id
|
1169
|
-
} : undefined,
|
1170
|
-
authUserId: props.customer.authUserId !== undefined ? {
|
1171
|
-
equals: props.customer.authUserId
|
1172
|
-
} : undefined,
|
1173
|
-
name: props.customer.name !== undefined ? {
|
1174
|
-
equals: props.customer.name
|
1175
|
-
} : undefined,
|
1176
|
-
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? {
|
1177
|
-
equals: props.customer.stripeCustomerId
|
1178
|
-
} : undefined,
|
1179
|
-
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? {
|
1180
|
-
equals: props.customer.stripeSubscriptionId
|
1181
|
-
} : undefined,
|
1182
|
-
stripePriceId: props.customer.stripePriceId !== undefined ? {
|
1183
|
-
equals: props.customer.stripePriceId
|
1184
|
-
} : undefined,
|
1185
|
-
},
|
1186
|
-
update: {
|
1187
|
-
authUserId: props.customer.authUserId !== undefined ? {
|
1188
|
-
set: props.customer.authUserId
|
1189
|
-
} : undefined,
|
1190
|
-
name: props.customer.name !== undefined ? {
|
1191
|
-
set: props.customer.name
|
1192
|
-
} : undefined,
|
1193
|
-
plan: props.customer.plan !== undefined ? {
|
1194
|
-
set: props.customer.plan
|
1195
|
-
} : undefined,
|
1196
|
-
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? {
|
1197
|
-
set: props.customer.stripeCustomerId
|
1198
|
-
} : undefined,
|
1199
|
-
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? {
|
1200
|
-
set: props.customer.stripeSubscriptionId
|
1201
|
-
} : undefined,
|
1202
|
-
stripePriceId: props.customer.stripePriceId !== undefined ? {
|
1203
|
-
set: props.customer.stripePriceId
|
1204
|
-
} : undefined,
|
1205
|
-
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? {
|
1206
|
-
set: props.customer.stripeCurrentPeriodEnd
|
1207
|
-
} : undefined,
|
1208
|
-
},
|
1209
|
-
create: {
|
1210
|
-
authUserId: props.customer.authUserId !== undefined ? props.customer.authUserId : undefined,
|
1211
|
-
name: props.customer.name !== undefined ? props.customer.name : undefined,
|
1212
|
-
plan: props.customer.plan !== undefined ? props.customer.plan : undefined,
|
1213
|
-
stripeCustomerId: props.customer.stripeCustomerId !== undefined ? props.customer.stripeCustomerId : undefined,
|
1214
|
-
stripeSubscriptionId: props.customer.stripeSubscriptionId !== undefined ? props.customer.stripeSubscriptionId : undefined,
|
1215
|
-
stripePriceId: props.customer.stripePriceId !== undefined ? props.customer.stripePriceId : undefined,
|
1216
|
-
stripeCurrentPeriodEnd: props.customer.stripeCurrentPeriodEnd !== undefined ? props.customer.stripeCurrentPeriodEnd : undefined,
|
1217
|
-
},
|
1218
|
-
}
|
1219
|
-
} : undefined,
|
1220
|
-
accounts: props.accounts ?
|
1221
|
-
Array.isArray(props.accounts) && props.accounts.length > 0 && props.accounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1222
|
-
connect: props.accounts.map((item) => ({
|
1223
|
-
id: item.id
|
1224
|
-
}))
|
1225
|
-
} : { upsert: props.accounts.map((item) => ({
|
1226
|
-
where: {
|
1227
|
-
id: item.id !== undefined ? item.id : undefined,
|
1228
|
-
userId: item.userId !== undefined ? {
|
1229
|
-
equals: item.userId
|
1230
|
-
} : undefined,
|
1231
|
-
providerAccountId: item.providerAccountId !== undefined ? {
|
1232
|
-
equals: item.providerAccountId
|
1233
|
-
} : undefined,
|
1234
|
-
},
|
1235
|
-
update: {
|
1236
|
-
id: item.id !== undefined ? {
|
1237
|
-
set: item.id
|
1238
|
-
} : undefined,
|
1239
|
-
type: item.type !== undefined ? {
|
1240
|
-
set: item.type
|
1241
|
-
} : undefined,
|
1242
|
-
provider: item.provider !== undefined ? {
|
1243
|
-
set: item.provider
|
1244
|
-
} : undefined,
|
1245
|
-
providerAccountId: item.providerAccountId !== undefined ? {
|
1246
|
-
set: item.providerAccountId
|
1247
|
-
} : undefined,
|
1248
|
-
refresh_token: item.refresh_token !== undefined ? {
|
1249
|
-
set: item.refresh_token
|
1250
|
-
} : undefined,
|
1251
|
-
access_token: item.access_token !== undefined ? {
|
1252
|
-
set: item.access_token
|
1253
|
-
} : undefined,
|
1254
|
-
expires_at: item.expires_at !== undefined ? {
|
1255
|
-
set: item.expires_at
|
1256
|
-
} : undefined,
|
1257
|
-
token_type: item.token_type !== undefined ? {
|
1258
|
-
set: item.token_type
|
1259
|
-
} : undefined,
|
1260
|
-
scope: item.scope !== undefined ? {
|
1261
|
-
set: item.scope
|
1262
|
-
} : undefined,
|
1263
|
-
id_token: item.id_token !== undefined ? {
|
1264
|
-
set: item.id_token
|
1265
|
-
} : undefined,
|
1266
|
-
session_state: item.session_state !== undefined ? {
|
1267
|
-
set: item.session_state
|
1268
|
-
} : undefined,
|
1269
|
-
},
|
1270
|
-
create: {
|
1271
|
-
type: item.type !== undefined ? item.type : undefined,
|
1272
|
-
provider: item.provider !== undefined ? item.provider : undefined,
|
1273
|
-
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
1274
|
-
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
1275
|
-
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
1276
|
-
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
1277
|
-
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
1278
|
-
scope: item.scope !== undefined ? item.scope : undefined,
|
1279
|
-
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
1280
|
-
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
1281
|
-
},
|
1282
|
-
}))
|
1283
|
-
} : undefined,
|
1284
|
-
sessions: props.sessions ?
|
1285
|
-
Array.isArray(props.sessions) && props.sessions.length > 0 && props.sessions.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1286
|
-
connect: props.sessions.map((item) => ({
|
1287
|
-
id: item.id
|
1288
|
-
}))
|
1289
|
-
} : { upsert: props.sessions.map((item) => ({
|
1290
|
-
where: {
|
1291
|
-
id: item.id !== undefined ? item.id : undefined,
|
1292
|
-
userId: item.userId !== undefined ? {
|
1293
|
-
equals: item.userId
|
1294
|
-
} : undefined,
|
1295
|
-
},
|
1296
|
-
update: {
|
1297
|
-
id: item.id !== undefined ? {
|
1298
|
-
set: item.id
|
1299
|
-
} : undefined,
|
1300
|
-
sessionToken: item.sessionToken !== undefined ? {
|
1301
|
-
set: item.sessionToken
|
1302
|
-
} : undefined,
|
1303
|
-
expires: item.expires !== undefined ? {
|
1304
|
-
set: item.expires
|
1305
|
-
} : undefined,
|
1306
|
-
},
|
1307
|
-
create: {
|
1308
|
-
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
1309
|
-
expires: item.expires !== undefined ? item.expires : undefined,
|
1310
|
-
},
|
1311
|
-
}))
|
1312
|
-
} : undefined,
|
1313
|
-
authenticators: props.authenticators ?
|
1314
|
-
Array.isArray(props.authenticators) && props.authenticators.length > 0 && props.authenticators.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1315
|
-
connect: props.authenticators.map((item) => ({
|
1316
|
-
id: item.id
|
1317
|
-
}))
|
1318
|
-
} : { upsert: props.authenticators.map((item) => ({
|
1319
|
-
where: {
|
1320
|
-
id: item.id !== undefined ? item.id : undefined,
|
1321
|
-
userId: item.userId !== undefined ? {
|
1322
|
-
equals: item.userId
|
1323
|
-
} : undefined,
|
1324
|
-
},
|
1325
|
-
update: {
|
1326
|
-
id: item.id !== undefined ? {
|
1327
|
-
set: item.id
|
1328
|
-
} : undefined,
|
1329
|
-
credentialID: item.credentialID !== undefined ? {
|
1330
|
-
set: item.credentialID
|
1331
|
-
} : undefined,
|
1332
|
-
publicKey: item.publicKey !== undefined ? {
|
1333
|
-
set: item.publicKey
|
1334
|
-
} : undefined,
|
1335
|
-
counter: item.counter !== undefined ? {
|
1336
|
-
set: item.counter
|
1337
|
-
} : undefined,
|
1338
|
-
},
|
1339
|
-
create: {
|
1340
|
-
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
1341
|
-
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
1342
|
-
counter: item.counter !== undefined ? item.counter : undefined,
|
1343
|
-
},
|
1344
|
-
}))
|
1345
|
-
} : undefined,
|
1346
|
-
alpacaAccounts: props.alpacaAccounts ?
|
1347
|
-
Array.isArray(props.alpacaAccounts) && props.alpacaAccounts.length > 0 && props.alpacaAccounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1348
|
-
connect: props.alpacaAccounts.map((item) => ({
|
1349
|
-
id: item.id
|
1350
|
-
}))
|
1351
|
-
} : { upsert: props.alpacaAccounts.map((item) => ({
|
1352
|
-
where: {
|
1353
|
-
id: item.id !== undefined ? item.id : undefined,
|
1354
|
-
userId: item.userId !== undefined ? {
|
1355
|
-
equals: item.userId
|
1356
|
-
} : undefined,
|
1357
|
-
},
|
1358
|
-
update: {
|
1359
|
-
id: item.id !== undefined ? {
|
1360
|
-
set: item.id
|
1361
|
-
} : undefined,
|
1362
|
-
type: item.type !== undefined ? {
|
1363
|
-
set: item.type
|
1364
|
-
} : undefined,
|
1365
|
-
APIKey: item.APIKey !== undefined ? {
|
1366
|
-
set: item.APIKey
|
1367
|
-
} : undefined,
|
1368
|
-
APISecret: item.APISecret !== undefined ? {
|
1369
|
-
set: item.APISecret
|
1370
|
-
} : undefined,
|
1371
|
-
configuration: item.configuration !== undefined ? {
|
1372
|
-
set: item.configuration
|
1373
|
-
} : undefined,
|
1374
|
-
marketOpen: item.marketOpen !== undefined ? {
|
1375
|
-
set: item.marketOpen
|
1376
|
-
} : undefined,
|
1377
|
-
realTime: item.realTime !== undefined ? {
|
1378
|
-
set: item.realTime
|
1379
|
-
} : undefined,
|
1380
|
-
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? {
|
1381
|
-
set: item.cryptoTradingEnabled
|
1382
|
-
} : undefined,
|
1383
|
-
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
1384
|
-
set: item.cryptoTradingPairs
|
1385
|
-
} : undefined,
|
1386
|
-
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? {
|
1387
|
-
set: item.cryptoTradeAllocationPct
|
1388
|
-
} : undefined,
|
1389
|
-
tradeAllocationPct: item.tradeAllocationPct !== undefined ? {
|
1390
|
-
set: item.tradeAllocationPct
|
1391
|
-
} : undefined,
|
1392
|
-
minPercentageChange: item.minPercentageChange !== undefined ? {
|
1393
|
-
set: item.minPercentageChange
|
1394
|
-
} : undefined,
|
1395
|
-
volumeThreshold: item.volumeThreshold !== undefined ? {
|
1396
|
-
set: item.volumeThreshold
|
1397
|
-
} : undefined,
|
1398
|
-
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? {
|
1399
|
-
set: item.enablePortfolioTrailingStop
|
1400
|
-
} : undefined,
|
1401
|
-
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? {
|
1402
|
-
set: item.portfolioTrailPercent
|
1403
|
-
} : undefined,
|
1404
|
-
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? {
|
1405
|
-
set: item.portfolioProfitThresholdPercent
|
1406
|
-
} : undefined,
|
1407
|
-
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? {
|
1408
|
-
set: item.reducedPortfolioTrailPercent
|
1409
|
-
} : undefined,
|
1410
|
-
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? {
|
1411
|
-
set: item.defaultTrailingStopPercentage100
|
1412
|
-
} : undefined,
|
1413
|
-
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? {
|
1414
|
-
set: item.firstTrailReductionThreshold100
|
1415
|
-
} : undefined,
|
1416
|
-
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? {
|
1417
|
-
set: item.secondTrailReductionThreshold100
|
1418
|
-
} : undefined,
|
1419
|
-
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? {
|
1420
|
-
set: item.firstReducedTrailPercentage100
|
1421
|
-
} : undefined,
|
1422
|
-
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? {
|
1423
|
-
set: item.secondReducedTrailPercentage100
|
1424
|
-
} : undefined,
|
1425
|
-
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? {
|
1426
|
-
set: item.minimumPriceChangePercent100
|
1427
|
-
} : undefined,
|
1428
|
-
allocation: item.allocation ?
|
1429
|
-
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && (Object.keys(item.allocation)[0] === 'id' || Object.keys(item.allocation)[0] === 'symbol')
|
1430
|
-
? {
|
1431
|
-
connect: {
|
1432
|
-
id: item.allocation.id
|
1433
|
-
}
|
1434
|
-
} : { upsert: {
|
1435
|
-
where: {
|
1436
|
-
id: item.allocation.id !== undefined ? {
|
1437
|
-
equals: item.allocation.id
|
1438
|
-
} : undefined,
|
1439
|
-
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? {
|
1440
|
-
equals: item.allocation.alpacaAccountId
|
1441
|
-
} : undefined,
|
1442
|
-
},
|
1443
|
-
update: {
|
1444
|
-
id: item.allocation.id !== undefined ? {
|
1445
|
-
set: item.allocation.id
|
1446
|
-
} : undefined,
|
1447
|
-
stocks: item.allocation.stocks !== undefined ? {
|
1448
|
-
set: item.allocation.stocks
|
1449
|
-
} : undefined,
|
1450
|
-
crypto: item.allocation.crypto !== undefined ? {
|
1451
|
-
set: item.allocation.crypto
|
1452
|
-
} : undefined,
|
1453
|
-
etfs: item.allocation.etfs !== undefined ? {
|
1454
|
-
set: item.allocation.etfs
|
1455
|
-
} : undefined,
|
1456
|
-
},
|
1457
|
-
create: {
|
1458
|
-
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
1459
|
-
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
1460
|
-
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
1461
|
-
},
|
1462
|
-
}
|
1463
|
-
} : undefined,
|
1464
|
-
alerts: item.alerts ?
|
1465
|
-
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1466
|
-
connect: item.alerts.map((item) => ({
|
1467
|
-
id: item.id
|
1468
|
-
}))
|
1469
|
-
} : { upsert: item.alerts.map((item) => ({
|
1470
|
-
where: {
|
1471
|
-
id: item.id !== undefined ? item.id : undefined,
|
1472
|
-
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
1473
|
-
equals: item.alpacaAccountId
|
1474
|
-
} : undefined,
|
1475
|
-
},
|
1476
|
-
update: {
|
1477
|
-
id: item.id !== undefined ? {
|
1478
|
-
set: item.id
|
1479
|
-
} : undefined,
|
1480
|
-
message: item.message !== undefined ? {
|
1481
|
-
set: item.message
|
1482
|
-
} : undefined,
|
1483
|
-
type: item.type !== undefined ? {
|
1484
|
-
set: item.type
|
1485
|
-
} : undefined,
|
1486
|
-
isRead: item.isRead !== undefined ? {
|
1487
|
-
set: item.isRead
|
1488
|
-
} : undefined,
|
1489
|
-
},
|
1490
|
-
create: {
|
1491
|
-
message: item.message !== undefined ? item.message : undefined,
|
1492
|
-
type: item.type !== undefined ? item.type : undefined,
|
1493
|
-
isRead: item.isRead !== undefined ? item.isRead : undefined,
|
1494
|
-
},
|
1495
|
-
}))
|
1496
|
-
} : undefined,
|
1497
|
-
},
|
1498
|
-
create: {
|
1499
|
-
type: item.type !== undefined ? item.type : undefined,
|
1500
|
-
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
1501
|
-
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
1502
|
-
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
1503
|
-
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
1504
|
-
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
1505
|
-
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
1506
|
-
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
1507
|
-
set: item.cryptoTradingPairs
|
1508
|
-
} : undefined,
|
1509
|
-
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
1510
|
-
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
1511
|
-
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
1512
|
-
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
1513
|
-
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
1514
|
-
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
1515
|
-
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
1516
|
-
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
1517
|
-
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
1518
|
-
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
1519
|
-
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
1520
|
-
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
1521
|
-
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
1522
|
-
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
1523
|
-
allocation: item.allocation ?
|
1524
|
-
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
1525
|
-
? { connect: {
|
1526
|
-
id: item.allocation.id
|
1527
|
-
}
|
1528
|
-
}
|
1529
|
-
: { connectOrCreate: {
|
1530
|
-
where: {
|
1531
|
-
id: item.allocation.id !== undefined ? item.allocation.id : undefined,
|
1532
|
-
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? item.allocation.alpacaAccountId : undefined,
|
1533
|
-
},
|
1534
|
-
create: {
|
1535
|
-
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
1536
|
-
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
1537
|
-
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
1538
|
-
},
|
1539
|
-
}
|
2131
|
+
},
|
2132
|
+
create: {
|
2133
|
+
type: item.type !== undefined ? item.type : undefined,
|
2134
|
+
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
2135
|
+
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
2136
|
+
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
2137
|
+
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
2138
|
+
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
2139
|
+
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
2140
|
+
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
2141
|
+
set: item.cryptoTradingPairs
|
1540
2142
|
} : undefined,
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
:
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
return response.data.upsertOneUser;
|
1573
|
-
}
|
1574
|
-
else {
|
1575
|
-
return null;
|
1576
|
-
}
|
1577
|
-
}
|
1578
|
-
catch (error) {
|
1579
|
-
console.error('Error in upsertOneUser:', error);
|
1580
|
-
throw error;
|
1581
|
-
}
|
1582
|
-
},
|
1583
|
-
/**
|
1584
|
-
* Update multiple User records.
|
1585
|
-
* @param props - Array of User objects for the updated records.
|
1586
|
-
* @param globalClient - Apollo Client instance.
|
1587
|
-
* @returns The count of created records or null.
|
1588
|
-
*/
|
1589
|
-
async updateMany(props, globalClient) {
|
1590
|
-
const [modules, client] = await Promise.all([
|
1591
|
-
(0, client_1.getApolloModules)(),
|
1592
|
-
globalClient
|
1593
|
-
? Promise.resolve(globalClient)
|
1594
|
-
: client_1.client
|
1595
|
-
]);
|
1596
|
-
const { gql, ApolloError } = modules;
|
1597
|
-
const UPDATE_MANY_USER = gql `
|
1598
|
-
mutation updateManyUser($data: [UserCreateManyInput!]!) {
|
1599
|
-
updateManyUser(data: $data) {
|
1600
|
-
count
|
1601
|
-
}
|
1602
|
-
}`;
|
1603
|
-
const variables = props.map(prop => ({
|
1604
|
-
where: {
|
1605
|
-
id: prop.id !== undefined ? prop.id : undefined,
|
1606
|
-
email: prop.email !== undefined ? prop.email : undefined,
|
1607
|
-
name: prop.name !== undefined ? {
|
1608
|
-
equals: prop.name
|
1609
|
-
} : undefined,
|
1610
|
-
},
|
1611
|
-
data: {
|
1612
|
-
id: prop.id !== undefined ? {
|
1613
|
-
set: prop.id
|
1614
|
-
} : undefined,
|
1615
|
-
name: prop.name !== undefined ? {
|
1616
|
-
set: prop.name
|
1617
|
-
} : undefined,
|
1618
|
-
email: prop.email !== undefined ? {
|
1619
|
-
set: prop.email
|
1620
|
-
} : undefined,
|
1621
|
-
emailVerified: prop.emailVerified !== undefined ? {
|
1622
|
-
set: prop.emailVerified
|
1623
|
-
} : undefined,
|
1624
|
-
image: prop.image !== undefined ? {
|
1625
|
-
set: prop.image
|
1626
|
-
} : undefined,
|
1627
|
-
createdAt: prop.createdAt !== undefined ? {
|
1628
|
-
set: prop.createdAt
|
1629
|
-
} : undefined,
|
1630
|
-
updatedAt: prop.updatedAt !== undefined ? {
|
1631
|
-
set: prop.updatedAt
|
1632
|
-
} : undefined,
|
1633
|
-
role: prop.role !== undefined ? {
|
1634
|
-
set: prop.role
|
1635
|
-
} : undefined,
|
1636
|
-
bio: prop.bio !== undefined ? {
|
1637
|
-
set: prop.bio
|
1638
|
-
} : undefined,
|
1639
|
-
jobTitle: prop.jobTitle !== undefined ? {
|
1640
|
-
set: prop.jobTitle
|
1641
|
-
} : undefined,
|
1642
|
-
currentAccount: prop.currentAccount !== undefined ? {
|
1643
|
-
set: prop.currentAccount
|
1644
|
-
} : undefined,
|
1645
|
-
plan: prop.plan !== undefined ? {
|
1646
|
-
set: prop.plan
|
1647
|
-
} : undefined,
|
1648
|
-
openaiAPIKey: prop.openaiAPIKey !== undefined ? {
|
1649
|
-
set: prop.openaiAPIKey
|
1650
|
-
} : undefined,
|
1651
|
-
openaiModel: prop.openaiModel !== undefined ? {
|
1652
|
-
set: prop.openaiModel
|
1653
|
-
} : undefined,
|
1654
|
-
customer: prop.customer ?
|
1655
|
-
typeof prop.customer === 'object' && Object.keys(prop.customer).length === 1 && (Object.keys(prop.customer)[0] === 'id' || Object.keys(prop.customer)[0] === 'symbol')
|
1656
|
-
? {
|
1657
|
-
connect: {
|
1658
|
-
id: prop.customer.id
|
1659
|
-
}
|
1660
|
-
} : { upsert: {
|
1661
|
-
where: {
|
1662
|
-
id: prop.customer.id !== undefined ? {
|
1663
|
-
equals: prop.customer.id
|
1664
|
-
} : undefined,
|
1665
|
-
authUserId: prop.customer.authUserId !== undefined ? {
|
1666
|
-
equals: prop.customer.authUserId
|
1667
|
-
} : undefined,
|
1668
|
-
name: prop.customer.name !== undefined ? {
|
1669
|
-
equals: prop.customer.name
|
1670
|
-
} : undefined,
|
1671
|
-
stripeCustomerId: prop.customer.stripeCustomerId !== undefined ? {
|
1672
|
-
equals: prop.customer.stripeCustomerId
|
1673
|
-
} : undefined,
|
1674
|
-
stripeSubscriptionId: prop.customer.stripeSubscriptionId !== undefined ? {
|
1675
|
-
equals: prop.customer.stripeSubscriptionId
|
1676
|
-
} : undefined,
|
1677
|
-
stripePriceId: prop.customer.stripePriceId !== undefined ? {
|
1678
|
-
equals: prop.customer.stripePriceId
|
1679
|
-
} : undefined,
|
1680
|
-
},
|
1681
|
-
update: {
|
1682
|
-
authUserId: prop.customer.authUserId !== undefined ? {
|
1683
|
-
set: prop.customer.authUserId
|
1684
|
-
} : undefined,
|
1685
|
-
name: prop.customer.name !== undefined ? {
|
1686
|
-
set: prop.customer.name
|
1687
|
-
} : undefined,
|
1688
|
-
plan: prop.customer.plan !== undefined ? {
|
1689
|
-
set: prop.customer.plan
|
1690
|
-
} : undefined,
|
1691
|
-
stripeCustomerId: prop.customer.stripeCustomerId !== undefined ? {
|
1692
|
-
set: prop.customer.stripeCustomerId
|
1693
|
-
} : undefined,
|
1694
|
-
stripeSubscriptionId: prop.customer.stripeSubscriptionId !== undefined ? {
|
1695
|
-
set: prop.customer.stripeSubscriptionId
|
1696
|
-
} : undefined,
|
1697
|
-
stripePriceId: prop.customer.stripePriceId !== undefined ? {
|
1698
|
-
set: prop.customer.stripePriceId
|
1699
|
-
} : undefined,
|
1700
|
-
stripeCurrentPeriodEnd: prop.customer.stripeCurrentPeriodEnd !== undefined ? {
|
1701
|
-
set: prop.customer.stripeCurrentPeriodEnd
|
1702
|
-
} : undefined,
|
1703
|
-
},
|
1704
|
-
create: {
|
1705
|
-
authUserId: prop.customer.authUserId !== undefined ? prop.customer.authUserId : undefined,
|
1706
|
-
name: prop.customer.name !== undefined ? prop.customer.name : undefined,
|
1707
|
-
plan: prop.customer.plan !== undefined ? prop.customer.plan : undefined,
|
1708
|
-
stripeCustomerId: prop.customer.stripeCustomerId !== undefined ? prop.customer.stripeCustomerId : undefined,
|
1709
|
-
stripeSubscriptionId: prop.customer.stripeSubscriptionId !== undefined ? prop.customer.stripeSubscriptionId : undefined,
|
1710
|
-
stripePriceId: prop.customer.stripePriceId !== undefined ? prop.customer.stripePriceId : undefined,
|
1711
|
-
stripeCurrentPeriodEnd: prop.customer.stripeCurrentPeriodEnd !== undefined ? prop.customer.stripeCurrentPeriodEnd : undefined,
|
1712
|
-
},
|
1713
|
-
}
|
1714
|
-
} : undefined,
|
1715
|
-
accounts: prop.accounts ?
|
1716
|
-
Array.isArray(prop.accounts) && prop.accounts.length > 0 && prop.accounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1717
|
-
connect: prop.accounts.map((item) => ({
|
1718
|
-
id: item.id
|
1719
|
-
}))
|
1720
|
-
} : { upsert: prop.accounts.map((item) => ({
|
1721
|
-
where: {
|
1722
|
-
id: item.id !== undefined ? item.id : undefined,
|
1723
|
-
userId: item.userId !== undefined ? {
|
1724
|
-
equals: item.userId
|
1725
|
-
} : undefined,
|
1726
|
-
providerAccountId: item.providerAccountId !== undefined ? {
|
1727
|
-
equals: item.providerAccountId
|
1728
|
-
} : undefined,
|
1729
|
-
},
|
1730
|
-
update: {
|
1731
|
-
id: item.id !== undefined ? {
|
1732
|
-
set: item.id
|
1733
|
-
} : undefined,
|
1734
|
-
type: item.type !== undefined ? {
|
1735
|
-
set: item.type
|
1736
|
-
} : undefined,
|
1737
|
-
provider: item.provider !== undefined ? {
|
1738
|
-
set: item.provider
|
1739
|
-
} : undefined,
|
1740
|
-
providerAccountId: item.providerAccountId !== undefined ? {
|
1741
|
-
set: item.providerAccountId
|
1742
|
-
} : undefined,
|
1743
|
-
refresh_token: item.refresh_token !== undefined ? {
|
1744
|
-
set: item.refresh_token
|
1745
|
-
} : undefined,
|
1746
|
-
access_token: item.access_token !== undefined ? {
|
1747
|
-
set: item.access_token
|
1748
|
-
} : undefined,
|
1749
|
-
expires_at: item.expires_at !== undefined ? {
|
1750
|
-
set: item.expires_at
|
1751
|
-
} : undefined,
|
1752
|
-
token_type: item.token_type !== undefined ? {
|
1753
|
-
set: item.token_type
|
1754
|
-
} : undefined,
|
1755
|
-
scope: item.scope !== undefined ? {
|
1756
|
-
set: item.scope
|
1757
|
-
} : undefined,
|
1758
|
-
id_token: item.id_token !== undefined ? {
|
1759
|
-
set: item.id_token
|
1760
|
-
} : undefined,
|
1761
|
-
session_state: item.session_state !== undefined ? {
|
1762
|
-
set: item.session_state
|
1763
|
-
} : undefined,
|
1764
|
-
},
|
1765
|
-
create: {
|
1766
|
-
type: item.type !== undefined ? item.type : undefined,
|
1767
|
-
provider: item.provider !== undefined ? item.provider : undefined,
|
1768
|
-
providerAccountId: item.providerAccountId !== undefined ? item.providerAccountId : undefined,
|
1769
|
-
refresh_token: item.refresh_token !== undefined ? item.refresh_token : undefined,
|
1770
|
-
access_token: item.access_token !== undefined ? item.access_token : undefined,
|
1771
|
-
expires_at: item.expires_at !== undefined ? item.expires_at : undefined,
|
1772
|
-
token_type: item.token_type !== undefined ? item.token_type : undefined,
|
1773
|
-
scope: item.scope !== undefined ? item.scope : undefined,
|
1774
|
-
id_token: item.id_token !== undefined ? item.id_token : undefined,
|
1775
|
-
session_state: item.session_state !== undefined ? item.session_state : undefined,
|
1776
|
-
},
|
1777
|
-
}))
|
1778
|
-
} : undefined,
|
1779
|
-
sessions: prop.sessions ?
|
1780
|
-
Array.isArray(prop.sessions) && prop.sessions.length > 0 && prop.sessions.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1781
|
-
connect: prop.sessions.map((item) => ({
|
1782
|
-
id: item.id
|
1783
|
-
}))
|
1784
|
-
} : { upsert: prop.sessions.map((item) => ({
|
1785
|
-
where: {
|
1786
|
-
id: item.id !== undefined ? item.id : undefined,
|
1787
|
-
userId: item.userId !== undefined ? {
|
1788
|
-
equals: item.userId
|
1789
|
-
} : undefined,
|
1790
|
-
},
|
1791
|
-
update: {
|
1792
|
-
id: item.id !== undefined ? {
|
1793
|
-
set: item.id
|
1794
|
-
} : undefined,
|
1795
|
-
sessionToken: item.sessionToken !== undefined ? {
|
1796
|
-
set: item.sessionToken
|
1797
|
-
} : undefined,
|
1798
|
-
expires: item.expires !== undefined ? {
|
1799
|
-
set: item.expires
|
1800
|
-
} : undefined,
|
1801
|
-
},
|
1802
|
-
create: {
|
1803
|
-
sessionToken: item.sessionToken !== undefined ? item.sessionToken : undefined,
|
1804
|
-
expires: item.expires !== undefined ? item.expires : undefined,
|
1805
|
-
},
|
1806
|
-
}))
|
1807
|
-
} : undefined,
|
1808
|
-
authenticators: prop.authenticators ?
|
1809
|
-
Array.isArray(prop.authenticators) && prop.authenticators.length > 0 && prop.authenticators.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1810
|
-
connect: prop.authenticators.map((item) => ({
|
1811
|
-
id: item.id
|
1812
|
-
}))
|
1813
|
-
} : { upsert: prop.authenticators.map((item) => ({
|
1814
|
-
where: {
|
1815
|
-
id: item.id !== undefined ? item.id : undefined,
|
1816
|
-
userId: item.userId !== undefined ? {
|
1817
|
-
equals: item.userId
|
1818
|
-
} : undefined,
|
1819
|
-
},
|
1820
|
-
update: {
|
1821
|
-
id: item.id !== undefined ? {
|
1822
|
-
set: item.id
|
1823
|
-
} : undefined,
|
1824
|
-
credentialID: item.credentialID !== undefined ? {
|
1825
|
-
set: item.credentialID
|
1826
|
-
} : undefined,
|
1827
|
-
publicKey: item.publicKey !== undefined ? {
|
1828
|
-
set: item.publicKey
|
1829
|
-
} : undefined,
|
1830
|
-
counter: item.counter !== undefined ? {
|
1831
|
-
set: item.counter
|
1832
|
-
} : undefined,
|
1833
|
-
},
|
1834
|
-
create: {
|
1835
|
-
credentialID: item.credentialID !== undefined ? item.credentialID : undefined,
|
1836
|
-
publicKey: item.publicKey !== undefined ? item.publicKey : undefined,
|
1837
|
-
counter: item.counter !== undefined ? item.counter : undefined,
|
1838
|
-
},
|
1839
|
-
}))
|
1840
|
-
} : undefined,
|
1841
|
-
alpacaAccounts: prop.alpacaAccounts ?
|
1842
|
-
Array.isArray(prop.alpacaAccounts) && prop.alpacaAccounts.length > 0 && prop.alpacaAccounts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1843
|
-
connect: prop.alpacaAccounts.map((item) => ({
|
1844
|
-
id: item.id
|
1845
|
-
}))
|
1846
|
-
} : { upsert: prop.alpacaAccounts.map((item) => ({
|
1847
|
-
where: {
|
1848
|
-
id: item.id !== undefined ? item.id : undefined,
|
1849
|
-
userId: item.userId !== undefined ? {
|
1850
|
-
equals: item.userId
|
1851
|
-
} : undefined,
|
1852
|
-
},
|
1853
|
-
update: {
|
1854
|
-
id: item.id !== undefined ? {
|
1855
|
-
set: item.id
|
1856
|
-
} : undefined,
|
1857
|
-
type: item.type !== undefined ? {
|
1858
|
-
set: item.type
|
1859
|
-
} : undefined,
|
1860
|
-
APIKey: item.APIKey !== undefined ? {
|
1861
|
-
set: item.APIKey
|
1862
|
-
} : undefined,
|
1863
|
-
APISecret: item.APISecret !== undefined ? {
|
1864
|
-
set: item.APISecret
|
1865
|
-
} : undefined,
|
1866
|
-
configuration: item.configuration !== undefined ? {
|
1867
|
-
set: item.configuration
|
1868
|
-
} : undefined,
|
1869
|
-
marketOpen: item.marketOpen !== undefined ? {
|
1870
|
-
set: item.marketOpen
|
1871
|
-
} : undefined,
|
1872
|
-
realTime: item.realTime !== undefined ? {
|
1873
|
-
set: item.realTime
|
1874
|
-
} : undefined,
|
1875
|
-
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? {
|
1876
|
-
set: item.cryptoTradingEnabled
|
1877
|
-
} : undefined,
|
1878
|
-
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
1879
|
-
set: item.cryptoTradingPairs
|
1880
|
-
} : undefined,
|
1881
|
-
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? {
|
1882
|
-
set: item.cryptoTradeAllocationPct
|
1883
|
-
} : undefined,
|
1884
|
-
tradeAllocationPct: item.tradeAllocationPct !== undefined ? {
|
1885
|
-
set: item.tradeAllocationPct
|
1886
|
-
} : undefined,
|
1887
|
-
minPercentageChange: item.minPercentageChange !== undefined ? {
|
1888
|
-
set: item.minPercentageChange
|
1889
|
-
} : undefined,
|
1890
|
-
volumeThreshold: item.volumeThreshold !== undefined ? {
|
1891
|
-
set: item.volumeThreshold
|
1892
|
-
} : undefined,
|
1893
|
-
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? {
|
1894
|
-
set: item.enablePortfolioTrailingStop
|
1895
|
-
} : undefined,
|
1896
|
-
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? {
|
1897
|
-
set: item.portfolioTrailPercent
|
1898
|
-
} : undefined,
|
1899
|
-
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? {
|
1900
|
-
set: item.portfolioProfitThresholdPercent
|
1901
|
-
} : undefined,
|
1902
|
-
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? {
|
1903
|
-
set: item.reducedPortfolioTrailPercent
|
1904
|
-
} : undefined,
|
1905
|
-
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? {
|
1906
|
-
set: item.defaultTrailingStopPercentage100
|
1907
|
-
} : undefined,
|
1908
|
-
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? {
|
1909
|
-
set: item.firstTrailReductionThreshold100
|
1910
|
-
} : undefined,
|
1911
|
-
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? {
|
1912
|
-
set: item.secondTrailReductionThreshold100
|
1913
|
-
} : undefined,
|
1914
|
-
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? {
|
1915
|
-
set: item.firstReducedTrailPercentage100
|
1916
|
-
} : undefined,
|
1917
|
-
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? {
|
1918
|
-
set: item.secondReducedTrailPercentage100
|
1919
|
-
} : undefined,
|
1920
|
-
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? {
|
1921
|
-
set: item.minimumPriceChangePercent100
|
1922
|
-
} : undefined,
|
1923
|
-
allocation: item.allocation ?
|
1924
|
-
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && (Object.keys(item.allocation)[0] === 'id' || Object.keys(item.allocation)[0] === 'symbol')
|
1925
|
-
? {
|
1926
|
-
connect: {
|
1927
|
-
id: item.allocation.id
|
1928
|
-
}
|
1929
|
-
} : { upsert: {
|
1930
|
-
where: {
|
1931
|
-
id: item.allocation.id !== undefined ? {
|
1932
|
-
equals: item.allocation.id
|
1933
|
-
} : undefined,
|
1934
|
-
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? {
|
1935
|
-
equals: item.allocation.alpacaAccountId
|
1936
|
-
} : undefined,
|
1937
|
-
},
|
1938
|
-
update: {
|
1939
|
-
id: item.allocation.id !== undefined ? {
|
1940
|
-
set: item.allocation.id
|
1941
|
-
} : undefined,
|
1942
|
-
stocks: item.allocation.stocks !== undefined ? {
|
1943
|
-
set: item.allocation.stocks
|
1944
|
-
} : undefined,
|
1945
|
-
crypto: item.allocation.crypto !== undefined ? {
|
1946
|
-
set: item.allocation.crypto
|
1947
|
-
} : undefined,
|
1948
|
-
etfs: item.allocation.etfs !== undefined ? {
|
1949
|
-
set: item.allocation.etfs
|
1950
|
-
} : undefined,
|
1951
|
-
},
|
1952
|
-
create: {
|
1953
|
-
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
1954
|
-
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
1955
|
-
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
1956
|
-
},
|
1957
|
-
}
|
1958
|
-
} : undefined,
|
1959
|
-
alerts: item.alerts ?
|
1960
|
-
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
|
1961
|
-
connect: item.alerts.map((item) => ({
|
1962
|
-
id: item.id
|
1963
|
-
}))
|
1964
|
-
} : { upsert: item.alerts.map((item) => ({
|
1965
|
-
where: {
|
1966
|
-
id: item.id !== undefined ? item.id : undefined,
|
1967
|
-
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
1968
|
-
equals: item.alpacaAccountId
|
1969
|
-
} : undefined,
|
1970
|
-
},
|
1971
|
-
update: {
|
1972
|
-
id: item.id !== undefined ? {
|
1973
|
-
set: item.id
|
1974
|
-
} : undefined,
|
1975
|
-
message: item.message !== undefined ? {
|
1976
|
-
set: item.message
|
1977
|
-
} : undefined,
|
1978
|
-
type: item.type !== undefined ? {
|
1979
|
-
set: item.type
|
1980
|
-
} : undefined,
|
1981
|
-
isRead: item.isRead !== undefined ? {
|
1982
|
-
set: item.isRead
|
2143
|
+
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
2144
|
+
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
2145
|
+
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
2146
|
+
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
2147
|
+
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
2148
|
+
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
2149
|
+
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
2150
|
+
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
2151
|
+
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
2152
|
+
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
2153
|
+
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
2154
|
+
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
2155
|
+
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
2156
|
+
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
2157
|
+
allocation: item.allocation ?
|
2158
|
+
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
2159
|
+
? { connect: {
|
2160
|
+
id: item.allocation.id
|
2161
|
+
}
|
2162
|
+
}
|
2163
|
+
: { connectOrCreate: {
|
2164
|
+
where: {
|
2165
|
+
id: item.allocation.id !== undefined ? item.allocation.id : undefined,
|
2166
|
+
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? item.allocation.alpacaAccountId : undefined,
|
2167
|
+
},
|
2168
|
+
create: {
|
2169
|
+
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
2170
|
+
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
2171
|
+
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
2172
|
+
},
|
2173
|
+
}
|
1983
2174
|
} : undefined,
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
},
|
1990
|
-
}))
|
1991
|
-
} : undefined,
|
1992
|
-
},
|
1993
|
-
create: {
|
1994
|
-
type: item.type !== undefined ? item.type : undefined,
|
1995
|
-
APIKey: item.APIKey !== undefined ? item.APIKey : undefined,
|
1996
|
-
APISecret: item.APISecret !== undefined ? item.APISecret : undefined,
|
1997
|
-
configuration: item.configuration !== undefined ? item.configuration : undefined,
|
1998
|
-
marketOpen: item.marketOpen !== undefined ? item.marketOpen : undefined,
|
1999
|
-
realTime: item.realTime !== undefined ? item.realTime : undefined,
|
2000
|
-
cryptoTradingEnabled: item.cryptoTradingEnabled !== undefined ? item.cryptoTradingEnabled : undefined,
|
2001
|
-
cryptoTradingPairs: item.cryptoTradingPairs !== undefined ? {
|
2002
|
-
set: item.cryptoTradingPairs
|
2003
|
-
} : undefined,
|
2004
|
-
cryptoTradeAllocationPct: item.cryptoTradeAllocationPct !== undefined ? item.cryptoTradeAllocationPct : undefined,
|
2005
|
-
tradeAllocationPct: item.tradeAllocationPct !== undefined ? item.tradeAllocationPct : undefined,
|
2006
|
-
minPercentageChange: item.minPercentageChange !== undefined ? item.minPercentageChange : undefined,
|
2007
|
-
volumeThreshold: item.volumeThreshold !== undefined ? item.volumeThreshold : undefined,
|
2008
|
-
enablePortfolioTrailingStop: item.enablePortfolioTrailingStop !== undefined ? item.enablePortfolioTrailingStop : undefined,
|
2009
|
-
portfolioTrailPercent: item.portfolioTrailPercent !== undefined ? item.portfolioTrailPercent : undefined,
|
2010
|
-
portfolioProfitThresholdPercent: item.portfolioProfitThresholdPercent !== undefined ? item.portfolioProfitThresholdPercent : undefined,
|
2011
|
-
reducedPortfolioTrailPercent: item.reducedPortfolioTrailPercent !== undefined ? item.reducedPortfolioTrailPercent : undefined,
|
2012
|
-
defaultTrailingStopPercentage100: item.defaultTrailingStopPercentage100 !== undefined ? item.defaultTrailingStopPercentage100 : undefined,
|
2013
|
-
firstTrailReductionThreshold100: item.firstTrailReductionThreshold100 !== undefined ? item.firstTrailReductionThreshold100 : undefined,
|
2014
|
-
secondTrailReductionThreshold100: item.secondTrailReductionThreshold100 !== undefined ? item.secondTrailReductionThreshold100 : undefined,
|
2015
|
-
firstReducedTrailPercentage100: item.firstReducedTrailPercentage100 !== undefined ? item.firstReducedTrailPercentage100 : undefined,
|
2016
|
-
secondReducedTrailPercentage100: item.secondReducedTrailPercentage100 !== undefined ? item.secondReducedTrailPercentage100 : undefined,
|
2017
|
-
minimumPriceChangePercent100: item.minimumPriceChangePercent100 !== undefined ? item.minimumPriceChangePercent100 : undefined,
|
2018
|
-
allocation: item.allocation ?
|
2019
|
-
typeof item.allocation === 'object' && Object.keys(item.allocation).length === 1 && Object.keys(item.allocation)[0] === 'id'
|
2020
|
-
? { connect: {
|
2021
|
-
id: item.allocation.id
|
2022
|
-
}
|
2023
|
-
}
|
2024
|
-
: { connectOrCreate: {
|
2025
|
-
where: {
|
2026
|
-
id: item.allocation.id !== undefined ? item.allocation.id : undefined,
|
2027
|
-
alpacaAccountId: item.allocation.alpacaAccountId !== undefined ? item.allocation.alpacaAccountId : undefined,
|
2028
|
-
},
|
2029
|
-
create: {
|
2030
|
-
stocks: item.allocation.stocks !== undefined ? item.allocation.stocks : undefined,
|
2031
|
-
crypto: item.allocation.crypto !== undefined ? item.allocation.crypto : undefined,
|
2032
|
-
etfs: item.allocation.etfs !== undefined ? item.allocation.etfs : undefined,
|
2033
|
-
},
|
2175
|
+
alerts: item.alerts ?
|
2176
|
+
Array.isArray(item.alerts) && item.alerts.length > 0 && item.alerts.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
|
2177
|
+
connect: item.alerts.map((item) => ({
|
2178
|
+
id: item.id
|
2179
|
+
}))
|
2034
2180
|
}
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
}
|
2048
|
-
},
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2181
|
+
: { connectOrCreate: item.alerts.map((item) => ({
|
2182
|
+
where: {
|
2183
|
+
id: item.id !== undefined ? item.id : undefined,
|
2184
|
+
alpacaAccountId: item.alpacaAccountId !== undefined ? {
|
2185
|
+
equals: item.alpacaAccountId
|
2186
|
+
} : undefined,
|
2187
|
+
},
|
2188
|
+
create: {
|
2189
|
+
message: item.message !== undefined ? item.message : undefined,
|
2190
|
+
type: item.type !== undefined ? item.type : undefined,
|
2191
|
+
isRead: item.isRead !== undefined ? item.isRead : undefined,
|
2192
|
+
},
|
2193
|
+
}))
|
2194
|
+
} : undefined,
|
2195
|
+
},
|
2196
|
+
}))
|
2197
|
+
} : undefined,
|
2198
|
+
},
|
2199
|
+
}));
|
2200
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
2201
|
+
const response = await client.mutate({
|
2202
|
+
mutation: UPDATE_MANY_USER,
|
2203
|
+
variables: filteredVariables,
|
2204
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
2205
|
+
fetchPolicy: 'no-cache'
|
2206
|
+
});
|
2207
|
+
if (response.errors && response.errors.length > 0)
|
2208
|
+
throw new Error(response.errors[0].message);
|
2209
|
+
if (response && response.data && response.data.updateManyUser) {
|
2210
|
+
return response.data.updateManyUser;
|
2211
|
+
}
|
2212
|
+
else {
|
2213
|
+
return null;
|
2214
|
+
}
|
2068
2215
|
}
|
2069
|
-
|
2070
|
-
|
2216
|
+
catch (error) {
|
2217
|
+
lastError = error;
|
2218
|
+
// Check if this is a database connection error that we should retry
|
2219
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
2220
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
2221
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
2222
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
2223
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
2224
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
2225
|
+
retryCount++;
|
2226
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
2227
|
+
console.warn("Database connection error, retrying...");
|
2228
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
2229
|
+
continue;
|
2230
|
+
}
|
2231
|
+
// Log the error and rethrow
|
2232
|
+
console.error("Database error occurred:", error);
|
2233
|
+
throw error;
|
2071
2234
|
}
|
2072
2235
|
}
|
2073
|
-
|
2074
|
-
|
2075
|
-
throw error;
|
2076
|
-
}
|
2236
|
+
// If we exhausted retries, throw the last error
|
2237
|
+
throw lastError;
|
2077
2238
|
},
|
2078
2239
|
/**
|
2079
2240
|
* Delete a single User record.
|
2080
|
-
*
|
2241
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
2242
|
+
* @param props - Properties to identify the record to delete.
|
2081
2243
|
* @param globalClient - Apollo Client instance.
|
2082
2244
|
* @returns The deleted User or null.
|
2083
2245
|
*/
|
2084
2246
|
async delete(props, globalClient) {
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2247
|
+
var _a, _b, _c, _d, _e;
|
2248
|
+
// Maximum number of retries for database connection issues
|
2249
|
+
const MAX_RETRIES = 3;
|
2250
|
+
let retryCount = 0;
|
2251
|
+
let lastError = null;
|
2252
|
+
// Retry loop to handle potential database connection issues
|
2253
|
+
while (retryCount < MAX_RETRIES) {
|
2254
|
+
try {
|
2255
|
+
const [modules, client] = await Promise.all([
|
2256
|
+
(0, client_1.getApolloModules)(),
|
2257
|
+
globalClient
|
2258
|
+
? Promise.resolve(globalClient)
|
2259
|
+
: client_1.client
|
2260
|
+
]);
|
2261
|
+
const { gql, ApolloError } = modules;
|
2262
|
+
const DELETE_ONE_USER = gql `
|
2263
|
+
mutation deleteOneUser($where: UserWhereUniqueInput!) {
|
2264
|
+
deleteOneUser(where: $where) {
|
2265
|
+
id
|
2101
2266
|
}
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2267
|
+
}`;
|
2268
|
+
const variables = {
|
2269
|
+
where: {
|
2270
|
+
id: props.id ? props.id : undefined,
|
2271
|
+
}
|
2272
|
+
};
|
2273
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
2274
|
+
const response = await client.mutate({
|
2275
|
+
mutation: DELETE_ONE_USER,
|
2276
|
+
variables: filteredVariables,
|
2277
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
2278
|
+
fetchPolicy: 'no-cache'
|
2279
|
+
});
|
2280
|
+
if (response.errors && response.errors.length > 0)
|
2281
|
+
throw new Error(response.errors[0].message);
|
2282
|
+
if (response && response.data && response.data.deleteOneUser) {
|
2283
|
+
return response.data.deleteOneUser;
|
2284
|
+
}
|
2285
|
+
else {
|
2286
|
+
return null;
|
2287
|
+
}
|
2110
2288
|
}
|
2111
|
-
|
2112
|
-
|
2289
|
+
catch (error) {
|
2290
|
+
lastError = error;
|
2291
|
+
// Check if this is a database connection error that we should retry
|
2292
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
2293
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
2294
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
2295
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
2296
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
2297
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
2298
|
+
retryCount++;
|
2299
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
2300
|
+
console.warn("Database connection error, retrying...");
|
2301
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
2302
|
+
continue;
|
2303
|
+
}
|
2304
|
+
// Log the error and rethrow
|
2305
|
+
console.error("Database error occurred:", error);
|
2306
|
+
throw error;
|
2113
2307
|
}
|
2114
2308
|
}
|
2115
|
-
|
2116
|
-
|
2117
|
-
throw error;
|
2118
|
-
}
|
2309
|
+
// If we exhausted retries, throw the last error
|
2310
|
+
throw lastError;
|
2119
2311
|
},
|
2120
2312
|
/**
|
2121
2313
|
* Retrieve a single User record by ID.
|
2122
|
-
*
|
2314
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
2315
|
+
* @param props - Properties to identify the record.
|
2123
2316
|
* @param globalClient - Apollo Client instance.
|
2317
|
+
* @param whereInput - Optional custom where input.
|
2124
2318
|
* @returns The retrieved User or null.
|
2125
2319
|
*/
|
2126
2320
|
async get(props, globalClient, whereInput) {
|
2127
|
-
var _a, _b;
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2136
|
-
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2321
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
2322
|
+
// Maximum number of retries for database connection issues
|
2323
|
+
const MAX_RETRIES = 3;
|
2324
|
+
let retryCount = 0;
|
2325
|
+
let lastError = null;
|
2326
|
+
// Retry loop to handle potential database connection issues
|
2327
|
+
while (retryCount < MAX_RETRIES) {
|
2328
|
+
try {
|
2329
|
+
const [modules, client] = await Promise.all([
|
2330
|
+
(0, client_1.getApolloModules)(),
|
2331
|
+
globalClient
|
2332
|
+
? Promise.resolve(globalClient)
|
2333
|
+
: client_1.client
|
2334
|
+
]);
|
2335
|
+
const { gql, ApolloError } = modules;
|
2336
|
+
const GET_USER = gql `
|
2337
|
+
query getUser($where: UserWhereUniqueInput!) {
|
2338
|
+
getUser(where: $where) {
|
2339
|
+
${selectionSet}
|
2340
|
+
}
|
2341
|
+
}`;
|
2342
|
+
const variables = {
|
2343
|
+
where: whereInput ? whereInput : {
|
2344
|
+
id: props.id !== undefined ? props.id : undefined,
|
2345
|
+
email: props.email !== undefined ? props.email : undefined,
|
2346
|
+
name: props.name !== undefined ? {
|
2347
|
+
equals: props.name
|
2348
|
+
} : undefined,
|
2349
|
+
},
|
2350
|
+
};
|
2351
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
2352
|
+
const response = await client.query({
|
2353
|
+
query: GET_USER,
|
2354
|
+
variables: filteredVariables,
|
2355
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
2356
|
+
});
|
2357
|
+
if (response.errors && response.errors.length > 0)
|
2358
|
+
throw new Error(response.errors[0].message);
|
2359
|
+
return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getUser) !== null && _b !== void 0 ? _b : null;
|
2160
2360
|
}
|
2161
|
-
|
2162
|
-
|
2361
|
+
catch (error) {
|
2362
|
+
lastError = error;
|
2363
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
2364
|
+
if (error.message === 'No User found') {
|
2365
|
+
return null;
|
2366
|
+
}
|
2367
|
+
// Check if this is a database connection error that we should retry
|
2368
|
+
const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
|
2369
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
|
2370
|
+
((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
|
2371
|
+
((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
2372
|
+
(error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
|
2373
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
2374
|
+
retryCount++;
|
2375
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
2376
|
+
console.warn("Database connection error, retrying...");
|
2377
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
2378
|
+
continue;
|
2379
|
+
}
|
2380
|
+
// Log the error and rethrow
|
2381
|
+
console.error("Database error occurred:", error);
|
2163
2382
|
throw error;
|
2164
2383
|
}
|
2165
2384
|
}
|
2385
|
+
// If we exhausted retries, throw the last error
|
2386
|
+
throw lastError;
|
2166
2387
|
},
|
2167
2388
|
/**
|
2168
2389
|
* Retrieve all Users records.
|
2390
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
2169
2391
|
* @param globalClient - Apollo Client instance.
|
2170
2392
|
* @returns An array of User records or null.
|
2171
2393
|
*/
|
2172
2394
|
async getAll(globalClient) {
|
2173
|
-
var _a, _b;
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2395
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
2396
|
+
// Maximum number of retries for database connection issues
|
2397
|
+
const MAX_RETRIES = 3;
|
2398
|
+
let retryCount = 0;
|
2399
|
+
let lastError = null;
|
2400
|
+
// Retry loop to handle potential database connection issues
|
2401
|
+
while (retryCount < MAX_RETRIES) {
|
2402
|
+
try {
|
2403
|
+
const [modules, client] = await Promise.all([
|
2404
|
+
(0, client_1.getApolloModules)(),
|
2405
|
+
globalClient
|
2406
|
+
? Promise.resolve(globalClient)
|
2407
|
+
: client_1.client
|
2408
|
+
]);
|
2409
|
+
const { gql, ApolloError } = modules;
|
2410
|
+
const GET_ALL_USER = gql `
|
2411
|
+
query getAllUser {
|
2412
|
+
users {
|
2413
|
+
${selectionSet}
|
2414
|
+
}
|
2415
|
+
}`;
|
2416
|
+
const response = await client.query({
|
2417
|
+
query: GET_ALL_USER,
|
2418
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
2419
|
+
});
|
2420
|
+
if (response.errors && response.errors.length > 0)
|
2421
|
+
throw new Error(response.errors[0].message);
|
2422
|
+
return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.users) !== null && _b !== void 0 ? _b : null;
|
2196
2423
|
}
|
2197
|
-
|
2198
|
-
|
2424
|
+
catch (error) {
|
2425
|
+
lastError = error;
|
2426
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
2427
|
+
if (error.message === 'No User found') {
|
2428
|
+
return null;
|
2429
|
+
}
|
2430
|
+
// Check if this is a database connection error that we should retry
|
2431
|
+
const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
|
2432
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
|
2433
|
+
((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
|
2434
|
+
((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
2435
|
+
(error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
|
2436
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
2437
|
+
retryCount++;
|
2438
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
2439
|
+
console.warn("Database connection error, retrying...");
|
2440
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
2441
|
+
continue;
|
2442
|
+
}
|
2443
|
+
// Log the error and rethrow
|
2444
|
+
console.error("Database error occurred:", error);
|
2199
2445
|
throw error;
|
2200
2446
|
}
|
2201
2447
|
}
|
2448
|
+
// If we exhausted retries, throw the last error
|
2449
|
+
throw lastError;
|
2202
2450
|
},
|
2203
2451
|
/**
|
2204
2452
|
* Find multiple User records based on conditions.
|
2453
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
2205
2454
|
* @param props - Conditions to find records.
|
2206
2455
|
* @param globalClient - Apollo Client instance.
|
2456
|
+
* @param whereInput - Optional custom where input.
|
2207
2457
|
* @returns An array of found User records or null.
|
2208
2458
|
*/
|
2209
2459
|
async findMany(props, globalClient, whereInput) {
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
equals: props.name
|
2230
|
-
} : undefined,
|
2231
|
-
email: props.email !== undefined ? {
|
2232
|
-
equals: props.email
|
2233
|
-
} : undefined,
|
2234
|
-
},
|
2235
|
-
};
|
2236
|
-
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
2237
|
-
try {
|
2238
|
-
const response = await client.query({ query: FIND_MANY_USER, variables: filteredVariables });
|
2239
|
-
if (response.errors && response.errors.length > 0)
|
2240
|
-
throw new Error(response.errors[0].message);
|
2241
|
-
if (response && response.data && response.data.users) {
|
2242
|
-
return response.data.users;
|
2243
|
-
}
|
2244
|
-
else {
|
2245
|
-
return [];
|
2460
|
+
var _a, _b, _c, _d, _e;
|
2461
|
+
// Maximum number of retries for database connection issues
|
2462
|
+
const MAX_RETRIES = 3;
|
2463
|
+
let retryCount = 0;
|
2464
|
+
let lastError = null;
|
2465
|
+
// Retry loop to handle potential database connection issues
|
2466
|
+
while (retryCount < MAX_RETRIES) {
|
2467
|
+
try {
|
2468
|
+
const [modules, client] = await Promise.all([
|
2469
|
+
(0, client_1.getApolloModules)(),
|
2470
|
+
globalClient
|
2471
|
+
? Promise.resolve(globalClient)
|
2472
|
+
: client_1.client
|
2473
|
+
]);
|
2474
|
+
const { gql, ApolloError } = modules;
|
2475
|
+
const FIND_MANY_USER = gql `
|
2476
|
+
query findManyUser($where: UserWhereInput!) {
|
2477
|
+
users(where: $where) {
|
2478
|
+
${selectionSet}
|
2246
2479
|
}
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2480
|
+
}`;
|
2481
|
+
const variables = {
|
2482
|
+
where: whereInput ? whereInput : {
|
2483
|
+
id: props.id !== undefined ? {
|
2484
|
+
equals: props.id
|
2485
|
+
} : undefined,
|
2486
|
+
name: props.name !== undefined ? {
|
2487
|
+
equals: props.name
|
2488
|
+
} : undefined,
|
2489
|
+
email: props.email !== undefined ? {
|
2490
|
+
equals: props.email
|
2491
|
+
} : undefined,
|
2492
|
+
},
|
2493
|
+
};
|
2494
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
2495
|
+
const response = await client.query({
|
2496
|
+
query: FIND_MANY_USER,
|
2497
|
+
variables: filteredVariables,
|
2498
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
2499
|
+
});
|
2500
|
+
if (response.errors && response.errors.length > 0)
|
2501
|
+
throw new Error(response.errors[0].message);
|
2502
|
+
if (response && response.data && response.data.users) {
|
2503
|
+
return response.data.users;
|
2504
|
+
}
|
2505
|
+
else {
|
2506
|
+
return [];
|
2507
|
+
}
|
2251
2508
|
}
|
2252
|
-
|
2253
|
-
|
2509
|
+
catch (error) {
|
2510
|
+
lastError = error;
|
2511
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
2512
|
+
if (error.message === 'No User found') {
|
2513
|
+
return null;
|
2514
|
+
}
|
2515
|
+
// Check if this is a database connection error that we should retry
|
2516
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
2517
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
2518
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
2519
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
2520
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
2521
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
2522
|
+
retryCount++;
|
2523
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
2524
|
+
console.warn("Database connection error, retrying...");
|
2525
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
2526
|
+
continue;
|
2527
|
+
}
|
2528
|
+
// Log the error and rethrow
|
2529
|
+
console.error("Database error occurred:", error);
|
2254
2530
|
throw error;
|
2255
2531
|
}
|
2256
2532
|
}
|
2533
|
+
// If we exhausted retries, throw the last error
|
2534
|
+
throw lastError;
|
2257
2535
|
}
|
2258
2536
|
};
|
2259
2537
|
//# sourceMappingURL=User.js.map
|