@@ -39,71 +39,75 @@ const queryDeviceType = require('../db/query-device-type.js')
3939 *
4040 * @param {* } options
4141 */
42- async function user_endpoints ( options ) {
43- let packageInfo = await templateUtil
42+ function user_endpoints ( options ) {
43+ let promise = templateUtil
4444 . ensureTemplatePackageId ( this )
4545 . then ( ( packageId ) =>
4646 queryPackage . getPackageByPackageId ( this . global . db , packageId )
4747 )
48- let packageInfoCategory = packageInfo . category
49- let promise = Promise . all ( [
50- queryEndpointType . selectAllEndpointTypes (
51- this . global . db ,
52- this . global . sessionId
53- ) ,
54- templateUtil
55- . ensureEndpointTypeIds ( this )
56- . then ( ( endpointTypes ) =>
57- queryImpexp . exportEndpoints (
48+ . then ( ( packageInfo ) => packageInfo . category )
49+ . then ( ( packageInfoCategory ) =>
50+ Promise . all ( [
51+ queryEndpointType . selectAllEndpointTypes (
5852 this . global . db ,
59- this . global . sessionId ,
60- endpointTypes
61- )
62- ) ,
63- ] )
64- . then (
65- ( EptEp ) =>
66- new Promise ( ( resolve , reject ) => {
67- let endpointTypeMap = { }
68- let endpointTypes = EptEp [ 0 ]
69- let endpoints = EptEp [ 1 ]
70- endpointTypes . forEach (
71- ( ept ) =>
72- ( endpointTypeMap [ ept . endpointTypeId ] = {
73- deviceVersions : ept . deviceVersion ,
74- deviceIdentifiers : ept . deviceIdentifier ,
75- deviceCategories : ept . deviceCategory ,
53+ this . global . sessionId
54+ ) ,
55+ templateUtil
56+ . ensureEndpointTypeIds ( this )
57+ . then ( ( endpointTypes ) =>
58+ queryImpexp . exportEndpoints (
59+ this . global . db ,
60+ this . global . sessionId ,
61+ endpointTypes
62+ )
63+ ) ,
64+ ] )
65+ . then (
66+ ( EptEp ) =>
67+ new Promise ( ( resolve , reject ) => {
68+ let endpointTypeMap = { }
69+ let endpointTypes = EptEp [ 0 ]
70+ let endpoints = EptEp [ 1 ]
71+ endpointTypes . forEach (
72+ ( ept ) =>
73+ ( endpointTypeMap [ ept . endpointTypeId ] = {
74+ deviceVersions : ept . deviceVersion ,
75+ deviceIdentifiers : ept . deviceIdentifier ,
76+ deviceCategories : ept . deviceCategory ,
77+ } )
78+ )
79+ // Adding device Identifiers and versions to endpoints from endpoint types
80+ endpoints . forEach ( ( ep ) => {
81+ ep . deviceIdentifier =
82+ endpointTypeMap [ ep . endpointTypeRef ] . deviceIdentifiers
83+ ep . endpointVersion =
84+ endpointTypeMap [ ep . endpointTypeRef ] . deviceVersions
85+ ep . endpointCategories =
86+ endpointTypeMap [ ep . endpointTypeRef ] . deviceCategories
7687 } )
77- )
78- // Adding device Identifiers and versions to endpoints from endpoint types
79- endpoints . forEach ( ( ep ) => {
80- ep . deviceIdentifier =
81- endpointTypeMap [ ep . endpointTypeRef ] . deviceIdentifiers
82- ep . endpointVersion =
83- endpointTypeMap [ ep . endpointTypeRef ] . deviceVersions
84- ep . endpointCategories =
85- endpointTypeMap [ ep . endpointTypeRef ] . deviceCategories
88+ resolve ( endpoints )
89+ } )
90+ )
91+ . then ( ( endpoints ) =>
92+ packageInfoCategory
93+ ? endpoints . filter (
94+ ( ep ) =>
95+ ep . endpointCategories . includes ( packageInfoCategory ) ||
96+ ep . endpointCategories . includes ( undefined ) ||
97+ ep . endpointCategories . includes ( null )
98+ )
99+ : endpoints
100+ )
101+ . then ( ( endpoints ) =>
102+ endpoints . map ( ( x ) => {
103+ x . endpointTypeId = x . endpointTypeRef
104+ return x
86105 } )
87- resolve ( endpoints )
88- } )
89- )
90- . then ( ( endpoints ) =>
91- packageInfoCategory
92- ? endpoints . filter (
93- ( ep ) =>
94- ep . endpointCategories . includes ( packageInfoCategory ) ||
95- ep . endpointCategories . includes ( undefined ) ||
96- ep . endpointCategories . includes ( null )
97- )
98- : endpoints
99- )
100- . then ( ( endpoints ) =>
101- endpoints . map ( ( x ) => {
102- x . endpointTypeId = x . endpointTypeRef
103- return x
104- } )
106+ )
107+ . then ( ( endpoints ) =>
108+ templateUtil . collectBlocks ( endpoints , options , this )
109+ )
105110 )
106- . then ( ( endpoints ) => templateUtil . collectBlocks ( endpoints , options , this ) )
107111
108112 return templateUtil . templatePromise ( this . global , promise )
109113}
0 commit comments