Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. <template>
  2. <div id="app">
  3. <button @click="getStore">CHANGE THEME</button>
  4. </div>
  5. </template>
  6.  
  7. <script lang="ts">
  8. import {Component, Vue} from "vue-property-decorator";
  9. import HelloWorld from "./components/HelloWorld.vue";
  10. import StoresData from "@/stores";
  11. import stores from "@/stores";
  12.  
  13. @Component({
  14. components: {
  15. HelloWorld,
  16. },
  17. })
  18. export default class App extends Vue {
  19.  
  20.  
  21. private url = "https://use1.ing.dev.fitstation4me.com/store/api/v1/stores/";
  22.  
  23. // private url = "http://hp-store-service.hp/store/api/v1/stores/";
  24.  
  25. async get(storeID: string): Promise<IStore> {
  26.  
  27. const query = await fetch(
  28. this.url + storeID,
  29. {method: "GET"}
  30. );
  31.  
  32. const response = await query.json();
  33. const configuration = response.configurations.find((i: { configuration_type: string; }) => i.configuration_type === "appinapp");
  34. return {
  35. companyID: response.company_id,
  36. storeID,
  37. configurationID: configuration ? configuration.configuration_id : undefined
  38. };
  39. }
  40.  
  41. async delete(storeID: string, configurationID: string) {
  42. return await fetch(
  43. this.url + storeID + "/configurations/id/" + configurationID,
  44. {method: "DELETE"}
  45. );
  46. }
  47.  
  48. async post(storeID: string, companyID: string, theme: string,
  49. configuration_type: string = "apollo", name: string = "Apollo configuration") {
  50.  
  51. const data = {
  52. company_id: companyID,
  53. configuration_type,
  54. name,
  55. data: {enabled: true}
  56. };
  57.  
  58. return await fetch(
  59. this.url + storeID + "/configurations",
  60. {
  61. method: "POST",
  62. headers: {
  63. "Content-Type": "application/json"
  64. },
  65. body: JSON.stringify(data)
  66. }
  67. );
  68. }
  69.  
  70. async getStore() {
  71. await this.setupStoreTheme("f3503d5c-bbfe-4672-8e0d-db44a0946e94", "napervilleRunning");
  72. }
  73.  
  74. async setupStoreTheme(storeID: string, theme: string) {
  75.  
  76. try {
  77.  
  78. const store: IStore = await this.get(storeID);
  79.  
  80. console.log(store);
  81. if (store.configurationID) {
  82. await this.delete(store.storeID, store.configurationID);
  83. }
  84.  
  85. await this.post(store.storeID, store.companyID, theme);
  86.  
  87. console.log("%c Theme " + theme + " set successfully for store " + storeID, "color: green");
  88. } catch (e) {
  89. console.warn("%c Error for store: " + storeID, "color: red");
  90. console.error(storeID, e);
  91. }
  92. }
  93.  
  94. async setupAllStores() {
  95.  
  96. const storeData = new StoresData();
  97. for (const store of storeData.stores) {
  98. await this.setupStoreTheme(store.StoreID, store.StoreThemeName);
  99. }
  100.  
  101. }
  102.  
  103. async healthCheck() {
  104.  
  105. const url = "http://hp-store-service.hp/store/api/v1/";
  106.  
  107. const response = await fetch(
  108. this.url + "health",
  109. {method: "GET"}
  110. );
  111.  
  112. console.log(response);
  113. }
  114. }
  115.  
  116. interface IStore {
  117. companyID: string,
  118. storeID: string,
  119. configurationID: string | undefined;
  120. }
  121.  
  122. </script>
  123.  
  124. <style>
  125. #app {
  126. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  127. -webkit-font-smoothing: antialiased;
  128. -moz-osx-font-smoothing: grayscale;
  129. text-align: center;
  130. color: #2c3e50;
  131. margin-top: 60px;
  132. }
  133. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement