pendingauthsession_update.go 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
  12. "github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
  13. "github.com/Wei-Shaw/sub2api/ent/predicate"
  14. "github.com/Wei-Shaw/sub2api/ent/user"
  15. )
  16. // PendingAuthSessionUpdate is the builder for updating PendingAuthSession entities.
  17. type PendingAuthSessionUpdate struct {
  18. config
  19. hooks []Hook
  20. mutation *PendingAuthSessionMutation
  21. }
  22. // Where appends a list predicates to the PendingAuthSessionUpdate builder.
  23. func (_u *PendingAuthSessionUpdate) Where(ps ...predicate.PendingAuthSession) *PendingAuthSessionUpdate {
  24. _u.mutation.Where(ps...)
  25. return _u
  26. }
  27. // SetUpdatedAt sets the "updated_at" field.
  28. func (_u *PendingAuthSessionUpdate) SetUpdatedAt(v time.Time) *PendingAuthSessionUpdate {
  29. _u.mutation.SetUpdatedAt(v)
  30. return _u
  31. }
  32. // SetSessionToken sets the "session_token" field.
  33. func (_u *PendingAuthSessionUpdate) SetSessionToken(v string) *PendingAuthSessionUpdate {
  34. _u.mutation.SetSessionToken(v)
  35. return _u
  36. }
  37. // SetNillableSessionToken sets the "session_token" field if the given value is not nil.
  38. func (_u *PendingAuthSessionUpdate) SetNillableSessionToken(v *string) *PendingAuthSessionUpdate {
  39. if v != nil {
  40. _u.SetSessionToken(*v)
  41. }
  42. return _u
  43. }
  44. // SetIntent sets the "intent" field.
  45. func (_u *PendingAuthSessionUpdate) SetIntent(v string) *PendingAuthSessionUpdate {
  46. _u.mutation.SetIntent(v)
  47. return _u
  48. }
  49. // SetNillableIntent sets the "intent" field if the given value is not nil.
  50. func (_u *PendingAuthSessionUpdate) SetNillableIntent(v *string) *PendingAuthSessionUpdate {
  51. if v != nil {
  52. _u.SetIntent(*v)
  53. }
  54. return _u
  55. }
  56. // SetProviderType sets the "provider_type" field.
  57. func (_u *PendingAuthSessionUpdate) SetProviderType(v string) *PendingAuthSessionUpdate {
  58. _u.mutation.SetProviderType(v)
  59. return _u
  60. }
  61. // SetNillableProviderType sets the "provider_type" field if the given value is not nil.
  62. func (_u *PendingAuthSessionUpdate) SetNillableProviderType(v *string) *PendingAuthSessionUpdate {
  63. if v != nil {
  64. _u.SetProviderType(*v)
  65. }
  66. return _u
  67. }
  68. // SetProviderKey sets the "provider_key" field.
  69. func (_u *PendingAuthSessionUpdate) SetProviderKey(v string) *PendingAuthSessionUpdate {
  70. _u.mutation.SetProviderKey(v)
  71. return _u
  72. }
  73. // SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
  74. func (_u *PendingAuthSessionUpdate) SetNillableProviderKey(v *string) *PendingAuthSessionUpdate {
  75. if v != nil {
  76. _u.SetProviderKey(*v)
  77. }
  78. return _u
  79. }
  80. // SetProviderSubject sets the "provider_subject" field.
  81. func (_u *PendingAuthSessionUpdate) SetProviderSubject(v string) *PendingAuthSessionUpdate {
  82. _u.mutation.SetProviderSubject(v)
  83. return _u
  84. }
  85. // SetNillableProviderSubject sets the "provider_subject" field if the given value is not nil.
  86. func (_u *PendingAuthSessionUpdate) SetNillableProviderSubject(v *string) *PendingAuthSessionUpdate {
  87. if v != nil {
  88. _u.SetProviderSubject(*v)
  89. }
  90. return _u
  91. }
  92. // SetTargetUserID sets the "target_user_id" field.
  93. func (_u *PendingAuthSessionUpdate) SetTargetUserID(v int64) *PendingAuthSessionUpdate {
  94. _u.mutation.SetTargetUserID(v)
  95. return _u
  96. }
  97. // SetNillableTargetUserID sets the "target_user_id" field if the given value is not nil.
  98. func (_u *PendingAuthSessionUpdate) SetNillableTargetUserID(v *int64) *PendingAuthSessionUpdate {
  99. if v != nil {
  100. _u.SetTargetUserID(*v)
  101. }
  102. return _u
  103. }
  104. // ClearTargetUserID clears the value of the "target_user_id" field.
  105. func (_u *PendingAuthSessionUpdate) ClearTargetUserID() *PendingAuthSessionUpdate {
  106. _u.mutation.ClearTargetUserID()
  107. return _u
  108. }
  109. // SetRedirectTo sets the "redirect_to" field.
  110. func (_u *PendingAuthSessionUpdate) SetRedirectTo(v string) *PendingAuthSessionUpdate {
  111. _u.mutation.SetRedirectTo(v)
  112. return _u
  113. }
  114. // SetNillableRedirectTo sets the "redirect_to" field if the given value is not nil.
  115. func (_u *PendingAuthSessionUpdate) SetNillableRedirectTo(v *string) *PendingAuthSessionUpdate {
  116. if v != nil {
  117. _u.SetRedirectTo(*v)
  118. }
  119. return _u
  120. }
  121. // SetResolvedEmail sets the "resolved_email" field.
  122. func (_u *PendingAuthSessionUpdate) SetResolvedEmail(v string) *PendingAuthSessionUpdate {
  123. _u.mutation.SetResolvedEmail(v)
  124. return _u
  125. }
  126. // SetNillableResolvedEmail sets the "resolved_email" field if the given value is not nil.
  127. func (_u *PendingAuthSessionUpdate) SetNillableResolvedEmail(v *string) *PendingAuthSessionUpdate {
  128. if v != nil {
  129. _u.SetResolvedEmail(*v)
  130. }
  131. return _u
  132. }
  133. // SetRegistrationPasswordHash sets the "registration_password_hash" field.
  134. func (_u *PendingAuthSessionUpdate) SetRegistrationPasswordHash(v string) *PendingAuthSessionUpdate {
  135. _u.mutation.SetRegistrationPasswordHash(v)
  136. return _u
  137. }
  138. // SetNillableRegistrationPasswordHash sets the "registration_password_hash" field if the given value is not nil.
  139. func (_u *PendingAuthSessionUpdate) SetNillableRegistrationPasswordHash(v *string) *PendingAuthSessionUpdate {
  140. if v != nil {
  141. _u.SetRegistrationPasswordHash(*v)
  142. }
  143. return _u
  144. }
  145. // SetUpstreamIdentityClaims sets the "upstream_identity_claims" field.
  146. func (_u *PendingAuthSessionUpdate) SetUpstreamIdentityClaims(v map[string]interface{}) *PendingAuthSessionUpdate {
  147. _u.mutation.SetUpstreamIdentityClaims(v)
  148. return _u
  149. }
  150. // SetLocalFlowState sets the "local_flow_state" field.
  151. func (_u *PendingAuthSessionUpdate) SetLocalFlowState(v map[string]interface{}) *PendingAuthSessionUpdate {
  152. _u.mutation.SetLocalFlowState(v)
  153. return _u
  154. }
  155. // SetBrowserSessionKey sets the "browser_session_key" field.
  156. func (_u *PendingAuthSessionUpdate) SetBrowserSessionKey(v string) *PendingAuthSessionUpdate {
  157. _u.mutation.SetBrowserSessionKey(v)
  158. return _u
  159. }
  160. // SetNillableBrowserSessionKey sets the "browser_session_key" field if the given value is not nil.
  161. func (_u *PendingAuthSessionUpdate) SetNillableBrowserSessionKey(v *string) *PendingAuthSessionUpdate {
  162. if v != nil {
  163. _u.SetBrowserSessionKey(*v)
  164. }
  165. return _u
  166. }
  167. // SetCompletionCodeHash sets the "completion_code_hash" field.
  168. func (_u *PendingAuthSessionUpdate) SetCompletionCodeHash(v string) *PendingAuthSessionUpdate {
  169. _u.mutation.SetCompletionCodeHash(v)
  170. return _u
  171. }
  172. // SetNillableCompletionCodeHash sets the "completion_code_hash" field if the given value is not nil.
  173. func (_u *PendingAuthSessionUpdate) SetNillableCompletionCodeHash(v *string) *PendingAuthSessionUpdate {
  174. if v != nil {
  175. _u.SetCompletionCodeHash(*v)
  176. }
  177. return _u
  178. }
  179. // SetCompletionCodeExpiresAt sets the "completion_code_expires_at" field.
  180. func (_u *PendingAuthSessionUpdate) SetCompletionCodeExpiresAt(v time.Time) *PendingAuthSessionUpdate {
  181. _u.mutation.SetCompletionCodeExpiresAt(v)
  182. return _u
  183. }
  184. // SetNillableCompletionCodeExpiresAt sets the "completion_code_expires_at" field if the given value is not nil.
  185. func (_u *PendingAuthSessionUpdate) SetNillableCompletionCodeExpiresAt(v *time.Time) *PendingAuthSessionUpdate {
  186. if v != nil {
  187. _u.SetCompletionCodeExpiresAt(*v)
  188. }
  189. return _u
  190. }
  191. // ClearCompletionCodeExpiresAt clears the value of the "completion_code_expires_at" field.
  192. func (_u *PendingAuthSessionUpdate) ClearCompletionCodeExpiresAt() *PendingAuthSessionUpdate {
  193. _u.mutation.ClearCompletionCodeExpiresAt()
  194. return _u
  195. }
  196. // SetEmailVerifiedAt sets the "email_verified_at" field.
  197. func (_u *PendingAuthSessionUpdate) SetEmailVerifiedAt(v time.Time) *PendingAuthSessionUpdate {
  198. _u.mutation.SetEmailVerifiedAt(v)
  199. return _u
  200. }
  201. // SetNillableEmailVerifiedAt sets the "email_verified_at" field if the given value is not nil.
  202. func (_u *PendingAuthSessionUpdate) SetNillableEmailVerifiedAt(v *time.Time) *PendingAuthSessionUpdate {
  203. if v != nil {
  204. _u.SetEmailVerifiedAt(*v)
  205. }
  206. return _u
  207. }
  208. // ClearEmailVerifiedAt clears the value of the "email_verified_at" field.
  209. func (_u *PendingAuthSessionUpdate) ClearEmailVerifiedAt() *PendingAuthSessionUpdate {
  210. _u.mutation.ClearEmailVerifiedAt()
  211. return _u
  212. }
  213. // SetPasswordVerifiedAt sets the "password_verified_at" field.
  214. func (_u *PendingAuthSessionUpdate) SetPasswordVerifiedAt(v time.Time) *PendingAuthSessionUpdate {
  215. _u.mutation.SetPasswordVerifiedAt(v)
  216. return _u
  217. }
  218. // SetNillablePasswordVerifiedAt sets the "password_verified_at" field if the given value is not nil.
  219. func (_u *PendingAuthSessionUpdate) SetNillablePasswordVerifiedAt(v *time.Time) *PendingAuthSessionUpdate {
  220. if v != nil {
  221. _u.SetPasswordVerifiedAt(*v)
  222. }
  223. return _u
  224. }
  225. // ClearPasswordVerifiedAt clears the value of the "password_verified_at" field.
  226. func (_u *PendingAuthSessionUpdate) ClearPasswordVerifiedAt() *PendingAuthSessionUpdate {
  227. _u.mutation.ClearPasswordVerifiedAt()
  228. return _u
  229. }
  230. // SetTotpVerifiedAt sets the "totp_verified_at" field.
  231. func (_u *PendingAuthSessionUpdate) SetTotpVerifiedAt(v time.Time) *PendingAuthSessionUpdate {
  232. _u.mutation.SetTotpVerifiedAt(v)
  233. return _u
  234. }
  235. // SetNillableTotpVerifiedAt sets the "totp_verified_at" field if the given value is not nil.
  236. func (_u *PendingAuthSessionUpdate) SetNillableTotpVerifiedAt(v *time.Time) *PendingAuthSessionUpdate {
  237. if v != nil {
  238. _u.SetTotpVerifiedAt(*v)
  239. }
  240. return _u
  241. }
  242. // ClearTotpVerifiedAt clears the value of the "totp_verified_at" field.
  243. func (_u *PendingAuthSessionUpdate) ClearTotpVerifiedAt() *PendingAuthSessionUpdate {
  244. _u.mutation.ClearTotpVerifiedAt()
  245. return _u
  246. }
  247. // SetExpiresAt sets the "expires_at" field.
  248. func (_u *PendingAuthSessionUpdate) SetExpiresAt(v time.Time) *PendingAuthSessionUpdate {
  249. _u.mutation.SetExpiresAt(v)
  250. return _u
  251. }
  252. // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
  253. func (_u *PendingAuthSessionUpdate) SetNillableExpiresAt(v *time.Time) *PendingAuthSessionUpdate {
  254. if v != nil {
  255. _u.SetExpiresAt(*v)
  256. }
  257. return _u
  258. }
  259. // SetConsumedAt sets the "consumed_at" field.
  260. func (_u *PendingAuthSessionUpdate) SetConsumedAt(v time.Time) *PendingAuthSessionUpdate {
  261. _u.mutation.SetConsumedAt(v)
  262. return _u
  263. }
  264. // SetNillableConsumedAt sets the "consumed_at" field if the given value is not nil.
  265. func (_u *PendingAuthSessionUpdate) SetNillableConsumedAt(v *time.Time) *PendingAuthSessionUpdate {
  266. if v != nil {
  267. _u.SetConsumedAt(*v)
  268. }
  269. return _u
  270. }
  271. // ClearConsumedAt clears the value of the "consumed_at" field.
  272. func (_u *PendingAuthSessionUpdate) ClearConsumedAt() *PendingAuthSessionUpdate {
  273. _u.mutation.ClearConsumedAt()
  274. return _u
  275. }
  276. // SetTargetUser sets the "target_user" edge to the User entity.
  277. func (_u *PendingAuthSessionUpdate) SetTargetUser(v *User) *PendingAuthSessionUpdate {
  278. return _u.SetTargetUserID(v.ID)
  279. }
  280. // SetAdoptionDecisionID sets the "adoption_decision" edge to the IdentityAdoptionDecision entity by ID.
  281. func (_u *PendingAuthSessionUpdate) SetAdoptionDecisionID(id int64) *PendingAuthSessionUpdate {
  282. _u.mutation.SetAdoptionDecisionID(id)
  283. return _u
  284. }
  285. // SetNillableAdoptionDecisionID sets the "adoption_decision" edge to the IdentityAdoptionDecision entity by ID if the given value is not nil.
  286. func (_u *PendingAuthSessionUpdate) SetNillableAdoptionDecisionID(id *int64) *PendingAuthSessionUpdate {
  287. if id != nil {
  288. _u = _u.SetAdoptionDecisionID(*id)
  289. }
  290. return _u
  291. }
  292. // SetAdoptionDecision sets the "adoption_decision" edge to the IdentityAdoptionDecision entity.
  293. func (_u *PendingAuthSessionUpdate) SetAdoptionDecision(v *IdentityAdoptionDecision) *PendingAuthSessionUpdate {
  294. return _u.SetAdoptionDecisionID(v.ID)
  295. }
  296. // Mutation returns the PendingAuthSessionMutation object of the builder.
  297. func (_u *PendingAuthSessionUpdate) Mutation() *PendingAuthSessionMutation {
  298. return _u.mutation
  299. }
  300. // ClearTargetUser clears the "target_user" edge to the User entity.
  301. func (_u *PendingAuthSessionUpdate) ClearTargetUser() *PendingAuthSessionUpdate {
  302. _u.mutation.ClearTargetUser()
  303. return _u
  304. }
  305. // ClearAdoptionDecision clears the "adoption_decision" edge to the IdentityAdoptionDecision entity.
  306. func (_u *PendingAuthSessionUpdate) ClearAdoptionDecision() *PendingAuthSessionUpdate {
  307. _u.mutation.ClearAdoptionDecision()
  308. return _u
  309. }
  310. // Save executes the query and returns the number of nodes affected by the update operation.
  311. func (_u *PendingAuthSessionUpdate) Save(ctx context.Context) (int, error) {
  312. _u.defaults()
  313. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  314. }
  315. // SaveX is like Save, but panics if an error occurs.
  316. func (_u *PendingAuthSessionUpdate) SaveX(ctx context.Context) int {
  317. affected, err := _u.Save(ctx)
  318. if err != nil {
  319. panic(err)
  320. }
  321. return affected
  322. }
  323. // Exec executes the query.
  324. func (_u *PendingAuthSessionUpdate) Exec(ctx context.Context) error {
  325. _, err := _u.Save(ctx)
  326. return err
  327. }
  328. // ExecX is like Exec, but panics if an error occurs.
  329. func (_u *PendingAuthSessionUpdate) ExecX(ctx context.Context) {
  330. if err := _u.Exec(ctx); err != nil {
  331. panic(err)
  332. }
  333. }
  334. // defaults sets the default values of the builder before save.
  335. func (_u *PendingAuthSessionUpdate) defaults() {
  336. if _, ok := _u.mutation.UpdatedAt(); !ok {
  337. v := pendingauthsession.UpdateDefaultUpdatedAt()
  338. _u.mutation.SetUpdatedAt(v)
  339. }
  340. }
  341. // check runs all checks and user-defined validators on the builder.
  342. func (_u *PendingAuthSessionUpdate) check() error {
  343. if v, ok := _u.mutation.SessionToken(); ok {
  344. if err := pendingauthsession.SessionTokenValidator(v); err != nil {
  345. return &ValidationError{Name: "session_token", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.session_token": %w`, err)}
  346. }
  347. }
  348. if v, ok := _u.mutation.Intent(); ok {
  349. if err := pendingauthsession.IntentValidator(v); err != nil {
  350. return &ValidationError{Name: "intent", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.intent": %w`, err)}
  351. }
  352. }
  353. if v, ok := _u.mutation.ProviderType(); ok {
  354. if err := pendingauthsession.ProviderTypeValidator(v); err != nil {
  355. return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.provider_type": %w`, err)}
  356. }
  357. }
  358. if v, ok := _u.mutation.ProviderKey(); ok {
  359. if err := pendingauthsession.ProviderKeyValidator(v); err != nil {
  360. return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.provider_key": %w`, err)}
  361. }
  362. }
  363. if v, ok := _u.mutation.ProviderSubject(); ok {
  364. if err := pendingauthsession.ProviderSubjectValidator(v); err != nil {
  365. return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.provider_subject": %w`, err)}
  366. }
  367. }
  368. return nil
  369. }
  370. func (_u *PendingAuthSessionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  371. if err := _u.check(); err != nil {
  372. return _node, err
  373. }
  374. _spec := sqlgraph.NewUpdateSpec(pendingauthsession.Table, pendingauthsession.Columns, sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64))
  375. if ps := _u.mutation.predicates; len(ps) > 0 {
  376. _spec.Predicate = func(selector *sql.Selector) {
  377. for i := range ps {
  378. ps[i](selector)
  379. }
  380. }
  381. }
  382. if value, ok := _u.mutation.UpdatedAt(); ok {
  383. _spec.SetField(pendingauthsession.FieldUpdatedAt, field.TypeTime, value)
  384. }
  385. if value, ok := _u.mutation.SessionToken(); ok {
  386. _spec.SetField(pendingauthsession.FieldSessionToken, field.TypeString, value)
  387. }
  388. if value, ok := _u.mutation.Intent(); ok {
  389. _spec.SetField(pendingauthsession.FieldIntent, field.TypeString, value)
  390. }
  391. if value, ok := _u.mutation.ProviderType(); ok {
  392. _spec.SetField(pendingauthsession.FieldProviderType, field.TypeString, value)
  393. }
  394. if value, ok := _u.mutation.ProviderKey(); ok {
  395. _spec.SetField(pendingauthsession.FieldProviderKey, field.TypeString, value)
  396. }
  397. if value, ok := _u.mutation.ProviderSubject(); ok {
  398. _spec.SetField(pendingauthsession.FieldProviderSubject, field.TypeString, value)
  399. }
  400. if value, ok := _u.mutation.RedirectTo(); ok {
  401. _spec.SetField(pendingauthsession.FieldRedirectTo, field.TypeString, value)
  402. }
  403. if value, ok := _u.mutation.ResolvedEmail(); ok {
  404. _spec.SetField(pendingauthsession.FieldResolvedEmail, field.TypeString, value)
  405. }
  406. if value, ok := _u.mutation.RegistrationPasswordHash(); ok {
  407. _spec.SetField(pendingauthsession.FieldRegistrationPasswordHash, field.TypeString, value)
  408. }
  409. if value, ok := _u.mutation.UpstreamIdentityClaims(); ok {
  410. _spec.SetField(pendingauthsession.FieldUpstreamIdentityClaims, field.TypeJSON, value)
  411. }
  412. if value, ok := _u.mutation.LocalFlowState(); ok {
  413. _spec.SetField(pendingauthsession.FieldLocalFlowState, field.TypeJSON, value)
  414. }
  415. if value, ok := _u.mutation.BrowserSessionKey(); ok {
  416. _spec.SetField(pendingauthsession.FieldBrowserSessionKey, field.TypeString, value)
  417. }
  418. if value, ok := _u.mutation.CompletionCodeHash(); ok {
  419. _spec.SetField(pendingauthsession.FieldCompletionCodeHash, field.TypeString, value)
  420. }
  421. if value, ok := _u.mutation.CompletionCodeExpiresAt(); ok {
  422. _spec.SetField(pendingauthsession.FieldCompletionCodeExpiresAt, field.TypeTime, value)
  423. }
  424. if _u.mutation.CompletionCodeExpiresAtCleared() {
  425. _spec.ClearField(pendingauthsession.FieldCompletionCodeExpiresAt, field.TypeTime)
  426. }
  427. if value, ok := _u.mutation.EmailVerifiedAt(); ok {
  428. _spec.SetField(pendingauthsession.FieldEmailVerifiedAt, field.TypeTime, value)
  429. }
  430. if _u.mutation.EmailVerifiedAtCleared() {
  431. _spec.ClearField(pendingauthsession.FieldEmailVerifiedAt, field.TypeTime)
  432. }
  433. if value, ok := _u.mutation.PasswordVerifiedAt(); ok {
  434. _spec.SetField(pendingauthsession.FieldPasswordVerifiedAt, field.TypeTime, value)
  435. }
  436. if _u.mutation.PasswordVerifiedAtCleared() {
  437. _spec.ClearField(pendingauthsession.FieldPasswordVerifiedAt, field.TypeTime)
  438. }
  439. if value, ok := _u.mutation.TotpVerifiedAt(); ok {
  440. _spec.SetField(pendingauthsession.FieldTotpVerifiedAt, field.TypeTime, value)
  441. }
  442. if _u.mutation.TotpVerifiedAtCleared() {
  443. _spec.ClearField(pendingauthsession.FieldTotpVerifiedAt, field.TypeTime)
  444. }
  445. if value, ok := _u.mutation.ExpiresAt(); ok {
  446. _spec.SetField(pendingauthsession.FieldExpiresAt, field.TypeTime, value)
  447. }
  448. if value, ok := _u.mutation.ConsumedAt(); ok {
  449. _spec.SetField(pendingauthsession.FieldConsumedAt, field.TypeTime, value)
  450. }
  451. if _u.mutation.ConsumedAtCleared() {
  452. _spec.ClearField(pendingauthsession.FieldConsumedAt, field.TypeTime)
  453. }
  454. if _u.mutation.TargetUserCleared() {
  455. edge := &sqlgraph.EdgeSpec{
  456. Rel: sqlgraph.M2O,
  457. Inverse: true,
  458. Table: pendingauthsession.TargetUserTable,
  459. Columns: []string{pendingauthsession.TargetUserColumn},
  460. Bidi: false,
  461. Target: &sqlgraph.EdgeTarget{
  462. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  463. },
  464. }
  465. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  466. }
  467. if nodes := _u.mutation.TargetUserIDs(); len(nodes) > 0 {
  468. edge := &sqlgraph.EdgeSpec{
  469. Rel: sqlgraph.M2O,
  470. Inverse: true,
  471. Table: pendingauthsession.TargetUserTable,
  472. Columns: []string{pendingauthsession.TargetUserColumn},
  473. Bidi: false,
  474. Target: &sqlgraph.EdgeTarget{
  475. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  476. },
  477. }
  478. for _, k := range nodes {
  479. edge.Target.Nodes = append(edge.Target.Nodes, k)
  480. }
  481. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  482. }
  483. if _u.mutation.AdoptionDecisionCleared() {
  484. edge := &sqlgraph.EdgeSpec{
  485. Rel: sqlgraph.O2O,
  486. Inverse: false,
  487. Table: pendingauthsession.AdoptionDecisionTable,
  488. Columns: []string{pendingauthsession.AdoptionDecisionColumn},
  489. Bidi: false,
  490. Target: &sqlgraph.EdgeTarget{
  491. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  492. },
  493. }
  494. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  495. }
  496. if nodes := _u.mutation.AdoptionDecisionIDs(); len(nodes) > 0 {
  497. edge := &sqlgraph.EdgeSpec{
  498. Rel: sqlgraph.O2O,
  499. Inverse: false,
  500. Table: pendingauthsession.AdoptionDecisionTable,
  501. Columns: []string{pendingauthsession.AdoptionDecisionColumn},
  502. Bidi: false,
  503. Target: &sqlgraph.EdgeTarget{
  504. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  505. },
  506. }
  507. for _, k := range nodes {
  508. edge.Target.Nodes = append(edge.Target.Nodes, k)
  509. }
  510. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  511. }
  512. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  513. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  514. err = &NotFoundError{pendingauthsession.Label}
  515. } else if sqlgraph.IsConstraintError(err) {
  516. err = &ConstraintError{msg: err.Error(), wrap: err}
  517. }
  518. return 0, err
  519. }
  520. _u.mutation.done = true
  521. return _node, nil
  522. }
  523. // PendingAuthSessionUpdateOne is the builder for updating a single PendingAuthSession entity.
  524. type PendingAuthSessionUpdateOne struct {
  525. config
  526. fields []string
  527. hooks []Hook
  528. mutation *PendingAuthSessionMutation
  529. }
  530. // SetUpdatedAt sets the "updated_at" field.
  531. func (_u *PendingAuthSessionUpdateOne) SetUpdatedAt(v time.Time) *PendingAuthSessionUpdateOne {
  532. _u.mutation.SetUpdatedAt(v)
  533. return _u
  534. }
  535. // SetSessionToken sets the "session_token" field.
  536. func (_u *PendingAuthSessionUpdateOne) SetSessionToken(v string) *PendingAuthSessionUpdateOne {
  537. _u.mutation.SetSessionToken(v)
  538. return _u
  539. }
  540. // SetNillableSessionToken sets the "session_token" field if the given value is not nil.
  541. func (_u *PendingAuthSessionUpdateOne) SetNillableSessionToken(v *string) *PendingAuthSessionUpdateOne {
  542. if v != nil {
  543. _u.SetSessionToken(*v)
  544. }
  545. return _u
  546. }
  547. // SetIntent sets the "intent" field.
  548. func (_u *PendingAuthSessionUpdateOne) SetIntent(v string) *PendingAuthSessionUpdateOne {
  549. _u.mutation.SetIntent(v)
  550. return _u
  551. }
  552. // SetNillableIntent sets the "intent" field if the given value is not nil.
  553. func (_u *PendingAuthSessionUpdateOne) SetNillableIntent(v *string) *PendingAuthSessionUpdateOne {
  554. if v != nil {
  555. _u.SetIntent(*v)
  556. }
  557. return _u
  558. }
  559. // SetProviderType sets the "provider_type" field.
  560. func (_u *PendingAuthSessionUpdateOne) SetProviderType(v string) *PendingAuthSessionUpdateOne {
  561. _u.mutation.SetProviderType(v)
  562. return _u
  563. }
  564. // SetNillableProviderType sets the "provider_type" field if the given value is not nil.
  565. func (_u *PendingAuthSessionUpdateOne) SetNillableProviderType(v *string) *PendingAuthSessionUpdateOne {
  566. if v != nil {
  567. _u.SetProviderType(*v)
  568. }
  569. return _u
  570. }
  571. // SetProviderKey sets the "provider_key" field.
  572. func (_u *PendingAuthSessionUpdateOne) SetProviderKey(v string) *PendingAuthSessionUpdateOne {
  573. _u.mutation.SetProviderKey(v)
  574. return _u
  575. }
  576. // SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
  577. func (_u *PendingAuthSessionUpdateOne) SetNillableProviderKey(v *string) *PendingAuthSessionUpdateOne {
  578. if v != nil {
  579. _u.SetProviderKey(*v)
  580. }
  581. return _u
  582. }
  583. // SetProviderSubject sets the "provider_subject" field.
  584. func (_u *PendingAuthSessionUpdateOne) SetProviderSubject(v string) *PendingAuthSessionUpdateOne {
  585. _u.mutation.SetProviderSubject(v)
  586. return _u
  587. }
  588. // SetNillableProviderSubject sets the "provider_subject" field if the given value is not nil.
  589. func (_u *PendingAuthSessionUpdateOne) SetNillableProviderSubject(v *string) *PendingAuthSessionUpdateOne {
  590. if v != nil {
  591. _u.SetProviderSubject(*v)
  592. }
  593. return _u
  594. }
  595. // SetTargetUserID sets the "target_user_id" field.
  596. func (_u *PendingAuthSessionUpdateOne) SetTargetUserID(v int64) *PendingAuthSessionUpdateOne {
  597. _u.mutation.SetTargetUserID(v)
  598. return _u
  599. }
  600. // SetNillableTargetUserID sets the "target_user_id" field if the given value is not nil.
  601. func (_u *PendingAuthSessionUpdateOne) SetNillableTargetUserID(v *int64) *PendingAuthSessionUpdateOne {
  602. if v != nil {
  603. _u.SetTargetUserID(*v)
  604. }
  605. return _u
  606. }
  607. // ClearTargetUserID clears the value of the "target_user_id" field.
  608. func (_u *PendingAuthSessionUpdateOne) ClearTargetUserID() *PendingAuthSessionUpdateOne {
  609. _u.mutation.ClearTargetUserID()
  610. return _u
  611. }
  612. // SetRedirectTo sets the "redirect_to" field.
  613. func (_u *PendingAuthSessionUpdateOne) SetRedirectTo(v string) *PendingAuthSessionUpdateOne {
  614. _u.mutation.SetRedirectTo(v)
  615. return _u
  616. }
  617. // SetNillableRedirectTo sets the "redirect_to" field if the given value is not nil.
  618. func (_u *PendingAuthSessionUpdateOne) SetNillableRedirectTo(v *string) *PendingAuthSessionUpdateOne {
  619. if v != nil {
  620. _u.SetRedirectTo(*v)
  621. }
  622. return _u
  623. }
  624. // SetResolvedEmail sets the "resolved_email" field.
  625. func (_u *PendingAuthSessionUpdateOne) SetResolvedEmail(v string) *PendingAuthSessionUpdateOne {
  626. _u.mutation.SetResolvedEmail(v)
  627. return _u
  628. }
  629. // SetNillableResolvedEmail sets the "resolved_email" field if the given value is not nil.
  630. func (_u *PendingAuthSessionUpdateOne) SetNillableResolvedEmail(v *string) *PendingAuthSessionUpdateOne {
  631. if v != nil {
  632. _u.SetResolvedEmail(*v)
  633. }
  634. return _u
  635. }
  636. // SetRegistrationPasswordHash sets the "registration_password_hash" field.
  637. func (_u *PendingAuthSessionUpdateOne) SetRegistrationPasswordHash(v string) *PendingAuthSessionUpdateOne {
  638. _u.mutation.SetRegistrationPasswordHash(v)
  639. return _u
  640. }
  641. // SetNillableRegistrationPasswordHash sets the "registration_password_hash" field if the given value is not nil.
  642. func (_u *PendingAuthSessionUpdateOne) SetNillableRegistrationPasswordHash(v *string) *PendingAuthSessionUpdateOne {
  643. if v != nil {
  644. _u.SetRegistrationPasswordHash(*v)
  645. }
  646. return _u
  647. }
  648. // SetUpstreamIdentityClaims sets the "upstream_identity_claims" field.
  649. func (_u *PendingAuthSessionUpdateOne) SetUpstreamIdentityClaims(v map[string]interface{}) *PendingAuthSessionUpdateOne {
  650. _u.mutation.SetUpstreamIdentityClaims(v)
  651. return _u
  652. }
  653. // SetLocalFlowState sets the "local_flow_state" field.
  654. func (_u *PendingAuthSessionUpdateOne) SetLocalFlowState(v map[string]interface{}) *PendingAuthSessionUpdateOne {
  655. _u.mutation.SetLocalFlowState(v)
  656. return _u
  657. }
  658. // SetBrowserSessionKey sets the "browser_session_key" field.
  659. func (_u *PendingAuthSessionUpdateOne) SetBrowserSessionKey(v string) *PendingAuthSessionUpdateOne {
  660. _u.mutation.SetBrowserSessionKey(v)
  661. return _u
  662. }
  663. // SetNillableBrowserSessionKey sets the "browser_session_key" field if the given value is not nil.
  664. func (_u *PendingAuthSessionUpdateOne) SetNillableBrowserSessionKey(v *string) *PendingAuthSessionUpdateOne {
  665. if v != nil {
  666. _u.SetBrowserSessionKey(*v)
  667. }
  668. return _u
  669. }
  670. // SetCompletionCodeHash sets the "completion_code_hash" field.
  671. func (_u *PendingAuthSessionUpdateOne) SetCompletionCodeHash(v string) *PendingAuthSessionUpdateOne {
  672. _u.mutation.SetCompletionCodeHash(v)
  673. return _u
  674. }
  675. // SetNillableCompletionCodeHash sets the "completion_code_hash" field if the given value is not nil.
  676. func (_u *PendingAuthSessionUpdateOne) SetNillableCompletionCodeHash(v *string) *PendingAuthSessionUpdateOne {
  677. if v != nil {
  678. _u.SetCompletionCodeHash(*v)
  679. }
  680. return _u
  681. }
  682. // SetCompletionCodeExpiresAt sets the "completion_code_expires_at" field.
  683. func (_u *PendingAuthSessionUpdateOne) SetCompletionCodeExpiresAt(v time.Time) *PendingAuthSessionUpdateOne {
  684. _u.mutation.SetCompletionCodeExpiresAt(v)
  685. return _u
  686. }
  687. // SetNillableCompletionCodeExpiresAt sets the "completion_code_expires_at" field if the given value is not nil.
  688. func (_u *PendingAuthSessionUpdateOne) SetNillableCompletionCodeExpiresAt(v *time.Time) *PendingAuthSessionUpdateOne {
  689. if v != nil {
  690. _u.SetCompletionCodeExpiresAt(*v)
  691. }
  692. return _u
  693. }
  694. // ClearCompletionCodeExpiresAt clears the value of the "completion_code_expires_at" field.
  695. func (_u *PendingAuthSessionUpdateOne) ClearCompletionCodeExpiresAt() *PendingAuthSessionUpdateOne {
  696. _u.mutation.ClearCompletionCodeExpiresAt()
  697. return _u
  698. }
  699. // SetEmailVerifiedAt sets the "email_verified_at" field.
  700. func (_u *PendingAuthSessionUpdateOne) SetEmailVerifiedAt(v time.Time) *PendingAuthSessionUpdateOne {
  701. _u.mutation.SetEmailVerifiedAt(v)
  702. return _u
  703. }
  704. // SetNillableEmailVerifiedAt sets the "email_verified_at" field if the given value is not nil.
  705. func (_u *PendingAuthSessionUpdateOne) SetNillableEmailVerifiedAt(v *time.Time) *PendingAuthSessionUpdateOne {
  706. if v != nil {
  707. _u.SetEmailVerifiedAt(*v)
  708. }
  709. return _u
  710. }
  711. // ClearEmailVerifiedAt clears the value of the "email_verified_at" field.
  712. func (_u *PendingAuthSessionUpdateOne) ClearEmailVerifiedAt() *PendingAuthSessionUpdateOne {
  713. _u.mutation.ClearEmailVerifiedAt()
  714. return _u
  715. }
  716. // SetPasswordVerifiedAt sets the "password_verified_at" field.
  717. func (_u *PendingAuthSessionUpdateOne) SetPasswordVerifiedAt(v time.Time) *PendingAuthSessionUpdateOne {
  718. _u.mutation.SetPasswordVerifiedAt(v)
  719. return _u
  720. }
  721. // SetNillablePasswordVerifiedAt sets the "password_verified_at" field if the given value is not nil.
  722. func (_u *PendingAuthSessionUpdateOne) SetNillablePasswordVerifiedAt(v *time.Time) *PendingAuthSessionUpdateOne {
  723. if v != nil {
  724. _u.SetPasswordVerifiedAt(*v)
  725. }
  726. return _u
  727. }
  728. // ClearPasswordVerifiedAt clears the value of the "password_verified_at" field.
  729. func (_u *PendingAuthSessionUpdateOne) ClearPasswordVerifiedAt() *PendingAuthSessionUpdateOne {
  730. _u.mutation.ClearPasswordVerifiedAt()
  731. return _u
  732. }
  733. // SetTotpVerifiedAt sets the "totp_verified_at" field.
  734. func (_u *PendingAuthSessionUpdateOne) SetTotpVerifiedAt(v time.Time) *PendingAuthSessionUpdateOne {
  735. _u.mutation.SetTotpVerifiedAt(v)
  736. return _u
  737. }
  738. // SetNillableTotpVerifiedAt sets the "totp_verified_at" field if the given value is not nil.
  739. func (_u *PendingAuthSessionUpdateOne) SetNillableTotpVerifiedAt(v *time.Time) *PendingAuthSessionUpdateOne {
  740. if v != nil {
  741. _u.SetTotpVerifiedAt(*v)
  742. }
  743. return _u
  744. }
  745. // ClearTotpVerifiedAt clears the value of the "totp_verified_at" field.
  746. func (_u *PendingAuthSessionUpdateOne) ClearTotpVerifiedAt() *PendingAuthSessionUpdateOne {
  747. _u.mutation.ClearTotpVerifiedAt()
  748. return _u
  749. }
  750. // SetExpiresAt sets the "expires_at" field.
  751. func (_u *PendingAuthSessionUpdateOne) SetExpiresAt(v time.Time) *PendingAuthSessionUpdateOne {
  752. _u.mutation.SetExpiresAt(v)
  753. return _u
  754. }
  755. // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
  756. func (_u *PendingAuthSessionUpdateOne) SetNillableExpiresAt(v *time.Time) *PendingAuthSessionUpdateOne {
  757. if v != nil {
  758. _u.SetExpiresAt(*v)
  759. }
  760. return _u
  761. }
  762. // SetConsumedAt sets the "consumed_at" field.
  763. func (_u *PendingAuthSessionUpdateOne) SetConsumedAt(v time.Time) *PendingAuthSessionUpdateOne {
  764. _u.mutation.SetConsumedAt(v)
  765. return _u
  766. }
  767. // SetNillableConsumedAt sets the "consumed_at" field if the given value is not nil.
  768. func (_u *PendingAuthSessionUpdateOne) SetNillableConsumedAt(v *time.Time) *PendingAuthSessionUpdateOne {
  769. if v != nil {
  770. _u.SetConsumedAt(*v)
  771. }
  772. return _u
  773. }
  774. // ClearConsumedAt clears the value of the "consumed_at" field.
  775. func (_u *PendingAuthSessionUpdateOne) ClearConsumedAt() *PendingAuthSessionUpdateOne {
  776. _u.mutation.ClearConsumedAt()
  777. return _u
  778. }
  779. // SetTargetUser sets the "target_user" edge to the User entity.
  780. func (_u *PendingAuthSessionUpdateOne) SetTargetUser(v *User) *PendingAuthSessionUpdateOne {
  781. return _u.SetTargetUserID(v.ID)
  782. }
  783. // SetAdoptionDecisionID sets the "adoption_decision" edge to the IdentityAdoptionDecision entity by ID.
  784. func (_u *PendingAuthSessionUpdateOne) SetAdoptionDecisionID(id int64) *PendingAuthSessionUpdateOne {
  785. _u.mutation.SetAdoptionDecisionID(id)
  786. return _u
  787. }
  788. // SetNillableAdoptionDecisionID sets the "adoption_decision" edge to the IdentityAdoptionDecision entity by ID if the given value is not nil.
  789. func (_u *PendingAuthSessionUpdateOne) SetNillableAdoptionDecisionID(id *int64) *PendingAuthSessionUpdateOne {
  790. if id != nil {
  791. _u = _u.SetAdoptionDecisionID(*id)
  792. }
  793. return _u
  794. }
  795. // SetAdoptionDecision sets the "adoption_decision" edge to the IdentityAdoptionDecision entity.
  796. func (_u *PendingAuthSessionUpdateOne) SetAdoptionDecision(v *IdentityAdoptionDecision) *PendingAuthSessionUpdateOne {
  797. return _u.SetAdoptionDecisionID(v.ID)
  798. }
  799. // Mutation returns the PendingAuthSessionMutation object of the builder.
  800. func (_u *PendingAuthSessionUpdateOne) Mutation() *PendingAuthSessionMutation {
  801. return _u.mutation
  802. }
  803. // ClearTargetUser clears the "target_user" edge to the User entity.
  804. func (_u *PendingAuthSessionUpdateOne) ClearTargetUser() *PendingAuthSessionUpdateOne {
  805. _u.mutation.ClearTargetUser()
  806. return _u
  807. }
  808. // ClearAdoptionDecision clears the "adoption_decision" edge to the IdentityAdoptionDecision entity.
  809. func (_u *PendingAuthSessionUpdateOne) ClearAdoptionDecision() *PendingAuthSessionUpdateOne {
  810. _u.mutation.ClearAdoptionDecision()
  811. return _u
  812. }
  813. // Where appends a list predicates to the PendingAuthSessionUpdate builder.
  814. func (_u *PendingAuthSessionUpdateOne) Where(ps ...predicate.PendingAuthSession) *PendingAuthSessionUpdateOne {
  815. _u.mutation.Where(ps...)
  816. return _u
  817. }
  818. // Select allows selecting one or more fields (columns) of the returned entity.
  819. // The default is selecting all fields defined in the entity schema.
  820. func (_u *PendingAuthSessionUpdateOne) Select(field string, fields ...string) *PendingAuthSessionUpdateOne {
  821. _u.fields = append([]string{field}, fields...)
  822. return _u
  823. }
  824. // Save executes the query and returns the updated PendingAuthSession entity.
  825. func (_u *PendingAuthSessionUpdateOne) Save(ctx context.Context) (*PendingAuthSession, error) {
  826. _u.defaults()
  827. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  828. }
  829. // SaveX is like Save, but panics if an error occurs.
  830. func (_u *PendingAuthSessionUpdateOne) SaveX(ctx context.Context) *PendingAuthSession {
  831. node, err := _u.Save(ctx)
  832. if err != nil {
  833. panic(err)
  834. }
  835. return node
  836. }
  837. // Exec executes the query on the entity.
  838. func (_u *PendingAuthSessionUpdateOne) Exec(ctx context.Context) error {
  839. _, err := _u.Save(ctx)
  840. return err
  841. }
  842. // ExecX is like Exec, but panics if an error occurs.
  843. func (_u *PendingAuthSessionUpdateOne) ExecX(ctx context.Context) {
  844. if err := _u.Exec(ctx); err != nil {
  845. panic(err)
  846. }
  847. }
  848. // defaults sets the default values of the builder before save.
  849. func (_u *PendingAuthSessionUpdateOne) defaults() {
  850. if _, ok := _u.mutation.UpdatedAt(); !ok {
  851. v := pendingauthsession.UpdateDefaultUpdatedAt()
  852. _u.mutation.SetUpdatedAt(v)
  853. }
  854. }
  855. // check runs all checks and user-defined validators on the builder.
  856. func (_u *PendingAuthSessionUpdateOne) check() error {
  857. if v, ok := _u.mutation.SessionToken(); ok {
  858. if err := pendingauthsession.SessionTokenValidator(v); err != nil {
  859. return &ValidationError{Name: "session_token", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.session_token": %w`, err)}
  860. }
  861. }
  862. if v, ok := _u.mutation.Intent(); ok {
  863. if err := pendingauthsession.IntentValidator(v); err != nil {
  864. return &ValidationError{Name: "intent", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.intent": %w`, err)}
  865. }
  866. }
  867. if v, ok := _u.mutation.ProviderType(); ok {
  868. if err := pendingauthsession.ProviderTypeValidator(v); err != nil {
  869. return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.provider_type": %w`, err)}
  870. }
  871. }
  872. if v, ok := _u.mutation.ProviderKey(); ok {
  873. if err := pendingauthsession.ProviderKeyValidator(v); err != nil {
  874. return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.provider_key": %w`, err)}
  875. }
  876. }
  877. if v, ok := _u.mutation.ProviderSubject(); ok {
  878. if err := pendingauthsession.ProviderSubjectValidator(v); err != nil {
  879. return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "PendingAuthSession.provider_subject": %w`, err)}
  880. }
  881. }
  882. return nil
  883. }
  884. func (_u *PendingAuthSessionUpdateOne) sqlSave(ctx context.Context) (_node *PendingAuthSession, err error) {
  885. if err := _u.check(); err != nil {
  886. return _node, err
  887. }
  888. _spec := sqlgraph.NewUpdateSpec(pendingauthsession.Table, pendingauthsession.Columns, sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64))
  889. id, ok := _u.mutation.ID()
  890. if !ok {
  891. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PendingAuthSession.id" for update`)}
  892. }
  893. _spec.Node.ID.Value = id
  894. if fields := _u.fields; len(fields) > 0 {
  895. _spec.Node.Columns = make([]string, 0, len(fields))
  896. _spec.Node.Columns = append(_spec.Node.Columns, pendingauthsession.FieldID)
  897. for _, f := range fields {
  898. if !pendingauthsession.ValidColumn(f) {
  899. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  900. }
  901. if f != pendingauthsession.FieldID {
  902. _spec.Node.Columns = append(_spec.Node.Columns, f)
  903. }
  904. }
  905. }
  906. if ps := _u.mutation.predicates; len(ps) > 0 {
  907. _spec.Predicate = func(selector *sql.Selector) {
  908. for i := range ps {
  909. ps[i](selector)
  910. }
  911. }
  912. }
  913. if value, ok := _u.mutation.UpdatedAt(); ok {
  914. _spec.SetField(pendingauthsession.FieldUpdatedAt, field.TypeTime, value)
  915. }
  916. if value, ok := _u.mutation.SessionToken(); ok {
  917. _spec.SetField(pendingauthsession.FieldSessionToken, field.TypeString, value)
  918. }
  919. if value, ok := _u.mutation.Intent(); ok {
  920. _spec.SetField(pendingauthsession.FieldIntent, field.TypeString, value)
  921. }
  922. if value, ok := _u.mutation.ProviderType(); ok {
  923. _spec.SetField(pendingauthsession.FieldProviderType, field.TypeString, value)
  924. }
  925. if value, ok := _u.mutation.ProviderKey(); ok {
  926. _spec.SetField(pendingauthsession.FieldProviderKey, field.TypeString, value)
  927. }
  928. if value, ok := _u.mutation.ProviderSubject(); ok {
  929. _spec.SetField(pendingauthsession.FieldProviderSubject, field.TypeString, value)
  930. }
  931. if value, ok := _u.mutation.RedirectTo(); ok {
  932. _spec.SetField(pendingauthsession.FieldRedirectTo, field.TypeString, value)
  933. }
  934. if value, ok := _u.mutation.ResolvedEmail(); ok {
  935. _spec.SetField(pendingauthsession.FieldResolvedEmail, field.TypeString, value)
  936. }
  937. if value, ok := _u.mutation.RegistrationPasswordHash(); ok {
  938. _spec.SetField(pendingauthsession.FieldRegistrationPasswordHash, field.TypeString, value)
  939. }
  940. if value, ok := _u.mutation.UpstreamIdentityClaims(); ok {
  941. _spec.SetField(pendingauthsession.FieldUpstreamIdentityClaims, field.TypeJSON, value)
  942. }
  943. if value, ok := _u.mutation.LocalFlowState(); ok {
  944. _spec.SetField(pendingauthsession.FieldLocalFlowState, field.TypeJSON, value)
  945. }
  946. if value, ok := _u.mutation.BrowserSessionKey(); ok {
  947. _spec.SetField(pendingauthsession.FieldBrowserSessionKey, field.TypeString, value)
  948. }
  949. if value, ok := _u.mutation.CompletionCodeHash(); ok {
  950. _spec.SetField(pendingauthsession.FieldCompletionCodeHash, field.TypeString, value)
  951. }
  952. if value, ok := _u.mutation.CompletionCodeExpiresAt(); ok {
  953. _spec.SetField(pendingauthsession.FieldCompletionCodeExpiresAt, field.TypeTime, value)
  954. }
  955. if _u.mutation.CompletionCodeExpiresAtCleared() {
  956. _spec.ClearField(pendingauthsession.FieldCompletionCodeExpiresAt, field.TypeTime)
  957. }
  958. if value, ok := _u.mutation.EmailVerifiedAt(); ok {
  959. _spec.SetField(pendingauthsession.FieldEmailVerifiedAt, field.TypeTime, value)
  960. }
  961. if _u.mutation.EmailVerifiedAtCleared() {
  962. _spec.ClearField(pendingauthsession.FieldEmailVerifiedAt, field.TypeTime)
  963. }
  964. if value, ok := _u.mutation.PasswordVerifiedAt(); ok {
  965. _spec.SetField(pendingauthsession.FieldPasswordVerifiedAt, field.TypeTime, value)
  966. }
  967. if _u.mutation.PasswordVerifiedAtCleared() {
  968. _spec.ClearField(pendingauthsession.FieldPasswordVerifiedAt, field.TypeTime)
  969. }
  970. if value, ok := _u.mutation.TotpVerifiedAt(); ok {
  971. _spec.SetField(pendingauthsession.FieldTotpVerifiedAt, field.TypeTime, value)
  972. }
  973. if _u.mutation.TotpVerifiedAtCleared() {
  974. _spec.ClearField(pendingauthsession.FieldTotpVerifiedAt, field.TypeTime)
  975. }
  976. if value, ok := _u.mutation.ExpiresAt(); ok {
  977. _spec.SetField(pendingauthsession.FieldExpiresAt, field.TypeTime, value)
  978. }
  979. if value, ok := _u.mutation.ConsumedAt(); ok {
  980. _spec.SetField(pendingauthsession.FieldConsumedAt, field.TypeTime, value)
  981. }
  982. if _u.mutation.ConsumedAtCleared() {
  983. _spec.ClearField(pendingauthsession.FieldConsumedAt, field.TypeTime)
  984. }
  985. if _u.mutation.TargetUserCleared() {
  986. edge := &sqlgraph.EdgeSpec{
  987. Rel: sqlgraph.M2O,
  988. Inverse: true,
  989. Table: pendingauthsession.TargetUserTable,
  990. Columns: []string{pendingauthsession.TargetUserColumn},
  991. Bidi: false,
  992. Target: &sqlgraph.EdgeTarget{
  993. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  994. },
  995. }
  996. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  997. }
  998. if nodes := _u.mutation.TargetUserIDs(); len(nodes) > 0 {
  999. edge := &sqlgraph.EdgeSpec{
  1000. Rel: sqlgraph.M2O,
  1001. Inverse: true,
  1002. Table: pendingauthsession.TargetUserTable,
  1003. Columns: []string{pendingauthsession.TargetUserColumn},
  1004. Bidi: false,
  1005. Target: &sqlgraph.EdgeTarget{
  1006. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  1007. },
  1008. }
  1009. for _, k := range nodes {
  1010. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1011. }
  1012. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1013. }
  1014. if _u.mutation.AdoptionDecisionCleared() {
  1015. edge := &sqlgraph.EdgeSpec{
  1016. Rel: sqlgraph.O2O,
  1017. Inverse: false,
  1018. Table: pendingauthsession.AdoptionDecisionTable,
  1019. Columns: []string{pendingauthsession.AdoptionDecisionColumn},
  1020. Bidi: false,
  1021. Target: &sqlgraph.EdgeTarget{
  1022. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  1023. },
  1024. }
  1025. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1026. }
  1027. if nodes := _u.mutation.AdoptionDecisionIDs(); len(nodes) > 0 {
  1028. edge := &sqlgraph.EdgeSpec{
  1029. Rel: sqlgraph.O2O,
  1030. Inverse: false,
  1031. Table: pendingauthsession.AdoptionDecisionTable,
  1032. Columns: []string{pendingauthsession.AdoptionDecisionColumn},
  1033. Bidi: false,
  1034. Target: &sqlgraph.EdgeTarget{
  1035. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  1036. },
  1037. }
  1038. for _, k := range nodes {
  1039. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1040. }
  1041. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1042. }
  1043. _node = &PendingAuthSession{config: _u.config}
  1044. _spec.Assign = _node.assignValues
  1045. _spec.ScanValues = _node.scanValues
  1046. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  1047. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1048. err = &NotFoundError{pendingauthsession.Label}
  1049. } else if sqlgraph.IsConstraintError(err) {
  1050. err = &ConstraintError{msg: err.Error(), wrap: err}
  1051. }
  1052. return nil, err
  1053. }
  1054. _u.mutation.done = true
  1055. return _node, nil
  1056. }