Skip to content

Commit

Permalink
works on REDLINE-17
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Jul 6, 2023
1 parent 004122b commit 301a766
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion service-node-koa/app/routes/movimentacao.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const movimentacaoRouter = new Router();
movimentacaoRouter.get("/:usuario_id/movimentacao", async ctx => {
const { usuario_id } = ctx.request.params;
const { q = "", limit = 50, offset = 0, conta_id } = ctx.request.query;
if (conta_id) ctx.body = await listMovimentacaoByConta({ usuario_id, q, limit, offset });
if (conta_id) ctx.body = await listMovimentacaoByConta({ conta_id, q, limit, offset });
else ctx.body = await listMovimentacaoByUsuario({ usuario_id, q, limit, offset });
});

Expand Down
5 changes: 5 additions & 0 deletions web-app-vue/src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ export const insertCategoria = async ({ id, categoria }) =>

export const delCategoria = async ({ id, categoria }) =>
await del({ uri: `/${id}/categoria/${categoria.id}` })

export const lisTiposMovimentacao = async () => await get({ uri: '/tipo_movimentacao' })

export const listMovimentacoes = async ({ id, q = '', limit = 50, offset = 0 }) =>
await get({ uri: `/${id}/movimentacao?q=${q}&limit=${limit}&offset=${offset}` })
4 changes: 3 additions & 1 deletion web-app-vue/src/services/redLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const getRedLine = () => {
},
tiposConta: [],
contas: [],
categorias: []
categorias: [],
movimentacoes: [],
tiposMovimentacao: []
};
} else {
redLine = JSON.parse(lastState);
Expand Down
3 changes: 2 additions & 1 deletion web-app-vue/src/stores/contaStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const useContaStore = defineStore('conta-store', () => {

const sincronizarContas = async () => {
const redLine = getRedLine()
const contas = await listContas({ id: uState.userData.id })
const { id } = uState.userData
const contas = await listContas({ id })
const tiposConta = await listTiposConta()
store.contas = contas
store.tiposConta = tiposConta
Expand Down
31 changes: 31 additions & 0 deletions web-app-vue/src/stores/movimentacaoStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { defineStore } from 'pinia'
import { useUserStore } from '@/stores/userStore'
import { reactive } from 'vue'
import { getRedLine, setRedLine } from '@/services/redLine'
import { lisTiposMovimentacao } from "@/services/api";

export const useMovimentacaoStore = defineStore('movimentacao-store', () => {
const uState = useUserStore()

function initStore() {
const redLine = getRedLine()
return reactive({
tiposMovimentacao: redLine.tiposMovimentacao || [],
movimentacoes: redLine?.movimentacoes || []
})
}

const store = initStore()

const sincronizarMovimentacoes = async () => {
const redLine = getRedLine()
store.tiposMovimentacao = await lisTiposMovimentacao()
setRedLine({
...redLine,
tiposMovimentacao: store.tiposMovimentacao,
movimentacoes: store.movimentacoes
})
}

return { store, sincronizarMovimentacoes }
})

0 comments on commit 301a766

Please sign in to comment.