Untitled
user_5113453
typescript
a month ago
3.1 kB
5
Indexable
Never
const activity = { "id": "9cf77f10-76b7-41d4-9d14-b7be79e15c4b", "datetime": "2024-09-09 14:46:41", "type": "game", "model": { "id": "9cf77f10-76b7-41d4-9d14-b7be79e15c4b", "created_at": "2024-09-09T07:47:06.000000Z", "updated_at": "2024-09-09T07:47:06.000000Z", "opponent": "11", "home_game": true, "date": "2024-09-09T14:46:41.000000Z", "minutes_played": 0, "home_team_final_score": 0, "away_team_final_score": 0, "goals_scored": 0, "saves": 0, "assists": 0, "self_rating": 5, "notes": null, "position": "GK", "intensity_rating": 5 } }; export const COMMENT_TYPES = { WORKOUT_COMPLETED: 'workoutCompleted', WORKOUT_SKIPPED: 'workoutSkipped', UPCOMING_WORKOUT: 'upcomingWorkout', IMPROVE_MORE_WORKOUT: 'improveMoreWorkout', GAME: 'game', ACTIVITY: 'activity', TEST: 'test', TEAM_TRAINING: 'teamTraining', REHAB: 'rehab', OTHER: 'other', }; export const ACT_TYPE = { UP_COMING_WORKOUT: 'UP_COMING_WORKOUT', CUSTOM_WORKOUT: 'CUSTOM_WORKOUT', WORKOUT_COMPLETED: 'WORKOUT_COMPLETED', WORKOUT_SKIPPED: 'WORKOUT_SKIPPED', IMPROVE_MORE_WORKOUT: 'IMPROVE_MORE_WORKOUT', GAME: 'GAME', TEAM_TRAINING: 'TEAM_TRAINING', REHAB: 'REHAB', TEST: 'TEST', INDIVIDUAL_ACTIVITY: 'INDIVIDUAL_ACTIVITY' } // get type của activity export const getActivityType = (activity) => { const modelType = activity?.model?.type; switch (activity.type) { case 'test': { return ACT_TYPE.TEST; } case 'game': { return ACT_TYPE.GAME; } case 'activity': { if (modelType === 'team training') { return ACT_TYPE.TEAM_TRAINING; } else if (modelType === 'rehab') { return ACT_TYPE.REHAB; } else { return ACT_TYPE.INDIVIDUAL_ACTIVITY; } } case 'workout': { const isSkip = activity.model.skipped; const isImproveMore = activity.model.improve_more; if (!isSkip && !isImproveMore) { return ACT_TYPE.WORKOUT_COMPLETED; } else if (isSkip) { return ACT_TYPE.WORKOUT_SKIPPED; } else { return ACT_TYPE.IMPROVE_MORE_WORKOUT; } } case ACT_TYPE.UP_COMING_WORKOUT: { return ACT_TYPE.UP_COMING_WORKOUT; } case ACT_TYPE.CUSTOM_WORKOUT: { return ACT_TYPE.CUSTOM_WORKOUT; } } }; const type = getActivityType(activity); const COMMENT_TYPE = { [ACT_TYPE.UP_COMING_WORKOUT]: COMMENT_TYPES.UPCOMING_WORKOUT, // activity type UP_COMING_WORKOUT => comment type: upcomingWorkout [ACT_TYPE.CUSTOM_WORKOUT]: COMMENT_TYPES.UPCOMING_WORKOUT, [ACT_TYPE.WORKOUT_COMPLETED]: COMMENT_TYPES.WORKOUT_COMPLETED, [ACT_TYPE.IMPROVE_MORE_WORKOUT]: COMMENT_TYPES.IMPROVE_MORE_WORKOUT, [ACT_TYPE.REHAB]: COMMENT_TYPES.REHAB, }
Leave a Comment