Skip to content

Commit

Permalink
🚧 were moving to rounds - simplifying our structure
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Sep 15, 2024
1 parent cacfc99 commit 6c4297a
Show file tree
Hide file tree
Showing 30 changed files with 195 additions and 792 deletions.
1 change: 1 addition & 0 deletions app/components/cartridge/CartridgeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const form = ref<Form<any>>()
const state = reactive({
user: route.params.user,
content: cartridgeContents[0],
color: penColors[0],
ml: cartridgeMls[0],
mg: cartridgeMgs[1],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<script setup lang="ts">
import type { Form } from '#ui/types/form'
import type { Pen } from '@prisma/client'
import type { Round } from '@prisma/client'
import { format } from 'date-fns'
import type { MetapiResponse } from '~/types/metapi'
import type { UserCycle } from '~/types/models'
const emit = defineEmits(['created', 'close'])
const route = useRoute()
const form = ref<Form<any>>()
const state = reactive<UserCycle>({
content: 'Tirzepatide',
const state = reactive<Round>({
content: cartridgeContents[0],
ml: cartridgeMls[0],
mg: cartridgeMgs[1],
portions: 4,
duration: 'weekly',
date: format(new Date(), 'yyyy-MM-dd'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { MetapiResponse } from '~/types/metapi'
import type { User } from '~/types/models'
const cycleModal = ref(false)
const roundModal = ref(false)
const route = useRoute()
const { data: user, refresh } = await useFetch<MetapiResponse<User>>(`/api/all/user/${route.params.user}`)
Expand All @@ -13,23 +13,23 @@ set(
fromLink('Home'),
fromLink('Users'),
{ label: user.value?.data.name as string, icon: 'i-mdi-account' },
{ label: 'Cycles', icon: 'i-mdi-calendar' },
{ label: 'Rounds', icon: 'i-mdi-calendar' },
)
action(
{ label: 'Add a Cycle', click: () => cycleModal.value = true },
{ label: 'Add a Round', click: () => roundModal.value = true },
)
</script>

<template>
<div>
<u-dashboard-modal
v-model="cycleModal"
title="Add a Cycle"
description="Give this user a new cycle"
v-model="roundModal"
title="Add a round"
description="Give this user a new round"
icon="i-mdi-calendar"
@close="cycleModal = false"
@close="roundModal = false"
>
<cycle-form @creaed="refresh" @close="cycleModal = false" />
<round-form @creaed="refresh" @close="roundModal = false" />
</u-dashboard-modal>
</div>
</template>
Expand Down
8 changes: 2 additions & 6 deletions app/pages/users/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const columns = [
{ label: 'User', key: 'user' },
{ label: 'Created At', key: 'createdAt' },
{ label: 'Updated At', key: 'updatedAt' },
{ label: 'Pens', key: 'pens' },
{ label: 'Rounds', key: 'rounds' },
{ label: 'Actions', key: 'actions' },
]
Expand Down Expand Up @@ -54,11 +54,7 @@ const { data: users } = await useFetch<MetapiResponse<User>>('/api/all/user')
</div>
</template>
<template #actions-data="{ row }">
<u-button-group>
<u-button icon="i-mdi-medical-bag" :to="`/users/${row.id}/equipment`" color="white" label="Pens" />
<u-button icon="i-mdi-syringe" :to="`/users/${row.id}/history`" color="white" label="Shots" />
<u-button icon="i-mdi-calendar" :to="`/users/${row.id}/cycles`" color="white" label="Cycles" />
</u-button-group>
<u-button icon="i-mdi-calendar" :to="`/users/${row.id}/rounds`" color="white" label="Rounds" />
</template>
</u-table>
</div>
Expand Down
21 changes: 0 additions & 21 deletions app/types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@ export interface Token extends PrismaToken {
}
}

export interface UserCycle {
content: string // Tirzepatide
portions: number // 4
duration: string // weekly
date: string
}

export interface UserPayload {
roles?: {
admin?: boolean
}
cycles?: UserCycle[]
}

export interface User extends PrismaUser {
Expand All @@ -39,16 +31,3 @@ export interface UserSession extends UserInfo {
session: User
cookie?: string
}

export interface Shot extends PrismaShot {
cartridge?: Cartridge
}

export interface Cartridge extends PrismaCartridge {
pen?: Pen
shots?: Shot[]
}

export interface Pen extends PrismaPen {
cartridge: Cartridge | null
}
87 changes: 0 additions & 87 deletions prisma/migrations/20240905080600_init/migration.sql

This file was deleted.

3 changes: 0 additions & 3 deletions prisma/migrations/migration_lock.toml

This file was deleted.

40 changes: 7 additions & 33 deletions prisma/schema/meds.prisma
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
model Cartridge {
model Round {
id Int @id @default(autoincrement())
userId Int
user User @relation(fields: [userId], references: [id])
content String
ml Decimal
mg Decimal
shots Shot[]
pen Pen?
color String
frequency String
duration String
portions Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("cartridges")
}

model Pen {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int
cartridge Cartridge? @relation(fields: [cartridgeId], references: [id], onDelete: Restrict)
cartridgeId Int? @unique
color String
shotDay String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("pens")
}

model Shot {
id Int @id @default(autoincrement())
userId Int
user User @relation(fields: [userId], references: [id])
cartridgeId Int
cartridge Cartridge @relation(fields: [cartridgeId], references: [id], onDelete: Cascade, onUpdate: Cascade)
units Int
date DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("shots")
}
@@map("rounds")
}
5 changes: 1 addition & 4 deletions prisma/schema/user.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ model User {
avatar String?
providers Provider[]
sessions Token[]
pens Pen[]
cartridges Cartridge[]
shots Shot[]
rounds Round[]
payload String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down Expand Up @@ -38,7 +36,6 @@ model Token {
ip String
agent String
location String
// coordinate Unsupported("Point")
coordinate String @default("30.2423 -97.7672")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down
12 changes: 3 additions & 9 deletions server/api/[...slug].ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { createRouter, useBase } from 'h3'
import type { Cartridge, Pen, Shot, Token, User, UserCycle } from '~/types/models'
import cartridge from '../controllers/cartridge'
import cycle from '../controllers/cycle'
import type { Token, User } from '~/types/models'
import logout from '../controllers/logout'
import { facebookHandler, githubHandler, googleHandler, microsoftHandler } from '../controllers/oauth'
import pen from '../controllers/pen'
import shot from '../controllers/shot'
import round from '../controllers/round'
import test from '../controllers/test'
import token from '../controllers/token'
import user from '../controllers/user'
Expand All @@ -32,10 +29,7 @@ router.get('/oauth/microsoft', microsoftHandler)
router.get('/logout', logout)

router.apiResource<{ token: Token }>('/token', token)
router.apiResource<{ user: User, pen: Pen }>('/user/{user}/pen', pen)
router.apiResource<{ user: User, cartridge: Cartridge }>('/user/{user}/cartridge', cartridge)
router.apiResource<{ user: User, shot: Shot }>('/user/{user}/shot', shot)
router.apiResource<{ user: User, cycle: UserCycle }>('/user/{user}/cycle', cycle)
router.apiResource<{ user: User, round: Round }>('/user/{user}/pen', round)
router.apiResource<{ user: User }>('/all/user', user)

export default useBase('/api', router.handler)
Loading

0 comments on commit 6c4297a

Please sign in to comment.