adaptic-backend 1.0.340 → 1.0.342

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