Skip to content

Commit

Permalink
fix query aliases so postgres stop complaining
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed May 14, 2024
1 parent 0d770fb commit 516053b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
3 changes: 3 additions & 0 deletions service-node-koa/.env.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALG=aes-256-cbc
SECRET=CH4NG3M3CH4NG3M3CH4NG3M3CH4NG3M3
PG_CONNECTION_URL=postgresql://<username>:<password>@<host>:<port>/<schema>
7 changes: 6 additions & 1 deletion service-node-koa/app/config/db/knexfile.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @type { Object.<string, import("knex").Knex.Config> }
* @type { import("knex").Knex.Config }
*/
const _cfg = {
client: 'sqlite3',
Expand Down Expand Up @@ -30,6 +30,11 @@ module.exports = {
// client: 'pg',
// connection: process.env.PG_CONNECTION_URL
},
staging: {
..._cfg,
client: 'pg',
connection: process.env.PG_CONNECTION_URL
},
production: {
..._cfg,
client: 'pg',
Expand Down
14 changes: 7 additions & 7 deletions service-node-koa/app/services/dashboard.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ async function receitaDespesaEfetivadaPeriodo({ usuario_id, inicio, fim }) {

async function despesaConta({ usuario_id, inicio, fim }) {
return knex.raw(`
with data_frame as (select conta.*, movimentacao.*
with data_frame as (select conta.descricao, conta.cor, movimentacao.valor
from conta
join movimentacao on conta.id = movimentacao.conta_id
where usuario_id = :usuario_id
and tipo_movimentacao_id = 2
and vencimento between :inicio and :fim)
select descricao as label,
cor as color,
cor as color,
sum(valor) as value
from data_frame
group by descricao, cor
Expand All @@ -91,7 +91,7 @@ async function despesaConta({ usuario_id, inicio, fim }) {

async function despesaCategoria({ usuario_id, inicio, fim }) {
return knex.raw(`
with data_frame as (select categoria.*, movimentacao.*
with data_frame as (select categoria.descricao, categoria.cor, movimentacao.valor
from movimentacao
left join categoria on categoria.id = movimentacao.categoria_id
where usuario_id = :usuario_id
Expand All @@ -108,7 +108,7 @@ async function despesaCategoria({ usuario_id, inicio, fim }) {

async function receitaConta({ usuario_id, inicio, fim }) {
return knex.raw(`
with data_frame as (select *
with data_frame as (select conta.descricao, conta.cor, movimentacao.valor
from conta
join movimentacao on conta.id = movimentacao.conta_id
where usuario_id = :usuario_id
Expand All @@ -124,7 +124,7 @@ async function receitaConta({ usuario_id, inicio, fim }) {

async function receitaCategoria({ usuario_id, inicio, fim }) {
return knex.raw(`
with data_frame as (select categoria.*, movimentacao.*
with data_frame as (select categoria.descricao, categoria.cor, movimentacao.valor
from movimentacao
left join categoria on categoria.id = movimentacao.categoria_id
where usuario_id = :usuario_id
Expand All @@ -144,7 +144,7 @@ async function composicaoDespesas({ usuario_id, inicio, fim }){
const conta_id = conta.id
conta.color = conta.cor
conta.data = await knex.raw(`
with data_frame as (select categoria.*, movimentacao.*
with data_frame as (select categoria.descricao, categoria.cor, movimentacao.valor
from movimentacao
left join categoria on categoria.id = movimentacao.categoria_id
where conta_id = :conta_id
Expand All @@ -164,7 +164,7 @@ async function composicaoReceitas({ usuario_id, inicio, fim }){
const conta_id = conta.id
conta.color = conta.cor
conta.data = await knex.raw(`
with data_frame as (select categoria.*, movimentacao.*
with data_frame as (select categoria.descricao, categoria.cor, movimentacao.valor
from movimentacao
left join categoria on categoria.id = movimentacao.categoria_id
where conta_id = :conta_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: '3.8'
---
# version: '3.8'

services:
db:
Expand Down
1 change: 1 addition & 0 deletions service-node-koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"start": "node -r dotenv-flow/config index.mjs",
"dev:service": "cross-env NODE_ENV=development nodemon -r dotenv-flow/config",
"staging:service": "cross-env NODE_ENV=staging nodemon -r dotenv-flow/config",
"test:service": "cross-env NODE_ENV=test mocha -r dotenv-flow/config -r app/config/_test_hooks.mjs --recursive app",
"test:service:coverage": "c8 npm run test:service",
"migrate:make": "knex migrate:make --knexfile app/config/db/knexfile.cjs -x mjs -- ",
Expand Down
28 changes: 14 additions & 14 deletions web-app-vue/src/components/dashboard/controles-dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
<h3>Composição de despesas</h3>
<div v-for="conta in composicaoDespesas" :key="conta.descricao">
<h4>{{ conta.descricao }}</h4>
<VueUiSparkStackbar
<VueUiSparkstackbar
:config="sparkStackBarConfig"
:dataset="conta.data"
></VueUiSparkStackbar>
></VueUiSparkstackbar>
</div>
<br />
<v-divider></v-divider>
Expand Down Expand Up @@ -165,7 +165,7 @@
<script setup>
import { endOfMonth, startOfMonth } from 'date-fns'
import { computed, onMounted, ref } from 'vue'
import { VueUiDonut, VueUiSparkbar, VueUiSparkStackbar, VueUiXy } from 'vue-data-ui'
import { VueUiDonut, VueUiSparkbar, VueUiSparkstackbar, VueUiXy } from 'vue-data-ui'
import ChipPeriodo from '@/shared/chip-periodo.vue'
import { useDashboardStore } from '@/stores/dashboardStore'
import ChipSaldo from '@/shared/chip-saldo.vue'
Expand All @@ -185,7 +185,7 @@ const dashboardState = useDashboardStore()
const receitaDespesaBarConfig = computed(() => {
const total =
dashboardState.store.dashboard.receitaDespesaTotalPeriodo?.reduce((acc, e) => {
dashboardState.store.dashboard?.receitaDespesaTotalPeriodo?.reduce((acc, e) => {
acc += e.value
return acc
}, 0) || 0
Expand All @@ -203,55 +203,55 @@ const receitaDespesaBarConfig = computed(() => {
})
const receitaDespesaTotalPeriodo = computed(() => {
return dashboardState.store.dashboard.receitaDespesaTotalPeriodo?.map((r) => ({
return dashboardState.store.dashboard?.receitaDespesaTotalPeriodo?.map((r) => ({
...r,
name: r.label,
prefix: 'R$ '
}))
})
const receitaDespesaEfetivadaPeriodo = computed(() => {
return dashboardState.store.dashboard.receitaDespesaEfetivadaPeriodo?.map((r) => ({
return dashboardState.store.dashboard?.receitaDespesaEfetivadaPeriodo?.map((r) => ({
...r,
name: r.label,
prefix: 'R$ '
}))
})
const despesaConta = computed(() => {
return dashboardState.store.dashboard.despesaConta.map((r) => ({
return dashboardState.store.dashboard?.despesaConta?.map((r) => ({
...r,
name: `${r.label}`,
values: [r.value]
}))
})
const despesaCategoria = computed(() => {
return dashboardState.store.dashboard.despesaCategoria.map((r) => ({
return dashboardState.store.dashboard?.despesaCategoria?.map((r) => ({
...r,
name: `${r.label}`,
values: [r.value]
}))
})
const receitaConta = computed(() => {
return dashboardState.store.dashboard.receitaConta.map((r) => ({
return dashboardState.store.dashboard?.receitaConta?.map((r) => ({
...r,
name: `${r.label}`,
values: [r.value]
}))
})
const receitaCategoria = computed(() => {
return dashboardState.store.dashboard.receitaCategoria.map((r) => ({
return dashboardState.store.dashboard?.receitaCategoria?.map((r) => ({
...r,
name: `${r.label}`,
values: [r.value]
}))
})
const composicaoDespesas = computed(() => {
return dashboardState.store.dashboard.composicaoDespesas.map((g) => {
return dashboardState.store.dashboard?.composicaoDespesas?.map((g) => {
return {
...g,
data: g.data.map((r) => ({
Expand All @@ -263,7 +263,7 @@ const composicaoDespesas = computed(() => {
})
const composicaoReceitas = computed(() => {
return dashboardState.store.dashboard.composicaoReceitas.map((g) => {
return dashboardState.store.dashboard?.composicaoReceitas?.map((g) => {
return {
...g,
data: g.data.map((r) => ({
Expand All @@ -275,11 +275,11 @@ const composicaoReceitas = computed(() => {
})
const limites = computed(() => {
return dashboardState.store.dashboard.limites
return dashboardState.store.dashboard?.limites
})
const planejamentos = computed(() => {
return dashboardState.store.dashboard.planejamentos
return dashboardState.store.dashboard?.planejamentos
})
const dataset = ref([
Expand Down

0 comments on commit 516053b

Please sign in to comment.