Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 154dbce

Browse files
authored
refactor: use date-fns (#52)
1 parent d6332b3 commit 154dbce

File tree

5 files changed

+10
-38
lines changed

5 files changed

+10
-38
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@prisma/client": "4.8.1",
3636
"class-transformer": "^0.5.1",
3737
"class-validator": "^0.14.0",
38+
"date-fns": "^2.29.3",
3839
"dinero.js": "^2.0.0-alpha.13",
3940
"got": "10",
4041
"nanoid": "3",

src/modules/trips/trip.repository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { TripMapper } from './trip.mapper'
33
import { Injectable } from '@nestjs/common'
44
import { Repository } from '../../common/persistance/repository'
55
import { PrismaService } from '../../infrastructure/prisma/prisma.service'
6-
import { Sql } from '@prisma/client/runtime'
7-
import { Prisma } from '@prisma/client'
8-
import { getStartAndEndDateOfCurrentWeek } from '../../utilities/get-week-dates/get-week-dates'
6+
import { previousMonday } from 'date-fns'
7+
import { nextSunday } from 'date-fns'
98

109
@Injectable()
1110
export class TripRepository implements Repository<Trip> {
@@ -47,7 +46,8 @@ export class TripRepository implements Repository<Trip> {
4746

4847
/** Summarise distance and prices from all trips that happened from monday to sunday in current week. */
4948
async getDistanceAndPriceFromTripsInThisWeek(): Promise<{ distance: number; price: number }> {
50-
const { start: monday, end: sunday } = getStartAndEndDateOfCurrentWeek()
49+
const monday = previousMonday(new Date())
50+
const sunday = nextSunday(new Date())
5151

5252
const execute = await this.prismaService.$queryRaw<
5353
[{ total_distance: number; total_price: number }]

src/utilities/get-week-dates/get-week-dates.spec.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/utilities/get-week-dates/get-week-dates.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
19921992
shebang-command "^2.0.0"
19931993
which "^2.0.1"
19941994

1995+
date-fns@^2.29.3:
1996+
version "2.29.3"
1997+
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"
1998+
integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==
1999+
19952000
debug@2.6.9:
19962001
version "2.6.9"
19972002
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"

0 commit comments

Comments
 (0)