| 1566 | } |
| 1567 | |
| 1568 | async function buildSemanticLayer(teamId) { |
| 1569 | const team = await db.Team.findByPk(teamId); |
| 1570 | if (!team) { |
| 1571 | throw new Error("Team not found"); |
| 1572 | } |
| 1573 | |
| 1574 | const connections = await db.Connection.findAll({ |
| 1575 | where: { |
| 1576 | team_id: teamId, |
| 1577 | }, |
| 1578 | attributes: ["id", "type", "subType", "name", "schema"], |
| 1579 | }); |
| 1580 | |
| 1581 | const projects = await db.Project.findAll({ |
| 1582 | where: { |
| 1583 | team_id: teamId, |
| 1584 | ghost: false, |
| 1585 | }, |
| 1586 | attributes: ["id", "name"], |
| 1587 | include: [ |
| 1588 | { |
| 1589 | model: db.Chart, |
| 1590 | attributes: ["id", "name", "type", "subType", "timeInterval", "stacked", "horizontal", "ranges"], |
| 1591 | }, |
| 1592 | ], |
| 1593 | }); |
| 1594 | |
| 1595 | const datasets = await db.Dataset.findAll({ |
| 1596 | where: { |
| 1597 | team_id: teamId, |
| 1598 | }, |
| 1599 | attributes: ["id", "name", "legend", "main_dr_id"], |
| 1600 | include: [{ |
| 1601 | model: db.DataRequest, |
| 1602 | attributes: ["id", "connection_id", "query", "conditions", "configuration", "variables", "transform"] |
| 1603 | }] |
| 1604 | }); |
| 1605 | |
| 1606 | const chartCatalog = [{ |
| 1607 | "line": { |
| 1608 | description: "A line chart can be used to show trends over time, can be used as an area chart by setting the fillColor", |
| 1609 | }, |
| 1610 | "bar": { |
| 1611 | description: "A bar chart can be used to compare values across categories, can be used as a stacked bar chart by setting the stacked property to true. Use fillColor for bar charts to make them more visually appealing.", |
| 1612 | }, |
| 1613 | "pie": { |
| 1614 | description: "A pie chart can be used to show the proportion of each category in a total", |
| 1615 | }, |
| 1616 | "doughnut": { |
| 1617 | description: "A doughnut chart can be used to show the proportion of each category in a total, similar to a pie chart but with a hole in the center", |
| 1618 | }, |
| 1619 | "radar": { |
| 1620 | description: "A radar chart can be used to show the relative values of each category in a total", |
| 1621 | }, |
| 1622 | "polar": { |
| 1623 | description: "A polar chart can be used to show the relative values of each category in a total, similar to a radar chart but with a polar axis", |
| 1624 | }, |
| 1625 | "table": { |