Skip to content

Commit

Permalink
Initial commit 💪
Browse files Browse the repository at this point in the history
  • Loading branch information
theted committed Jul 11, 2023
0 parents commit 73a450e
Show file tree
Hide file tree
Showing 51 changed files with 9,562 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
extends: [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier/skip-formatting'
],
overrides: [
{
files: ['cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}'],
extends: ['plugin:cypress/recommended']
}
],
parserOptions: {
ecmaVersion: 'latest'
}
}
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
}
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# habit-tracker

Simple Habit-tracking app. Keep statistics of your good (and bad!) habits!

## Features
- Typescript
- Vue 3
- Prisma
- Tailwind
- Vite


## Project Setup

```sh
npm install
```

### Compile and Hot-Reload for Development

```sh
npm run dev
```

## Build css

```sh
npx tailwindcss -i ./src/input.css -o ./src/assets/output.css --watch
```

### Type-Check, Compile and Minify for Production

```sh
npm run build
```

### Run Unit Tests with [Vitest](https://vitest.dev/)

```sh
npm run test:unit
```

### Run End-to-End Tests with [Cypress](https://www.cypress.io/)

```sh
npm run test:e2e:dev
```

```sh
npm run build
npm run test:e2e
```

### Lint with [ESLint](https://eslint.org/)

```sh
npm run lint
```
65 changes: 65 additions & 0 deletions api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

const getUsers = async () => prisma.user.findMany()

const getHabits = async () =>
prisma.habit.findMany({
include: {
_count: {
select: { tracks: true }
}
}
})

const getHabit = async (id: number) =>
prisma.habit.findUnique({
where: { id },
include: {
tracks: {
select: {
id: true,
date: true,
habitId: true
}
}
}
})

const createHabit = async (title: string, userId: number) => {
const habit = await prisma.habit.create({
data: {
title,
user: { connect: { id: userId } }
}
})

return habit
}

const deleteHabit = async (id: number) => {
// delete tracks for habit first
await prisma.track.deleteMany({
where: {
habitId: id
}
})

const habit = await prisma.habit.delete({
where: { id }
})

return habit
}

const getTracks = async () => prisma.track.findMany()

const addTrack = async (habitId: number) =>
prisma.track.create({
data: {
habitId
}
})

export { getUsers, getHabits, getHabit, createHabit, deleteHabit, getTracks, addTrack }
8 changes: 8 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
baseUrl: 'http://localhost:4173'
}
})
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<link
href="https://fonts.googleapis.com/css?family=Poppins:400,700&display=swap"
rel="stylesheet"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Habit Tracker</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Loading

0 comments on commit 73a450e

Please sign in to comment.