employee_update.go 47 KB

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