Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sg ls postevents #81

Merged
merged 14 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ yarn-error.log*

# SQLite
prisma/dev.*

# NPM
lucass0717 marked this conversation as resolved.
Show resolved Hide resolved
package-lock.json
package.json
269 changes: 141 additions & 128 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,128 +1,141 @@
# 🏡 Virtual Senior Center

The mission of the outstandinglife.org is to improve the quality of life of LGBTQ older adults in Massachusetts. Through this project, C4C aims to help LBFE find new creative ways to connect older adults: engaging hearts, transforming lives and breaking down boundaries.

Website: [Outstanding Life](https://outstandinglife.org/)

## 👷 Todo

- [x] Setup Next.js
- [x] Prisma
- [x] next-connect + middleware
- [x] Chakra UI
- [x] React Query
- [x] Environment Variables
- [x] Next Auth
- [x] Testing
- [x] Jest/Ava
- [x] React Testing Library
- [x] Cypress
- [x] API Mocks
- [ ] Documentation
- [ ] Swagger
- [ ] Pretty & Complete README
- [ ] Sentry
- [ ] Pull request template

## 🛠️ Getting Started

Install Node version 17.3.0 (npm 8.3.0)

Clone this repo and enter the root directory

```bash
git clone https://github.com/Code-4-Community/vsc.git
cd vsc
```

Install dependencies

```bash
npm install
npm install prisma --save-dev
```

Start the development server. (warning: not _not_ use `npm start` that starts up the server in production mode)

```bash
npm run dev
```

The web app should be running on `localhost:3000`

## 🧪 Tests

Our tests run on the [Jest](https://jestjs.io/) framework.

```bash
# Unit tests
npm run test # runs all unit tests
npm run test:frontend # runs all *frontend* unit tests
npm run test:backend # runs all *backend* unit tests

# E2E tests
# requires a running DB (warning: clears DB)
npm run test:e2e # runs all E2E tests in headless mode
npm run test:cy # opens the Cypress app to run E2E tests visually
```

## 📂 Project Structure

There are 5 main folders in this project:

- pages
- Covers all of the pages in the website.
- Each page has their own folder with an `index.tsx` file containing the source code for that page.
- An `_app.tsx` file is also included which has the overall page structure as well as an `index.tsx` file for the initial landing page.
- Contains `dev_reference.md` with useful tips on how to build our web components.
- prisma
- There is an `schema.prisma` file which outlines the schema of our database in one place.
- The migrations folder contains any updates to the schema that are made overtime.
- The `prisma.ts` file connects Prisma to the application.
- lib
- Frontend components
- Helpers/DTOs for the API routes
- styles
- Contains our global CSS files. Fonts, margins, colors, etc. are defined here.
- A `theme.js` file contains our custom brand color scheme to use in our Chakra components.
- test
- Unit tests
- E2E tests
- Integration tests

## Sessions

### `useSession()`

`useSession()` returns an object like this

Note: this is different from the default behavior (includes `privilegeLevel`)
If you want to add more information from the prisma schema, add to the callbacks in `/api/auth/[...nextauth].js`

```json
{
"user": {
"name": null,
"email": "[email protected]",
"image": null,
"privilegeLevel": "BASIC"
},
"expires": "2022-03-31T01:53:23.176Z"
}
```

## 🔧 Troubleshooting

Various commands that may help in the development process:

| Command | Description |
| ------------------------ | ------------------------------------------------------------ |
| `npx prisma studio` | Runs Prisma studio |
| `npx prisma migrate dev` | Allows you to run changes/db migrations in the Prisma schema |
| `npm run prepush:fix` | Helps when CI tests are failing |

## 🔎 Learn More

- [The C4C Website](https://www.c4cneu.com/)

- [The LBFE Website](https://lbfeboston.org/)
# 🏡 Virtual Senior Center

The mission of the outstandinglife.org is to improve the quality of life of LGBTQ older adults in Massachusetts. Through this project, C4C aims to help LBFE find new creative ways to connect older adults: engaging hearts, transforming lives and breaking down boundaries.

Website: [Outstanding Life](https://outstandinglife.org/)

## 👷 Todo

- [x] Setup Next.js
- [x] Prisma
- [x] next-connect + middleware
- [x] Chakra UI
- [x] React Query
- [x] Environment Variables
- [x] Next Auth
- [x] Testing
- [x] Jest/Ava
- [x] React Testing Library
- [x] Cypress
- [x] API Mocks
- [ ] Documentation
- [ ] Swagger
- [ ] Pretty & Complete README
- [ ] Sentry
- [ ] Pull request template

## 🛠️ Getting Started

Install Node version 17.3.0 (npm 8.3.0)

Clone this repo and enter the root directory

```bash
git clone https://github.com/Code-4-Community/vsc.git
cd vsc
```

Install dependencies

```bash
npm install
npm install prisma --save-dev
```

Start the development server. (warning: not _not_ use `npm start` that starts up the server in production mode)

```bash
npm run dev
```

The web app should be running on `localhost:3000`

## 🧪 Tests

Our tests run on the [Jest](https://jestjs.io/) framework.

```bash
# Unit tests
npm run test # runs all unit tests
npm run test:frontend # runs all *frontend* unit tests
npm run test:backend # runs all *backend* unit tests

# E2E tests
# requires a running DB (warning: clears DB)
npm run test:e2e # runs all E2E tests in headless mode
npm run test:cy # opens the Cypress app to run E2E tests visually
```

## 📂 Project Structure

There are 5 main folders in this project:

- pages
- Covers all of the pages in the website.
- Each page has their own folder with an `index.tsx` file containing the source code for that page.
- An `_app.tsx` file is also included which has the overall page structure as well as an `index.tsx` file for the initial landing page.
- Contains `dev_reference.md` with useful tips on how to build our web components.
- prisma
- There is an `schema.prisma` file which outlines the schema of our database in one place.
- The migrations folder contains any updates to the schema that are made overtime.
- The `prisma.ts` file connects Prisma to the application.
- lib
- Frontend components
- Helpers/DTOs for the API routes
- styles
- Contains our global CSS files. Fonts, margins, colors, etc. are defined here.
- A `theme.js` file contains our custom brand color scheme to use in our Chakra components.
- test
- Unit tests
- E2E tests
- Integration tests

## Sessions

### `useSession()`

`useSession()` returns an object like this

Note: this is different from the default behavior (includes `privilegeLevel`)
If you want to add more information from the prisma schema, add to the callbacks in `/api/auth/[...nextauth].js`

```json
{
"user": {
"name": null,
"email": "[email protected]",
"image": null,
"privilegeLevel": "BASIC"
},
"expires": "2022-03-31T01:53:23.176Z"
}
```

## 🔧 Troubleshooting

Various commands that may help in the development process:

| Command | Description |
| ------------------------ | ------------------------------------------------------------ |
| `npx prisma studio` | Runs Prisma studio |
| `npx prisma migrate dev` | Allows you to run changes/db migrations in the Prisma schema |
| `npm run prepush:fix` | Helps when CI tests are failing |

Troubleshooting Postgres Issues:
lucass0717 marked this conversation as resolved.
Show resolved Hide resolved

- Make sure your .env file is updated with your postgresql user and password
- username often defaults to 'postgres' upon installation

- Make sure your postgres server is running and is in an environment that shares processes with your dev environment (e.g. using WSL for both)
- `sudo service postgresql status`
- `sudo service postgresql start`

- If you are having trouble with psql authentication or need to reset a postgres user's password follow these guides
- [Peer authentication failed for user postgres](https://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge)
- [Changing a postgres user password](https://stackoverflow.com/questions/12720967/how-can-i-change-a-postgresql-user-password)

## 🔎 Learn More

- [The C4C Website](https://www.c4cneu.com/)

- [The LBFE Website](https://lbfeboston.org/)
22 changes: 0 additions & 22 deletions lib/api/newsLogic.ts

This file was deleted.

22 changes: 22 additions & 0 deletions lib/api/programsLogic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import prisma from '../../prisma/prisma';
import { programsWriteSchema } from '../types/dtos/createProgramRequest.dto';
import { BadRequestError } from '../utils/errors/badRequestError';
import type { NextApiRequest, NextApiResponse } from 'next';

export const getNewsHandler = async (req: NextApiRequest, res: NextApiResponse) => {
lucass0717 marked this conversation as resolved.
Show resolved Hide resolved
res.status(200).json({ news: await prisma.program.findMany() });
};

export const postProgramsHandler = async (req: NextApiRequest, res: NextApiResponse) => {
const validatedProgram = validateCreateProgramRequest(req.body);
lucass0717 marked this conversation as resolved.
Show resolved Hide resolved
await prisma.program.create({ data: validatedProgram });
res.status(201).end();
};

const validateCreateProgramRequest = (maybeProgram: unknown) => {
try {
return programsWriteSchema.parse(maybeProgram);
} catch (e) {
throw new BadRequestError('Program must contain: title, content, link, program start and program end times.');
}
};
8 changes: 0 additions & 8 deletions lib/types/dtos/createNewsRequest.dto.ts

This file was deleted.

11 changes: 11 additions & 0 deletions lib/types/dtos/createProgramRequest.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from 'zod';

export const programsWriteSchema = z.object({
title: z.string().min(1),
content: z.string().min(1),
link: z.string().min(1),
eventStart: z.date(),
eventEnd: z.date()
});

export type ProgramsWrite = z.infer<typeof programsWriteSchema>;
Loading