whatsapp_update.go 33 KB

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