-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46ee8cb
commit c11bf42
Showing
9 changed files
with
169 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* internetmarke | ||
* Copyright (c) 2018 Manuel Schächinger | ||
* MIT Lisenced | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Cachable = require('../helper/Cachable'); | ||
|
||
class PageFormat extends Cachable { | ||
/** | ||
* Defines a page format with the metadata and the id used in the api. | ||
* | ||
* @constructor | ||
* @param {Obect} data | ||
*/ | ||
constructor(data) { | ||
super({ prefix: 'PAGE_FORMAT', id: data.id, data }); | ||
} | ||
} | ||
|
||
module.exports = PageFormat; |
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,54 @@ | ||
/** | ||
* internetmarke | ||
* Copyright (c) 2018 Manuel Schächinger | ||
* MIT Lisenced | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const NodeCache = require('node-cache'); | ||
|
||
const PageFormat = require('./PageFormat'), | ||
OneClickForAppService = require('../Service/Soap/OneClickForApp'); | ||
|
||
class PageFormatList { | ||
constructor() { | ||
/** @type {NodeCache} */ | ||
this._nodeCache = new NodeCache({ stdTTL: 3600 * 24 }); | ||
|
||
this._pageFormats = {}; | ||
} | ||
|
||
/** | ||
* Loads the list of available page formats if not cached. | ||
* | ||
* @param {OneClickForAppService} oneClickForAppService - The 1C4A service to | ||
* load the latest list of page formats if necessary. | ||
* @returns {Promise.<Object>} | ||
*/ | ||
loadList(oneClickForAppService) { | ||
let promise = null; | ||
|
||
console.log(this._nodeCache.getStats()); | ||
|
||
if (!this._nodeCache.getStats().keys) { | ||
promise = oneClickForAppService.retrievePageFormats() | ||
.then(pages => { | ||
page.pageFormat.forEach(data => { | ||
const pageFormat = new PageFormat(data); | ||
pagFormat.save(); | ||
this._pageFormats[pageFormat.getId] = pageFormat; | ||
}); | ||
|
||
return this._pageFormats; | ||
}); | ||
} | ||
else { | ||
promise = Promise.resolve(this._pageFormats); | ||
} | ||
|
||
return promise; | ||
} | ||
} | ||
|
||
module.exports = PageFormatList; |
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 @@ | ||
/** | ||
* internetmarke | ||
* Copyright (c) 2018 Manuel Schächinger | ||
* MIT Licensed | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = require('./PageFormatList'); |
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,46 @@ | ||
/** | ||
* internetmarke | ||
* Copyright (c) 2018 Manuel Schächinger | ||
* MIT Lisenced | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const NodeCache = require('node-cache'); | ||
|
||
class Cachable { | ||
/** | ||
* Defines an abstract instanse of a cachable entity. | ||
* | ||
* @constructor | ||
* @param {Object} config | ||
* @param {string} config.prefix | ||
* @param {*} config.id | ||
* @param {Object} config.data | ||
*/ | ||
constructor({ prefix, id, data }) { | ||
/** @type {string} */ | ||
this._prefix = prefix; | ||
/** @type {*} */ | ||
this._id = id; | ||
|
||
if (data.id) { | ||
delete data.id; | ||
} | ||
/** @type {Object} */ | ||
this._data = data; | ||
|
||
/** @type {NodeCache} */ | ||
this._cache = new NodeCache({ stdTTL: 86400 }); | ||
} | ||
|
||
save() { | ||
this._cache.set(this.getId(), this._data); | ||
} | ||
|
||
getId() { | ||
return `${this._prefix}_${this._id}`; | ||
} | ||
} | ||
|
||
module.exports = Cachable; |
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