Refactoring to use entities over sites and networks.
This commit is contained in:
@@ -17,7 +17,10 @@ function curateEntity(entity, includeParameters = false) {
|
||||
type: entity.type,
|
||||
parameters: includeParameters ? entity.parameters : null,
|
||||
parent: entity.parent,
|
||||
children: (entity.children || []).map(child => curateEntity(child)),
|
||||
children: (entity.children || []).map(child => curateEntity({
|
||||
...child,
|
||||
parent: entity,
|
||||
})),
|
||||
};
|
||||
|
||||
return curatedEntity;
|
||||
@@ -28,7 +31,8 @@ async function curateEntities(entities, includeParameters) {
|
||||
}
|
||||
|
||||
async function fetchSitesFromArgv() {
|
||||
const rawEntities = await knex.raw(`
|
||||
const rawNetworks = await knex.raw(`
|
||||
/* networks from argument with sites as children */
|
||||
WITH RECURSIVE temp AS (
|
||||
SELECT
|
||||
id, parent_id, name, slug, type, url, description, parameters
|
||||
@@ -57,8 +61,10 @@ async function fetchSitesFromArgv() {
|
||||
GROUP BY
|
||||
temp.parent_id, entities.id, entities.name, parents.id
|
||||
UNION ALL
|
||||
|
||||
/* sites from argument as the child of network with parent */
|
||||
SELECT
|
||||
entities.*, row_to_json(parents) as parent, json_build_array(row_to_json(children))
|
||||
entities.*, row_to_json(parents) as parent, json_agg(row_to_json(children))
|
||||
FROM
|
||||
entities AS children
|
||||
LEFT JOIN
|
||||
@@ -68,15 +74,13 @@ async function fetchSitesFromArgv() {
|
||||
WHERE
|
||||
children.slug = ANY(?) AND children.type = 2
|
||||
GROUP BY
|
||||
entities.id, parents.id, children.id;
|
||||
entities.id, parents.id;
|
||||
`, [argv.networks || [], argv.sites || []]);
|
||||
|
||||
const curatedEntities = await curateEntities(rawEntities.rows, true);
|
||||
logger.info(`Found ${curatedEntities.length} entities in database`);
|
||||
const curatedNetworks = await curateEntities(rawNetworks.rows, true);
|
||||
logger.info(`Found ${curatedNetworks.length} networks in database`);
|
||||
|
||||
console.log(rawEntities.rows);
|
||||
|
||||
return curatedEntities;
|
||||
return curatedNetworks;
|
||||
}
|
||||
|
||||
async function fetchSitesFromConfig() {
|
||||
|
||||
Reference in New Issue
Block a user