Skip to content

Commit

Permalink
fix(): clean & rename
Browse files Browse the repository at this point in the history
  • Loading branch information
lanathlor committed Apr 19, 2021
1 parent e54d9a2 commit f02c531
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 204 deletions.
2 changes: 1 addition & 1 deletion @types/express/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ declare module 'express-serve-static-core' {
}

interface Response {
bridgeResponse: TResponder
backResponse: TResponder
}
}
59 changes: 0 additions & 59 deletions src/Middlewares/Extern/ContactValidator.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/Middlewares/Extern/StripeValidator.ts

This file was deleted.

76 changes: 0 additions & 76 deletions src/Middlewares/Physics/RunValidator.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Response } from 'express';
import { IResponseType } from '../Types/responseTypes'

export default function setResponseFunction ({}, res : Response, next : Function) {
res.bridgeResponse = (response : IResponseType) : void => {
export function backResponse ({}, res : Response, next : Function) {
res.backResponse = (response : IResponseType) : void => {
if (response.payload)
res.status(response.status).json(response.payload);
else
Expand Down
39 changes: 0 additions & 39 deletions src/Types/responseTypes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// import { Schema } from 'mongoose';
import { HttpStatusCode } from './httpStatus'

import { IUser } from './user'
import { ICode } from './code'

export type TResponder = (IResponseType: IResponseType) => void

export interface IResponseType {
Expand All @@ -18,41 +15,5 @@ export var ResponseType = {

BAD_REQUEST: {status: HttpStatusCode.BAD_REQUEST, message:'bad request', code:'BAD_REQUEST'},

USER_REGISTERED: {status: HttpStatusCode.CREATED, message:'User registered successfully', code:'USER_REGISTERED'},

FORBIDDEN: {status: HttpStatusCode.FORBIDDEN, message:'User not allowed', code:'FORBIDDEN'},

USER_ACTIVATED: {status: HttpStatusCode.OK, message:'user activated successfully', code:'USER_ACTIVATED'},

CODE_USED: {status: HttpStatusCode.BAD_REQUEST, message:'code already used', code:'CODE_USED'},

INTERNAL_SERVER_ERROR: {status: HttpStatusCode.INTERNAL_SERVER_ERROR, message:'Internal server error', code:'INTERNAL_SERVER_ERROR'},

BAD_IP: {status: HttpStatusCode.FORBIDDEN, message:'bad ip', code:'BAD_IP'},

NO_CONTENT: {status: HttpStatusCode.NO_CONTENT, message:'', code:'NO_CONTENT'},

NO_SUB : {status: HttpStatusCode.FORBIDDEN, message: 'User is not subscribed', code: 'NO_SUB'},

USER_INFO: (infos : IUser) : IResponseType => {return {status: HttpStatusCode.OK, payload: infos, code:'USER_INFO'}},

USER_HISTORY: (calculs : object[]) : IResponseType => {return {status: HttpStatusCode.OK, payload: calculs, code:'USER_HISTORY'}},

CODE_CREATED: (code : ICode) : IResponseType => {return {status: HttpStatusCode.OK, payload: code, code:'CODE_CREATED'}},

STRIPE_SESSION_CREATED: (session : object) : IResponseType => {return {status: HttpStatusCode.OK, payload: session, code:'STRIPE_SESSION_CREATED'}},

STRIPE_SESSION: (session : object) : IResponseType => {return {status: HttpStatusCode.OK, payload: session, code:'STRIPE_SESSION'}},

STRIPE_PORTAL_SESSION: (session : object) : IResponseType => {return {status: HttpStatusCode.OK, payload: session, code:'STRIPE_PORTAL_SESSION'}},

WALLS_LIST: (walls : object) : IResponseType => {return {status: HttpStatusCode.OK, payload: walls, code:'WALLS_LIST'}},

RNS_LIST: (rns : object) : IResponseType => {return {status: HttpStatusCode.OK, payload: rns, code:'RNS_LIST'}},

COEFS_LIST: (coefs : object) : IResponseType => {return {status: HttpStatusCode.OK, payload: coefs, code:'COEFS_LIST'}},

EXEC_CALCUL: (calcul : object) : IResponseType => {return {status: HttpStatusCode.OK, payload: calcul, code:'EXEC_CALCUL'}},

BAD_REQUEST_NOT_FOUND: (attemptedRequest : string) : IResponseType => ({status: HttpStatusCode.NOT_FOUND, message:`endpoint not found : ${attemptedRequest}`, code: 'BAD_REQUEST_NOT_FOUND'}),
};
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { connect, connected } from './Helpers/MongoConnection';
const expressApp = express();
import * as bodyParser from 'body-parser';
import logger, { LoggerStream } from './Utils/Logger';
import BridgeResponse from './Middlewares/bridgeResponse';
import { backResponse } from './Middlewares/backResponse';
import { ResponseType } from './Types/responseTypes'

/*
Expand All @@ -27,15 +27,15 @@ import { ResponseType } from './Types/responseTypes'
expressApp.use(cors());
expressApp.use(bodyParser.urlencoded({ extended: true }));

expressApp.use(BridgeResponse);
expressApp.use(backResponse);
expressApp.use(morgan("combined", { stream: new LoggerStream() }));
/*
* ROUTES CONFIGURATION
*/


expressApp.use((req : Request, res : Response) => {
res.bridgeResponse(ResponseType.BAD_REQUEST_NOT_FOUND(req.url));
res.backResponse(ResponseType.BAD_REQUEST_NOT_FOUND(req.url));
});

function mongoConnect() {
Expand Down

0 comments on commit f02c531

Please sign in to comment.