whatsapp_update.go 30 KB

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