Room Office Mapping / Home screen now functional / Bugfixes
This commit is contained in:
@@ -5,7 +5,7 @@ import { Menu } from 'semantic-ui-react';
|
|||||||
import { mainMenuItems } from '../../constants/menuItems';
|
import { mainMenuItems } from '../../constants/menuItems';
|
||||||
|
|
||||||
const MainMenu = () =>
|
const MainMenu = () =>
|
||||||
(<Menu>
|
(<Menu size={'huge'}>
|
||||||
{
|
{
|
||||||
mainMenuItems.map(mainMenuItem => {
|
mainMenuItems.map(mainMenuItem => {
|
||||||
if (!mainMenuItem.showInMenu){
|
if (!mainMenuItem.showInMenu){
|
||||||
|
|||||||
35
client/src/components/PromptMessage/index.js
Normal file
35
client/src/components/PromptMessage/index.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
import {Button, Modal} from "semantic-ui-react";
|
||||||
|
|
||||||
|
|
||||||
|
class PromptMessage extends Component {
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
show = false,
|
||||||
|
size = 'tiny',
|
||||||
|
title = '',
|
||||||
|
message = '',
|
||||||
|
noActionLabel = 'No',
|
||||||
|
yesActionLabel = 'Yes',
|
||||||
|
yesActionIconName = 'checkmark',
|
||||||
|
onClose = null,
|
||||||
|
onActionNo = null,
|
||||||
|
onActionYes = null,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal size={size} open={show} onClose={onClose}>
|
||||||
|
<Modal.Header>{title}</Modal.Header>
|
||||||
|
<Modal.Content>
|
||||||
|
<p>{message}</p>
|
||||||
|
</Modal.Content>
|
||||||
|
<Modal.Actions>
|
||||||
|
<Button negative onClick={onActionNo}>{noActionLabel}</Button>
|
||||||
|
<Button positive icon={yesActionIconName} onClick={onActionYes} labelPosition='right' content={yesActionLabel} />
|
||||||
|
</Modal.Actions>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PromptMessage;
|
||||||
@@ -3,11 +3,13 @@ import Home from '../scenes/Home';
|
|||||||
import IncidentsReport from '../scenes/IncidentsReport';
|
import IncidentsReport from '../scenes/IncidentsReport';
|
||||||
import SpecificMemberIncidentsReport from '../scenes/SpecificMemberIncidentsReport';
|
import SpecificMemberIncidentsReport from '../scenes/SpecificMemberIncidentsReport';
|
||||||
import MemberPracticeSummaryReport from '../scenes/MemberPracticeSummaryReport';
|
import MemberPracticeSummaryReport from '../scenes/MemberPracticeSummaryReport';
|
||||||
|
import RoomOfficeNameMapping from '../scenes/RoomOfficeNameMapping';
|
||||||
|
|
||||||
export const mainMenuItems = [
|
export const mainMenuItems = [
|
||||||
{
|
{
|
||||||
id: 'home',
|
id: 'home',
|
||||||
showInMenu: true,
|
showInMenu: true,
|
||||||
|
showOnHomePage: false,
|
||||||
title: 'Home',
|
title: 'Home',
|
||||||
url: '/',
|
url: '/',
|
||||||
component: Home,
|
component: Home,
|
||||||
@@ -15,35 +17,53 @@ export const mainMenuItems = [
|
|||||||
{
|
{
|
||||||
id: 'memberPracticeSummaryReport',
|
id: 'memberPracticeSummaryReport',
|
||||||
showInMenu: true,
|
showInMenu: true,
|
||||||
|
showOnHomePage: true,
|
||||||
title: 'Member Practice Summary Report',
|
title: 'Member Practice Summary Report',
|
||||||
url: '/member-practice-summary-report',
|
url: '/member-practice-summary-report',
|
||||||
component: MemberPracticeSummaryReport,
|
component: MemberPracticeSummaryReport,
|
||||||
|
description: 'Generate a report for a year, for all members',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'specificMemberIncidentsReport',
|
id: 'specificMemberIncidentsReport',
|
||||||
showInMenu: true,
|
showInMenu: true,
|
||||||
|
showOnHomePage: true,
|
||||||
title: 'Member Incidents Report',
|
title: 'Member Incidents Report',
|
||||||
url: '/specific-member-incidents-report',
|
url: '/specific-member-incidents-report',
|
||||||
component: SpecificMemberIncidentsReport,
|
component: SpecificMemberIncidentsReport,
|
||||||
|
description: 'Displays all incidents with a total charge amount in a selected month for a selected member. It is also possible to send displayed fees to the ORD',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'specificMemberIncidentsReportWithMemberId',
|
id: 'specificMemberIncidentsReportWithMemberId',
|
||||||
showInMenu: false,
|
showInMenu: false,
|
||||||
|
showOnHomePage: false,
|
||||||
url: '/specific-member-incidents-report/:memberId',
|
url: '/specific-member-incidents-report/:memberId',
|
||||||
component: SpecificMemberIncidentsReport,
|
component: SpecificMemberIncidentsReport,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'report',
|
id: 'report',
|
||||||
showInMenu: true,
|
showInMenu: true,
|
||||||
|
showOnHomePage: true,
|
||||||
title: 'Incidents Report',
|
title: 'Incidents Report',
|
||||||
url: '/incidents-report',
|
url: '/incidents-report',
|
||||||
component: IncidentsReport,
|
component: IncidentsReport,
|
||||||
|
description: 'Display all incidents in a selected month for all members. It is also possible to send displayed fees to the ORD',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'uploadDLockData',
|
id: 'uploadDLockData',
|
||||||
showInMenu: true,
|
showInMenu: true,
|
||||||
|
showOnHomePage: true,
|
||||||
title: 'DLock',
|
title: 'DLock',
|
||||||
url: '/dlock',
|
url: '/dlock',
|
||||||
component: UploadDLockData,
|
component: UploadDLockData,
|
||||||
|
description: 'Upload DLock files to the system',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'roomOfficeNameMapping',
|
||||||
|
showInMenu: true,
|
||||||
|
showOnHomePage: true,
|
||||||
|
title: 'Room Office Mapping',
|
||||||
|
url: '/room-office-name-mapping',
|
||||||
|
component: RoomOfficeNameMapping,
|
||||||
|
description: 'Edit / delete existing office-room mappings',
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
import { Container, Form } from 'semantic-ui-react';
|
import { Container, Message } from 'semantic-ui-react';
|
||||||
|
|
||||||
import MainMenu from '../../components/MainMenu';
|
import MainMenu from '../../components/MainMenu';
|
||||||
|
import { mainMenuItems } from '../../constants/menuItems';
|
||||||
|
|
||||||
class Home extends Component {
|
class Home extends Component {
|
||||||
|
|
||||||
@@ -10,25 +11,23 @@ class Home extends Component {
|
|||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<MainMenu/>
|
<MainMenu/>
|
||||||
<h3>Report</h3>
|
<h3>SIMA SPACE </h3>
|
||||||
<hr/>
|
<hr/>
|
||||||
<Form>
|
{
|
||||||
<Form.Group widths="equal">
|
mainMenuItems.map((menuItem) => {
|
||||||
<Form.Input
|
const { showOnHomePage, title, description, url} = menuItem;
|
||||||
fluid
|
if (showOnHomePage){
|
||||||
required
|
|
||||||
label="Start date"
|
return (
|
||||||
type="date"
|
<Message size={'large'}>
|
||||||
/>
|
<a href={url}><Message.Header>{title}</Message.Header></a>
|
||||||
<Form.Input
|
<br/>
|
||||||
fluid
|
{description}
|
||||||
required
|
</Message>
|
||||||
label="End date"
|
);
|
||||||
type="date"
|
}
|
||||||
/>
|
})
|
||||||
</Form.Group>
|
}
|
||||||
<Form.Button>Show report</Form.Button>
|
|
||||||
</Form>
|
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
|
import { Table, Label, Icon, Dropdown } from 'semantic-ui-react';
|
||||||
|
import PromptMessage from '../../../components/PromptMessage';
|
||||||
|
import { deleteMapping, updateMapping } from '../../../store/actions';
|
||||||
|
|
||||||
|
class SingleMapping extends Component {
|
||||||
|
state = {showDeletePrompt: false, newOfficeId: null, newResourceId: null};
|
||||||
|
|
||||||
|
deleteMapping = () => {
|
||||||
|
this.setState({showDeletePrompt: true});
|
||||||
|
};
|
||||||
|
|
||||||
|
onPromptClose = () => {
|
||||||
|
this.setState({showDeletePrompt: false});
|
||||||
|
};
|
||||||
|
|
||||||
|
onPromptYes = () => {
|
||||||
|
const { singleMapping: { id }, deleteMapping } = this.props;
|
||||||
|
if (parseInt(id)){
|
||||||
|
deleteMapping(id);
|
||||||
|
}
|
||||||
|
this.onPromptClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
onOfficeChange = (event, data) => {
|
||||||
|
const newOfficeId = data.value;
|
||||||
|
const { allResourceOptions, officeId: oldOfficeId } = this.props;
|
||||||
|
|
||||||
|
if (oldOfficeId !== newOfficeId){
|
||||||
|
let newResourceId = null;
|
||||||
|
const roomOptionsForOffice = allResourceOptions[newOfficeId] && allResourceOptions[newOfficeId].roomOptions ?
|
||||||
|
allResourceOptions[newOfficeId].roomOptions : [];
|
||||||
|
|
||||||
|
if (roomOptionsForOffice.length > 0){
|
||||||
|
newResourceId = roomOptionsForOffice[0].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({newOfficeId, newResourceId});
|
||||||
|
}else{
|
||||||
|
this.setState({newOfficeId: null, newResourceId: null});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onResourceChange = (event, data) => {
|
||||||
|
const newResourceId = data.value;
|
||||||
|
const oldResourceId = this.props.resourceId;
|
||||||
|
|
||||||
|
if (oldResourceId !== newResourceId){
|
||||||
|
this.setState({newResourceId});
|
||||||
|
}else{
|
||||||
|
this.setState({newResourceId: null});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMappingUpdate = () => {
|
||||||
|
const { singleMapping: { id, officeSlug, resourceSlug }, updateMapping, officeId, resourceId } = this.props;
|
||||||
|
const { newOfficeId, newResourceId } = this.state;
|
||||||
|
|
||||||
|
const selectedOfficeId = newOfficeId ? newOfficeId : officeId;
|
||||||
|
const selectedResourceId = newResourceId ? newResourceId : resourceId;
|
||||||
|
|
||||||
|
if (parseInt(id)){
|
||||||
|
|
||||||
|
const modifiedMapping = {
|
||||||
|
officeSlug,
|
||||||
|
resourceSlug,
|
||||||
|
officeId: selectedOfficeId,
|
||||||
|
resourceId: selectedResourceId,
|
||||||
|
};
|
||||||
|
|
||||||
|
updateMapping(id, modifiedMapping);
|
||||||
|
this.setState({newOfficeId: null, newResourceId: null});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { singleMapping: { officeSlug, resourceSlug } } = this.props;
|
||||||
|
const { officeId, resourceId, officeOptions, allResourceOptions, pendingMappings } = this.props;
|
||||||
|
const { showDeletePrompt, newOfficeId, newResourceId } = this.state;
|
||||||
|
|
||||||
|
const selectedOfficeId = newOfficeId ? newOfficeId : officeId;
|
||||||
|
const selectedResourceId = newResourceId ? newResourceId : resourceId;
|
||||||
|
|
||||||
|
const resourceOptions = allResourceOptions && officeId ? allResourceOptions[selectedOfficeId].roomOptions : [];
|
||||||
|
|
||||||
|
const enableActions = !pendingMappings;
|
||||||
|
const enableSave = enableActions && ((newOfficeId !== null) || (newResourceId !== null));
|
||||||
|
const saveIconColor = enableSave ? 'green' : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table.Row>
|
||||||
|
<PromptMessage
|
||||||
|
onClose={this.onPromptClose}
|
||||||
|
onActionNo={this.onPromptClose}
|
||||||
|
onActionYes={this.onPromptYes}
|
||||||
|
title={'Delete mapping'}
|
||||||
|
message={'Do you want to delete this mapping ?'}
|
||||||
|
show={showDeletePrompt}
|
||||||
|
/>
|
||||||
|
<Table.Cell>
|
||||||
|
<Label size={'big'}>{`[${officeSlug}-${resourceSlug}]`}</Label>
|
||||||
|
</Table.Cell>
|
||||||
|
<Table.Cell>
|
||||||
|
<Dropdown
|
||||||
|
options={officeOptions}
|
||||||
|
defaultValue={officeId}
|
||||||
|
onChange={this.onOfficeChange}
|
||||||
|
/>
|
||||||
|
</Table.Cell>
|
||||||
|
<Table.Cell>
|
||||||
|
<Dropdown
|
||||||
|
options={resourceOptions}
|
||||||
|
value={selectedResourceId}
|
||||||
|
onChange={this.onResourceChange}
|
||||||
|
/>
|
||||||
|
</Table.Cell>
|
||||||
|
<Table.Cell>
|
||||||
|
<Icon
|
||||||
|
circular
|
||||||
|
name={'check'}
|
||||||
|
size={'large'}
|
||||||
|
disabled={!enableSave}
|
||||||
|
link={enableSave || null}
|
||||||
|
color={saveIconColor}
|
||||||
|
onClick={this.onMappingUpdate}
|
||||||
|
/>
|
||||||
|
<Icon
|
||||||
|
circular
|
||||||
|
name={'trash'}
|
||||||
|
size={'large'}
|
||||||
|
disabled={!enableActions}
|
||||||
|
link={enableActions || null}
|
||||||
|
onClick={this.deleteMapping}
|
||||||
|
/>
|
||||||
|
</Table.Cell>
|
||||||
|
</Table.Row>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
pendingMappings: state.mappingsData.pending,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
deleteMapping: (id) => deleteMapping(dispatch, id),
|
||||||
|
updateMapping: (id, mapping) => updateMapping(dispatch, id, mapping),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(SingleMapping);
|
||||||
99
client/src/scenes/RoomOfficeNameMapping/index.js
Normal file
99
client/src/scenes/RoomOfficeNameMapping/index.js
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { Container, Message, Loader, Table } from 'semantic-ui-react';
|
||||||
|
|
||||||
|
import MainMenu from '../../components/MainMenu';
|
||||||
|
import { fetchMappings } from '../../store/actions';
|
||||||
|
import SingleMapping from './components/SingleMapping';
|
||||||
|
|
||||||
|
class RoomOfficeNameMapping extends Component {
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const { fetchMappings } = this.props;
|
||||||
|
|
||||||
|
fetchMappings();
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { pendingMappings, mappings } = this.props;
|
||||||
|
const existingMappings = mappings && mappings.existingMappings ? mappings.existingMappings : [];
|
||||||
|
const offices = mappings && mappings.offices ? mappings.offices : [];
|
||||||
|
const resources = mappings && mappings.resources ? mappings.resources : [];
|
||||||
|
|
||||||
|
const officeDropdownOptions = offices.map((office) => {
|
||||||
|
const { officeId, officeName } = office;
|
||||||
|
return {
|
||||||
|
key: officeId,
|
||||||
|
value: officeId,
|
||||||
|
text: officeName,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const allResourceOptions = {};
|
||||||
|
resources.forEach((resource) => {
|
||||||
|
const { resourceId, resourceName, officeId } = resource;
|
||||||
|
|
||||||
|
if (!allResourceOptions[officeId]){
|
||||||
|
allResourceOptions[officeId] = {
|
||||||
|
roomOptions: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allResourceOptions[officeId].roomOptions.push({
|
||||||
|
key: resourceId,
|
||||||
|
value: resourceId,
|
||||||
|
text: resourceName,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container>
|
||||||
|
<Loader active={pendingMappings} />
|
||||||
|
<MainMenu/>
|
||||||
|
<h3>Room Office Mapping</h3>
|
||||||
|
<hr/>
|
||||||
|
<br/>
|
||||||
|
<Table singleLine unstackable>
|
||||||
|
<Table.Header>
|
||||||
|
<Table.Row>
|
||||||
|
<Table.HeaderCell>File name</Table.HeaderCell>
|
||||||
|
<Table.HeaderCell>Office</Table.HeaderCell>
|
||||||
|
<Table.HeaderCell>Resource</Table.HeaderCell>
|
||||||
|
<Table.HeaderCell>Actions</Table.HeaderCell>
|
||||||
|
</Table.Row>
|
||||||
|
</Table.Header>
|
||||||
|
<Table.Body>
|
||||||
|
{
|
||||||
|
existingMappings.map((singleMapping) => {
|
||||||
|
const { officeId, resourceId } = singleMapping;
|
||||||
|
return <SingleMapping
|
||||||
|
key={singleMapping.id}
|
||||||
|
singleMapping={singleMapping}
|
||||||
|
officeId={officeId}
|
||||||
|
resourceId={resourceId}
|
||||||
|
officeOptions={officeDropdownOptions}
|
||||||
|
allResourceOptions={allResourceOptions}
|
||||||
|
/>
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</Table.Body>
|
||||||
|
</Table>
|
||||||
|
<br/>
|
||||||
|
<Message>
|
||||||
|
<h4>To add the mapping, upload new DL lock files and you will be prompted with new mapping options if the file name contains the unknown location</h4>
|
||||||
|
</Message>
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
pendingMappings: state.mappingsData.pending,
|
||||||
|
mappings: state.mappingsData.result,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
fetchMappings: () => fetchMappings(dispatch),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(RoomOfficeNameMapping);
|
||||||
@@ -38,6 +38,30 @@ export const fetchMappings = (dispatch) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deleteMapping = (dispatch, mappingId) => {
|
||||||
|
dispatch({type: FETCH_MAPPINGS_PENDING});
|
||||||
|
API.delete(`integration/mappings/${mappingId}`)
|
||||||
|
.then(response => {
|
||||||
|
dispatch({type: FETCH_MAPPINGS_SUCCESS, payload: response.data});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dispatch({type: FETCH_MAPPINGS_FAILED, payload: error.response});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateMapping = (dispatch, id, mapping) => {
|
||||||
|
dispatch({type: FETCH_MAPPINGS_PENDING});
|
||||||
|
API.put(`integration/mappings/${id}`, {
|
||||||
|
mapping
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
dispatch({type: FETCH_MAPPINGS_SUCCESS, payload: response.data});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dispatch({type: FETCH_MAPPINGS_FAILED, payload: error.response});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const addNewMapping = (dispatch, mapping) => {
|
export const addNewMapping = (dispatch, mapping) => {
|
||||||
dispatch({type: ADD_NEW_MAPPING_PENDING});
|
dispatch({type: ADD_NEW_MAPPING_PENDING});
|
||||||
API.post('integration/mappings', {
|
API.post('integration/mappings', {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
|
|
||||||
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase } = require('../services/officeRnD/resources');
|
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase, deleteMappingById, updateMappingById } = require('../services/officeRnD/resources');
|
||||||
const { getAllIncidents, getMemberPracticeSummaryReport } = require('../services/integration/reports');
|
const { getAllIncidents, getMemberPracticeSummaryReport } = require('../services/integration/reports');
|
||||||
const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
|
const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
|
||||||
const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees');
|
const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees');
|
||||||
@@ -13,7 +13,7 @@ const { checkIfProcessing } = require('../services/integration/processingStatus'
|
|||||||
const { UI_TIMEZONE } = require('../constants/constants');
|
const { UI_TIMEZONE } = require('../constants/constants');
|
||||||
|
|
||||||
const getKnownOfficeResourceMappings = (req, res) => {
|
const getKnownOfficeResourceMappings = (req, res) => {
|
||||||
const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources() ];
|
const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources()];
|
||||||
|
|
||||||
Promise.all(dataToFetch)
|
Promise.all(dataToFetch)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
@@ -24,6 +24,7 @@ const getKnownOfficeResourceMappings = (req, res) => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
console.log('Error with fetching mappings : ', error);
|
||||||
res.status(500).send();
|
res.status(500).send();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -41,6 +42,43 @@ const addNewMapping = (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteMapping = (req, res) => {
|
||||||
|
const mappingId = req.params.mappingId;
|
||||||
|
|
||||||
|
if (mappingId && parseInt(mappingId)){
|
||||||
|
deleteMappingById(mappingId)
|
||||||
|
.then(() => {
|
||||||
|
getKnownOfficeResourceMappings(req, res);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error deleting mapping with id = ', mappingId);
|
||||||
|
console.log(error);
|
||||||
|
res.status(500).send();
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
getKnownOfficeResourceMappings(req, res);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateMapping = (req, res) => {
|
||||||
|
const mappingId = req.params.mappingId;
|
||||||
|
const mapping = req.body && req.body.mapping ? req.body.mapping : null;
|
||||||
|
|
||||||
|
if (mappingId && parseInt(mappingId)){
|
||||||
|
updateMappingById(mappingId, mapping)
|
||||||
|
.then(() => {
|
||||||
|
getKnownOfficeResourceMappings(req, res);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error updating mapping with id = ', mappingId);
|
||||||
|
console.log(error);
|
||||||
|
res.status(500).send();
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
getKnownOfficeResourceMappings(req, res);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getAllIncidentsController = (req, res) => {
|
const getAllIncidentsController = (req, res) => {
|
||||||
const dateRange = {
|
const dateRange = {
|
||||||
startDate: req.params.startDate,
|
startDate: req.params.startDate,
|
||||||
@@ -170,6 +208,8 @@ const getPracticeSummaryReport = (req, res) => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
getKnownOfficeResourceMappings,
|
getKnownOfficeResourceMappings,
|
||||||
addNewMapping,
|
addNewMapping,
|
||||||
|
deleteMapping,
|
||||||
|
updateMapping,
|
||||||
getAllIncidentsController,
|
getAllIncidentsController,
|
||||||
getMemberIncidents,
|
getMemberIncidents,
|
||||||
addFees,
|
addFees,
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ const { fetchMembersList } = require('../controllers/officeRnD');
|
|||||||
const {
|
const {
|
||||||
getKnownOfficeResourceMappings,
|
getKnownOfficeResourceMappings,
|
||||||
addNewMapping,
|
addNewMapping,
|
||||||
|
deleteMapping,
|
||||||
|
updateMapping,
|
||||||
getAllIncidentsController,
|
getAllIncidentsController,
|
||||||
getMemberIncidents,
|
getMemberIncidents,
|
||||||
addFees,
|
addFees,
|
||||||
@@ -23,6 +25,8 @@ router.get('/', apiStatusCheck);
|
|||||||
router.post('/doorLock/upload', uploadDoorLockData);
|
router.post('/doorLock/upload', uploadDoorLockData);
|
||||||
router.get('/integration/mappings', getKnownOfficeResourceMappings);
|
router.get('/integration/mappings', getKnownOfficeResourceMappings);
|
||||||
router.post('/integration/mappings', addNewMapping);
|
router.post('/integration/mappings', addNewMapping);
|
||||||
|
router.delete('/integration/mappings/:mappingId', deleteMapping);
|
||||||
|
router.put('/integration/mappings/:mappingId', updateMapping);
|
||||||
|
|
||||||
router.get('/integration/report/member/:memberId/:startDate/:endDate', getMemberIncidents);
|
router.get('/integration/report/member/:memberId/:startDate/:endDate', getMemberIncidents);
|
||||||
router.get('/integration/report/allIncidents/:startDate/:endDate', getAllIncidentsController);
|
router.get('/integration/report/allIncidents/:startDate/:endDate', getAllIncidentsController);
|
||||||
|
|||||||
@@ -70,7 +70,19 @@ const getResourceMappings = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getMappingsFromDatabase = () => {
|
const getMappingsFromDatabase = () => {
|
||||||
return db.officeResourceMapping.findAll();
|
return db.officeResourceMapping.findAll({order: [['id']]});
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteMappingById = (id) => {
|
||||||
|
return db.officeResourceMapping.destroy({where: {id}});
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateMappingById = (id, mapping) => {
|
||||||
|
if (mapping.id) {
|
||||||
|
delete mapping.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.officeResourceMapping.update(mapping, {where: {id}});
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveNewMappingToDatabase = (mapping) => {
|
const saveNewMappingToDatabase = (mapping) => {
|
||||||
@@ -83,4 +95,6 @@ module.exports = {
|
|||||||
fetchResources,
|
fetchResources,
|
||||||
getResourceMappings,
|
getResourceMappings,
|
||||||
saveNewMappingToDatabase,
|
saveNewMappingToDatabase,
|
||||||
|
deleteMappingById,
|
||||||
|
updateMappingById,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user