whatsapp_update.go 37 KB

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