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