Skip to content

Commit

Permalink
chore(core): updates
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Apr 10, 2019
1 parent 6e6647d commit d743389
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
21 changes: 15 additions & 6 deletions src/client/containers/Modals/CreateTicketModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { head, orderBy } from 'lodash'
import axios from 'axios'
import Log from '../../logger'
import { createTicket } from 'actions/tickets'
import { fetchGroups } from 'actions/groups'

import $ from 'jquery'
import helpers from 'lib/helpers'
import socket from 'lib/socket'
Expand All @@ -44,6 +46,7 @@ class CreateTicketModal extends React.Component {
}

componentDidMount () {
this.props.fetchGroups()
helpers.UI.inputs()
helpers.formvalidator()
this.defaultTicketTypeWatcher = when(
Expand Down Expand Up @@ -131,9 +134,12 @@ class CreateTicketModal extends React.Component {

render () {
const { viewdata } = this.props
const mappedGroups = this.props.viewdata.groups.map(grp => {
return { text: grp.name, value: grp._id }
})
const mappedGroups = this.props.groups
.map(grp => {
return { text: grp.get('name'), value: grp.get('_id') }
})
.toArray()

const mappedTicketTypes = this.props.viewdata.ticketTypes.map(type => {
return { text: type.name, value: type._id }
})
Expand Down Expand Up @@ -262,14 +268,17 @@ class CreateTicketModal extends React.Component {

CreateTicketModal.propTypes = {
viewdata: PropTypes.object.isRequired,
createTicket: PropTypes.func.isRequired
groups: PropTypes.object.isRequired,
createTicket: PropTypes.func.isRequired,
fetchGroups: PropTypes.func.isRequired
}

const mapStateToProps = state => ({
viewdata: state.common
viewdata: state.common,
groups: state.groupsState.groups
})

export default connect(
mapStateToProps,
{ createTicket }
{ createTicket, fetchGroups }
)(CreateTicketModal)
2 changes: 1 addition & 1 deletion src/client/containers/Modals/EditTeamModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EditTeamModal extends React.Component {
@observable members = []
componentDidMount () {
this.props.fetchAccounts()
this.props.fetchAccounts({ type: 'all' })
this.name = this.props.team.name
helpers.UI.inputs()
Expand Down
2 changes: 1 addition & 1 deletion src/client/reducers/accountsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const reducer = handleActions(
return {
...state,
accounts: fromJS(arr),
type: action.payload.payload.type
type: action.payload.payload && action.payload.payload.type ? action.payload.payload.type : 'customers'
}
},

Expand Down
3 changes: 2 additions & 1 deletion src/client/reducers/groupsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const initialState = {
const reducer = handleActions(
{
[FETCH_GROUPS.SUCCESS]: (state, action) => {
const groups = fromJS(action.response.groups)
return {
...state,
groups: fromJS(action.response.groups)
groups: groups.sortBy(group => group.get('name'))
}
},

Expand Down
35 changes: 24 additions & 11 deletions src/controllers/api/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,34 @@ apiGroups.get = function (req, res) {
var permissions = require('../../../permissions')
var hasPublic = permissions.canThis(user.role, 'tickets:public')

GroupSchema.getAllGroupsOfUser(user._id, function (err, groups) {
if (err) return res.status(400).json({ success: false, error: err.message })
if (user.role.isAgent || user.role.isAdmin) {
GroupSchema.getAllGroups(function (err, groups) {
if (err) return res.status(400).json({ success: false, error: err.message })

if (hasPublic) {
GroupSchema.getAllPublicGroups(function (err, grps) {
if (err) return res.status(400).json({ success: false, error: err })
if (!hasPublic)
groups = _.filter(function (g) {
return !g.public
})

groups = groups.concat(grps)
return res.json({ success: true, groups: groups })
})
} else {
GroupSchema.getAllGroupsOfUser(user._id, function (err, groups) {
if (err) return res.status(400).json({ success: false, error: err.message })

if (hasPublic) {
GroupSchema.getAllPublicGroups(function (err, grps) {
if (err) return res.status(400).json({ success: false, error: err })

groups = groups.concat(grps)

return res.json({ success: true, groups: groups })
})
} else {
return res.json({ success: true, groups: groups })
})
} else {
return res.json({ success: true, groups: groups })
}
})
}
})
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/controllers/api/v2/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ accountsApi.get = function (req, res) {
}

switch (type) {
case 'all':
User.getUserWithObject(obj, function (err, accounts) {
if (err) return apiUtil.sendApiError(res, 500, err.message)

return apiUtil.sendApiSuccess(res, { accounts: accounts, count: accounts.length })
})
break
case 'customers':
User.getCustomers(obj, function (err, accounts) {
if (err) return apiUtil.sendApiError(res, 500, err.message)
Expand Down
2 changes: 1 addition & 1 deletion src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ userSchema.statics.getUserWithObject = function (object, callback) {
q.where({ fullname: new RegExp('^' + search.toLowerCase(), 'i') })
}

q.exec(callback)
return q.exec(callback)
}

/**
Expand Down

0 comments on commit d743389

Please sign in to comment.