whatsapp_update.go 35 KB

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