Skip to content

Commit

Permalink
Some bug fixes and updates to the README.md (#49)
Browse files Browse the repository at this point in the history
* Update yarn files + gitignore

* Added error message that came up during maintenance

* Fix issue where columns were displayed alphabetically instead of in their intended order

* Some basic formatting for the User schema

* Show error in backend when connecting even if there isn't a nice message

* Make stylistic edits including minor edits to DB schema

* Update schema slightly

* Delete unneeded CD.yml file

* (Tried to) upgrade packages

* Update README.md
  • Loading branch information
leeaj8-uci committed Aug 2, 2023
1 parent 02ffc1f commit 6757b3b
Show file tree
Hide file tree
Showing 20 changed files with 5,854 additions and 3,659 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/CD.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ typings/
# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
# Optional npm/yarn cache directories
.npm
.yarn/

# Optional eslint cache
.eslintcache
Expand Down
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
114 changes: 87 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,101 @@
# Get Inspired
<p align="center">
<img width=200 height=200 src="public/logo512.png" alt="Get Inspired Logo" />
</p>

This is the backend for the Get Inspired project!
<p align="center">
<b>🌐</b><a href="https://getinspiredinc.org/">Website</a> |
<a href="https://www.facebook.com/GetInspired20/">Facebook</a> |
<a href="https://www.instagram.com/getinspiredinc/">Instagram</a> |
<a href="https://www.youtube.com/user/TheKelplady">Youtube</a>
</p>

## Setting up development environment
<b>Get Inspired promotes ocean restoration awareness and education among youths through engaging the community in environmental stewardship. They host programs that educate students on marine life and provide volunteer opportunities to restore and preserve marine ecosystems.</b>

To start working on with this project, follow these steps:
1. Install the [EditorConfig plugin](https://editorconfig.org/#download) for your IDE.
1. Add the `.env` file stored in your projects Google Drive folder to the root of the project.
1. Navigate to the project folder in your terminal and run `npm install` to install required packages.
<p align="center">
<img src="./public/readme-images/dashboard.png" alt="The Get Inspired Prismo Clam Database Dashboard"/>
</p>

## Project branching structure
## 🔎 About the Project

Due to complications with some of the GitHub Actions this project uses, the git branch structure is non-standard.
*Nancy, the director of Get Inspired, has been maintaining Pismo clam data using spreadsheets. However, as the volume of data grows, efficiently collecting and displaying the information has become increasingly challenging.*

1. `dev`: This is the main branch of the project. All PRs should be merged into this branch, as if it was "main".
1. `main`: This is the "production-ready" branch of the project; `dev` should only be merged into `main` when it is at a presentable state.
🆙 We built a web application and database to store and display a variety of information about Pismo clams, including their color, location, date and time of survey, and other key characteristics. Our interface allows Nancy to easily input, view, and query the data as necessary. The dashboard shows each survey's automatically calculated statistics, which will be used to identify ways to restore the clam population.

## Available Scripts
<p align="center">
<img src="public/readme-images/dashboard-popup.png" alt="A modal that shows more information about one survey on the Dashboard Page"/>
<img src="public/readme-images/add-data.png" alt="Adding a .csv file for clam data on the Add Data page"/>
<img src="public/readme-images/manage-data.png" alt="Using the Manage Data Page to edit clam data"/>
<img src="public/readme-images/query-data.png" alt="Using the Advanced Search function on the Query Data Page to search for particular clams"/>
</p>

### Tech Stack

**🔼 [Frontend](https://github.com/ctc-uci/get-inspired-frontend/):** React (UI Kit: [AntDesign](https://ant.design/)) + Firebase (Authentication)

**🔽 [Backend](https://github.com/ctc-uci/get-inspired-backend):** NodeJS + MySQL

---

## 💻 Development

This subsection contains further details on the more technical aspects of the project, including information for developers.


### Project branching structure

In the project directory, you can run:
Due to complications with some of the GitHub Actions this project uses, the git branch structure is non-standard: `dev` is the main branch of the project. All PRs should be merged into this branch, as if it were the "main" branch.

### `npm start`

Runs the app in the development mode, with hot-reload support from [nodemon](https://github.com/remy/nodemon).\
The server will be accessible from http://localhost:3001, and will reload if you make edits.\
You will also see any lint errors in the console.
## 🔨 Setting up the Development Environment

To start working on with this project, follow these steps:
1. Install [Node.js](https://nodejs.org/en) and [Yarn](https://yarnpkg.com/getting-started/install), if you haven't already.
2. Clone the repository and navigate to the project folder:
```
git clone https://github.com/ctc-uci/get-inspired-backend.git
cd get-inspired-backend
```
3. Place the `.env` file in the project's root directory.
- If you are currently maintaining this project, ask your organziation or contact CTC for the most up-to-date `.env` file.
- If you are making the `.env` file youself, it should follow this structure:
```bash
NODE_ENV=development

# react info
REACT_APP_HOST=
REACT_APP_PROD_HOST=
REACT_APP_PROD_PORT=

# aws info
AWS_REGION=
AWS_HOST=
AWS_DB_NAME=
AWS_USER=
AWS_PORT=
AWS_PASSWORD=

# react app info
REACT_APP_EMAIL_FIRST_NAME=
REACT_APP_EMAIL_LAST_NAME=
REACT_APP_EMAIL_USERNAME=
REACT_APP_EMAIL_PASSWORD=
```
4. Install the [EditorConfig plugin](https://editorconfig.org/#download) for your IDE.
5. Run `yarn` to install the required packages.
6. (Optionally) Run `yarn start` to run the project locally!

## Available Scripts

### Run (Development): `yarn start`
To run the project locally in development mode, use `yarn start`, then open [http://localhost:3000](http://localhost:3000) to view it in the browser. The console will show any lint errors, and the apge will reload after you make local edits to the code.

### `npm run format`

Formats `.js` files with Prettier.\
See the [Prettier docs](https://prettier.io/docs/en/index.html) for more information.
### Format: `yarn format`
Run `yarn format` to format all `.js`, `.jsx`, `.css` files with [Prettier](https://prettier.io/docs/en/index.html) (see [ESLint and Prettier](#eslint-and-prettier) below).

### Build: `yarn build`
Builds the app for production to the `build` folder.

## ESLint and Prettier

Expand All @@ -38,7 +104,8 @@ This project uses ESLint and Prettier to enforce the [Airbnb JavaScript Style Gu
### ESLint Plugins

Currently, the following ESLint plugins are installed:
1. [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier)
- [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react)
- [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier)

Visit the links to learn more about each plugin.

Expand All @@ -61,10 +128,3 @@ Use the `--no-verify` option to skip pre-commit checks, but please note that thi
The configuration for lint-staged is inside the `lint-staged` object inside of `package.json`. Learn more about lint-staged [here](https://github.com/okonet/lint-staged).

The configuration for husky is in the `.husky` directory, located in the root of the project. Learn more about husky [here](https://typicode.github.io/husky/).


## Learn more about Node and ExpressJS

You can learn about Node [here](https://nodejs.org/en/).

To learn about express, check out the this express tutorial [here](https://www.tutorialspoint.com/nodejs/nodejs_express_framework.htm).
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
"*.js": "yarn run eslint"
},
"dependencies": {
"@babel/runtime": "^7.21.0",
"@react-awesome-query-builder/core": "^6.1.1",
"@babel/runtime": "^7.22.6",
"@react-awesome-query-builder/core": "^6.4.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"csv-parse": "^5.3.6",
"csv-parse": "^5.4.0",
"dotenv": "^10.0.0",
"eslint": "^8.1.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.0.0",
"express": "^4.17.1",
"firebase-admin": "^11.3.0",
"eslint": "^8.46.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-prettier": "^4.2.1",
"express": "^4.18.2",
"firebase-admin": "^11.10.1",
"mysql": "^2.18.1",
"named-placeholders": "^1.1.3",
"nodemon": "^2.0.20",
"prettier": "^2.4.1"
"nodemon": "^2.0.22",
"prettier": "^2.8.8"
},
"devDependencies": {
"eslint-config-prettier": "^8.3.0",
"eslint-config-prettier": "^8.9.0",
"husky": "^7.0.4",
"lint-staged": "^11.2.6"
}
Expand Down
Binary file added public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/readme-images/add-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/readme-images/dashboard-popup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/readme-images/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/readme-images/manage-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/readme-images/query-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions routes/rakers.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ router.get('/survey/:surveyId', async (req, res) => {
});

// create raker
// TODO: GET ALL COLUMNS DYNAMICALLY
router.post('/', async (req, res) => {
try {
// Get all column names dynamically
Expand Down Expand Up @@ -87,15 +86,14 @@ router.post('/', async (req, res) => {
})
.reduce((acc, dict) => Object.assign(acc, dict), {}),
);
// console.log(query);
// console.log(params);
const raker = await pool.query(query, params);
res.status(200).json(raker);
} catch (err) {
res.status(500).send(err.message);
console.log(err.message);
}
});

// delete raker
router.delete('/', async (req, res) => {
try {
Expand Down
9 changes: 6 additions & 3 deletions routes/tables.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ tablesRouter.get('/:table/columns', async (req, res) => {
try {
const { table } = req.params;
const [query, params] = toUnnamed(
`SELECT COLUMN_NAME, DATA_TYPE from information_schema.columns
WHERE table_schema = "${process.env.AWS_DB_NAME}"
AND table_name = :table`,
`
SELECT COLUMN_NAME, DATA_TYPE from information_schema.columns
WHERE table_schema = "${process.env.AWS_DB_NAME}"
AND table_name = :table
ORDER BY ORDINAL_POSITION
`,
{
table,
},
Expand Down
3 changes: 2 additions & 1 deletion server/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ pool.getConnection((e, connection) => {
PROTOCOL_CONNECTION_LOST: 'Database connection was closed.',
ER_CON_COUNT_ERROR: 'Database has too many connections.',
ECONNREFUSED: 'Database connection was refused.',
ENOTFOUND: 'Could not find the address: double check the RDS URl in the .env file?',
};
// eslint-disable-line
console.error(codes[e.code]);
console.error(codes[e.code] || e);
}
if (connection) {
// eslint-disable-line
Expand Down
36 changes: 13 additions & 23 deletions server/schema/clams.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
CREATE TABLE clam (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
survey_id INTEGER NOT NULL,
<<<<<<< HEAD
[Name] TEXT NOT NULL,
[Color] TEXT NOT NULL,
[Lat] DOUBLE NOT NULL,
[Long] DOUBLE NOT NULL,
[Length] DOUBLE NOT NULL,
[Width] DOUBLE NOT NULL,
[Weight] DOUBLE NOT NULL,
[Comments] TEXT NULL,
[Image] TEXT NULL,
=======
`Name` TEXT,
`Lat` DOUBLE,
`Long` DOUBLE,
`Length` DOUBLE,
`Width` DOUBLE,
`Weight` DOUBLE,
`Color` TEXT,
`Comments` TEXT,
>>>>>>> dev
FOREIGN KEY (survey_id) REFERENCES survey(id) ON DELETE CASCADE ON UPDATE CASCADE
id INTEGER PRIMARY KEY AUTO_INCREMENT,
survey_id INTEGER NOT NULL,
`Name` TEXT,
`Lat` DOUBLE,
`Long` DOUBLE,
`Length` DOUBLE,
`Width` DOUBLE,
`Weight` DOUBLE,
`Color` TEXT,
`Comments` TEXT,
FOREIGN KEY (survey_id) REFERENCES survey(id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
22 changes: 11 additions & 11 deletions server/schema/computation.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
CREATE TABLE computation (
survey_id INTEGER PRIMARY KEY REFERENCES survey.id,
`# people` INTEGER NOT NULL DEFAULT 0,
`# clams found` INTEGER NOT NULL DEFAULT 0,
`# man hours` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`distance covered` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`clams/man hr` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`clam density` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`area raked` DECIMAL (65, 3) NOT NULL DEFAULT 0,
survey_id INTEGER PRIMARY KEY REFERENCES survey.id,
`# people` INTEGER NOT NULL DEFAULT 0,
`# clams found` INTEGER NOT NULL DEFAULT 0,
`# man hours` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`distance covered` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`clams/man hr` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`clam density` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`area raked` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`total time raking` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`avg weight` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`avg width` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`avg length` DECIMAL (65, 3) NOT NULL DEFAULT 0
`avg weight` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`avg width` DECIMAL (65, 3) NOT NULL DEFAULT 0,
`avg length` DECIMAL (65, 3) NOT NULL DEFAULT 0
);

delimiter //
Expand Down
Loading

0 comments on commit 6757b3b

Please sign in to comment.