@jetthai/cuora 1.1.149 → 1.1.153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.1.153](https://github.com/jetthai/cuora-module/compare/v1.1.152...v1.1.153) (2023-08-01)
6
+
7
+ ### [1.1.152](https://github.com/jetthai/cuora-module/compare/v1.1.151...v1.1.152) (2023-07-31)
8
+
9
+ ### [1.1.151](https://github.com/jetthai/cuora-module/compare/v1.1.150...v1.1.151) (2023-07-31)
10
+
11
+ ### [1.1.150](https://github.com/jetthai/cuora-module/compare/v1.1.149...v1.1.150) (2023-07-31)
12
+
5
13
  ### [1.1.149](https://github.com/jetthai/cuora-module/compare/v1.1.148...v1.1.149) (2023-07-31)
6
14
 
7
15
  ### [1.1.148](https://github.com/jetthai/cuora-module/compare/v1.1.143-1...v1.1.148) (2023-07-25)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.149",
3
+ "version": "1.1.153",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
package/src/api/common.js CHANGED
@@ -2,5 +2,5 @@ export default {
2
2
  getConfig: ({ appSecret }) => ({ url: 'getConfig', method: 'get', params: { appSecret }, isPublic: true }),
3
3
  feeds: ({ appSecret }) => ({ url: 'feeds', method: 'get', params: { appSecret }, isPublic: true }),
4
4
  broadcast: () => ({ url: 'broadcast', method: 'get', isPublic: true }),
5
- getAnnouncements: () => ({ url: 'getAnnouncements', method: 'get', isPublic: true }),
5
+ getAnnouncements: ({ appSecret }) => ({ url: 'getAnnouncements', params: { appSecret }, method: 'get', isPublic: true }),
6
6
  }
@@ -172,8 +172,8 @@ export default function (request) {
172
172
  fetchActivitiesDetail: async (context, event) => {
173
173
  const { activityList = [], specifyActivities = [] } = context
174
174
  const filterActivityList = activityList.filter((activity) => specifyActivities.includes(activity.activityType))
175
- const promiseArray = filterActivityList.map((activity) => {
176
- return request.send(activity.getActivityDetail({ activityNo: activity.activityNo, appSecret }))
175
+ const promiseArray = filterActivityList.map((item) => {
176
+ return request.send(activity.getActivityDetail({ activityNo: item.activityNo, appSecret }))
177
177
  })
178
178
  const activitiesDetail = await Promise.all(promiseArray)
179
179
  return activitiesDetail
@@ -14,13 +14,15 @@ export default function (request) {
14
14
  tournamentList: [],
15
15
  promotionList: [],
16
16
  uidSite: '',
17
+ detailNeededActivityTypes: [29],
18
+ activityDetailList: [],
17
19
  },
18
20
  states: {
19
21
  fetchingList: {
20
22
  invoke: {
21
23
  src: 'fetchList',
22
24
  onDone: {
23
- target: 'pending',
25
+ target: 'checking',
24
26
  actions: ['setActivityList', 'setTournamentList', 'setPromotionList'],
25
27
  },
26
28
  onError: {
@@ -28,6 +30,21 @@ export default function (request) {
28
30
  },
29
31
  },
30
32
  },
33
+ checking: {
34
+ always: [{ target: 'fetchingDetailList', cond: 'needFetchingDetail' }, { target: 'pending' }],
35
+ },
36
+ fetchingDetailList: {
37
+ invoke: {
38
+ src: 'fetchActivityDetailList',
39
+ onDone: {
40
+ target: 'pending',
41
+ actions: 'setActivityDetailList',
42
+ },
43
+ onError: {
44
+ target: 'pending',
45
+ },
46
+ },
47
+ },
31
48
  pending: {
32
49
  after: {
33
50
  TIMEOUT: {
@@ -94,6 +111,17 @@ export default function (request) {
94
111
  uidSite,
95
112
  }
96
113
  }),
114
+ setActivityDetailList: assign((context, event) => {
115
+ return {
116
+ activityDetailList: event.data.map((item) => item.data),
117
+ }
118
+ }),
119
+ },
120
+ guards: {
121
+ needFetchingDetail: (context, event) => {
122
+ const { activityList = [], detailNeededActivityTypes } = context
123
+ return activityList.filter((activity) => detailNeededActivityTypes.includes(activity.activityType)).length > 0
124
+ },
97
125
  },
98
126
  delays: {
99
127
  TIMEOUT: (context, event) => {
@@ -111,6 +139,15 @@ export default function (request) {
111
139
 
112
140
  return { activityList: data, promotionList }
113
141
  },
142
+ fetchActivityDetailList: async (context, event) => {
143
+ const { activityList = [], detailNeededActivityTypes } = context
144
+ const filteredActivityList = activityList.filter((activity) => detailNeededActivityTypes.includes(activity.activityType))
145
+ return await Promise.all(
146
+ filteredActivityList.map((item) => {
147
+ return request.send(activity.getActivityDetail({ activityNo: item.activityNo, appSecret }))
148
+ })
149
+ )
150
+ },
114
151
  },
115
152
  }
116
153
  )
@@ -1,13 +1,14 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import api from '../../api/activity.js'
3
3
 
4
- export default function (request) {
4
+ export default function (request, context) {
5
+ const { activityNo } = context || {}
5
6
  const { appSecret } = request.config
6
7
  return createMachine(
7
8
  {
8
9
  id: 'roulette_activity_v2',
9
10
  context: {
10
- activityNo: null,
11
+ activityNo,
11
12
  activityDetail: null,
12
13
  duration: null,
13
14
  },
@@ -44,6 +45,14 @@ export default function (request) {
44
45
  },
45
46
  expired: {},
46
47
  },
48
+ on: {
49
+ START: {
50
+ target: '.loading',
51
+ },
52
+ STOP: {
53
+ target: '.idle',
54
+ },
55
+ },
47
56
  },
48
57
  {
49
58
  actions: {
@@ -94,6 +94,30 @@ export default function (request) {
94
94
  },
95
95
  },
96
96
  },
97
+ getAnnouncements: {
98
+ initial: 'updating',
99
+ states: {
100
+ updating: {
101
+ invoke: {
102
+ src: 'fetchAnnouncements',
103
+ onDone: {
104
+ target: 'idle',
105
+ actions: 'setAnnouncements',
106
+ },
107
+ onError: {
108
+ target: 'idle',
109
+ },
110
+ },
111
+ },
112
+ idle: {
113
+ on: {
114
+ FETCH_ANNOUNCEMENTS: {
115
+ target: 'updating',
116
+ },
117
+ },
118
+ },
119
+ },
120
+ },
97
121
  broadcast: {
98
122
  initial: 'idle',
99
123
  states: {
@@ -199,6 +223,10 @@ export default function (request) {
199
223
  }
200
224
  }
201
225
  }),
226
+ setAnnouncements: assign((context, event) => {
227
+ const { data } = event.data
228
+ return { announcementList: data }
229
+ }),
202
230
  setFeeds: assign((context, event) => {
203
231
  const { announcementList, broadcastList, mailBoxInfo } = event.data
204
232
  const promotions = announcementList?.announcements?.filter?.((item) => item.category === 3) || []
@@ -244,6 +272,9 @@ export default function (request) {
244
272
  fetchFeeds: async (context, event) => {
245
273
  return await request.send(api.feeds({ appSecret }))
246
274
  },
275
+ fetchAnnouncements: async (context, event) => {
276
+ return await request.send(api.getAnnouncements({ appSecret }))
277
+ },
247
278
  },
248
279
  }
249
280
  )