Skip to content

Commit 8cd263b

Browse files
Merge pull request #13 from ChangePlusPlusVandy/setup/dev-setup
Setup/dev setup
2 parents 0fad9cb + 0d8e0df commit 8cd263b

File tree

13 files changed

+39
-59
lines changed

13 files changed

+39
-59
lines changed

backend/__tests__/controllers/organizationController.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ jest.mock('firebase-admin', () => ({
5050
}),
5151
}));
5252

53+
jest.mock('../../config/prisma', () => ({
54+
prisma: prismaMock,
55+
}));
56+
5357
import {
5458
getAllOrganizations,
5559
registerOrganization,

backend/__tests__/setup/prisma-mock.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ jest.mock('@prisma/client', () => ({
88
PrismaClient: jest.fn().mockImplementation(() => prismaMock),
99
}));
1010

11+
jest.mock('../../config/prisma', () => ({
12+
prisma: prismaMock,
13+
}));
14+
1115
beforeEach(() => {
1216
mockReset(prismaMock);
1317
});

backend/app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import express from 'express';
22
import cors from 'cors';
3-
import { PrismaClient } from '@prisma/client';
43
import organizationRoutes from './routes/organizationRoutes';
4+
import { prisma } from './config/prisma';
55

66
const app = express();
7-
const prisma = new PrismaClient();
87

98
app.use(cors());
109
app.use(express.json());

backend/config/database.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

backend/config/prisma.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { PrismaClient } from '@prisma/client';
2+
3+
const globalPrisma = global as unknown as { prisma: PrismaClient };
4+
export const prisma = globalPrisma.prisma || new PrismaClient();
5+
6+
if (process.env.NODE_ENV !== 'production') {
7+
globalPrisma.prisma = prisma;
8+
}

backend/config/sendgrid.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

backend/controllers/organizationController.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { Request, Response } from 'express';
22
import {
3-
PrismaClient,
43
OrganizationRole,
54
OrganizationStatus,
65
TennesseeRegion,
76
OrganizationSize,
87
} from '@prisma/client';
98
import { AuthenticatedRequest } from '../types/index.js';
109
import admin from 'firebase-admin';
11-
12-
const prisma = new PrismaClient();
10+
import { prisma } from '../config/prisma.js';
1311

1412
/**
1513
* @desc Get all organizations with optional search/filter

backend/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
},
1313
],
1414
},
15-
moduleNameMapping: {
15+
moduleNameMapper: {
1616
'^(\\.{1,2}/.*)\\.js$': '$1',
1717
},
1818
setupFilesAfterEnv: ['<rootDir>/__tests__/setup/prisma-mock.ts'],

backend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"type": "module",
55
"main": "server.ts",
66
"scripts": {
7-
"dev": "tsx server.ts",
7+
"dev": "NODE_ENV=development tsx server.ts",
88
"build": "tsc",
9-
"start": "node dist/server.js",
10-
"test": "jest",
9+
"start": "NODE_ENV=production node dist/server.js",
10+
"test": "NODE_ENV=test jest",
1111
"format": "prettier --write \"**/*.{ts,tsx,js,json,md}\"",
1212
"format:check": "prettier --check \"**/*.{ts,tsx,js,json,md}\""
1313
},
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import { PrismaClient } from '@prisma/client';
2-
3-
const prisma = new PrismaClient();
1+
import { prisma } from '../config/prisma';

0 commit comments

Comments
 (0)