-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(survey): add support for additional attributes on model (#20)
- Loading branch information
1 parent
5ce0305
commit f2a3fd8
Showing
12 changed files
with
81 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
exports.address = require('./address'); | ||
exports.surveyAddressState = require('./surveyAddressState'); | ||
exports.SurveyAddress = require('./surveyAddress'); | ||
exports.SurveyAddressAdditionalAttributes = require('./surveyAddressAdditionalAttributes'); | ||
exports.surveyAddressState = require('./surveyAddressState'); | ||
exports.SurveyDump = require('./surveyDump'); | ||
exports.SyncLog = require('./syncLog'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const logger = require('../helpers/logger'); | ||
const UtilService = require('../services/util'); | ||
|
||
const surveyAddress = UtilService.tryRequire('./model/surveyAddress.js'); | ||
|
||
if (surveyAddress) { | ||
logger.info('Loading SurveyAddress additional attributes...'); | ||
module.exports = surveyAddress; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
exports.StatusService = require('./status'); | ||
exports.SurveyService = require('./survey'); | ||
exports.SyncService = require('./sync'); | ||
exports.UtilService = require('./util'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const {forEach, keys} = require('lodash'); | ||
|
||
const {SurveyAddressAdditionalAttributes, surveyAddressState} = require('../model'); | ||
|
||
class SurveyService { | ||
static assign(surveyAddress, survey) { | ||
surveyAddress.surveyAddressState = survey.closed ? surveyAddressState.RESOLVED : surveyAddressState.IN_PROGRESS; | ||
surveyAddress.dwellings = survey.dwellings; | ||
surveyAddress.valid = survey.valid; | ||
|
||
forEach( | ||
keys(SurveyAddressAdditionalAttributes), | ||
key => { | ||
surveyAddress[key] = survey[key]; | ||
} | ||
); | ||
} | ||
} | ||
|
||
module.exports = SurveyService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
class UtilService { | ||
/** | ||
* Try to require a file if that exists. | ||
* @param {String} from The path to the required file. | ||
*/ | ||
static tryRequire(from) { | ||
const file = path.resolve(from); | ||
return fs.existsSync(file) ? require(file) : null; | ||
} | ||
} | ||
|
||
module.exports = UtilService; |