Skip to content

Commit 5cbb42b

Browse files
committed
Add payload builder for create_gig command
1 parent a954642 commit 5cbb42b

File tree

9 files changed

+42
-25
lines changed

9 files changed

+42
-25
lines changed

src/app/pages/Days/days-actions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
FETCH_DAYS_ERROR
55
} from './days-mutations'
66

7-
import { retrieveDays } from '../../shared/mosica-api'
7+
import { retrieveDays } from '../../services/mosica-api'
88

99
export function buildRetrieveDaysAction() {
1010
return retrieveDaysAction(retrieveDays).run
@@ -26,6 +26,9 @@ export function retrieveDaysAction(retrieveDays) {
2626
}
2727

2828
// Test to check how we can abstract common action patterns
29+
// We should add params (payload) in case the query needs it
30+
// Creating a command engine to excute commands (with type and payload) sounds like a
31+
// good idea
2932
export function retrieveDaysActionUsingQueryAction(retrieveDays) {
3033
return queryAction(retrieveDays, FETCH_DAYS_REQUEST, FETCH_DAYS_SUCCESS, FETCH_DAYS_ERROR)
3134
}

src/app/pages/Days/days-mutations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function fetchDaysSuccess(state, days) {
1414
}
1515

1616
export function fetchDaysError(state, error) {
17-
console.log('EMOS SIDO ENGAÑADO', error)
17+
// console.error('Error fetching days', error.toString())
1818
state.loading = false
1919
state.error = error
2020
}

src/app/pages/NewGig/NewGig.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323

2424
<script>
2525
import { mapActions } from 'vuex'
26-
import { CREATE_GIG } from '../../shared/mosica-actions'
26+
import { CREATE_GIG } from '../../services/mosica-commands'
2727
import { required, minLength, maxLength } from 'vuelidate/lib/validators'
2828
import TextInput from '../../shared/TextInput.vue'
2929
import DateTimeInput from '../../shared/DateTimeInput.vue'
3030
import { isFutureDatetime } from './customValidations'
31+
import { createGigPayload } from '../../services/mosica-api'
3132
3233
export default {
3334
props: {
@@ -63,7 +64,7 @@
6364
methods: {
6465
...mapActions([CREATE_GIG]),
6566
save() {
66-
this.create_gig({title: this.title, day: this.dateTime})
67+
this.create_gig(createGigPayload(this.title, this.dateTime))
6768
}
6869
},
6970
components: {

src/app/pages/NewGig/new-gig-actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createGig } from '../../shared/mosica-api'
1+
import { createGig } from '../../services/mosica-api'
22
import { CREATE_GIG_ERROR, CREATE_GIG_REQUEST, CREATE_GIG_SUCCESS } from './new-gig-mutations'
33

44
export function buildCreateGigAction() {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { stubNow } from '../../../../test/helpers'
2+
import { createGigPayload } from '../mosica-api';
3+
4+
describe('mosica api', () => {
5+
6+
beforeEach(() => stubNow('2017-09-18'))
7+
8+
it('Builds create Gig Payload', () => {
9+
const payload = createGigPayload('a title', '2017-09-18T19:32')
10+
11+
expect(payload.title).toBe('a title')
12+
expect(payload.day).toBe('2017-09-18')
13+
})
14+
})

src/app/services/mosica-api.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { gigService } from './mosica-instances'
2+
3+
export function retrieveDays() {
4+
return gigService.retrieveNextGigs()
5+
}
6+
7+
export function createGig(payload) {
8+
return Promise.resolve(payload)
9+
}
10+
11+
export function createGigPayload(title, dateTime) {
12+
return {
13+
title: title,
14+
day: dateTime.substring(0, 10),
15+
description: 'Fake gig created by mosica-api',
16+
place: 'Fake place'
17+
}
18+
}

src/app/shared/mosica-api.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/vuex/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
3-
import { CREATE_GIG, RETRIEVE_DAYS } from '../app/shared/mosica-actions'
3+
import { CREATE_GIG, RETRIEVE_DAYS } from '../app/services/mosica-commands'
44
import { buildRetrieveDaysAction } from '../app/pages/Days/days-actions'
55
import {
66
CREATE_GIG_ERROR,

0 commit comments

Comments
 (0)