Skip to content

Commit

Permalink
restructure backend
Browse files Browse the repository at this point in the history
  • Loading branch information
youngbryanyu committed Feb 23, 2024
1 parent 613a7ce commit 435efe3
Show file tree
Hide file tree
Showing 24 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions backend/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ global.console = {
debug: jest.fn(), // Mock console.debug
}

/* Mock Redis client in all unit tests */
jest.mock('./src/redis/redisClient', () => ({
/* Mock Redis client in all unit tests. Needed since redis is used by express-rate-limit in top level code which is imported by App.ts when the routes are loaded */
jest.mock('./src/database/redis/redisClient', () => ({
getClient: jest.fn().mockImplementation(() => ({
sendCommand: jest.fn().mockResolvedValue('OK'),
})),
Expand Down
6 changes: 3 additions & 3 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Application setup */
import express, { Express } from 'express';
import mongoose from 'mongoose';
import healthCheckRouter from './healthCheck/routes/healthCheckRoutes';
import userRouter from './user/routes/userRoutes';
import { ApiUrlsV1 } from './constants';
import healthCheckRouter from './features/healthCheck/routes/healthCheckRoutes';
import userRouter from './features/user/routes/userRoutes';
import { ApiUrlsV1 } from './features/common/constants';
import logger from './logging/logger';
import Config from 'simple-app-config';
import helmet from 'helmet';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Config from 'simple-app-config';
import { createClient, RedisClientType } from 'redis';
import logger from '../logging/logger';
import logger from '../../logging/logger';

/**
* Client class used to interact with redis
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Interface that all official and custom food documents extend */
import { BaseDocument } from '../../baseDocument';
import { BaseDocument } from '../../common/baseDocument';

/**
* Interface for a generic food document that is trackable
Expand Down
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Business logic for application health checks */
import { Request, Response } from 'express';
import mongoose, { STATES } from 'mongoose';
import logger from '../../logging/logger';
import { HealthCheckResponses } from '../constants';
import logger from '../../../logging/logger';

/**
* Business logic for application health checks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* Routes for application health checks */
import express from 'express';
import rateLimit, { MemoryStore } from 'express-rate-limit';
import logger from '../../logging/logger';
import Config from 'simple-app-config';
import HealthCheckController from '../controllers/healthCheckController';
import { API_URLS_V1_PREFIX, Environments, GenericResponses } from '../../constants';
import { API_URLS_V1_PREFIX, Environments, GenericResponses } from '../../common/constants';
import RedisStore from 'rate-limit-redis';
import RedisClient from '../../redis/redisClient';
import _ from 'lodash';
import logger from '../../../logging/logger';
import RedisClient from '../../../database/redis/redisClient';

const healthCheckRouter = express.Router();

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { Request, Response } from 'express';
import { User } from '../models/user';
import { UserResponses } from '../constants';
import { GenericResponses } from '../../constants';
import logger from '../../logging/logger';
import { GenericResponses } from '../../common/constants';
import logger from '../../../logging/logger';

/**
* Business logic for user related APIs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Schema definition for a user */
import mongoose, { Schema } from 'mongoose';
import { BaseDocument } from '../../baseDocument';
import { BaseDocument } from '../../common/baseDocument';

/**
* Interface for user document
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* Routes for user authentication */
import express from 'express';
import rateLimit, { MemoryStore } from 'express-rate-limit';
import logger from '../../logging/logger';
import logger from '../../../logging/logger';
import Config from 'simple-app-config';
import { API_URLS_V1_PREFIX, Environments, GenericResponses } from '../../constants';
import { API_URLS_V1_PREFIX, Environments, GenericResponses } from '../../common/constants';
import UserController from '../controllers/userController';
import RedisStore from 'rate-limit-redis';
import RedisClient from '../../redis/redisClient';
import _ from 'lodash';
import RedisClient from '../../../database/redis/redisClient';

export const userRouter = express.Router();

Expand Down
2 changes: 1 addition & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Import DB clients and logger before all else
*/
import logger from './logging/logger';
import RedisClient from './redis/redisClient';
import RedisClient from './database/redis/redisClient';

/**
* IIFE to ensure database connections are established synchronously before anything else uses the DBs
Expand Down
2 changes: 1 addition & 1 deletion backend/src/logging/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Setup for logger */
import DailyRotateFile from 'winston-daily-rotate-file';
import winston from 'winston';
import { Environments } from '../constants';
import { Environments } from '../features/common/constants';

/* Set up file transport and rotation */
const fileTransport = new DailyRotateFile({
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Unit tests for the backend application server class */
import mongoose from 'mongoose';
import App from '../src/app';
import { Environments } from '../src/constants';
import { Environments } from '../src/features/common/constants';
import logger from '../src/logging/logger';
import Config, { EnvParser } from 'simple-app-config';
import http from 'http';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response } from 'express';
import { MockRequest, MockResponse, createRequest, createResponse } from 'node-mocks-http';
import HealthCheckController from '../../../src/healthCheck/controllers/healthCheckController';
import { HealthCheckResponses } from '../../../src/healthCheck/constants';
import HealthCheckController from '../../../src/features/healthCheck/controllers/healthCheckController';
import { HealthCheckResponses } from '../../../src/features/healthCheck/constants';
import mongoose from 'mongoose';

describe('Health Check Controller Tests', () => {
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/healthCheck/routes/healthCheckRoutes.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* Unit tests for the health check routes */
import request from 'supertest';
import { ApiUrlsV1, GenericResponses } from '../../../src/constants';
import { ApiUrlsV1, GenericResponses } from '../../../src/features/common/constants';
import App from '../../../src/app';
import Config from 'simple-app-config';
import HealthCheckController from '../../../src/healthCheck/controllers/healthCheckController';
import HealthCheckController from '../../../src/features/healthCheck/controllers/healthCheckController';

/* Mock the controller functions */
jest.mock('../../../src/healthCheck/controllers/healthCheckController', () => ({
jest.mock('../../../src/features/healthCheck/controllers/healthCheckController', () => ({
checkHealth: jest.fn().mockImplementation((req, res) => {
res.sendStatus(200);
})
Expand Down

0 comments on commit 435efe3

Please sign in to comment.