Skip to content

Commit 6aa926f

Browse files
committed
minor enhancements
1 parent b3f13e4 commit 6aa926f

File tree

8 files changed

+103
-16
lines changed

8 files changed

+103
-16
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param { import('knex').Knex } knex
3+
* @returns { Promise<void> }
4+
*/
5+
export const up = async (knex) =>
6+
knex.schema.table('planejamento', tb => {
7+
tb.integer('tipo_movimentacao_id').unsigned().notNullable()
8+
.references('tipo_movimentacao.id').defaultTo(2)
9+
})
10+
11+
/**
12+
* @param { import('knex').Knex } knex
13+
* @returns { Promise<void> }
14+
*/
15+
export const down = async (knex) =>
16+
knex.schema.table('planejamento', tb => {
17+
tb.dropColumn("tipo_movimentacao_id")
18+
})

service-node-koa/app/services/recorrencia.mjs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { knex } from '../config/db/index.mjs'
2-
import { addMonths, differenceInDays, differenceInMonths, differenceInYears } from 'date-fns'
2+
import { addDays, addMonths, addYears, differenceInDays, differenceInMonths, differenceInYears } from 'date-fns'
33

44
export const listRecorrencia = ({ usuario_id = -1, q = '', limit = 10, offset = 0 }) => {
55
return knex('recorrencia')
@@ -41,16 +41,16 @@ export const geraLancamentos = async ({ usuario_id, id }) => {
4141
recorrencia_id: recorrencia.id,
4242
conta_id: recorrencia.conta_id,
4343
tipo_movimentacao_id: recorrencia.tipo_movimentacao_id,
44-
vencimento: addMonths(recorrencia.inicial, i).toISOString(),
44+
vencimento: proximoVencimento(recorrencia, i),
4545
valor: recorrencia.valorParcela
4646
})
4747
}
4848
const result = await knex('movimentacao').insert(lancamentos)
49-
return { success: true }
49+
return { success: true, result }
5050
}
5151

5252
const limparParcelas = async (recorrencia) => {
53-
return await knex('movimentacao').del().where({ recorrencia_id: recorrencia.id })
53+
return knex('movimentacao').del().where({ recorrencia_id: recorrencia.id })
5454
}
5555

5656
const calculaParcelas = ({ tipo_recorrencia_id, inicial, final }) => {
@@ -63,3 +63,14 @@ const calculaParcelas = ({ tipo_recorrencia_id, inicial, final }) => {
6363
return 1 + differenceInDays(final, inicial)
6464
}
6565
}
66+
67+
const proximoVencimento = (recorrencia, i) => {
68+
switch (recorrencia.tipo_recorrencia_id) {
69+
case 1:
70+
return addMonths(recorrencia.inicial, i).toISOString()
71+
case 2:
72+
return addYears(recorrencia.inicial, i).toISOString()
73+
default:
74+
return addDays(recorrencia.inicial, i).toISOString()
75+
}
76+
}

web-app-vue/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<link rel="icon" href="/favicon.ico">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=1.5">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.1, maximum-scale=1.5">
77
<title>Redline Finance</title>
88
</head>
99
<body>

web-app-vue/package-lock.json

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)