Skip to content
Snippets Groups Projects
Commit 883b9a3a authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

Add startDate to events

parent e75e39d8
Branches
Tags
1 merge request!348Features/create aggregation usage service
......@@ -37,6 +37,7 @@ const ActionDone: React.FC<ActionDoneProps> = ({
? currentChallenge.action.ecogesture.id
: '',
context: currentChallenge.id,
startDate: currentChallenge.action.startDate,
})
dispatch(toggleChallengeActionNotification(false))
dispatch(updateUserChallengeList(updatedChallenge))
......
......@@ -69,10 +69,12 @@ const DuelOngoing: React.FC<DuelOngoingProps> = ({
result: winChallenge
? 'Win'
: 'Loss' + ' / ' + userChallenge.duel.userConsumption,
startDate: userChallenge.startDate,
})
await UsageEventService.addEvent(client, {
type: UsageEventType.CHALLENGE_END_EVENT,
target: userChallenge.id,
startDate: userChallenge.startDate,
})
dispatch(updateUserChallengeList(updatedChallenge))
dispatch(unlockNextUserChallenge(updatedChallenge))
......
......@@ -13,6 +13,8 @@ import ChallengeService from 'services/challenge.service'
import { Client, useClient } from 'cozy-client'
import { useDispatch } from 'react-redux'
import { toggleChallengeExplorationNotification } from 'store/global/global.actions'
import { UsageEventType } from 'enum/usageEvent.enum'
import UsageEventService from 'services/usageEvent.service'
interface ExplorationFinishedProps {
userChallenge: UserChallenge
......@@ -33,6 +35,12 @@ const ExplorationFinished: React.FC<ExplorationFinishedProps> = ({
userChallenge,
UserChallengeUpdateFlag.EXPLORATION_DONE
)
await UsageEventService.addEvent(client, {
type: UsageEventType.EXPLORATION_END_EVENT,
target: userChallenge.exploration.id,
context: userChallenge.id,
startDate: userChallenge.exploration.date,
})
dispatch(toggleChallengeExplorationNotification(false))
dispatch(updateUserChallengeList(updatedChallenge))
}
......
......@@ -61,6 +61,7 @@ const ExplorationOngoing: React.FC<ExplorationOngoingProps> = ({
type: UsageEventType.EXPLORATION_END_EVENT,
target: userChallenge.exploration.id,
context: userChallenge.id,
startDate: userChallenge.exploration.date,
})
dispatch(updateUserChallengeList(updatedChallenge))
history.push('/challenges')
......
......@@ -2,18 +2,21 @@ import { UsageEventType } from 'enum/usageEvent.enum'
import { DateTime } from 'luxon'
export interface UsageEventCreationEntity {
date: string
eventDate: string
type: UsageEventType
target?: string
result?: string
context?: string
aggregated: boolean
startDate?: string
}
export interface UsageEventEntity extends UsageEventCreationEntity {
_id: string
}
export interface UsageEvent extends Omit<UsageEventEntity, 'date'> {
date: DateTime
export interface UsageEvent
extends Omit<UsageEventEntity, 'eventDate' | 'startDate'> {
eventDate: DateTime
startDate?: DateTime
}
......@@ -15,6 +15,7 @@ interface AddEventParams {
target?: string
result?: string
context?: string
startDate?: DateTime | null
}
export default class UsageEventService {
......@@ -30,11 +31,12 @@ export default class UsageEventService {
): Promise<UsageEvent> {
const usageEvent: UsageEventCreationEntity = {
...params,
date: DateTime.local()
eventDate: DateTime.local()
.setZone('utc', {
keepLocalTime: true,
})
.toString(),
startDate: params.startDate ? params.startDate.toString() : undefined,
aggregated: false,
}
const { data }: QueryResult<UsageEventEntity> = await client.create(
......@@ -97,9 +99,14 @@ export default class UsageEventService {
): UsageEvent {
const usageEvent: UsageEvent = {
...usageEventEntity,
date: DateTime.fromISO(usageEventEntity.date, {
eventDate: DateTime.fromISO(usageEventEntity.eventDate, {
zone: 'utc',
}),
startDate: usageEventEntity.startDate
? DateTime.fromISO(usageEventEntity.startDate, {
zone: 'utc',
})
: undefined,
}
return usageEvent
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment