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

Eslint prettier #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
working-directory: ./apps/backend
run: |
yarn
- name: Lint
working-directory: ./apps/backend
run: |
yarn lint
- name: Run test
working-directory: ./apps/backend
run: |
Expand Down
12 changes: 12 additions & 0 deletions apps/backend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable no-undef */
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
};
12 changes: 7 additions & 5 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"test": "jest",
"build": "tsc -p .",
"postinstall": "yarn build",
"test:dev": "jest --watch"
"test:dev": "jest --watch",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"engines": {
"node": "16.13.0"
Expand All @@ -21,16 +22,17 @@
"@types/express": "^4.17.13",
"@types/jest": "^27.4.0",
"@types/node": "^16.10.2",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"eslint": "^7.32.0",
"@types/xml2js": "^0.4.9",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"eslint": "^8.11.0",
"jest": "^27.5.1",
"jest-fetch-mock": "^3.0.3",
"nodemon": "^2.0.13",
"ts-jest": "^27.1.3",
"ts-node": "^10.2.1",
"ts-node-dev": "^1.1.8",
"typescript": "^4.4.3"
"typescript": "^4.6.2"
},
"dependencies": {
"@js-temporal/polyfill": "^0.3.0",
Expand Down
29 changes: 20 additions & 9 deletions apps/backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@

require('dotenv').config();
import express from 'express';
import dotenv from 'dotenv'
dotenv.config()

import express from 'express';
const app = express();

app.use('/', require('./routes/greetings'));
app.use('/beaches', require('./routes/beaches'));
app.use('/historical', require('./routes/historical'));
app.use('/backfill', require('./routes/backfill'));
app.use('/status', require('./routes/status'));
app.use('/import', require('./routes/import'));
app.use('/health', require('./routes/health'));

import greetingsRoute from './routes/greetings';
import beachesRoute from './routes/beaches';
import historicalRoute from './routes/historical';
import backfillRoute from './routes/backfill';
import statusRoute from './routes/status';
import importRoute from './routes/import';
import healthRoute from './routes/health';


app.use('/', greetingsRoute);
app.use('/beaches', beachesRoute);
app.use('/historical', historicalRoute);
app.use('/backfill', backfillRoute);
app.use('/status', statusRoute);
app.use('/import', importRoute);
app.use('/health', healthRoute);

export default app;
3 changes: 1 addition & 2 deletions apps/backend/src/routes/backfill/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ router.get('/weather', async (req, res) => {
res.status(200).send(result);
});


module.exports = router;
export default router
3 changes: 1 addition & 2 deletions apps/backend/src/routes/beaches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ router.get('/:id', async (req: Request<{ id: BeachIds }>, res) => {




module.exports = router;
export default router;
3 changes: 1 addition & 2 deletions apps/backend/src/routes/greetings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ router.get('/', async (req, res) => {
res.send('Checkout the code at https://github.com/mikaalnaik/beach-backend');
});


module.exports = router;
export default router;
2 changes: 1 addition & 1 deletion apps/backend/src/routes/health/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ router.get('/', async (_, res) => {
});


module.exports = router;
export default router
2 changes: 1 addition & 1 deletion apps/backend/src/routes/historical/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ router.get('/:id', async (req: Request<{ id: BeachIds }>, res) => {



module.exports = router;
export default router;
4 changes: 2 additions & 2 deletions apps/backend/src/routes/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const router = express.Router();

router.use(function timeLog(req, res, next) {
const expectedHeader = `Bearer ${process.env.API_KEY}`;
const gotHeader = req.headers['authorization']
const gotHeader = req.headers['authorization'];

if (!gotHeader || gotHeader !== expectedHeader) {
res.status(401).send('Unauthorized');
Expand All @@ -30,4 +30,4 @@ router.get('/weather', async (req, res) => {
});


module.exports = router;
export default router
3 changes: 1 addition & 2 deletions apps/backend/src/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ router.get('/', async (req, res) => {
});



module.exports = router;
export default router
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@ import {
TFormattedBeachReadings,
} from '../../../types/toronto-city-response';

type formattedBackfillResponse = {
_id: string;
beachReadings: Record<string, FormattedBeachReading>;
}[];

type FormattedBeachReading = {
provider: string;
providerId: ProviderId;
beachId: number;
beachName: string;
eColi: number | null;
advisory: string;
statusFlag: string;
};


export default function formatBackfill(d: RawTorontoBeachDateResponse[]): TFormattedBeachReadings[] {
const test = d.reduce((accum: TFormattedBeachReadings[], day) => {
if (day.data) {
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/utils/backfill/weather/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getWeather } from '../../weather/get-weather';
import { WeatherStations } from '../../../consts/weatherStations';
import { isValidWeatherDataPoint } from '../../weather/weather-data-validator';

const parseString = require('xml2js').parseString;
import xml2js from 'xml2js';

export const backfillWeather = async () => {
const years = getArrayOfYearsSince2017();
Expand Down Expand Up @@ -43,7 +43,7 @@ export const getParsedWeather = async (year: number, stationID: WeatherStations)

export const parseWeatherXML = (weather: string): Promise<TRawWeatherResponse> => {
return new Promise((resolve, reject) => {
parseString(weather, (err, result: TRawWeatherResponse) => {
xml2js.parseString(weather, (err, result: TRawWeatherResponse) => {
if (err) {
reject(err);
} else {
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/utils/import/ontario-place/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const getLatestReadingForSpecificBeach = async (beachId: BeachIds) => {
const db = mongo.getDb();
const collection = db.collection('records');

// FIX: this type is incorrectly used here
const latest = await collection.find<WaterKepperReading>({
[`beachReadings.${beachId}`]: {
$exists: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


// TODO: add unit tests!
describe('Format Weather Point', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
it('produces the correct date format', () => {

});
Expand Down
Loading