Skip to content

Commit

Permalink
Convertir columna dia en tipo fecha (#79)
Browse files Browse the repository at this point in the history
* Convertir columna dia en tipo fecha

* Remove dayjs

* Poner comentarios ene spañol

* Poner columna dia como unica
  • Loading branch information
francosang authored May 6, 2024
1 parent a07f6b4 commit 14d23d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"compression": "^1.7.4",
"cors": "^2.8.5",
"crypto": "^1.0.1",
"dayjs": "^1.11.10",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"express-rate-limit": "^7.2.0",
Expand Down
20 changes: 4 additions & 16 deletions server/tontos/tontos.service.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
const dayjs = require('dayjs');

const tontoRepository = require('./tontos.repository');

function getTodayString() {
const date = new Date();
return getDateString(date);
}

function getDateString(date) {
return dayjs(date).format('DD/MM/YYYY');
}

async function saveTodays(cowboyId) {
const date = new Date();
const strToday = getDateString(date);
const today = await tontoRepository.getTontoByDate(strToday);
const today = await tontoRepository.getTontoByDate(date);
if (today) return today;

await tontoRepository.saveTonto(strToday, cowboyId, date);
await tontoRepository.saveTonto(date, cowboyId, new Date());

return await tontoRepository.getTontoById(cowboyId)
}
Expand All @@ -29,8 +17,8 @@ async function getTontoByMes(year, month) {
}

async function getToday() {
const strToday = getTodayString();
return await tontoRepository.getTontoByDate(strToday);
const date = new Date();
return await tontoRepository.getTontoByDate(date);
}

async function getTontoById(idCowboy) {
Expand Down
17 changes: 17 additions & 0 deletions sql/010_update_dia_column.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Paso 1: Agregar una nueva columna dia_temp con tipo de dato date
ALTER TABLE tontos ADD COLUMN dia_temp DATE;

-- Paso 2: Establecer los valores de dia_temp a partir de dia
UPDATE tontos SET dia_temp = TO_DATE(dia, 'DD/MM/YYYY');

-- Paso 3: Eliminar la antigua columna dia
ALTER TABLE tontos DROP COLUMN dia;

-- Paso 4: Renombrar dia_temp a dia
ALTER TABLE tontos RENAME COLUMN dia_temp TO dia;

-- Paso 5: Establecer la nueva columna dia como no nula
ALTER TABLE tontos ALTER COLUMN dia SET NOT NULL;

-- Paso 6: Establecer la nueva columna dia como única
ALTER TABLE tontos ADD UNIQUE (dia);

0 comments on commit 14d23d2

Please sign in to comment.