employee_update.go 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  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. // SetChatURL sets the "chat_url" field.
  319. func (eu *EmployeeUpdate) SetChatURL(s string) *EmployeeUpdate {
  320. eu.mutation.SetChatURL(s)
  321. return eu
  322. }
  323. // SetNillableChatURL sets the "chat_url" field if the given value is not nil.
  324. func (eu *EmployeeUpdate) SetNillableChatURL(s *string) *EmployeeUpdate {
  325. if s != nil {
  326. eu.SetChatURL(*s)
  327. }
  328. return eu
  329. }
  330. // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
  331. func (eu *EmployeeUpdate) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
  332. eu.mutation.AddEmWorkExperienceIDs(ids...)
  333. return eu
  334. }
  335. // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
  336. func (eu *EmployeeUpdate) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
  337. ids := make([]uint64, len(w))
  338. for i := range w {
  339. ids[i] = w[i].ID
  340. }
  341. return eu.AddEmWorkExperienceIDs(ids...)
  342. }
  343. // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
  344. func (eu *EmployeeUpdate) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
  345. eu.mutation.AddEmTutorialIDs(ids...)
  346. return eu
  347. }
  348. // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
  349. func (eu *EmployeeUpdate) AddEmTutorial(t ...*Tutorial) *EmployeeUpdate {
  350. ids := make([]uint64, len(t))
  351. for i := range t {
  352. ids[i] = t[i].ID
  353. }
  354. return eu.AddEmTutorialIDs(ids...)
  355. }
  356. // Mutation returns the EmployeeMutation object of the builder.
  357. func (eu *EmployeeUpdate) Mutation() *EmployeeMutation {
  358. return eu.mutation
  359. }
  360. // ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
  361. func (eu *EmployeeUpdate) ClearEmWorkExperiences() *EmployeeUpdate {
  362. eu.mutation.ClearEmWorkExperiences()
  363. return eu
  364. }
  365. // RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
  366. func (eu *EmployeeUpdate) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
  367. eu.mutation.RemoveEmWorkExperienceIDs(ids...)
  368. return eu
  369. }
  370. // RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
  371. func (eu *EmployeeUpdate) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
  372. ids := make([]uint64, len(w))
  373. for i := range w {
  374. ids[i] = w[i].ID
  375. }
  376. return eu.RemoveEmWorkExperienceIDs(ids...)
  377. }
  378. // ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
  379. func (eu *EmployeeUpdate) ClearEmTutorial() *EmployeeUpdate {
  380. eu.mutation.ClearEmTutorial()
  381. return eu
  382. }
  383. // RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
  384. func (eu *EmployeeUpdate) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
  385. eu.mutation.RemoveEmTutorialIDs(ids...)
  386. return eu
  387. }
  388. // RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
  389. func (eu *EmployeeUpdate) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdate {
  390. ids := make([]uint64, len(t))
  391. for i := range t {
  392. ids[i] = t[i].ID
  393. }
  394. return eu.RemoveEmTutorialIDs(ids...)
  395. }
  396. // Save executes the query and returns the number of nodes affected by the update operation.
  397. func (eu *EmployeeUpdate) Save(ctx context.Context) (int, error) {
  398. if err := eu.defaults(); err != nil {
  399. return 0, err
  400. }
  401. return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
  402. }
  403. // SaveX is like Save, but panics if an error occurs.
  404. func (eu *EmployeeUpdate) SaveX(ctx context.Context) int {
  405. affected, err := eu.Save(ctx)
  406. if err != nil {
  407. panic(err)
  408. }
  409. return affected
  410. }
  411. // Exec executes the query.
  412. func (eu *EmployeeUpdate) Exec(ctx context.Context) error {
  413. _, err := eu.Save(ctx)
  414. return err
  415. }
  416. // ExecX is like Exec, but panics if an error occurs.
  417. func (eu *EmployeeUpdate) ExecX(ctx context.Context) {
  418. if err := eu.Exec(ctx); err != nil {
  419. panic(err)
  420. }
  421. }
  422. // defaults sets the default values of the builder before save.
  423. func (eu *EmployeeUpdate) defaults() error {
  424. if _, ok := eu.mutation.UpdatedAt(); !ok {
  425. if employee.UpdateDefaultUpdatedAt == nil {
  426. return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  427. }
  428. v := employee.UpdateDefaultUpdatedAt()
  429. eu.mutation.SetUpdatedAt(v)
  430. }
  431. return nil
  432. }
  433. // check runs all checks and user-defined validators on the builder.
  434. func (eu *EmployeeUpdate) check() error {
  435. if v, ok := eu.mutation.Title(); ok {
  436. if err := employee.TitleValidator(v); err != nil {
  437. return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
  438. }
  439. }
  440. if v, ok := eu.mutation.HireCount(); ok {
  441. if err := employee.HireCountValidator(v); err != nil {
  442. return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
  443. }
  444. }
  445. if v, ok := eu.mutation.ServiceCount(); ok {
  446. if err := employee.ServiceCountValidator(v); err != nil {
  447. return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
  448. }
  449. }
  450. if v, ok := eu.mutation.AchievementCount(); ok {
  451. if err := employee.AchievementCountValidator(v); err != nil {
  452. return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
  453. }
  454. }
  455. if v, ok := eu.mutation.OrganizationID(); ok {
  456. if err := employee.OrganizationIDValidator(v); err != nil {
  457. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
  458. }
  459. }
  460. if v, ok := eu.mutation.CategoryID(); ok {
  461. if err := employee.CategoryIDValidator(v); err != nil {
  462. return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
  463. }
  464. }
  465. return nil
  466. }
  467. func (eu *EmployeeUpdate) sqlSave(ctx context.Context) (n int, err error) {
  468. if err := eu.check(); err != nil {
  469. return n, err
  470. }
  471. _spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
  472. if ps := eu.mutation.predicates; len(ps) > 0 {
  473. _spec.Predicate = func(selector *sql.Selector) {
  474. for i := range ps {
  475. ps[i](selector)
  476. }
  477. }
  478. }
  479. if value, ok := eu.mutation.UpdatedAt(); ok {
  480. _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
  481. }
  482. if value, ok := eu.mutation.DeletedAt(); ok {
  483. _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
  484. }
  485. if eu.mutation.DeletedAtCleared() {
  486. _spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
  487. }
  488. if value, ok := eu.mutation.Title(); ok {
  489. _spec.SetField(employee.FieldTitle, field.TypeString, value)
  490. }
  491. if value, ok := eu.mutation.Avatar(); ok {
  492. _spec.SetField(employee.FieldAvatar, field.TypeString, value)
  493. }
  494. if value, ok := eu.mutation.Tags(); ok {
  495. _spec.SetField(employee.FieldTags, field.TypeString, value)
  496. }
  497. if value, ok := eu.mutation.HireCount(); ok {
  498. _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
  499. }
  500. if value, ok := eu.mutation.AddedHireCount(); ok {
  501. _spec.AddField(employee.FieldHireCount, field.TypeInt, value)
  502. }
  503. if value, ok := eu.mutation.ServiceCount(); ok {
  504. _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
  505. }
  506. if value, ok := eu.mutation.AddedServiceCount(); ok {
  507. _spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
  508. }
  509. if value, ok := eu.mutation.AchievementCount(); ok {
  510. _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
  511. }
  512. if value, ok := eu.mutation.AddedAchievementCount(); ok {
  513. _spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
  514. }
  515. if value, ok := eu.mutation.Intro(); ok {
  516. _spec.SetField(employee.FieldIntro, field.TypeString, value)
  517. }
  518. if value, ok := eu.mutation.Estimate(); ok {
  519. _spec.SetField(employee.FieldEstimate, field.TypeString, value)
  520. }
  521. if value, ok := eu.mutation.Skill(); ok {
  522. _spec.SetField(employee.FieldSkill, field.TypeString, value)
  523. }
  524. if value, ok := eu.mutation.AbilityType(); ok {
  525. _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
  526. }
  527. if value, ok := eu.mutation.Scene(); ok {
  528. _spec.SetField(employee.FieldScene, field.TypeString, value)
  529. }
  530. if value, ok := eu.mutation.SwitchIn(); ok {
  531. _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
  532. }
  533. if value, ok := eu.mutation.VideoURL(); ok {
  534. _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
  535. }
  536. if value, ok := eu.mutation.OrganizationID(); ok {
  537. _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
  538. }
  539. if value, ok := eu.mutation.AddedOrganizationID(); ok {
  540. _spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
  541. }
  542. if value, ok := eu.mutation.CategoryID(); ok {
  543. _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
  544. }
  545. if value, ok := eu.mutation.AddedCategoryID(); ok {
  546. _spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
  547. }
  548. if value, ok := eu.mutation.APIBase(); ok {
  549. _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
  550. }
  551. if value, ok := eu.mutation.APIKey(); ok {
  552. _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
  553. }
  554. if value, ok := eu.mutation.AiInfo(); ok {
  555. _spec.SetField(employee.FieldAiInfo, field.TypeString, value)
  556. }
  557. if eu.mutation.AiInfoCleared() {
  558. _spec.ClearField(employee.FieldAiInfo, field.TypeString)
  559. }
  560. if value, ok := eu.mutation.IsVip(); ok {
  561. _spec.SetField(employee.FieldIsVip, field.TypeInt, value)
  562. }
  563. if value, ok := eu.mutation.AddedIsVip(); ok {
  564. _spec.AddField(employee.FieldIsVip, field.TypeInt, value)
  565. }
  566. if value, ok := eu.mutation.ChatURL(); ok {
  567. _spec.SetField(employee.FieldChatURL, field.TypeString, value)
  568. }
  569. if eu.mutation.EmWorkExperiencesCleared() {
  570. edge := &sqlgraph.EdgeSpec{
  571. Rel: sqlgraph.O2M,
  572. Inverse: false,
  573. Table: employee.EmWorkExperiencesTable,
  574. Columns: []string{employee.EmWorkExperiencesColumn},
  575. Bidi: false,
  576. Target: &sqlgraph.EdgeTarget{
  577. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  578. },
  579. }
  580. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  581. }
  582. if nodes := eu.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !eu.mutation.EmWorkExperiencesCleared() {
  583. edge := &sqlgraph.EdgeSpec{
  584. Rel: sqlgraph.O2M,
  585. Inverse: false,
  586. Table: employee.EmWorkExperiencesTable,
  587. Columns: []string{employee.EmWorkExperiencesColumn},
  588. Bidi: false,
  589. Target: &sqlgraph.EdgeTarget{
  590. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  591. },
  592. }
  593. for _, k := range nodes {
  594. edge.Target.Nodes = append(edge.Target.Nodes, k)
  595. }
  596. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  597. }
  598. if nodes := eu.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
  599. edge := &sqlgraph.EdgeSpec{
  600. Rel: sqlgraph.O2M,
  601. Inverse: false,
  602. Table: employee.EmWorkExperiencesTable,
  603. Columns: []string{employee.EmWorkExperiencesColumn},
  604. Bidi: false,
  605. Target: &sqlgraph.EdgeTarget{
  606. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  607. },
  608. }
  609. for _, k := range nodes {
  610. edge.Target.Nodes = append(edge.Target.Nodes, k)
  611. }
  612. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  613. }
  614. if eu.mutation.EmTutorialCleared() {
  615. edge := &sqlgraph.EdgeSpec{
  616. Rel: sqlgraph.O2M,
  617. Inverse: false,
  618. Table: employee.EmTutorialTable,
  619. Columns: []string{employee.EmTutorialColumn},
  620. Bidi: false,
  621. Target: &sqlgraph.EdgeTarget{
  622. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  623. },
  624. }
  625. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  626. }
  627. if nodes := eu.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !eu.mutation.EmTutorialCleared() {
  628. edge := &sqlgraph.EdgeSpec{
  629. Rel: sqlgraph.O2M,
  630. Inverse: false,
  631. Table: employee.EmTutorialTable,
  632. Columns: []string{employee.EmTutorialColumn},
  633. Bidi: false,
  634. Target: &sqlgraph.EdgeTarget{
  635. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  636. },
  637. }
  638. for _, k := range nodes {
  639. edge.Target.Nodes = append(edge.Target.Nodes, k)
  640. }
  641. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  642. }
  643. if nodes := eu.mutation.EmTutorialIDs(); len(nodes) > 0 {
  644. edge := &sqlgraph.EdgeSpec{
  645. Rel: sqlgraph.O2M,
  646. Inverse: false,
  647. Table: employee.EmTutorialTable,
  648. Columns: []string{employee.EmTutorialColumn},
  649. Bidi: false,
  650. Target: &sqlgraph.EdgeTarget{
  651. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  652. },
  653. }
  654. for _, k := range nodes {
  655. edge.Target.Nodes = append(edge.Target.Nodes, k)
  656. }
  657. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  658. }
  659. if n, err = sqlgraph.UpdateNodes(ctx, eu.driver, _spec); err != nil {
  660. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  661. err = &NotFoundError{employee.Label}
  662. } else if sqlgraph.IsConstraintError(err) {
  663. err = &ConstraintError{msg: err.Error(), wrap: err}
  664. }
  665. return 0, err
  666. }
  667. eu.mutation.done = true
  668. return n, nil
  669. }
  670. // EmployeeUpdateOne is the builder for updating a single Employee entity.
  671. type EmployeeUpdateOne struct {
  672. config
  673. fields []string
  674. hooks []Hook
  675. mutation *EmployeeMutation
  676. }
  677. // SetUpdatedAt sets the "updated_at" field.
  678. func (euo *EmployeeUpdateOne) SetUpdatedAt(t time.Time) *EmployeeUpdateOne {
  679. euo.mutation.SetUpdatedAt(t)
  680. return euo
  681. }
  682. // SetDeletedAt sets the "deleted_at" field.
  683. func (euo *EmployeeUpdateOne) SetDeletedAt(t time.Time) *EmployeeUpdateOne {
  684. euo.mutation.SetDeletedAt(t)
  685. return euo
  686. }
  687. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  688. func (euo *EmployeeUpdateOne) SetNillableDeletedAt(t *time.Time) *EmployeeUpdateOne {
  689. if t != nil {
  690. euo.SetDeletedAt(*t)
  691. }
  692. return euo
  693. }
  694. // ClearDeletedAt clears the value of the "deleted_at" field.
  695. func (euo *EmployeeUpdateOne) ClearDeletedAt() *EmployeeUpdateOne {
  696. euo.mutation.ClearDeletedAt()
  697. return euo
  698. }
  699. // SetTitle sets the "title" field.
  700. func (euo *EmployeeUpdateOne) SetTitle(s string) *EmployeeUpdateOne {
  701. euo.mutation.SetTitle(s)
  702. return euo
  703. }
  704. // SetNillableTitle sets the "title" field if the given value is not nil.
  705. func (euo *EmployeeUpdateOne) SetNillableTitle(s *string) *EmployeeUpdateOne {
  706. if s != nil {
  707. euo.SetTitle(*s)
  708. }
  709. return euo
  710. }
  711. // SetAvatar sets the "avatar" field.
  712. func (euo *EmployeeUpdateOne) SetAvatar(s string) *EmployeeUpdateOne {
  713. euo.mutation.SetAvatar(s)
  714. return euo
  715. }
  716. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  717. func (euo *EmployeeUpdateOne) SetNillableAvatar(s *string) *EmployeeUpdateOne {
  718. if s != nil {
  719. euo.SetAvatar(*s)
  720. }
  721. return euo
  722. }
  723. // SetTags sets the "tags" field.
  724. func (euo *EmployeeUpdateOne) SetTags(s string) *EmployeeUpdateOne {
  725. euo.mutation.SetTags(s)
  726. return euo
  727. }
  728. // SetNillableTags sets the "tags" field if the given value is not nil.
  729. func (euo *EmployeeUpdateOne) SetNillableTags(s *string) *EmployeeUpdateOne {
  730. if s != nil {
  731. euo.SetTags(*s)
  732. }
  733. return euo
  734. }
  735. // SetHireCount sets the "hire_count" field.
  736. func (euo *EmployeeUpdateOne) SetHireCount(i int) *EmployeeUpdateOne {
  737. euo.mutation.ResetHireCount()
  738. euo.mutation.SetHireCount(i)
  739. return euo
  740. }
  741. // SetNillableHireCount sets the "hire_count" field if the given value is not nil.
  742. func (euo *EmployeeUpdateOne) SetNillableHireCount(i *int) *EmployeeUpdateOne {
  743. if i != nil {
  744. euo.SetHireCount(*i)
  745. }
  746. return euo
  747. }
  748. // AddHireCount adds i to the "hire_count" field.
  749. func (euo *EmployeeUpdateOne) AddHireCount(i int) *EmployeeUpdateOne {
  750. euo.mutation.AddHireCount(i)
  751. return euo
  752. }
  753. // SetServiceCount sets the "service_count" field.
  754. func (euo *EmployeeUpdateOne) SetServiceCount(i int) *EmployeeUpdateOne {
  755. euo.mutation.ResetServiceCount()
  756. euo.mutation.SetServiceCount(i)
  757. return euo
  758. }
  759. // SetNillableServiceCount sets the "service_count" field if the given value is not nil.
  760. func (euo *EmployeeUpdateOne) SetNillableServiceCount(i *int) *EmployeeUpdateOne {
  761. if i != nil {
  762. euo.SetServiceCount(*i)
  763. }
  764. return euo
  765. }
  766. // AddServiceCount adds i to the "service_count" field.
  767. func (euo *EmployeeUpdateOne) AddServiceCount(i int) *EmployeeUpdateOne {
  768. euo.mutation.AddServiceCount(i)
  769. return euo
  770. }
  771. // SetAchievementCount sets the "achievement_count" field.
  772. func (euo *EmployeeUpdateOne) SetAchievementCount(i int) *EmployeeUpdateOne {
  773. euo.mutation.ResetAchievementCount()
  774. euo.mutation.SetAchievementCount(i)
  775. return euo
  776. }
  777. // SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
  778. func (euo *EmployeeUpdateOne) SetNillableAchievementCount(i *int) *EmployeeUpdateOne {
  779. if i != nil {
  780. euo.SetAchievementCount(*i)
  781. }
  782. return euo
  783. }
  784. // AddAchievementCount adds i to the "achievement_count" field.
  785. func (euo *EmployeeUpdateOne) AddAchievementCount(i int) *EmployeeUpdateOne {
  786. euo.mutation.AddAchievementCount(i)
  787. return euo
  788. }
  789. // SetIntro sets the "intro" field.
  790. func (euo *EmployeeUpdateOne) SetIntro(s string) *EmployeeUpdateOne {
  791. euo.mutation.SetIntro(s)
  792. return euo
  793. }
  794. // SetNillableIntro sets the "intro" field if the given value is not nil.
  795. func (euo *EmployeeUpdateOne) SetNillableIntro(s *string) *EmployeeUpdateOne {
  796. if s != nil {
  797. euo.SetIntro(*s)
  798. }
  799. return euo
  800. }
  801. // SetEstimate sets the "estimate" field.
  802. func (euo *EmployeeUpdateOne) SetEstimate(s string) *EmployeeUpdateOne {
  803. euo.mutation.SetEstimate(s)
  804. return euo
  805. }
  806. // SetNillableEstimate sets the "estimate" field if the given value is not nil.
  807. func (euo *EmployeeUpdateOne) SetNillableEstimate(s *string) *EmployeeUpdateOne {
  808. if s != nil {
  809. euo.SetEstimate(*s)
  810. }
  811. return euo
  812. }
  813. // SetSkill sets the "skill" field.
  814. func (euo *EmployeeUpdateOne) SetSkill(s string) *EmployeeUpdateOne {
  815. euo.mutation.SetSkill(s)
  816. return euo
  817. }
  818. // SetNillableSkill sets the "skill" field if the given value is not nil.
  819. func (euo *EmployeeUpdateOne) SetNillableSkill(s *string) *EmployeeUpdateOne {
  820. if s != nil {
  821. euo.SetSkill(*s)
  822. }
  823. return euo
  824. }
  825. // SetAbilityType sets the "ability_type" field.
  826. func (euo *EmployeeUpdateOne) SetAbilityType(s string) *EmployeeUpdateOne {
  827. euo.mutation.SetAbilityType(s)
  828. return euo
  829. }
  830. // SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
  831. func (euo *EmployeeUpdateOne) SetNillableAbilityType(s *string) *EmployeeUpdateOne {
  832. if s != nil {
  833. euo.SetAbilityType(*s)
  834. }
  835. return euo
  836. }
  837. // SetScene sets the "scene" field.
  838. func (euo *EmployeeUpdateOne) SetScene(s string) *EmployeeUpdateOne {
  839. euo.mutation.SetScene(s)
  840. return euo
  841. }
  842. // SetNillableScene sets the "scene" field if the given value is not nil.
  843. func (euo *EmployeeUpdateOne) SetNillableScene(s *string) *EmployeeUpdateOne {
  844. if s != nil {
  845. euo.SetScene(*s)
  846. }
  847. return euo
  848. }
  849. // SetSwitchIn sets the "switch_in" field.
  850. func (euo *EmployeeUpdateOne) SetSwitchIn(s string) *EmployeeUpdateOne {
  851. euo.mutation.SetSwitchIn(s)
  852. return euo
  853. }
  854. // SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
  855. func (euo *EmployeeUpdateOne) SetNillableSwitchIn(s *string) *EmployeeUpdateOne {
  856. if s != nil {
  857. euo.SetSwitchIn(*s)
  858. }
  859. return euo
  860. }
  861. // SetVideoURL sets the "video_url" field.
  862. func (euo *EmployeeUpdateOne) SetVideoURL(s string) *EmployeeUpdateOne {
  863. euo.mutation.SetVideoURL(s)
  864. return euo
  865. }
  866. // SetNillableVideoURL sets the "video_url" field if the given value is not nil.
  867. func (euo *EmployeeUpdateOne) SetNillableVideoURL(s *string) *EmployeeUpdateOne {
  868. if s != nil {
  869. euo.SetVideoURL(*s)
  870. }
  871. return euo
  872. }
  873. // SetOrganizationID sets the "organization_id" field.
  874. func (euo *EmployeeUpdateOne) SetOrganizationID(u uint64) *EmployeeUpdateOne {
  875. euo.mutation.ResetOrganizationID()
  876. euo.mutation.SetOrganizationID(u)
  877. return euo
  878. }
  879. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  880. func (euo *EmployeeUpdateOne) SetNillableOrganizationID(u *uint64) *EmployeeUpdateOne {
  881. if u != nil {
  882. euo.SetOrganizationID(*u)
  883. }
  884. return euo
  885. }
  886. // AddOrganizationID adds u to the "organization_id" field.
  887. func (euo *EmployeeUpdateOne) AddOrganizationID(u int64) *EmployeeUpdateOne {
  888. euo.mutation.AddOrganizationID(u)
  889. return euo
  890. }
  891. // SetCategoryID sets the "category_id" field.
  892. func (euo *EmployeeUpdateOne) SetCategoryID(u uint64) *EmployeeUpdateOne {
  893. euo.mutation.ResetCategoryID()
  894. euo.mutation.SetCategoryID(u)
  895. return euo
  896. }
  897. // SetNillableCategoryID sets the "category_id" field if the given value is not nil.
  898. func (euo *EmployeeUpdateOne) SetNillableCategoryID(u *uint64) *EmployeeUpdateOne {
  899. if u != nil {
  900. euo.SetCategoryID(*u)
  901. }
  902. return euo
  903. }
  904. // AddCategoryID adds u to the "category_id" field.
  905. func (euo *EmployeeUpdateOne) AddCategoryID(u int64) *EmployeeUpdateOne {
  906. euo.mutation.AddCategoryID(u)
  907. return euo
  908. }
  909. // SetAPIBase sets the "api_base" field.
  910. func (euo *EmployeeUpdateOne) SetAPIBase(s string) *EmployeeUpdateOne {
  911. euo.mutation.SetAPIBase(s)
  912. return euo
  913. }
  914. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  915. func (euo *EmployeeUpdateOne) SetNillableAPIBase(s *string) *EmployeeUpdateOne {
  916. if s != nil {
  917. euo.SetAPIBase(*s)
  918. }
  919. return euo
  920. }
  921. // SetAPIKey sets the "api_key" field.
  922. func (euo *EmployeeUpdateOne) SetAPIKey(s string) *EmployeeUpdateOne {
  923. euo.mutation.SetAPIKey(s)
  924. return euo
  925. }
  926. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  927. func (euo *EmployeeUpdateOne) SetNillableAPIKey(s *string) *EmployeeUpdateOne {
  928. if s != nil {
  929. euo.SetAPIKey(*s)
  930. }
  931. return euo
  932. }
  933. // SetAiInfo sets the "ai_info" field.
  934. func (euo *EmployeeUpdateOne) SetAiInfo(s string) *EmployeeUpdateOne {
  935. euo.mutation.SetAiInfo(s)
  936. return euo
  937. }
  938. // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
  939. func (euo *EmployeeUpdateOne) SetNillableAiInfo(s *string) *EmployeeUpdateOne {
  940. if s != nil {
  941. euo.SetAiInfo(*s)
  942. }
  943. return euo
  944. }
  945. // ClearAiInfo clears the value of the "ai_info" field.
  946. func (euo *EmployeeUpdateOne) ClearAiInfo() *EmployeeUpdateOne {
  947. euo.mutation.ClearAiInfo()
  948. return euo
  949. }
  950. // SetIsVip sets the "is_vip" field.
  951. func (euo *EmployeeUpdateOne) SetIsVip(i int) *EmployeeUpdateOne {
  952. euo.mutation.ResetIsVip()
  953. euo.mutation.SetIsVip(i)
  954. return euo
  955. }
  956. // SetNillableIsVip sets the "is_vip" field if the given value is not nil.
  957. func (euo *EmployeeUpdateOne) SetNillableIsVip(i *int) *EmployeeUpdateOne {
  958. if i != nil {
  959. euo.SetIsVip(*i)
  960. }
  961. return euo
  962. }
  963. // AddIsVip adds i to the "is_vip" field.
  964. func (euo *EmployeeUpdateOne) AddIsVip(i int) *EmployeeUpdateOne {
  965. euo.mutation.AddIsVip(i)
  966. return euo
  967. }
  968. // SetChatURL sets the "chat_url" field.
  969. func (euo *EmployeeUpdateOne) SetChatURL(s string) *EmployeeUpdateOne {
  970. euo.mutation.SetChatURL(s)
  971. return euo
  972. }
  973. // SetNillableChatURL sets the "chat_url" field if the given value is not nil.
  974. func (euo *EmployeeUpdateOne) SetNillableChatURL(s *string) *EmployeeUpdateOne {
  975. if s != nil {
  976. euo.SetChatURL(*s)
  977. }
  978. return euo
  979. }
  980. // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
  981. func (euo *EmployeeUpdateOne) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
  982. euo.mutation.AddEmWorkExperienceIDs(ids...)
  983. return euo
  984. }
  985. // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
  986. func (euo *EmployeeUpdateOne) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
  987. ids := make([]uint64, len(w))
  988. for i := range w {
  989. ids[i] = w[i].ID
  990. }
  991. return euo.AddEmWorkExperienceIDs(ids...)
  992. }
  993. // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
  994. func (euo *EmployeeUpdateOne) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
  995. euo.mutation.AddEmTutorialIDs(ids...)
  996. return euo
  997. }
  998. // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
  999. func (euo *EmployeeUpdateOne) AddEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
  1000. ids := make([]uint64, len(t))
  1001. for i := range t {
  1002. ids[i] = t[i].ID
  1003. }
  1004. return euo.AddEmTutorialIDs(ids...)
  1005. }
  1006. // Mutation returns the EmployeeMutation object of the builder.
  1007. func (euo *EmployeeUpdateOne) Mutation() *EmployeeMutation {
  1008. return euo.mutation
  1009. }
  1010. // ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
  1011. func (euo *EmployeeUpdateOne) ClearEmWorkExperiences() *EmployeeUpdateOne {
  1012. euo.mutation.ClearEmWorkExperiences()
  1013. return euo
  1014. }
  1015. // RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
  1016. func (euo *EmployeeUpdateOne) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
  1017. euo.mutation.RemoveEmWorkExperienceIDs(ids...)
  1018. return euo
  1019. }
  1020. // RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
  1021. func (euo *EmployeeUpdateOne) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
  1022. ids := make([]uint64, len(w))
  1023. for i := range w {
  1024. ids[i] = w[i].ID
  1025. }
  1026. return euo.RemoveEmWorkExperienceIDs(ids...)
  1027. }
  1028. // ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
  1029. func (euo *EmployeeUpdateOne) ClearEmTutorial() *EmployeeUpdateOne {
  1030. euo.mutation.ClearEmTutorial()
  1031. return euo
  1032. }
  1033. // RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
  1034. func (euo *EmployeeUpdateOne) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
  1035. euo.mutation.RemoveEmTutorialIDs(ids...)
  1036. return euo
  1037. }
  1038. // RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
  1039. func (euo *EmployeeUpdateOne) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
  1040. ids := make([]uint64, len(t))
  1041. for i := range t {
  1042. ids[i] = t[i].ID
  1043. }
  1044. return euo.RemoveEmTutorialIDs(ids...)
  1045. }
  1046. // Where appends a list predicates to the EmployeeUpdate builder.
  1047. func (euo *EmployeeUpdateOne) Where(ps ...predicate.Employee) *EmployeeUpdateOne {
  1048. euo.mutation.Where(ps...)
  1049. return euo
  1050. }
  1051. // Select allows selecting one or more fields (columns) of the returned entity.
  1052. // The default is selecting all fields defined in the entity schema.
  1053. func (euo *EmployeeUpdateOne) Select(field string, fields ...string) *EmployeeUpdateOne {
  1054. euo.fields = append([]string{field}, fields...)
  1055. return euo
  1056. }
  1057. // Save executes the query and returns the updated Employee entity.
  1058. func (euo *EmployeeUpdateOne) Save(ctx context.Context) (*Employee, error) {
  1059. if err := euo.defaults(); err != nil {
  1060. return nil, err
  1061. }
  1062. return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
  1063. }
  1064. // SaveX is like Save, but panics if an error occurs.
  1065. func (euo *EmployeeUpdateOne) SaveX(ctx context.Context) *Employee {
  1066. node, err := euo.Save(ctx)
  1067. if err != nil {
  1068. panic(err)
  1069. }
  1070. return node
  1071. }
  1072. // Exec executes the query on the entity.
  1073. func (euo *EmployeeUpdateOne) Exec(ctx context.Context) error {
  1074. _, err := euo.Save(ctx)
  1075. return err
  1076. }
  1077. // ExecX is like Exec, but panics if an error occurs.
  1078. func (euo *EmployeeUpdateOne) ExecX(ctx context.Context) {
  1079. if err := euo.Exec(ctx); err != nil {
  1080. panic(err)
  1081. }
  1082. }
  1083. // defaults sets the default values of the builder before save.
  1084. func (euo *EmployeeUpdateOne) defaults() error {
  1085. if _, ok := euo.mutation.UpdatedAt(); !ok {
  1086. if employee.UpdateDefaultUpdatedAt == nil {
  1087. return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  1088. }
  1089. v := employee.UpdateDefaultUpdatedAt()
  1090. euo.mutation.SetUpdatedAt(v)
  1091. }
  1092. return nil
  1093. }
  1094. // check runs all checks and user-defined validators on the builder.
  1095. func (euo *EmployeeUpdateOne) check() error {
  1096. if v, ok := euo.mutation.Title(); ok {
  1097. if err := employee.TitleValidator(v); err != nil {
  1098. return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
  1099. }
  1100. }
  1101. if v, ok := euo.mutation.HireCount(); ok {
  1102. if err := employee.HireCountValidator(v); err != nil {
  1103. return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
  1104. }
  1105. }
  1106. if v, ok := euo.mutation.ServiceCount(); ok {
  1107. if err := employee.ServiceCountValidator(v); err != nil {
  1108. return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
  1109. }
  1110. }
  1111. if v, ok := euo.mutation.AchievementCount(); ok {
  1112. if err := employee.AchievementCountValidator(v); err != nil {
  1113. return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
  1114. }
  1115. }
  1116. if v, ok := euo.mutation.OrganizationID(); ok {
  1117. if err := employee.OrganizationIDValidator(v); err != nil {
  1118. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
  1119. }
  1120. }
  1121. if v, ok := euo.mutation.CategoryID(); ok {
  1122. if err := employee.CategoryIDValidator(v); err != nil {
  1123. return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
  1124. }
  1125. }
  1126. return nil
  1127. }
  1128. func (euo *EmployeeUpdateOne) sqlSave(ctx context.Context) (_node *Employee, err error) {
  1129. if err := euo.check(); err != nil {
  1130. return _node, err
  1131. }
  1132. _spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
  1133. id, ok := euo.mutation.ID()
  1134. if !ok {
  1135. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Employee.id" for update`)}
  1136. }
  1137. _spec.Node.ID.Value = id
  1138. if fields := euo.fields; len(fields) > 0 {
  1139. _spec.Node.Columns = make([]string, 0, len(fields))
  1140. _spec.Node.Columns = append(_spec.Node.Columns, employee.FieldID)
  1141. for _, f := range fields {
  1142. if !employee.ValidColumn(f) {
  1143. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1144. }
  1145. if f != employee.FieldID {
  1146. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1147. }
  1148. }
  1149. }
  1150. if ps := euo.mutation.predicates; len(ps) > 0 {
  1151. _spec.Predicate = func(selector *sql.Selector) {
  1152. for i := range ps {
  1153. ps[i](selector)
  1154. }
  1155. }
  1156. }
  1157. if value, ok := euo.mutation.UpdatedAt(); ok {
  1158. _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
  1159. }
  1160. if value, ok := euo.mutation.DeletedAt(); ok {
  1161. _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
  1162. }
  1163. if euo.mutation.DeletedAtCleared() {
  1164. _spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
  1165. }
  1166. if value, ok := euo.mutation.Title(); ok {
  1167. _spec.SetField(employee.FieldTitle, field.TypeString, value)
  1168. }
  1169. if value, ok := euo.mutation.Avatar(); ok {
  1170. _spec.SetField(employee.FieldAvatar, field.TypeString, value)
  1171. }
  1172. if value, ok := euo.mutation.Tags(); ok {
  1173. _spec.SetField(employee.FieldTags, field.TypeString, value)
  1174. }
  1175. if value, ok := euo.mutation.HireCount(); ok {
  1176. _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
  1177. }
  1178. if value, ok := euo.mutation.AddedHireCount(); ok {
  1179. _spec.AddField(employee.FieldHireCount, field.TypeInt, value)
  1180. }
  1181. if value, ok := euo.mutation.ServiceCount(); ok {
  1182. _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
  1183. }
  1184. if value, ok := euo.mutation.AddedServiceCount(); ok {
  1185. _spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
  1186. }
  1187. if value, ok := euo.mutation.AchievementCount(); ok {
  1188. _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
  1189. }
  1190. if value, ok := euo.mutation.AddedAchievementCount(); ok {
  1191. _spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
  1192. }
  1193. if value, ok := euo.mutation.Intro(); ok {
  1194. _spec.SetField(employee.FieldIntro, field.TypeString, value)
  1195. }
  1196. if value, ok := euo.mutation.Estimate(); ok {
  1197. _spec.SetField(employee.FieldEstimate, field.TypeString, value)
  1198. }
  1199. if value, ok := euo.mutation.Skill(); ok {
  1200. _spec.SetField(employee.FieldSkill, field.TypeString, value)
  1201. }
  1202. if value, ok := euo.mutation.AbilityType(); ok {
  1203. _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
  1204. }
  1205. if value, ok := euo.mutation.Scene(); ok {
  1206. _spec.SetField(employee.FieldScene, field.TypeString, value)
  1207. }
  1208. if value, ok := euo.mutation.SwitchIn(); ok {
  1209. _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
  1210. }
  1211. if value, ok := euo.mutation.VideoURL(); ok {
  1212. _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
  1213. }
  1214. if value, ok := euo.mutation.OrganizationID(); ok {
  1215. _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
  1216. }
  1217. if value, ok := euo.mutation.AddedOrganizationID(); ok {
  1218. _spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
  1219. }
  1220. if value, ok := euo.mutation.CategoryID(); ok {
  1221. _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
  1222. }
  1223. if value, ok := euo.mutation.AddedCategoryID(); ok {
  1224. _spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
  1225. }
  1226. if value, ok := euo.mutation.APIBase(); ok {
  1227. _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
  1228. }
  1229. if value, ok := euo.mutation.APIKey(); ok {
  1230. _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
  1231. }
  1232. if value, ok := euo.mutation.AiInfo(); ok {
  1233. _spec.SetField(employee.FieldAiInfo, field.TypeString, value)
  1234. }
  1235. if euo.mutation.AiInfoCleared() {
  1236. _spec.ClearField(employee.FieldAiInfo, field.TypeString)
  1237. }
  1238. if value, ok := euo.mutation.IsVip(); ok {
  1239. _spec.SetField(employee.FieldIsVip, field.TypeInt, value)
  1240. }
  1241. if value, ok := euo.mutation.AddedIsVip(); ok {
  1242. _spec.AddField(employee.FieldIsVip, field.TypeInt, value)
  1243. }
  1244. if value, ok := euo.mutation.ChatURL(); ok {
  1245. _spec.SetField(employee.FieldChatURL, field.TypeString, value)
  1246. }
  1247. if euo.mutation.EmWorkExperiencesCleared() {
  1248. edge := &sqlgraph.EdgeSpec{
  1249. Rel: sqlgraph.O2M,
  1250. Inverse: false,
  1251. Table: employee.EmWorkExperiencesTable,
  1252. Columns: []string{employee.EmWorkExperiencesColumn},
  1253. Bidi: false,
  1254. Target: &sqlgraph.EdgeTarget{
  1255. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1256. },
  1257. }
  1258. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1259. }
  1260. if nodes := euo.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !euo.mutation.EmWorkExperiencesCleared() {
  1261. edge := &sqlgraph.EdgeSpec{
  1262. Rel: sqlgraph.O2M,
  1263. Inverse: false,
  1264. Table: employee.EmWorkExperiencesTable,
  1265. Columns: []string{employee.EmWorkExperiencesColumn},
  1266. Bidi: false,
  1267. Target: &sqlgraph.EdgeTarget{
  1268. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1269. },
  1270. }
  1271. for _, k := range nodes {
  1272. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1273. }
  1274. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1275. }
  1276. if nodes := euo.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
  1277. edge := &sqlgraph.EdgeSpec{
  1278. Rel: sqlgraph.O2M,
  1279. Inverse: false,
  1280. Table: employee.EmWorkExperiencesTable,
  1281. Columns: []string{employee.EmWorkExperiencesColumn},
  1282. Bidi: false,
  1283. Target: &sqlgraph.EdgeTarget{
  1284. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1285. },
  1286. }
  1287. for _, k := range nodes {
  1288. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1289. }
  1290. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1291. }
  1292. if euo.mutation.EmTutorialCleared() {
  1293. edge := &sqlgraph.EdgeSpec{
  1294. Rel: sqlgraph.O2M,
  1295. Inverse: false,
  1296. Table: employee.EmTutorialTable,
  1297. Columns: []string{employee.EmTutorialColumn},
  1298. Bidi: false,
  1299. Target: &sqlgraph.EdgeTarget{
  1300. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1301. },
  1302. }
  1303. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1304. }
  1305. if nodes := euo.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !euo.mutation.EmTutorialCleared() {
  1306. edge := &sqlgraph.EdgeSpec{
  1307. Rel: sqlgraph.O2M,
  1308. Inverse: false,
  1309. Table: employee.EmTutorialTable,
  1310. Columns: []string{employee.EmTutorialColumn},
  1311. Bidi: false,
  1312. Target: &sqlgraph.EdgeTarget{
  1313. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1314. },
  1315. }
  1316. for _, k := range nodes {
  1317. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1318. }
  1319. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1320. }
  1321. if nodes := euo.mutation.EmTutorialIDs(); len(nodes) > 0 {
  1322. edge := &sqlgraph.EdgeSpec{
  1323. Rel: sqlgraph.O2M,
  1324. Inverse: false,
  1325. Table: employee.EmTutorialTable,
  1326. Columns: []string{employee.EmTutorialColumn},
  1327. Bidi: false,
  1328. Target: &sqlgraph.EdgeTarget{
  1329. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1330. },
  1331. }
  1332. for _, k := range nodes {
  1333. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1334. }
  1335. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1336. }
  1337. _node = &Employee{config: euo.config}
  1338. _spec.Assign = _node.assignValues
  1339. _spec.ScanValues = _node.scanValues
  1340. if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
  1341. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1342. err = &NotFoundError{employee.Label}
  1343. } else if sqlgraph.IsConstraintError(err) {
  1344. err = &ConstraintError{msg: err.Error(), wrap: err}
  1345. }
  1346. return nil, err
  1347. }
  1348. euo.mutation.done = true
  1349. return _node, nil
  1350. }