Skip to content

Commit

Permalink
Merge branch 'develop' into Folder-Structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Till-B committed Apr 15, 2021
2 parents f3bcf60 + 6068bdf commit cf0e014
Show file tree
Hide file tree
Showing 43 changed files with 727 additions and 113 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build applicaiton

on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
build:
name: Build
runs-on: ubuntu-latest
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_USER: entel
POSTGRES_PASSWORD: crazypassword
POSTGRES_DB: enteldb
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
env:
DATABASE_URL: postgresql://entel:crazypassword@localhost:5432/enteldb
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: Install dependencies
id: install-dependencies
run: yarn install
- name: Migrate database
id: migrate-database
run: npx blitz prisma migrate deploy --preview-feature
- name: Build application
id: build-application
run: npm run build
- name: Run unittests
id: run-unittests
run: npm run test
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,95 @@ A hosted version can be found at [**entel.me**](https://www.entel.me/)
Many thanks to Roman for creating the cute logo 💖

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## Setup entel locally

To run entel locally, you need to install [NodeJS](https://nodejs.org/en/) and [npm](https://www.npmjs.com/). Additionally, you should be able to run PostgreSQL on your machine. You can achieve this by

- installing it natively on your computer or
- via docker.

### First steps ✨

But first of all, you have to clone and open this repository.

```bash
git clone https://github.com/entel-me/entel.git
cd entel
```

After that, you should be able to install the dependencies with npm.

```bash
npm i
```

Great! Let's start with setting up environment variables. 🔥

### Setup enviroment variables 📝

First, you have to create two empty files`.env.local` and `env.test.local`. You can specify environment variables in these files. Afterward, you call them with `process.env.`.

`DATABASE_URL` is an important variable that connects the PostgreSQL database with our application. If you're running PostgreSQL in docker, you set

- username,
- password,
- the name of the database
on your own and include them in a URL. Here is an example:

```txt
POSTGRES_USER=entel
POSTGRES_PASSWORD=crazypassword
POSTGRES_DB=enteldb
DATABASE_URL=postgresql://entel:crazypassword@localhost:5432/enteldb
```

If you're running PostgreSQL natively on your computer, you have to enter the URL of your database in each `.local` file. Please be aware that you have to remove the [`predev` script](https://github.com/entel-me/entel/blob/1f352942b6f9cec4aabad566766f752c4c3c82f5/package.json#L5) from package.json to run entel without errors.

```txt
DATABASE_URL=postgresql://entel:crazypassword@localhost:5432/enteldb
```

If you want to test the mailer in [`mailers/`](https://github.com/entel-me/entel/tree/develop/mailers), you have to add your

- mail,
- password,
- and mail host
to the `.local` files too:

```txt
MAIL_HOST=mail.privateemail.com
[email protected]
MAIL_PASSWORD=crazypassword
```

Great! After that, we take care of the database itself.

### Run the database 📋

The last thing we have to do is migrating the database with [prisma](https://www.prisma.io/). For the following step, the database should already be running. You can achieve this with docker with the command:

```bash
docker-compose up -d
```

Now you can set up the database by entering:

```bash
blitz prisma migrate dev --preview-feature
```

Btw, if you change something in [schema.prisma](https://github.com/entel-me/entel/blob/develop/db/schema.prisma) you have to re-run the last command.
Now we can try out our application. 🥳

### Run the application

To run entel you execute

```bash
blitz dev
```

and view your new app at [http://localhost:3000/](http://localhost:3000/)! Perfect 🎉

Have fun with the app :)
4 changes: 4 additions & 0 deletions app/auth/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import login from "app/auth/mutations/login"
import { Login } from "app/auth/validations"
import { Flex, Heading, Button, useDisclosure, Box } from "@chakra-ui/react"
import ForgotPasswordPage from "app/auth/components/forgot-password"
import { appLogger as log } from "app/lib/logger"

type LoginFormProps = {
onSuccess?: () => Promise<void> | void
Expand Down Expand Up @@ -41,10 +42,13 @@ export const LoginForm = (props: LoginFormProps) => {
try {
await loginMutation(values)
await props.onSuccess?.()
log.info("Login was successfull.")
} catch (error) {
if (error instanceof AuthenticationError) {
log.warn("Login failed, because of invalid credentials.")
return { [FORM_ERROR]: "Sorry, those credentials are invalid" }
} else {
log.error("Login failed, because of an unexpected error.", { error: error })
return {
[FORM_ERROR]:
"Sorry, we had an unexpected error. Please try again. - " + error.toString(),
Expand Down
7 changes: 4 additions & 3 deletions app/auth/components/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { Form, FORM_ERROR } from "app/core/components/Form"
import signup from "app/auth/mutations/signup"
import { Signup } from "app/auth/validations"
import { Heading, Flex, Button, useDisclosure, Box } from "@chakra-ui/react"

import { appLogger as log } from "app/lib/logger"
type SignupFormProps = {
onSuccess?: () => Promise<void>
}

export const SignupForm = (props: SignupFormProps) => {
const [signupMutation] = useMutation(signup)
const { isOpen, onOpen, onClose } = useDisclosure()

return (
<Flex direction="column" alignItems="center" justifyContent="center" alignContent="center">
<Box
Expand Down Expand Up @@ -40,11 +39,13 @@ export const SignupForm = (props: SignupFormProps) => {
try {
await signupMutation(values)
await props.onSuccess?.()
log.info("Sign up was successfull.")
} catch (error) {
if (error.code === "P2002" && error.meta?.target?.includes("email")) {
// This error comes from Prisma
log.warn("Login failed, because the email is already being used.")
return { email: "This email is already being used" }
} else {
log.error("Login failed, because of an unexpected error.", { error: error })
return { [FORM_ERROR]: error.toString() }
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/auth/components/changePasswordModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import changePassword from "app/auth/mutations/changePassword"
import { Form, Field } from "react-final-form"
import { FORM_ERROR } from "final-form"
import * as z from "zod"
import { appLogger as log } from "app/lib/logger"

export function ChangePassword({ isOpen, onClose }) {
const [changePasswordMutation] = useMutation(changePassword)
Expand All @@ -43,10 +44,15 @@ export function ChangePassword({ isOpen, onClose }) {
isClosable: true,
})
onClose()
log.info("A user changed her/his password successfully.")
} catch (error) {
if (error instanceof AuthenticationError) {
log.warn("Password change failed, because of invalid credentials.")
return { [FORM_ERROR]: "Sorry, those credentials are invalid" }
} else {
log.error("Password change failed, because of an unexpected error.", {
error: error,
})
toast({
title: "Sorry",
description: "Something went wrong. Please try again.",
Expand Down
3 changes: 3 additions & 0 deletions app/chats/mutations/createAdminMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import db from "db"
import { Ctx } from "blitz"
import { newMessageMailer } from "mailers/newMessageMailer"
import { dbLogger as log } from "app/lib/logger"

export default async function createAdminMessage({ content, chatId }, context: Ctx) {
context.session.$authorize()
await db.adminMessage.create({
data: { content: content, sentIn: { connect: { id: chatId } } },
})
await sentMail(chatId, content)

log.info("AdminMessage was sent")
}

async function sentMail(chatId, content) {
Expand Down
2 changes: 2 additions & 0 deletions app/chats/mutations/createChat.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import db from "db"
import { Ctx } from "blitz"
import { dbLogger as log } from "app/lib/logger"

export default async function createChat({ opponentId }, context: Ctx) {
context.session.$authorize()
Expand All @@ -10,5 +11,6 @@ export default async function createChat({ opponentId }, context: Ctx) {

select: { id: true },
})
log.debug("Created new chat.")
return lists
}
2 changes: 2 additions & 0 deletions app/chats/mutations/markAdminAsRead.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import db from "db"
import { Ctx } from "blitz"
import { dbLogger as log } from "app/lib/logger"

export default async function markAdminMessagesAsRead({ chatId }, context: Ctx) {
context.session.$authorize()
Expand All @@ -14,4 +15,5 @@ export default async function markAdminMessagesAsRead({ chatId }, context: Ctx)
})
})
await Promise.all(promisses)
log.debug("AdminMessages marked as read.")
}
2 changes: 2 additions & 0 deletions app/chats/mutations/markMessagesAsRead.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import db from "db"
import { Ctx } from "blitz"
import { dbLogger as log } from "app/lib/logger"

export default async function markMessagesAsRead({ chatId }, context: Ctx) {
context.session.$authorize()
await db.message.updateMany({
where: { sentInId: chatId, sentToId: context.session.userId },
data: { wasRead: true },
})
log.debug("Messages marked as read.")
}
2 changes: 2 additions & 0 deletions app/chats/mutations/sendMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from "db"
import { Ctx } from "blitz"
import { newMessageMailer } from "mailers/newMessageMailer"
import { dbLogger as log } from "app/lib/logger"

export default async function sendMessage({ content, chatId, partId }, context: Ctx) {
context.session.$authorize()
Expand All @@ -14,6 +15,7 @@ export default async function sendMessage({ content, chatId, partId }, context:
})

sentMail(chatId, partId, content, context)
log.info("A Message was sent.")
}

async function sentMail(chatId, partId, content, context: Ctx) {
Expand Down
41 changes: 27 additions & 14 deletions app/core/layouts/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ export default function Layout({
<>
<Head>
<link rel="icon" href="/logo_1.png" />
<meta charSet="utf-8" />
<meta
name="keywords"
content="entel, share, shopping, shoppinglist, tool, chat, community"
/>
<meta name="author" content="Till Bergmann, Antony Kamp" />
<meta name="copyright" content="Till Bergmann, Antony Kamp" />
<meta
name="description"
content="Share your needs! Replace the unnecessary walk to the next supermarket by a new shoppinglist in entel."
/>
</Head>
<ColorModeScript initialColorMode="light" />
<Flex direction="column" alignItems="center" height="100vh">
Expand All @@ -75,12 +86,16 @@ export default function Layout({
alignItems="flex-end"
marginTop="5px"
>
<HStack as="a" href="/">
<Image src="/logo_1.png" width="90" alt="entel logo" height="90" />
<Heading fontSize="6xl" fontWeight="extrabold" fontFamily="Raleway">
entel
</Heading>
</HStack>
<Link href="/">
<HStack>
{(user || !isMobile) && (
<Image src="/logo_1.png" width="90" alt="entel logo" height="90" />
)}
<Heading fontSize="6xl" fontWeight="extrabold" fontFamily="Raleway">
entel
</Heading>
</HStack>
</Link>
<Flex
direction="row"
justifyContent="space-between"
Expand Down Expand Up @@ -286,14 +301,12 @@ export default function Layout({
textAlign="center"
alignItems="center"
>
<BlitzLink href="https://github.com/till-B/entel">
<Link>
<HStack>
<AiFillGithub size={24} />
<Text>This project is open source. Feel free reach out.</Text>
</HStack>
</Link>
</BlitzLink>
<Link href="https://github.com/entel-me/entel">
<HStack>
<AiFillGithub size={24} />
<Text>This project is open source. Feel free reach out.</Text>
</HStack>
</Link>
<Text fontFamily="Raleway" fontWeight="medium">
<BlitzLink href="/impressum">
<Link>Impressum</Link>
Expand Down
2 changes: 2 additions & 0 deletions app/core/mutations/updatePoisition.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import db from "db"
import { Ctx } from "blitz"
import { dbLogger as log } from "app/lib/logger"

export default async function updatePosition({ new_longitude, new_latitude }, context: Ctx) {
context.session.$authorize()
await db.user.update({
where: { id: context.session.userId },
data: { last_latitude: new_latitude, last_longitude: new_longitude },
})
log.info("A Position was updated.")
}
Loading

0 comments on commit cf0e014

Please sign in to comment.