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

Auto format all files via Prettier #98

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 26 additions & 22 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
module.exports = {
apps : [{
script: 'server/index.js',
name: 'wtt_server',
instances: 'max',
exec_mode: 'fork',
node_args: '--require dotenv/config',
env: {
NODE_ENV: 'production',
apps: [
{
script: 'server/index.js',
name: 'wtt_server',
instances: 'max',
exec_mode: 'fork',
node_args: '--require dotenv/config',
env: {
NODE_ENV: 'production',
},
env_development: {
DOTENV_CONFIG_DEBUG: true,
DOTENV_CONFIG_PATH:
'/var/www/html/dev.waterthetrees.com/wtt_server/.env',
},
},
env_development: {
DOTENV_CONFIG_DEBUG: true,
DOTENV_CONFIG_PATH: '/var/www/html/dev.waterthetrees.com/wtt_server/.env',
}
}],
deploy : {
production : {
user : 'trees',
host : 'localhost',
ref : 'origin/master',
],
deploy: {
production: {
user: 'trees',
host: 'localhost',
ref: 'origin/master',
'pre-deploy-local': '',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production',
'pre-setup': ''
}
}
'post-deploy':
'npm install && pm2 reload ecosystem.config.js --env production',
'pre-setup': '',
},
},
};
9 changes: 6 additions & 3 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const consoleLevel = 'debug';

const generalLevels = {
levels: {
error: 0, warn: 1, info: 2, verbose: 3, debug: 4,
error: 0,
warn: 1,
info: 2,
verbose: 3,
debug: 4,
},
colors: {
error: 'red',
Expand Down Expand Up @@ -101,11 +105,10 @@ const logger = winston.createLogger({
],
});


export const stream = {
write(message, encoding) {
logger.info(`${message}, ${encoding}`);
},
};

export default logger;
export default logger;
4 changes: 2 additions & 2 deletions server/db/db-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* https://github.com/vitaly-t/pg-promise/wiki/Connection-Syntax
*/
import dotenv from "dotenv";
import dotenv from 'dotenv';
dotenv.config();

const dbConfig = {
Expand All @@ -11,4 +11,4 @@ const dbConfig = {
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
};
export default dbConfig
export default dbConfig;
8 changes: 4 additions & 4 deletions server/db/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pgp from 'pg-promise'
import dbConfig from './db-config.js'
import pgPromiseConfig from './pg-promise-config.js'
import pgp from 'pg-promise';
import dbConfig from './db-config.js';
import pgPromiseConfig from './pg-promise-config.js';

export const pgPromise = pgp(pgPromiseConfig);
export const db = pgPromise(dbConfig);
export const db = pgPromise(dbConfig);
4 changes: 2 additions & 2 deletions server/db/pg-promise-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */
import pgp from 'pg-promise'
import pgp from 'pg-promise';

/**
* source:
Expand All @@ -25,4 +25,4 @@ const pgPromiseConfig = {
receive: (data) => camelizeColumns(data),
};

export default pgPromiseConfig;
export default pgPromiseConfig;
2 changes: 1 addition & 1 deletion server/errors/AppError.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export default class AppError extends Error {
this.statusCode = statusCode;
this.message = message;
}
}
}
6 changes: 3 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cors from 'cors';
import express from 'express';
import 'express-async-errors';
import morgan from 'morgan';
import dotenv from "dotenv";
import dotenv from 'dotenv';
import logger from '../logger.js';
import unknownEndpointHandler from './middleware/unknown-endpoint-handler.js';
// import expressErrorHandler from './middleware/express-error-handler.js';
Expand Down Expand Up @@ -67,8 +67,8 @@ const options = {
const app = express();

app.use(compression());
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// for logging on command line
app.use(morgan('dev'));
// app.use(bodyParser.json());
Expand Down
6 changes: 3 additions & 3 deletions server/middleware/express-error-handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logger from '../../logger.js'
import { pgPromise } from '../db/index.js'
import logger from '../../logger.js';
import { pgPromise } from '../db/index.js';

export default function expressErrorHandler(err, req, res, next) {
logger.error(`HERE ${err.toString()}`);
Expand All @@ -11,4 +11,4 @@ export default function expressErrorHandler(err, req, res, next) {

res.status(err.statusCode || 500).json({ error: err.message });
next();
}
}
2 changes: 1 addition & 1 deletion server/middleware/unknown-endpoint-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default function unknownEndpointHandler(req, res) {
res
.status(404)
.send({ error: `Unknown endpoint: ${req.method} ${req.path}` });
}
}
2 changes: 1 addition & 1 deletion server/routes/cities/cities-queries.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { db } from '../../db/index.js'
import { db } from '../../db/index.js';

export async function createCity(newCityData) {
const query = `
Expand Down
2 changes: 1 addition & 1 deletion server/routes/cities/cities-router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express';
import AppError from '../../errors/AppError.js'
import AppError from '../../errors/AppError.js';
import { findAllCities, findCityByName } from './cities-queries.js';

const citiesRouter = express.Router();
Expand Down
2 changes: 1 addition & 1 deletion server/routes/countries/countries-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ async function getCountries() {
const countries = await db.many(query);
return countries;
}
export default getCountries;
export default getCountries;
2 changes: 1 addition & 1 deletion server/routes/countries/countries-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ countriesRouter.get('/', async (req, res) => {
const rows = await getCountries();

if (!rows?.length) {
return res.status(404).json({ error: "Failed to get countries." });
return res.status(404).json({ error: 'Failed to get countries.' });
}

// otherwise return data
Expand Down
2 changes: 1 addition & 1 deletion server/routes/csv/csv-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export default async function getAllTreeDataByCity(cityName) {
const values = [cityName];
const cityTreeData = await db.manyOrNone(query, values);
return cityTreeData;
}
}
8 changes: 2 additions & 6 deletions server/routes/csv/csv-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ csvRouter.get('/', async (req, res) => {

fastcsv
.write(jsonData, { headers: true })
.on("finish", () => {
res.download(cityPath)
.on('finish', () => {
res.download(cityPath);
})
.pipe(ws);


});

export default csvRouter;


2 changes: 1 addition & 1 deletion server/routes/shared-routes-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export default function convertObjectKeysToSnakeCase(obj) {
}
}
return newObj;
}
}
32 changes: 17 additions & 15 deletions server/routes/treeadoptions/treeadoptions-queries.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { db } from '../../db/index.js';
import convertObjectKeysToSnakeCase from '../shared-routes-utils.js';


export async function findTreeAdoptionsByTreeId(id) {
const query = `
SELECT id_adopted, id, email
FROM treeadoption
WHERE id = $1;
`;
const values = [id];
const treeAdoptions = db.manyOrNone(query, values)
.then(data => data)
.catch(error => error);
const treeAdoptions = db
.manyOrNone(query, values)
.then((data) => data)
.catch((error) => error);

return treeAdoptions;
}
Expand All @@ -26,15 +26,16 @@ export async function adoptTree(adoptedTreeData) {
WHERE td.id = $3
RETURNING *;`;
const values = [
adoptedTreeDataInSnakeCase.nickname,
adoptedTreeDataInSnakeCase.email,
adoptedTreeDataInSnakeCase.id
adoptedTreeDataInSnakeCase.nickname,
adoptedTreeDataInSnakeCase.email,
adoptedTreeDataInSnakeCase.id,
];

const newTreeAdoption = db.one(query, values)
.then(data => data)
.catch(error => error);

const newTreeAdoption = db
.one(query, values)
.then((data) => data)
.catch((error) => error);

return newTreeAdoption;
}

Expand All @@ -44,9 +45,10 @@ export async function unadoptTree({ id, email }) {
WHERE id = $1 AND email = $2;
`;
const values = [id, email];
const results = db.result(query, values)
.then(data => data)
.catch(error => error);
const results = db
.result(query, values)
.then((data) => data)
.catch((error) => error);

return results;
}
}
12 changes: 9 additions & 3 deletions server/routes/treeadoptions/treeadoptions-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ treeadoptionsRouter.get('/', async (req, res) => {
const { id, email } = req.query;

if (!id || !email) {
throw new AppError(400, `treeadoptionsRouter.get Missing required parameter(s) id: ${id} or email: ${email}.`);
return
throw new AppError(
400,
`treeadoptionsRouter.get Missing required parameter(s) id: ${id} or email: ${email}.`,
);
return;
}

const treeAdoptions = await findTreeAdoptionsByTreeId(id);
Expand All @@ -34,7 +37,10 @@ treeadoptionsRouter.post('/', async (req, res) => {
const isValidated = validatePostTreeAdoptions(req);

if (!isValidated) {
throw new AppError(400, `TreeAdoption post Missing required parameter(s) ${req.body}.`);
throw new AppError(
400,
`TreeAdoption post Missing required parameter(s) ${req.body}.`,
);
}
const { request, ...body } = req.body;
if (request.type === 'DELETE') {
Expand Down
2 changes: 1 addition & 1 deletion server/routes/treeadoptions/treeadoptions-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default function validatePostTreeAdoptions(req) {
if (request.type === undefined) return false;

return true;
}
}
8 changes: 4 additions & 4 deletions server/routes/treeadoptions/treeadoptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('/treesadoptions', () => {

const newTreeAdoption = await axiosAPIClient.post(
'/treeadoptions',
newTreeAdoptionData
newTreeAdoptionData,
);

/** Act */
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('/treesadoptions', () => {

const adoptedTree = await axiosAPIClient.post(
'/treeadoptions',
treeLikeData
treeLikeData,
);

/** Act */
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('/treesadoptions', () => {

const adoptedTree = await axiosAPIClient.post(
'/treeadoptions',
adoptedTreeData
adoptedTreeData,
);

/** Act */
Expand All @@ -221,7 +221,7 @@ describe('/treesadoptions', () => {

const unAdoptedTree = await axiosAPIClient.post(
'/treeadoptions',
unAdoptedTreeBody
unAdoptedTreeBody,
);

/** Assert */
Expand Down
Loading