whatsapp_update.go 35 KB

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