Commit 05bf2200 authored by Sidson's avatar Sidson
Browse files

.gitignore is now ignoring log files

parent 3fc52b65
# Affluence Serv
Affluence backend Nodejs app.
## Install
`npm install`
## Run the app
* `npm run start:dev` to run the server in dev mode (hot reload/compile).
* `npm run start:debug` to run the server in debug mode (hot reload/compile + debuger).
* `npm run build && npm run start` to run the server in production mode.
## REST API
| Resource | Method | Type | Documentation |
| ------------------- | ------ | ---- | ------------------- |
| `/occupancy/report` | POST | JSON | Save a user report. |
......@@ -8,9 +8,8 @@ Backend Nodejs de l'application Affluence.
## Exécution
* `npm run start:dev` pour lancer le serveur en mode dev (rechargement/compilation à chaud).
* `npm run build` pour lancer la compilation( en mode production).
* `npm run start:debug` pour lancer le serveur en mode debug (rechargement/compilation à chaud + debugueur).
* `npm run build && npm run start` pour lancer le serveur en mode production.
## REST API
......
This diff is collapsed.
This diff is collapsed.
......@@ -23,7 +23,7 @@ export default class DbCron implements OnTick, OnInit {
await client.query(`CREATE TABLE IF NOT EXISTS ${config.db.affluence.schema}.user_report (stop_code text NOT NULL,time timestamp with time zone NOT NULL,data json, CONSTRAINT user_report_pk PRIMARY KEY(time,stop_code)) WITH (oids = false)`);
client.end();
} catch (e) {
} catch (e: any) {
client?.end();
this.log.logger.error(`[cron][DbCron][onInit] ${e}`);
}
......@@ -40,7 +40,7 @@ export default class DbCron implements OnTick, OnInit {
}
client.end();
} catch (e) {
} catch (e: any) {
client?.end();
this.log.logger.error(`[cron][DbCron][onTick] ${e}`);
}
......
......@@ -23,7 +23,7 @@ export class AffluenceClient extends Client {
let result = await this.query<{ ident: number }>(queryConfig);
if (result.rowCount !== 1) throw new Error(`${table} : Unable to perform ${result.command}.`);
return true;
} catch (e: any) {
} catch (e: any) {
if (e.details) this.log.logger.error(`[client][AffluenceClient][insert] ${e.details}`);
throw (e);
}
......
......@@ -9,7 +9,7 @@ export default class JoiErrors implements MiddlewareInterface {
async use(ctx: Context, next: Next) {
try {
await next();
} catch (e : any) {
} catch (e: any) {
if (e.isJoi) {
this.log.logger.error(`[middleware][JoiErrors] ${e}`);
}
......
......@@ -14,7 +14,11 @@ export default class RateLimitMiddleware implements MiddlewareInterface {
duration: 1000 * 60, //1 min
max: 2,
id: (ctx) => {
return (ctx.request.header['x-real-ip'] ? ctx.request.header['x-real-ip'] : ctx.request.ip);
let header;
if (Array.isArray(ctx.request.header['x-real-ip'])) header = ctx.request.header['x-real-ip'][0];
else header = ctx.request.header['x-real-ip'];
return (header ? header : ctx.request.ip);
},
errorMessage: 'Qu\'est ce qu\'il nous fait Noureyef, là ?'
//blackList: ['127.0.0.1']
......
import { Context } from "koa";
import { AffluenceClient } from "@app/db/affluence.client";
import JoiErrors from "@app/joi-error.middleware";
import { Joi } from "koa-joi-router";
import { ClientFactoryService } from "@app/db/client.factory";
......@@ -24,8 +22,8 @@ export default class UserReportController {
time: Joi.date().timestamp().required(),
stopId: Joi.string().required(),
routeId: Joi.string().required(),
directionId: Joi.number().only(1, 2).required(),
occupancy: Joi.string().only('LOW', 'MIDDLE', 'HIGH').required(),
directionId: Joi.number().valid(1, 2).required(),
occupancy: Joi.string().valid('LOW', 'MIDDLE', 'HIGH').required(),
headsign: Joi.string()
}
})
......@@ -45,7 +43,7 @@ export default class UserReportController {
})
client = this.clientFactory.getAffluenceClient();
ctx.response.body = { success: true, status: 200 };
} catch (e: any) {
} catch (e: any) {
client?.end();
this.log.logger.error(`[controller][UserReportController][postUserReport] ${e}`);
ctx.response.body = { errors: [{ code: 'OPERATION_FAILED', message: e.message }] };
......
......@@ -3,4 +3,5 @@ import { bootstrap, loadConfigFile } from '@m-backend/core';
import { AppModule } from '@app/app.module';
loadConfigFile('db');
bootstrap(AppModule);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment