employee_update.go 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  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/employee"
  9. "wechat-api/ent/predicate"
  10. "wechat-api/ent/tutorial"
  11. "wechat-api/ent/workexperience"
  12. "entgo.io/ent/dialect/sql"
  13. "entgo.io/ent/dialect/sql/sqlgraph"
  14. "entgo.io/ent/schema/field"
  15. )
  16. // EmployeeUpdate is the builder for updating Employee entities.
  17. type EmployeeUpdate struct {
  18. config
  19. hooks []Hook
  20. mutation *EmployeeMutation
  21. }
  22. // Where appends a list predicates to the EmployeeUpdate builder.
  23. func (eu *EmployeeUpdate) Where(ps ...predicate.Employee) *EmployeeUpdate {
  24. eu.mutation.Where(ps...)
  25. return eu
  26. }
  27. // SetUpdatedAt sets the "updated_at" field.
  28. func (eu *EmployeeUpdate) SetUpdatedAt(t time.Time) *EmployeeUpdate {
  29. eu.mutation.SetUpdatedAt(t)
  30. return eu
  31. }
  32. // SetDeletedAt sets the "deleted_at" field.
  33. func (eu *EmployeeUpdate) SetDeletedAt(t time.Time) *EmployeeUpdate {
  34. eu.mutation.SetDeletedAt(t)
  35. return eu
  36. }
  37. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  38. func (eu *EmployeeUpdate) SetNillableDeletedAt(t *time.Time) *EmployeeUpdate {
  39. if t != nil {
  40. eu.SetDeletedAt(*t)
  41. }
  42. return eu
  43. }
  44. // ClearDeletedAt clears the value of the "deleted_at" field.
  45. func (eu *EmployeeUpdate) ClearDeletedAt() *EmployeeUpdate {
  46. eu.mutation.ClearDeletedAt()
  47. return eu
  48. }
  49. // SetTitle sets the "title" field.
  50. func (eu *EmployeeUpdate) SetTitle(s string) *EmployeeUpdate {
  51. eu.mutation.SetTitle(s)
  52. return eu
  53. }
  54. // SetNillableTitle sets the "title" field if the given value is not nil.
  55. func (eu *EmployeeUpdate) SetNillableTitle(s *string) *EmployeeUpdate {
  56. if s != nil {
  57. eu.SetTitle(*s)
  58. }
  59. return eu
  60. }
  61. // SetAvatar sets the "avatar" field.
  62. func (eu *EmployeeUpdate) SetAvatar(s string) *EmployeeUpdate {
  63. eu.mutation.SetAvatar(s)
  64. return eu
  65. }
  66. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  67. func (eu *EmployeeUpdate) SetNillableAvatar(s *string) *EmployeeUpdate {
  68. if s != nil {
  69. eu.SetAvatar(*s)
  70. }
  71. return eu
  72. }
  73. // SetTags sets the "tags" field.
  74. func (eu *EmployeeUpdate) SetTags(s string) *EmployeeUpdate {
  75. eu.mutation.SetTags(s)
  76. return eu
  77. }
  78. // SetNillableTags sets the "tags" field if the given value is not nil.
  79. func (eu *EmployeeUpdate) SetNillableTags(s *string) *EmployeeUpdate {
  80. if s != nil {
  81. eu.SetTags(*s)
  82. }
  83. return eu
  84. }
  85. // SetHireCount sets the "hire_count" field.
  86. func (eu *EmployeeUpdate) SetHireCount(i int) *EmployeeUpdate {
  87. eu.mutation.ResetHireCount()
  88. eu.mutation.SetHireCount(i)
  89. return eu
  90. }
  91. // SetNillableHireCount sets the "hire_count" field if the given value is not nil.
  92. func (eu *EmployeeUpdate) SetNillableHireCount(i *int) *EmployeeUpdate {
  93. if i != nil {
  94. eu.SetHireCount(*i)
  95. }
  96. return eu
  97. }
  98. // AddHireCount adds i to the "hire_count" field.
  99. func (eu *EmployeeUpdate) AddHireCount(i int) *EmployeeUpdate {
  100. eu.mutation.AddHireCount(i)
  101. return eu
  102. }
  103. // SetServiceCount sets the "service_count" field.
  104. func (eu *EmployeeUpdate) SetServiceCount(i int) *EmployeeUpdate {
  105. eu.mutation.ResetServiceCount()
  106. eu.mutation.SetServiceCount(i)
  107. return eu
  108. }
  109. // SetNillableServiceCount sets the "service_count" field if the given value is not nil.
  110. func (eu *EmployeeUpdate) SetNillableServiceCount(i *int) *EmployeeUpdate {
  111. if i != nil {
  112. eu.SetServiceCount(*i)
  113. }
  114. return eu
  115. }
  116. // AddServiceCount adds i to the "service_count" field.
  117. func (eu *EmployeeUpdate) AddServiceCount(i int) *EmployeeUpdate {
  118. eu.mutation.AddServiceCount(i)
  119. return eu
  120. }
  121. // SetAchievementCount sets the "achievement_count" field.
  122. func (eu *EmployeeUpdate) SetAchievementCount(i int) *EmployeeUpdate {
  123. eu.mutation.ResetAchievementCount()
  124. eu.mutation.SetAchievementCount(i)
  125. return eu
  126. }
  127. // SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
  128. func (eu *EmployeeUpdate) SetNillableAchievementCount(i *int) *EmployeeUpdate {
  129. if i != nil {
  130. eu.SetAchievementCount(*i)
  131. }
  132. return eu
  133. }
  134. // AddAchievementCount adds i to the "achievement_count" field.
  135. func (eu *EmployeeUpdate) AddAchievementCount(i int) *EmployeeUpdate {
  136. eu.mutation.AddAchievementCount(i)
  137. return eu
  138. }
  139. // SetIntro sets the "intro" field.
  140. func (eu *EmployeeUpdate) SetIntro(s string) *EmployeeUpdate {
  141. eu.mutation.SetIntro(s)
  142. return eu
  143. }
  144. // SetNillableIntro sets the "intro" field if the given value is not nil.
  145. func (eu *EmployeeUpdate) SetNillableIntro(s *string) *EmployeeUpdate {
  146. if s != nil {
  147. eu.SetIntro(*s)
  148. }
  149. return eu
  150. }
  151. // SetEstimate sets the "estimate" field.
  152. func (eu *EmployeeUpdate) SetEstimate(s string) *EmployeeUpdate {
  153. eu.mutation.SetEstimate(s)
  154. return eu
  155. }
  156. // SetNillableEstimate sets the "estimate" field if the given value is not nil.
  157. func (eu *EmployeeUpdate) SetNillableEstimate(s *string) *EmployeeUpdate {
  158. if s != nil {
  159. eu.SetEstimate(*s)
  160. }
  161. return eu
  162. }
  163. // SetSkill sets the "skill" field.
  164. func (eu *EmployeeUpdate) SetSkill(s string) *EmployeeUpdate {
  165. eu.mutation.SetSkill(s)
  166. return eu
  167. }
  168. // SetNillableSkill sets the "skill" field if the given value is not nil.
  169. func (eu *EmployeeUpdate) SetNillableSkill(s *string) *EmployeeUpdate {
  170. if s != nil {
  171. eu.SetSkill(*s)
  172. }
  173. return eu
  174. }
  175. // SetAbilityType sets the "ability_type" field.
  176. func (eu *EmployeeUpdate) SetAbilityType(s string) *EmployeeUpdate {
  177. eu.mutation.SetAbilityType(s)
  178. return eu
  179. }
  180. // SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
  181. func (eu *EmployeeUpdate) SetNillableAbilityType(s *string) *EmployeeUpdate {
  182. if s != nil {
  183. eu.SetAbilityType(*s)
  184. }
  185. return eu
  186. }
  187. // SetScene sets the "scene" field.
  188. func (eu *EmployeeUpdate) SetScene(s string) *EmployeeUpdate {
  189. eu.mutation.SetScene(s)
  190. return eu
  191. }
  192. // SetNillableScene sets the "scene" field if the given value is not nil.
  193. func (eu *EmployeeUpdate) SetNillableScene(s *string) *EmployeeUpdate {
  194. if s != nil {
  195. eu.SetScene(*s)
  196. }
  197. return eu
  198. }
  199. // SetSwitchIn sets the "switch_in" field.
  200. func (eu *EmployeeUpdate) SetSwitchIn(s string) *EmployeeUpdate {
  201. eu.mutation.SetSwitchIn(s)
  202. return eu
  203. }
  204. // SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
  205. func (eu *EmployeeUpdate) SetNillableSwitchIn(s *string) *EmployeeUpdate {
  206. if s != nil {
  207. eu.SetSwitchIn(*s)
  208. }
  209. return eu
  210. }
  211. // SetVideoURL sets the "video_url" field.
  212. func (eu *EmployeeUpdate) SetVideoURL(s string) *EmployeeUpdate {
  213. eu.mutation.SetVideoURL(s)
  214. return eu
  215. }
  216. // SetNillableVideoURL sets the "video_url" field if the given value is not nil.
  217. func (eu *EmployeeUpdate) SetNillableVideoURL(s *string) *EmployeeUpdate {
  218. if s != nil {
  219. eu.SetVideoURL(*s)
  220. }
  221. return eu
  222. }
  223. // SetOrganizationID sets the "organization_id" field.
  224. func (eu *EmployeeUpdate) SetOrganizationID(u uint64) *EmployeeUpdate {
  225. eu.mutation.ResetOrganizationID()
  226. eu.mutation.SetOrganizationID(u)
  227. return eu
  228. }
  229. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  230. func (eu *EmployeeUpdate) SetNillableOrganizationID(u *uint64) *EmployeeUpdate {
  231. if u != nil {
  232. eu.SetOrganizationID(*u)
  233. }
  234. return eu
  235. }
  236. // AddOrganizationID adds u to the "organization_id" field.
  237. func (eu *EmployeeUpdate) AddOrganizationID(u int64) *EmployeeUpdate {
  238. eu.mutation.AddOrganizationID(u)
  239. return eu
  240. }
  241. // SetCategoryID sets the "category_id" field.
  242. func (eu *EmployeeUpdate) SetCategoryID(u uint64) *EmployeeUpdate {
  243. eu.mutation.ResetCategoryID()
  244. eu.mutation.SetCategoryID(u)
  245. return eu
  246. }
  247. // SetNillableCategoryID sets the "category_id" field if the given value is not nil.
  248. func (eu *EmployeeUpdate) SetNillableCategoryID(u *uint64) *EmployeeUpdate {
  249. if u != nil {
  250. eu.SetCategoryID(*u)
  251. }
  252. return eu
  253. }
  254. // AddCategoryID adds u to the "category_id" field.
  255. func (eu *EmployeeUpdate) AddCategoryID(u int64) *EmployeeUpdate {
  256. eu.mutation.AddCategoryID(u)
  257. return eu
  258. }
  259. // SetAPIBase sets the "api_base" field.
  260. func (eu *EmployeeUpdate) SetAPIBase(s string) *EmployeeUpdate {
  261. eu.mutation.SetAPIBase(s)
  262. return eu
  263. }
  264. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  265. func (eu *EmployeeUpdate) SetNillableAPIBase(s *string) *EmployeeUpdate {
  266. if s != nil {
  267. eu.SetAPIBase(*s)
  268. }
  269. return eu
  270. }
  271. // SetAPIKey sets the "api_key" field.
  272. func (eu *EmployeeUpdate) SetAPIKey(s string) *EmployeeUpdate {
  273. eu.mutation.SetAPIKey(s)
  274. return eu
  275. }
  276. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  277. func (eu *EmployeeUpdate) SetNillableAPIKey(s *string) *EmployeeUpdate {
  278. if s != nil {
  279. eu.SetAPIKey(*s)
  280. }
  281. return eu
  282. }
  283. // SetAiInfo sets the "ai_info" field.
  284. func (eu *EmployeeUpdate) SetAiInfo(s string) *EmployeeUpdate {
  285. eu.mutation.SetAiInfo(s)
  286. return eu
  287. }
  288. // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
  289. func (eu *EmployeeUpdate) SetNillableAiInfo(s *string) *EmployeeUpdate {
  290. if s != nil {
  291. eu.SetAiInfo(*s)
  292. }
  293. return eu
  294. }
  295. // ClearAiInfo clears the value of the "ai_info" field.
  296. func (eu *EmployeeUpdate) ClearAiInfo() *EmployeeUpdate {
  297. eu.mutation.ClearAiInfo()
  298. return eu
  299. }
  300. // SetIsVip sets the "is_vip" field.
  301. func (eu *EmployeeUpdate) SetIsVip(i int) *EmployeeUpdate {
  302. eu.mutation.ResetIsVip()
  303. eu.mutation.SetIsVip(i)
  304. return eu
  305. }
  306. // SetNillableIsVip sets the "is_vip" field if the given value is not nil.
  307. func (eu *EmployeeUpdate) SetNillableIsVip(i *int) *EmployeeUpdate {
  308. if i != nil {
  309. eu.SetIsVip(*i)
  310. }
  311. return eu
  312. }
  313. // AddIsVip adds i to the "is_vip" field.
  314. func (eu *EmployeeUpdate) AddIsVip(i int) *EmployeeUpdate {
  315. eu.mutation.AddIsVip(i)
  316. return eu
  317. }
  318. // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
  319. func (eu *EmployeeUpdate) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
  320. eu.mutation.AddEmWorkExperienceIDs(ids...)
  321. return eu
  322. }
  323. // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
  324. func (eu *EmployeeUpdate) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
  325. ids := make([]uint64, len(w))
  326. for i := range w {
  327. ids[i] = w[i].ID
  328. }
  329. return eu.AddEmWorkExperienceIDs(ids...)
  330. }
  331. // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
  332. func (eu *EmployeeUpdate) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
  333. eu.mutation.AddEmTutorialIDs(ids...)
  334. return eu
  335. }
  336. // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
  337. func (eu *EmployeeUpdate) AddEmTutorial(t ...*Tutorial) *EmployeeUpdate {
  338. ids := make([]uint64, len(t))
  339. for i := range t {
  340. ids[i] = t[i].ID
  341. }
  342. return eu.AddEmTutorialIDs(ids...)
  343. }
  344. // Mutation returns the EmployeeMutation object of the builder.
  345. func (eu *EmployeeUpdate) Mutation() *EmployeeMutation {
  346. return eu.mutation
  347. }
  348. // ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
  349. func (eu *EmployeeUpdate) ClearEmWorkExperiences() *EmployeeUpdate {
  350. eu.mutation.ClearEmWorkExperiences()
  351. return eu
  352. }
  353. // RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
  354. func (eu *EmployeeUpdate) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
  355. eu.mutation.RemoveEmWorkExperienceIDs(ids...)
  356. return eu
  357. }
  358. // RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
  359. func (eu *EmployeeUpdate) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
  360. ids := make([]uint64, len(w))
  361. for i := range w {
  362. ids[i] = w[i].ID
  363. }
  364. return eu.RemoveEmWorkExperienceIDs(ids...)
  365. }
  366. // ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
  367. func (eu *EmployeeUpdate) ClearEmTutorial() *EmployeeUpdate {
  368. eu.mutation.ClearEmTutorial()
  369. return eu
  370. }
  371. // RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
  372. func (eu *EmployeeUpdate) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
  373. eu.mutation.RemoveEmTutorialIDs(ids...)
  374. return eu
  375. }
  376. // RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
  377. func (eu *EmployeeUpdate) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdate {
  378. ids := make([]uint64, len(t))
  379. for i := range t {
  380. ids[i] = t[i].ID
  381. }
  382. return eu.RemoveEmTutorialIDs(ids...)
  383. }
  384. // Save executes the query and returns the number of nodes affected by the update operation.
  385. func (eu *EmployeeUpdate) Save(ctx context.Context) (int, error) {
  386. if err := eu.defaults(); err != nil {
  387. return 0, err
  388. }
  389. return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
  390. }
  391. // SaveX is like Save, but panics if an error occurs.
  392. func (eu *EmployeeUpdate) SaveX(ctx context.Context) int {
  393. affected, err := eu.Save(ctx)
  394. if err != nil {
  395. panic(err)
  396. }
  397. return affected
  398. }
  399. // Exec executes the query.
  400. func (eu *EmployeeUpdate) Exec(ctx context.Context) error {
  401. _, err := eu.Save(ctx)
  402. return err
  403. }
  404. // ExecX is like Exec, but panics if an error occurs.
  405. func (eu *EmployeeUpdate) ExecX(ctx context.Context) {
  406. if err := eu.Exec(ctx); err != nil {
  407. panic(err)
  408. }
  409. }
  410. // defaults sets the default values of the builder before save.
  411. func (eu *EmployeeUpdate) defaults() error {
  412. if _, ok := eu.mutation.UpdatedAt(); !ok {
  413. if employee.UpdateDefaultUpdatedAt == nil {
  414. return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  415. }
  416. v := employee.UpdateDefaultUpdatedAt()
  417. eu.mutation.SetUpdatedAt(v)
  418. }
  419. return nil
  420. }
  421. // check runs all checks and user-defined validators on the builder.
  422. func (eu *EmployeeUpdate) check() error {
  423. if v, ok := eu.mutation.Title(); ok {
  424. if err := employee.TitleValidator(v); err != nil {
  425. return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
  426. }
  427. }
  428. if v, ok := eu.mutation.Avatar(); ok {
  429. if err := employee.AvatarValidator(v); err != nil {
  430. return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "Employee.avatar": %w`, err)}
  431. }
  432. }
  433. if v, ok := eu.mutation.Tags(); ok {
  434. if err := employee.TagsValidator(v); err != nil {
  435. return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Employee.tags": %w`, err)}
  436. }
  437. }
  438. if v, ok := eu.mutation.HireCount(); ok {
  439. if err := employee.HireCountValidator(v); err != nil {
  440. return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
  441. }
  442. }
  443. if v, ok := eu.mutation.ServiceCount(); ok {
  444. if err := employee.ServiceCountValidator(v); err != nil {
  445. return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
  446. }
  447. }
  448. if v, ok := eu.mutation.AchievementCount(); ok {
  449. if err := employee.AchievementCountValidator(v); err != nil {
  450. return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
  451. }
  452. }
  453. if v, ok := eu.mutation.Intro(); ok {
  454. if err := employee.IntroValidator(v); err != nil {
  455. return &ValidationError{Name: "intro", err: fmt.Errorf(`ent: validator failed for field "Employee.intro": %w`, err)}
  456. }
  457. }
  458. if v, ok := eu.mutation.Estimate(); ok {
  459. if err := employee.EstimateValidator(v); err != nil {
  460. return &ValidationError{Name: "estimate", err: fmt.Errorf(`ent: validator failed for field "Employee.estimate": %w`, err)}
  461. }
  462. }
  463. if v, ok := eu.mutation.Skill(); ok {
  464. if err := employee.SkillValidator(v); err != nil {
  465. return &ValidationError{Name: "skill", err: fmt.Errorf(`ent: validator failed for field "Employee.skill": %w`, err)}
  466. }
  467. }
  468. if v, ok := eu.mutation.VideoURL(); ok {
  469. if err := employee.VideoURLValidator(v); err != nil {
  470. return &ValidationError{Name: "video_url", err: fmt.Errorf(`ent: validator failed for field "Employee.video_url": %w`, err)}
  471. }
  472. }
  473. if v, ok := eu.mutation.OrganizationID(); ok {
  474. if err := employee.OrganizationIDValidator(v); err != nil {
  475. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
  476. }
  477. }
  478. if v, ok := eu.mutation.CategoryID(); ok {
  479. if err := employee.CategoryIDValidator(v); err != nil {
  480. return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
  481. }
  482. }
  483. return nil
  484. }
  485. func (eu *EmployeeUpdate) sqlSave(ctx context.Context) (n int, err error) {
  486. if err := eu.check(); err != nil {
  487. return n, err
  488. }
  489. _spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
  490. if ps := eu.mutation.predicates; len(ps) > 0 {
  491. _spec.Predicate = func(selector *sql.Selector) {
  492. for i := range ps {
  493. ps[i](selector)
  494. }
  495. }
  496. }
  497. if value, ok := eu.mutation.UpdatedAt(); ok {
  498. _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
  499. }
  500. if value, ok := eu.mutation.DeletedAt(); ok {
  501. _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
  502. }
  503. if eu.mutation.DeletedAtCleared() {
  504. _spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
  505. }
  506. if value, ok := eu.mutation.Title(); ok {
  507. _spec.SetField(employee.FieldTitle, field.TypeString, value)
  508. }
  509. if value, ok := eu.mutation.Avatar(); ok {
  510. _spec.SetField(employee.FieldAvatar, field.TypeString, value)
  511. }
  512. if value, ok := eu.mutation.Tags(); ok {
  513. _spec.SetField(employee.FieldTags, field.TypeString, value)
  514. }
  515. if value, ok := eu.mutation.HireCount(); ok {
  516. _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
  517. }
  518. if value, ok := eu.mutation.AddedHireCount(); ok {
  519. _spec.AddField(employee.FieldHireCount, field.TypeInt, value)
  520. }
  521. if value, ok := eu.mutation.ServiceCount(); ok {
  522. _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
  523. }
  524. if value, ok := eu.mutation.AddedServiceCount(); ok {
  525. _spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
  526. }
  527. if value, ok := eu.mutation.AchievementCount(); ok {
  528. _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
  529. }
  530. if value, ok := eu.mutation.AddedAchievementCount(); ok {
  531. _spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
  532. }
  533. if value, ok := eu.mutation.Intro(); ok {
  534. _spec.SetField(employee.FieldIntro, field.TypeString, value)
  535. }
  536. if value, ok := eu.mutation.Estimate(); ok {
  537. _spec.SetField(employee.FieldEstimate, field.TypeString, value)
  538. }
  539. if value, ok := eu.mutation.Skill(); ok {
  540. _spec.SetField(employee.FieldSkill, field.TypeString, value)
  541. }
  542. if value, ok := eu.mutation.AbilityType(); ok {
  543. _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
  544. }
  545. if value, ok := eu.mutation.Scene(); ok {
  546. _spec.SetField(employee.FieldScene, field.TypeString, value)
  547. }
  548. if value, ok := eu.mutation.SwitchIn(); ok {
  549. _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
  550. }
  551. if value, ok := eu.mutation.VideoURL(); ok {
  552. _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
  553. }
  554. if value, ok := eu.mutation.OrganizationID(); ok {
  555. _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
  556. }
  557. if value, ok := eu.mutation.AddedOrganizationID(); ok {
  558. _spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
  559. }
  560. if value, ok := eu.mutation.CategoryID(); ok {
  561. _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
  562. }
  563. if value, ok := eu.mutation.AddedCategoryID(); ok {
  564. _spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
  565. }
  566. if value, ok := eu.mutation.APIBase(); ok {
  567. _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
  568. }
  569. if value, ok := eu.mutation.APIKey(); ok {
  570. _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
  571. }
  572. if value, ok := eu.mutation.AiInfo(); ok {
  573. _spec.SetField(employee.FieldAiInfo, field.TypeString, value)
  574. }
  575. if eu.mutation.AiInfoCleared() {
  576. _spec.ClearField(employee.FieldAiInfo, field.TypeString)
  577. }
  578. if value, ok := eu.mutation.IsVip(); ok {
  579. _spec.SetField(employee.FieldIsVip, field.TypeInt, value)
  580. }
  581. if value, ok := eu.mutation.AddedIsVip(); ok {
  582. _spec.AddField(employee.FieldIsVip, field.TypeInt, value)
  583. }
  584. if eu.mutation.EmWorkExperiencesCleared() {
  585. edge := &sqlgraph.EdgeSpec{
  586. Rel: sqlgraph.O2M,
  587. Inverse: false,
  588. Table: employee.EmWorkExperiencesTable,
  589. Columns: []string{employee.EmWorkExperiencesColumn},
  590. Bidi: false,
  591. Target: &sqlgraph.EdgeTarget{
  592. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  593. },
  594. }
  595. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  596. }
  597. if nodes := eu.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !eu.mutation.EmWorkExperiencesCleared() {
  598. edge := &sqlgraph.EdgeSpec{
  599. Rel: sqlgraph.O2M,
  600. Inverse: false,
  601. Table: employee.EmWorkExperiencesTable,
  602. Columns: []string{employee.EmWorkExperiencesColumn},
  603. Bidi: false,
  604. Target: &sqlgraph.EdgeTarget{
  605. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  606. },
  607. }
  608. for _, k := range nodes {
  609. edge.Target.Nodes = append(edge.Target.Nodes, k)
  610. }
  611. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  612. }
  613. if nodes := eu.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
  614. edge := &sqlgraph.EdgeSpec{
  615. Rel: sqlgraph.O2M,
  616. Inverse: false,
  617. Table: employee.EmWorkExperiencesTable,
  618. Columns: []string{employee.EmWorkExperiencesColumn},
  619. Bidi: false,
  620. Target: &sqlgraph.EdgeTarget{
  621. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  622. },
  623. }
  624. for _, k := range nodes {
  625. edge.Target.Nodes = append(edge.Target.Nodes, k)
  626. }
  627. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  628. }
  629. if eu.mutation.EmTutorialCleared() {
  630. edge := &sqlgraph.EdgeSpec{
  631. Rel: sqlgraph.O2M,
  632. Inverse: false,
  633. Table: employee.EmTutorialTable,
  634. Columns: []string{employee.EmTutorialColumn},
  635. Bidi: false,
  636. Target: &sqlgraph.EdgeTarget{
  637. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  638. },
  639. }
  640. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  641. }
  642. if nodes := eu.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !eu.mutation.EmTutorialCleared() {
  643. edge := &sqlgraph.EdgeSpec{
  644. Rel: sqlgraph.O2M,
  645. Inverse: false,
  646. Table: employee.EmTutorialTable,
  647. Columns: []string{employee.EmTutorialColumn},
  648. Bidi: false,
  649. Target: &sqlgraph.EdgeTarget{
  650. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  651. },
  652. }
  653. for _, k := range nodes {
  654. edge.Target.Nodes = append(edge.Target.Nodes, k)
  655. }
  656. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  657. }
  658. if nodes := eu.mutation.EmTutorialIDs(); len(nodes) > 0 {
  659. edge := &sqlgraph.EdgeSpec{
  660. Rel: sqlgraph.O2M,
  661. Inverse: false,
  662. Table: employee.EmTutorialTable,
  663. Columns: []string{employee.EmTutorialColumn},
  664. Bidi: false,
  665. Target: &sqlgraph.EdgeTarget{
  666. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  667. },
  668. }
  669. for _, k := range nodes {
  670. edge.Target.Nodes = append(edge.Target.Nodes, k)
  671. }
  672. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  673. }
  674. if n, err = sqlgraph.UpdateNodes(ctx, eu.driver, _spec); err != nil {
  675. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  676. err = &NotFoundError{employee.Label}
  677. } else if sqlgraph.IsConstraintError(err) {
  678. err = &ConstraintError{msg: err.Error(), wrap: err}
  679. }
  680. return 0, err
  681. }
  682. eu.mutation.done = true
  683. return n, nil
  684. }
  685. // EmployeeUpdateOne is the builder for updating a single Employee entity.
  686. type EmployeeUpdateOne struct {
  687. config
  688. fields []string
  689. hooks []Hook
  690. mutation *EmployeeMutation
  691. }
  692. // SetUpdatedAt sets the "updated_at" field.
  693. func (euo *EmployeeUpdateOne) SetUpdatedAt(t time.Time) *EmployeeUpdateOne {
  694. euo.mutation.SetUpdatedAt(t)
  695. return euo
  696. }
  697. // SetDeletedAt sets the "deleted_at" field.
  698. func (euo *EmployeeUpdateOne) SetDeletedAt(t time.Time) *EmployeeUpdateOne {
  699. euo.mutation.SetDeletedAt(t)
  700. return euo
  701. }
  702. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  703. func (euo *EmployeeUpdateOne) SetNillableDeletedAt(t *time.Time) *EmployeeUpdateOne {
  704. if t != nil {
  705. euo.SetDeletedAt(*t)
  706. }
  707. return euo
  708. }
  709. // ClearDeletedAt clears the value of the "deleted_at" field.
  710. func (euo *EmployeeUpdateOne) ClearDeletedAt() *EmployeeUpdateOne {
  711. euo.mutation.ClearDeletedAt()
  712. return euo
  713. }
  714. // SetTitle sets the "title" field.
  715. func (euo *EmployeeUpdateOne) SetTitle(s string) *EmployeeUpdateOne {
  716. euo.mutation.SetTitle(s)
  717. return euo
  718. }
  719. // SetNillableTitle sets the "title" field if the given value is not nil.
  720. func (euo *EmployeeUpdateOne) SetNillableTitle(s *string) *EmployeeUpdateOne {
  721. if s != nil {
  722. euo.SetTitle(*s)
  723. }
  724. return euo
  725. }
  726. // SetAvatar sets the "avatar" field.
  727. func (euo *EmployeeUpdateOne) SetAvatar(s string) *EmployeeUpdateOne {
  728. euo.mutation.SetAvatar(s)
  729. return euo
  730. }
  731. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  732. func (euo *EmployeeUpdateOne) SetNillableAvatar(s *string) *EmployeeUpdateOne {
  733. if s != nil {
  734. euo.SetAvatar(*s)
  735. }
  736. return euo
  737. }
  738. // SetTags sets the "tags" field.
  739. func (euo *EmployeeUpdateOne) SetTags(s string) *EmployeeUpdateOne {
  740. euo.mutation.SetTags(s)
  741. return euo
  742. }
  743. // SetNillableTags sets the "tags" field if the given value is not nil.
  744. func (euo *EmployeeUpdateOne) SetNillableTags(s *string) *EmployeeUpdateOne {
  745. if s != nil {
  746. euo.SetTags(*s)
  747. }
  748. return euo
  749. }
  750. // SetHireCount sets the "hire_count" field.
  751. func (euo *EmployeeUpdateOne) SetHireCount(i int) *EmployeeUpdateOne {
  752. euo.mutation.ResetHireCount()
  753. euo.mutation.SetHireCount(i)
  754. return euo
  755. }
  756. // SetNillableHireCount sets the "hire_count" field if the given value is not nil.
  757. func (euo *EmployeeUpdateOne) SetNillableHireCount(i *int) *EmployeeUpdateOne {
  758. if i != nil {
  759. euo.SetHireCount(*i)
  760. }
  761. return euo
  762. }
  763. // AddHireCount adds i to the "hire_count" field.
  764. func (euo *EmployeeUpdateOne) AddHireCount(i int) *EmployeeUpdateOne {
  765. euo.mutation.AddHireCount(i)
  766. return euo
  767. }
  768. // SetServiceCount sets the "service_count" field.
  769. func (euo *EmployeeUpdateOne) SetServiceCount(i int) *EmployeeUpdateOne {
  770. euo.mutation.ResetServiceCount()
  771. euo.mutation.SetServiceCount(i)
  772. return euo
  773. }
  774. // SetNillableServiceCount sets the "service_count" field if the given value is not nil.
  775. func (euo *EmployeeUpdateOne) SetNillableServiceCount(i *int) *EmployeeUpdateOne {
  776. if i != nil {
  777. euo.SetServiceCount(*i)
  778. }
  779. return euo
  780. }
  781. // AddServiceCount adds i to the "service_count" field.
  782. func (euo *EmployeeUpdateOne) AddServiceCount(i int) *EmployeeUpdateOne {
  783. euo.mutation.AddServiceCount(i)
  784. return euo
  785. }
  786. // SetAchievementCount sets the "achievement_count" field.
  787. func (euo *EmployeeUpdateOne) SetAchievementCount(i int) *EmployeeUpdateOne {
  788. euo.mutation.ResetAchievementCount()
  789. euo.mutation.SetAchievementCount(i)
  790. return euo
  791. }
  792. // SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
  793. func (euo *EmployeeUpdateOne) SetNillableAchievementCount(i *int) *EmployeeUpdateOne {
  794. if i != nil {
  795. euo.SetAchievementCount(*i)
  796. }
  797. return euo
  798. }
  799. // AddAchievementCount adds i to the "achievement_count" field.
  800. func (euo *EmployeeUpdateOne) AddAchievementCount(i int) *EmployeeUpdateOne {
  801. euo.mutation.AddAchievementCount(i)
  802. return euo
  803. }
  804. // SetIntro sets the "intro" field.
  805. func (euo *EmployeeUpdateOne) SetIntro(s string) *EmployeeUpdateOne {
  806. euo.mutation.SetIntro(s)
  807. return euo
  808. }
  809. // SetNillableIntro sets the "intro" field if the given value is not nil.
  810. func (euo *EmployeeUpdateOne) SetNillableIntro(s *string) *EmployeeUpdateOne {
  811. if s != nil {
  812. euo.SetIntro(*s)
  813. }
  814. return euo
  815. }
  816. // SetEstimate sets the "estimate" field.
  817. func (euo *EmployeeUpdateOne) SetEstimate(s string) *EmployeeUpdateOne {
  818. euo.mutation.SetEstimate(s)
  819. return euo
  820. }
  821. // SetNillableEstimate sets the "estimate" field if the given value is not nil.
  822. func (euo *EmployeeUpdateOne) SetNillableEstimate(s *string) *EmployeeUpdateOne {
  823. if s != nil {
  824. euo.SetEstimate(*s)
  825. }
  826. return euo
  827. }
  828. // SetSkill sets the "skill" field.
  829. func (euo *EmployeeUpdateOne) SetSkill(s string) *EmployeeUpdateOne {
  830. euo.mutation.SetSkill(s)
  831. return euo
  832. }
  833. // SetNillableSkill sets the "skill" field if the given value is not nil.
  834. func (euo *EmployeeUpdateOne) SetNillableSkill(s *string) *EmployeeUpdateOne {
  835. if s != nil {
  836. euo.SetSkill(*s)
  837. }
  838. return euo
  839. }
  840. // SetAbilityType sets the "ability_type" field.
  841. func (euo *EmployeeUpdateOne) SetAbilityType(s string) *EmployeeUpdateOne {
  842. euo.mutation.SetAbilityType(s)
  843. return euo
  844. }
  845. // SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
  846. func (euo *EmployeeUpdateOne) SetNillableAbilityType(s *string) *EmployeeUpdateOne {
  847. if s != nil {
  848. euo.SetAbilityType(*s)
  849. }
  850. return euo
  851. }
  852. // SetScene sets the "scene" field.
  853. func (euo *EmployeeUpdateOne) SetScene(s string) *EmployeeUpdateOne {
  854. euo.mutation.SetScene(s)
  855. return euo
  856. }
  857. // SetNillableScene sets the "scene" field if the given value is not nil.
  858. func (euo *EmployeeUpdateOne) SetNillableScene(s *string) *EmployeeUpdateOne {
  859. if s != nil {
  860. euo.SetScene(*s)
  861. }
  862. return euo
  863. }
  864. // SetSwitchIn sets the "switch_in" field.
  865. func (euo *EmployeeUpdateOne) SetSwitchIn(s string) *EmployeeUpdateOne {
  866. euo.mutation.SetSwitchIn(s)
  867. return euo
  868. }
  869. // SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
  870. func (euo *EmployeeUpdateOne) SetNillableSwitchIn(s *string) *EmployeeUpdateOne {
  871. if s != nil {
  872. euo.SetSwitchIn(*s)
  873. }
  874. return euo
  875. }
  876. // SetVideoURL sets the "video_url" field.
  877. func (euo *EmployeeUpdateOne) SetVideoURL(s string) *EmployeeUpdateOne {
  878. euo.mutation.SetVideoURL(s)
  879. return euo
  880. }
  881. // SetNillableVideoURL sets the "video_url" field if the given value is not nil.
  882. func (euo *EmployeeUpdateOne) SetNillableVideoURL(s *string) *EmployeeUpdateOne {
  883. if s != nil {
  884. euo.SetVideoURL(*s)
  885. }
  886. return euo
  887. }
  888. // SetOrganizationID sets the "organization_id" field.
  889. func (euo *EmployeeUpdateOne) SetOrganizationID(u uint64) *EmployeeUpdateOne {
  890. euo.mutation.ResetOrganizationID()
  891. euo.mutation.SetOrganizationID(u)
  892. return euo
  893. }
  894. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  895. func (euo *EmployeeUpdateOne) SetNillableOrganizationID(u *uint64) *EmployeeUpdateOne {
  896. if u != nil {
  897. euo.SetOrganizationID(*u)
  898. }
  899. return euo
  900. }
  901. // AddOrganizationID adds u to the "organization_id" field.
  902. func (euo *EmployeeUpdateOne) AddOrganizationID(u int64) *EmployeeUpdateOne {
  903. euo.mutation.AddOrganizationID(u)
  904. return euo
  905. }
  906. // SetCategoryID sets the "category_id" field.
  907. func (euo *EmployeeUpdateOne) SetCategoryID(u uint64) *EmployeeUpdateOne {
  908. euo.mutation.ResetCategoryID()
  909. euo.mutation.SetCategoryID(u)
  910. return euo
  911. }
  912. // SetNillableCategoryID sets the "category_id" field if the given value is not nil.
  913. func (euo *EmployeeUpdateOne) SetNillableCategoryID(u *uint64) *EmployeeUpdateOne {
  914. if u != nil {
  915. euo.SetCategoryID(*u)
  916. }
  917. return euo
  918. }
  919. // AddCategoryID adds u to the "category_id" field.
  920. func (euo *EmployeeUpdateOne) AddCategoryID(u int64) *EmployeeUpdateOne {
  921. euo.mutation.AddCategoryID(u)
  922. return euo
  923. }
  924. // SetAPIBase sets the "api_base" field.
  925. func (euo *EmployeeUpdateOne) SetAPIBase(s string) *EmployeeUpdateOne {
  926. euo.mutation.SetAPIBase(s)
  927. return euo
  928. }
  929. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  930. func (euo *EmployeeUpdateOne) SetNillableAPIBase(s *string) *EmployeeUpdateOne {
  931. if s != nil {
  932. euo.SetAPIBase(*s)
  933. }
  934. return euo
  935. }
  936. // SetAPIKey sets the "api_key" field.
  937. func (euo *EmployeeUpdateOne) SetAPIKey(s string) *EmployeeUpdateOne {
  938. euo.mutation.SetAPIKey(s)
  939. return euo
  940. }
  941. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  942. func (euo *EmployeeUpdateOne) SetNillableAPIKey(s *string) *EmployeeUpdateOne {
  943. if s != nil {
  944. euo.SetAPIKey(*s)
  945. }
  946. return euo
  947. }
  948. // SetAiInfo sets the "ai_info" field.
  949. func (euo *EmployeeUpdateOne) SetAiInfo(s string) *EmployeeUpdateOne {
  950. euo.mutation.SetAiInfo(s)
  951. return euo
  952. }
  953. // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
  954. func (euo *EmployeeUpdateOne) SetNillableAiInfo(s *string) *EmployeeUpdateOne {
  955. if s != nil {
  956. euo.SetAiInfo(*s)
  957. }
  958. return euo
  959. }
  960. // ClearAiInfo clears the value of the "ai_info" field.
  961. func (euo *EmployeeUpdateOne) ClearAiInfo() *EmployeeUpdateOne {
  962. euo.mutation.ClearAiInfo()
  963. return euo
  964. }
  965. // SetIsVip sets the "is_vip" field.
  966. func (euo *EmployeeUpdateOne) SetIsVip(i int) *EmployeeUpdateOne {
  967. euo.mutation.ResetIsVip()
  968. euo.mutation.SetIsVip(i)
  969. return euo
  970. }
  971. // SetNillableIsVip sets the "is_vip" field if the given value is not nil.
  972. func (euo *EmployeeUpdateOne) SetNillableIsVip(i *int) *EmployeeUpdateOne {
  973. if i != nil {
  974. euo.SetIsVip(*i)
  975. }
  976. return euo
  977. }
  978. // AddIsVip adds i to the "is_vip" field.
  979. func (euo *EmployeeUpdateOne) AddIsVip(i int) *EmployeeUpdateOne {
  980. euo.mutation.AddIsVip(i)
  981. return euo
  982. }
  983. // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
  984. func (euo *EmployeeUpdateOne) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
  985. euo.mutation.AddEmWorkExperienceIDs(ids...)
  986. return euo
  987. }
  988. // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
  989. func (euo *EmployeeUpdateOne) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
  990. ids := make([]uint64, len(w))
  991. for i := range w {
  992. ids[i] = w[i].ID
  993. }
  994. return euo.AddEmWorkExperienceIDs(ids...)
  995. }
  996. // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
  997. func (euo *EmployeeUpdateOne) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
  998. euo.mutation.AddEmTutorialIDs(ids...)
  999. return euo
  1000. }
  1001. // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
  1002. func (euo *EmployeeUpdateOne) AddEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
  1003. ids := make([]uint64, len(t))
  1004. for i := range t {
  1005. ids[i] = t[i].ID
  1006. }
  1007. return euo.AddEmTutorialIDs(ids...)
  1008. }
  1009. // Mutation returns the EmployeeMutation object of the builder.
  1010. func (euo *EmployeeUpdateOne) Mutation() *EmployeeMutation {
  1011. return euo.mutation
  1012. }
  1013. // ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
  1014. func (euo *EmployeeUpdateOne) ClearEmWorkExperiences() *EmployeeUpdateOne {
  1015. euo.mutation.ClearEmWorkExperiences()
  1016. return euo
  1017. }
  1018. // RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
  1019. func (euo *EmployeeUpdateOne) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
  1020. euo.mutation.RemoveEmWorkExperienceIDs(ids...)
  1021. return euo
  1022. }
  1023. // RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
  1024. func (euo *EmployeeUpdateOne) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
  1025. ids := make([]uint64, len(w))
  1026. for i := range w {
  1027. ids[i] = w[i].ID
  1028. }
  1029. return euo.RemoveEmWorkExperienceIDs(ids...)
  1030. }
  1031. // ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
  1032. func (euo *EmployeeUpdateOne) ClearEmTutorial() *EmployeeUpdateOne {
  1033. euo.mutation.ClearEmTutorial()
  1034. return euo
  1035. }
  1036. // RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
  1037. func (euo *EmployeeUpdateOne) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
  1038. euo.mutation.RemoveEmTutorialIDs(ids...)
  1039. return euo
  1040. }
  1041. // RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
  1042. func (euo *EmployeeUpdateOne) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
  1043. ids := make([]uint64, len(t))
  1044. for i := range t {
  1045. ids[i] = t[i].ID
  1046. }
  1047. return euo.RemoveEmTutorialIDs(ids...)
  1048. }
  1049. // Where appends a list predicates to the EmployeeUpdate builder.
  1050. func (euo *EmployeeUpdateOne) Where(ps ...predicate.Employee) *EmployeeUpdateOne {
  1051. euo.mutation.Where(ps...)
  1052. return euo
  1053. }
  1054. // Select allows selecting one or more fields (columns) of the returned entity.
  1055. // The default is selecting all fields defined in the entity schema.
  1056. func (euo *EmployeeUpdateOne) Select(field string, fields ...string) *EmployeeUpdateOne {
  1057. euo.fields = append([]string{field}, fields...)
  1058. return euo
  1059. }
  1060. // Save executes the query and returns the updated Employee entity.
  1061. func (euo *EmployeeUpdateOne) Save(ctx context.Context) (*Employee, error) {
  1062. if err := euo.defaults(); err != nil {
  1063. return nil, err
  1064. }
  1065. return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
  1066. }
  1067. // SaveX is like Save, but panics if an error occurs.
  1068. func (euo *EmployeeUpdateOne) SaveX(ctx context.Context) *Employee {
  1069. node, err := euo.Save(ctx)
  1070. if err != nil {
  1071. panic(err)
  1072. }
  1073. return node
  1074. }
  1075. // Exec executes the query on the entity.
  1076. func (euo *EmployeeUpdateOne) Exec(ctx context.Context) error {
  1077. _, err := euo.Save(ctx)
  1078. return err
  1079. }
  1080. // ExecX is like Exec, but panics if an error occurs.
  1081. func (euo *EmployeeUpdateOne) ExecX(ctx context.Context) {
  1082. if err := euo.Exec(ctx); err != nil {
  1083. panic(err)
  1084. }
  1085. }
  1086. // defaults sets the default values of the builder before save.
  1087. func (euo *EmployeeUpdateOne) defaults() error {
  1088. if _, ok := euo.mutation.UpdatedAt(); !ok {
  1089. if employee.UpdateDefaultUpdatedAt == nil {
  1090. return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  1091. }
  1092. v := employee.UpdateDefaultUpdatedAt()
  1093. euo.mutation.SetUpdatedAt(v)
  1094. }
  1095. return nil
  1096. }
  1097. // check runs all checks and user-defined validators on the builder.
  1098. func (euo *EmployeeUpdateOne) check() error {
  1099. if v, ok := euo.mutation.Title(); ok {
  1100. if err := employee.TitleValidator(v); err != nil {
  1101. return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
  1102. }
  1103. }
  1104. if v, ok := euo.mutation.Avatar(); ok {
  1105. if err := employee.AvatarValidator(v); err != nil {
  1106. return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "Employee.avatar": %w`, err)}
  1107. }
  1108. }
  1109. if v, ok := euo.mutation.Tags(); ok {
  1110. if err := employee.TagsValidator(v); err != nil {
  1111. return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Employee.tags": %w`, err)}
  1112. }
  1113. }
  1114. if v, ok := euo.mutation.HireCount(); ok {
  1115. if err := employee.HireCountValidator(v); err != nil {
  1116. return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
  1117. }
  1118. }
  1119. if v, ok := euo.mutation.ServiceCount(); ok {
  1120. if err := employee.ServiceCountValidator(v); err != nil {
  1121. return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
  1122. }
  1123. }
  1124. if v, ok := euo.mutation.AchievementCount(); ok {
  1125. if err := employee.AchievementCountValidator(v); err != nil {
  1126. return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
  1127. }
  1128. }
  1129. if v, ok := euo.mutation.Intro(); ok {
  1130. if err := employee.IntroValidator(v); err != nil {
  1131. return &ValidationError{Name: "intro", err: fmt.Errorf(`ent: validator failed for field "Employee.intro": %w`, err)}
  1132. }
  1133. }
  1134. if v, ok := euo.mutation.Estimate(); ok {
  1135. if err := employee.EstimateValidator(v); err != nil {
  1136. return &ValidationError{Name: "estimate", err: fmt.Errorf(`ent: validator failed for field "Employee.estimate": %w`, err)}
  1137. }
  1138. }
  1139. if v, ok := euo.mutation.Skill(); ok {
  1140. if err := employee.SkillValidator(v); err != nil {
  1141. return &ValidationError{Name: "skill", err: fmt.Errorf(`ent: validator failed for field "Employee.skill": %w`, err)}
  1142. }
  1143. }
  1144. if v, ok := euo.mutation.VideoURL(); ok {
  1145. if err := employee.VideoURLValidator(v); err != nil {
  1146. return &ValidationError{Name: "video_url", err: fmt.Errorf(`ent: validator failed for field "Employee.video_url": %w`, err)}
  1147. }
  1148. }
  1149. if v, ok := euo.mutation.OrganizationID(); ok {
  1150. if err := employee.OrganizationIDValidator(v); err != nil {
  1151. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
  1152. }
  1153. }
  1154. if v, ok := euo.mutation.CategoryID(); ok {
  1155. if err := employee.CategoryIDValidator(v); err != nil {
  1156. return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
  1157. }
  1158. }
  1159. return nil
  1160. }
  1161. func (euo *EmployeeUpdateOne) sqlSave(ctx context.Context) (_node *Employee, err error) {
  1162. if err := euo.check(); err != nil {
  1163. return _node, err
  1164. }
  1165. _spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
  1166. id, ok := euo.mutation.ID()
  1167. if !ok {
  1168. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Employee.id" for update`)}
  1169. }
  1170. _spec.Node.ID.Value = id
  1171. if fields := euo.fields; len(fields) > 0 {
  1172. _spec.Node.Columns = make([]string, 0, len(fields))
  1173. _spec.Node.Columns = append(_spec.Node.Columns, employee.FieldID)
  1174. for _, f := range fields {
  1175. if !employee.ValidColumn(f) {
  1176. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1177. }
  1178. if f != employee.FieldID {
  1179. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1180. }
  1181. }
  1182. }
  1183. if ps := euo.mutation.predicates; len(ps) > 0 {
  1184. _spec.Predicate = func(selector *sql.Selector) {
  1185. for i := range ps {
  1186. ps[i](selector)
  1187. }
  1188. }
  1189. }
  1190. if value, ok := euo.mutation.UpdatedAt(); ok {
  1191. _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
  1192. }
  1193. if value, ok := euo.mutation.DeletedAt(); ok {
  1194. _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
  1195. }
  1196. if euo.mutation.DeletedAtCleared() {
  1197. _spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
  1198. }
  1199. if value, ok := euo.mutation.Title(); ok {
  1200. _spec.SetField(employee.FieldTitle, field.TypeString, value)
  1201. }
  1202. if value, ok := euo.mutation.Avatar(); ok {
  1203. _spec.SetField(employee.FieldAvatar, field.TypeString, value)
  1204. }
  1205. if value, ok := euo.mutation.Tags(); ok {
  1206. _spec.SetField(employee.FieldTags, field.TypeString, value)
  1207. }
  1208. if value, ok := euo.mutation.HireCount(); ok {
  1209. _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
  1210. }
  1211. if value, ok := euo.mutation.AddedHireCount(); ok {
  1212. _spec.AddField(employee.FieldHireCount, field.TypeInt, value)
  1213. }
  1214. if value, ok := euo.mutation.ServiceCount(); ok {
  1215. _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
  1216. }
  1217. if value, ok := euo.mutation.AddedServiceCount(); ok {
  1218. _spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
  1219. }
  1220. if value, ok := euo.mutation.AchievementCount(); ok {
  1221. _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
  1222. }
  1223. if value, ok := euo.mutation.AddedAchievementCount(); ok {
  1224. _spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
  1225. }
  1226. if value, ok := euo.mutation.Intro(); ok {
  1227. _spec.SetField(employee.FieldIntro, field.TypeString, value)
  1228. }
  1229. if value, ok := euo.mutation.Estimate(); ok {
  1230. _spec.SetField(employee.FieldEstimate, field.TypeString, value)
  1231. }
  1232. if value, ok := euo.mutation.Skill(); ok {
  1233. _spec.SetField(employee.FieldSkill, field.TypeString, value)
  1234. }
  1235. if value, ok := euo.mutation.AbilityType(); ok {
  1236. _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
  1237. }
  1238. if value, ok := euo.mutation.Scene(); ok {
  1239. _spec.SetField(employee.FieldScene, field.TypeString, value)
  1240. }
  1241. if value, ok := euo.mutation.SwitchIn(); ok {
  1242. _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
  1243. }
  1244. if value, ok := euo.mutation.VideoURL(); ok {
  1245. _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
  1246. }
  1247. if value, ok := euo.mutation.OrganizationID(); ok {
  1248. _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
  1249. }
  1250. if value, ok := euo.mutation.AddedOrganizationID(); ok {
  1251. _spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
  1252. }
  1253. if value, ok := euo.mutation.CategoryID(); ok {
  1254. _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
  1255. }
  1256. if value, ok := euo.mutation.AddedCategoryID(); ok {
  1257. _spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
  1258. }
  1259. if value, ok := euo.mutation.APIBase(); ok {
  1260. _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
  1261. }
  1262. if value, ok := euo.mutation.APIKey(); ok {
  1263. _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
  1264. }
  1265. if value, ok := euo.mutation.AiInfo(); ok {
  1266. _spec.SetField(employee.FieldAiInfo, field.TypeString, value)
  1267. }
  1268. if euo.mutation.AiInfoCleared() {
  1269. _spec.ClearField(employee.FieldAiInfo, field.TypeString)
  1270. }
  1271. if value, ok := euo.mutation.IsVip(); ok {
  1272. _spec.SetField(employee.FieldIsVip, field.TypeInt, value)
  1273. }
  1274. if value, ok := euo.mutation.AddedIsVip(); ok {
  1275. _spec.AddField(employee.FieldIsVip, field.TypeInt, value)
  1276. }
  1277. if euo.mutation.EmWorkExperiencesCleared() {
  1278. edge := &sqlgraph.EdgeSpec{
  1279. Rel: sqlgraph.O2M,
  1280. Inverse: false,
  1281. Table: employee.EmWorkExperiencesTable,
  1282. Columns: []string{employee.EmWorkExperiencesColumn},
  1283. Bidi: false,
  1284. Target: &sqlgraph.EdgeTarget{
  1285. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1286. },
  1287. }
  1288. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1289. }
  1290. if nodes := euo.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !euo.mutation.EmWorkExperiencesCleared() {
  1291. edge := &sqlgraph.EdgeSpec{
  1292. Rel: sqlgraph.O2M,
  1293. Inverse: false,
  1294. Table: employee.EmWorkExperiencesTable,
  1295. Columns: []string{employee.EmWorkExperiencesColumn},
  1296. Bidi: false,
  1297. Target: &sqlgraph.EdgeTarget{
  1298. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1299. },
  1300. }
  1301. for _, k := range nodes {
  1302. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1303. }
  1304. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1305. }
  1306. if nodes := euo.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
  1307. edge := &sqlgraph.EdgeSpec{
  1308. Rel: sqlgraph.O2M,
  1309. Inverse: false,
  1310. Table: employee.EmWorkExperiencesTable,
  1311. Columns: []string{employee.EmWorkExperiencesColumn},
  1312. Bidi: false,
  1313. Target: &sqlgraph.EdgeTarget{
  1314. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1315. },
  1316. }
  1317. for _, k := range nodes {
  1318. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1319. }
  1320. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1321. }
  1322. if euo.mutation.EmTutorialCleared() {
  1323. edge := &sqlgraph.EdgeSpec{
  1324. Rel: sqlgraph.O2M,
  1325. Inverse: false,
  1326. Table: employee.EmTutorialTable,
  1327. Columns: []string{employee.EmTutorialColumn},
  1328. Bidi: false,
  1329. Target: &sqlgraph.EdgeTarget{
  1330. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1331. },
  1332. }
  1333. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1334. }
  1335. if nodes := euo.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !euo.mutation.EmTutorialCleared() {
  1336. edge := &sqlgraph.EdgeSpec{
  1337. Rel: sqlgraph.O2M,
  1338. Inverse: false,
  1339. Table: employee.EmTutorialTable,
  1340. Columns: []string{employee.EmTutorialColumn},
  1341. Bidi: false,
  1342. Target: &sqlgraph.EdgeTarget{
  1343. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1344. },
  1345. }
  1346. for _, k := range nodes {
  1347. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1348. }
  1349. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1350. }
  1351. if nodes := euo.mutation.EmTutorialIDs(); len(nodes) > 0 {
  1352. edge := &sqlgraph.EdgeSpec{
  1353. Rel: sqlgraph.O2M,
  1354. Inverse: false,
  1355. Table: employee.EmTutorialTable,
  1356. Columns: []string{employee.EmTutorialColumn},
  1357. Bidi: false,
  1358. Target: &sqlgraph.EdgeTarget{
  1359. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1360. },
  1361. }
  1362. for _, k := range nodes {
  1363. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1364. }
  1365. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1366. }
  1367. _node = &Employee{config: euo.config}
  1368. _spec.Assign = _node.assignValues
  1369. _spec.ScanValues = _node.scanValues
  1370. if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
  1371. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1372. err = &NotFoundError{employee.Label}
  1373. } else if sqlgraph.IsConstraintError(err) {
  1374. err = &ConstraintError{msg: err.Error(), wrap: err}
  1375. }
  1376. return nil, err
  1377. }
  1378. euo.mutation.done = true
  1379. return _node, nil
  1380. }