agent_update.go 35 KB

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