Skip to content

Commit

Permalink
moved mililitre field
Browse files Browse the repository at this point in the history
  • Loading branch information
murtagh27 committed Sep 25, 2024
1 parent dfc3971 commit 6e3f7be
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
31 changes: 15 additions & 16 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ model User {
}

model Drink {
id String @id @default(uuid())
id String @id @default(uuid())
name String
type DrinkType
alcoholContent Float
custom Boolean
description String?
createdAt DateTime @default(now())
drinkActions DrinkAction[]
favouriteTo User[]
milliliter Int
createdAt DateTime @default(now())
drinkActions DrinkAction[]
favouriteTo User[]
}

model Event {
Expand All @@ -68,15 +68,14 @@ model Event {
}

model DrinkAction {
id String @id @default(uuid())
price Int
milliliter Int
drinkId String
drink Drink @relation(fields: [drinkId], references: [id])
eventId String
event Event @relation(fields: [eventId], references: [id])
userId String
user User @relation(fields: [userId], references: [authSchId])
hasEffect Boolean @default(true)
createdAt DateTime @default(now())
id String @id @default(uuid())
price Int
drinkId String
drink Drink @relation(fields: [drinkId], references: [id])
eventId String
event Event @relation(fields: [eventId], references: [id])
userId String
user User @relation(fields: [userId], references: [authSchId])
hasEffect Boolean @default(true)
createdAt DateTime @default(now())
}
8 changes: 0 additions & 8 deletions apps/backend/src/drink-action/entities/drink-action.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ export class DrinkAction {
@Min(0)
price: number;

/**
* Quantity of the drink in milliliter
* @example 500
*/
@IsNumber()
@Min(0)
milliliter: number;

/**
* Shows if the alcohol still has effect on the user.
* @example false
Expand Down
20 changes: 19 additions & 1 deletion apps/backend/src/drinks/entities/drink.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { DrinkType } from '@prisma/client';
import { IsBoolean, IsDateString, IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID, Min } from 'class-validator';
import {
IsBoolean,
IsDateString,
IsEnum,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
IsUUID,
Min,
} from 'class-validator';
import { IsFloat } from 'src/util/is-float.validator';

export class Drink {
Expand All @@ -24,6 +34,14 @@ export class Drink {
@IsEnum(DrinkType)
type: DrinkType;

/**
* Quantity of the drink in milliliter
* @example 500
*/
@IsNumber()
@Min(0)
milliliter: number;

/**
* Alcohol content of the drink
* @example 4.5
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export class UsersService {

const drinkActions = await this.prisma.drinkAction.findMany({
where: { hasEffect: true },
include: { drink: { select: { alcoholContent: true } } },
include: { drink: { select: { alcoholContent: true, milliliter: true } } },
});

let totalBac = 0;

for (const drinkAction of drinkActions) {
const dose = drinkAction.milliliter * (drinkAction.drink.alcoholContent / 100) * 0.789;
const dose = drinkAction.drink.milliliter * (drinkAction.drink.alcoholContent / 100) * 0.789;
const timeDifferenceMs = currentTime.getTime() - drinkAction.createdAt.getTime();
const eliminated = (timeDifferenceMs / (1000 * 60 * 60)) * 0.016;

Expand Down

0 comments on commit 6e3f7be

Please sign in to comment.