whatsapp_update.go 36 KB

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