settings-data.service.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import { FetchPolicy } from 'apollo-client';
  2. import { pick } from 'shared/pick';
  3. import {
  4. AddMembersToZone,
  5. CreateChannel,
  6. CreateChannelInput,
  7. CreateCountry,
  8. CreateCountryInput,
  9. CreateTaxCategory,
  10. CreateTaxCategoryInput,
  11. CreateTaxRate,
  12. CreateTaxRateInput,
  13. CreateZone,
  14. CreateZoneInput,
  15. DeleteCountry,
  16. GetActiveChannel,
  17. GetAllJobs,
  18. GetAvailableCountries,
  19. GetChannel,
  20. GetChannels,
  21. GetCountry,
  22. GetCountryList,
  23. GetGlobalSettings,
  24. GetJobInfo,
  25. GetPaymentMethod,
  26. GetPaymentMethodList,
  27. GetTaxCategories,
  28. GetTaxCategory,
  29. GetTaxRate,
  30. GetTaxRateList,
  31. GetZone,
  32. GetZones,
  33. JobState,
  34. RemoveMembersFromZone,
  35. UpdateChannel,
  36. UpdateChannelInput,
  37. UpdateCountry,
  38. UpdateCountryInput,
  39. UpdateGlobalSettings,
  40. UpdateGlobalSettingsInput,
  41. UpdatePaymentMethod,
  42. UpdatePaymentMethodInput,
  43. UpdateTaxCategory,
  44. UpdateTaxCategoryInput,
  45. UpdateTaxRate,
  46. UpdateTaxRateInput,
  47. UpdateZone,
  48. UpdateZoneInput,
  49. } from '../../common/generated-types';
  50. import {
  51. ADD_MEMBERS_TO_ZONE,
  52. CREATE_CHANNEL,
  53. CREATE_COUNTRY,
  54. CREATE_TAX_CATEGORY,
  55. CREATE_TAX_RATE,
  56. CREATE_ZONE,
  57. DELETE_COUNTRY,
  58. GET_ACTIVE_CHANNEL,
  59. GET_ALL_JOBS,
  60. GET_AVAILABLE_COUNTRIES,
  61. GET_CHANNEL,
  62. GET_CHANNELS,
  63. GET_COUNTRY,
  64. GET_COUNTRY_LIST,
  65. GET_GLOBAL_SETTINGS,
  66. GET_JOB_INFO,
  67. GET_PAYMENT_METHOD,
  68. GET_PAYMENT_METHOD_LIST,
  69. GET_TAX_CATEGORIES,
  70. GET_TAX_CATEGORY,
  71. GET_TAX_RATE,
  72. GET_TAX_RATE_LIST,
  73. GET_ZONES,
  74. REMOVE_MEMBERS_FROM_ZONE,
  75. UPDATE_CHANNEL,
  76. UPDATE_COUNTRY,
  77. UPDATE_GLOBAL_SETTINGS,
  78. UPDATE_PAYMENT_METHOD,
  79. UPDATE_TAX_CATEGORY,
  80. UPDATE_TAX_RATE,
  81. UPDATE_ZONE,
  82. } from '../definitions/settings-definitions';
  83. import { BaseDataService } from './base-data.service';
  84. export class SettingsDataService {
  85. constructor(private baseDataService: BaseDataService) {}
  86. getCountries(take: number = 10, skip: number = 0) {
  87. return this.baseDataService.query<GetCountryList.Query, GetCountryList.Variables>(GET_COUNTRY_LIST, {
  88. options: {
  89. take,
  90. skip,
  91. },
  92. });
  93. }
  94. getAvailableCountries() {
  95. return this.baseDataService.query<GetAvailableCountries.Query>(GET_AVAILABLE_COUNTRIES);
  96. }
  97. getCountry(id: string) {
  98. return this.baseDataService.query<GetCountry.Query, GetCountry.Variables>(GET_COUNTRY, { id });
  99. }
  100. createCountry(input: CreateCountryInput) {
  101. return this.baseDataService.mutate<CreateCountry.Mutation, CreateCountry.Variables>(CREATE_COUNTRY, {
  102. input: pick(input, ['code', 'enabled', 'translations']),
  103. });
  104. }
  105. updateCountry(input: UpdateCountryInput) {
  106. return this.baseDataService.mutate<UpdateCountry.Mutation, UpdateCountry.Variables>(UPDATE_COUNTRY, {
  107. input: pick(input, ['id', 'code', 'enabled', 'translations']),
  108. });
  109. }
  110. deleteCountry(id: string) {
  111. return this.baseDataService.mutate<DeleteCountry.Mutation, DeleteCountry.Variables>(DELETE_COUNTRY, {
  112. id,
  113. });
  114. }
  115. getZones() {
  116. return this.baseDataService.query<GetZones.Query>(GET_ZONES);
  117. }
  118. getZone(id: string) {
  119. return this.baseDataService.query<GetZone.Query, GetZone.Variables>(GET_ZONES, { id });
  120. }
  121. createZone(input: CreateZoneInput) {
  122. return this.baseDataService.mutate<CreateZone.Mutation, CreateZone.Variables>(CREATE_ZONE, {
  123. input,
  124. });
  125. }
  126. updateZone(input: UpdateZoneInput) {
  127. return this.baseDataService.mutate<UpdateZone.Mutation, UpdateZone.Variables>(UPDATE_ZONE, {
  128. input,
  129. });
  130. }
  131. addMembersToZone(zoneId: string, memberIds: string[]) {
  132. return this.baseDataService.mutate<AddMembersToZone.Mutation, AddMembersToZone.Variables>(
  133. ADD_MEMBERS_TO_ZONE,
  134. {
  135. zoneId,
  136. memberIds,
  137. },
  138. );
  139. }
  140. removeMembersFromZone(zoneId: string, memberIds: string[]) {
  141. return this.baseDataService.mutate<RemoveMembersFromZone.Mutation, RemoveMembersFromZone.Variables>(
  142. REMOVE_MEMBERS_FROM_ZONE,
  143. {
  144. zoneId,
  145. memberIds,
  146. },
  147. );
  148. }
  149. getTaxCategories() {
  150. return this.baseDataService.query<GetTaxCategories.Query>(GET_TAX_CATEGORIES);
  151. }
  152. getTaxCategory(id: string) {
  153. return this.baseDataService.query<GetTaxCategory.Query, GetTaxCategory.Variables>(GET_TAX_CATEGORY, {
  154. id,
  155. });
  156. }
  157. createTaxCategory(input: CreateTaxCategoryInput) {
  158. return this.baseDataService.mutate<CreateTaxCategory.Mutation, CreateTaxCategory.Variables>(
  159. CREATE_TAX_CATEGORY,
  160. {
  161. input,
  162. },
  163. );
  164. }
  165. updateTaxCategory(input: UpdateTaxCategoryInput) {
  166. return this.baseDataService.mutate<UpdateTaxCategory.Mutation, UpdateTaxCategory.Variables>(
  167. UPDATE_TAX_CATEGORY,
  168. {
  169. input,
  170. },
  171. );
  172. }
  173. getTaxRates(take: number = 10, skip: number = 0, fetchPolicy?: FetchPolicy) {
  174. return this.baseDataService.query<GetTaxRateList.Query, GetTaxRateList.Variables>(
  175. GET_TAX_RATE_LIST,
  176. {
  177. options: {
  178. take,
  179. skip,
  180. },
  181. },
  182. fetchPolicy,
  183. );
  184. }
  185. getTaxRate(id: string) {
  186. return this.baseDataService.query<GetTaxRate.Query, GetTaxRate.Variables>(GET_TAX_RATE, {
  187. id,
  188. });
  189. }
  190. createTaxRate(input: CreateTaxRateInput) {
  191. return this.baseDataService.mutate<CreateTaxRate.Mutation, CreateTaxRate.Variables>(CREATE_TAX_RATE, {
  192. input,
  193. });
  194. }
  195. updateTaxRate(input: UpdateTaxRateInput) {
  196. return this.baseDataService.mutate<UpdateTaxRate.Mutation, UpdateTaxRate.Variables>(UPDATE_TAX_RATE, {
  197. input,
  198. });
  199. }
  200. getChannels() {
  201. return this.baseDataService.query<GetChannels.Query>(GET_CHANNELS);
  202. }
  203. getChannel(id: string) {
  204. return this.baseDataService.query<GetChannel.Query, GetChannel.Variables>(GET_CHANNEL, {
  205. id,
  206. });
  207. }
  208. getActiveChannel(fetchPolicy?: FetchPolicy) {
  209. return this.baseDataService.query<GetActiveChannel.Query, GetActiveChannel.Variables>(
  210. GET_ACTIVE_CHANNEL,
  211. {},
  212. fetchPolicy,
  213. );
  214. }
  215. createChannel(input: CreateChannelInput) {
  216. return this.baseDataService.mutate<CreateChannel.Mutation, CreateChannel.Variables>(CREATE_CHANNEL, {
  217. input,
  218. });
  219. }
  220. updateChannel(input: UpdateChannelInput) {
  221. return this.baseDataService.mutate<UpdateChannel.Mutation, UpdateChannel.Variables>(UPDATE_CHANNEL, {
  222. input,
  223. });
  224. }
  225. getPaymentMethods(take: number = 10, skip: number = 0) {
  226. return this.baseDataService.query<GetPaymentMethodList.Query, GetPaymentMethodList.Variables>(
  227. GET_PAYMENT_METHOD_LIST,
  228. {
  229. options: {
  230. skip,
  231. take,
  232. },
  233. },
  234. );
  235. }
  236. getPaymentMethod(id: string) {
  237. return this.baseDataService.query<GetPaymentMethod.Query, GetPaymentMethod.Variables>(
  238. GET_PAYMENT_METHOD,
  239. {
  240. id,
  241. },
  242. );
  243. }
  244. updatePaymentMethod(input: UpdatePaymentMethodInput) {
  245. return this.baseDataService.mutate<UpdatePaymentMethod.Mutation, UpdatePaymentMethod.Variables>(
  246. UPDATE_PAYMENT_METHOD,
  247. {
  248. input,
  249. },
  250. );
  251. }
  252. getGlobalSettings() {
  253. return this.baseDataService.query<GetGlobalSettings.Query>(GET_GLOBAL_SETTINGS);
  254. }
  255. updateGlobalSettings(input: UpdateGlobalSettingsInput) {
  256. return this.baseDataService.mutate<UpdateGlobalSettings.Mutation, UpdateGlobalSettings.Variables>(
  257. UPDATE_GLOBAL_SETTINGS,
  258. {
  259. input,
  260. },
  261. );
  262. }
  263. getJob(id: string) {
  264. return this.baseDataService.query<GetJobInfo.Query, GetJobInfo.Variables>(GET_JOB_INFO, { id });
  265. }
  266. pollJobs(ids: string[]) {
  267. return this.baseDataService.query<GetAllJobs.Query, GetAllJobs.Variables>(GET_ALL_JOBS, {
  268. input: { ids },
  269. });
  270. }
  271. getRunningJobs() {
  272. return this.baseDataService.query<GetAllJobs.Query, GetAllJobs.Variables>(GET_ALL_JOBS, {
  273. input: { state: JobState.RUNNING },
  274. });
  275. }
  276. }