Skip to content

Commit a6a364e

Browse files
authored
Merge pull request #47 from GBSL-Informatik:update-prisma
Update-prisma
2 parents f6f8ccb + ffdca6e commit a6a364e

File tree

5 files changed

+294
-222
lines changed

5 files changed

+294
-222
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org $SENTRY_ORG --project $SENTRY_PROJECT ./dist && sentry-cli sourcemaps upload --org $SENTRY_ORG --project $SENTRY_PROJECT ./dist"
2121
},
2222
"dependencies": {
23-
"@prisma/client": "^6.6.0",
23+
"@prisma/adapter-pg": "^6.15.0",
24+
"@prisma/client": "^6.15.0",
2425
"@sentry/cli": "^2.43.0",
2526
"@sentry/node": "^9.12.0",
2627
"connect-pg-simple": "^9.0.1",
@@ -52,7 +53,7 @@
5253
"dotenv-cli": "^7.4.2",
5354
"nodemon": "^3.1.3",
5455
"prettier": "^3.3.2",
55-
"prisma": "^6.6.0",
56+
"prisma": "^6.15.0",
5657
"prisma-dbml-generator": "^0.12.0",
5758
"prisma-docs-generator": "^0.8.0",
5859
"prisma-erd-generator": "^2.0.4",

prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
generator client {
22
provider = "prisma-client-js"
3-
previewFeatures = ["postgresqlExtensions", "views", "relationJoins"]
3+
previewFeatures = ["postgresqlExtensions", "views", "relationJoins", "queryCompiler", "driverAdapters"]
44
}
55

66
generator docs {

src/app.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,22 @@ passport.serializeUser((user, done) => {
9393
done(null, user.id);
9494
});
9595

96-
passport.deserializeUser(async (id: string, done) => {
96+
const deserializeUser = async (id: string, done: (err: any, user?: User | null) => void) => {
9797
const user = await prisma.user.findUnique({ where: { id: id } });
9898
done(null, user);
99-
});
99+
};
100+
101+
passport.deserializeUser(deserializeUser);
100102

101103
// Serve the static files to be accessed by the docs app
102104
app.use(express.static(path.join(__dirname, '..', 'docs')));
103105

104-
// Public Endpoints
105-
app.get(`${API_URL}`, (req, res) => {
106+
const welcomeApi = (req: Request, res: Response) => {
106107
return res.status(200).send('Welcome to the TEACHING-WEBSITE-API V1.0');
107-
});
108+
};
109+
110+
// Public Endpoints
111+
app.get(`${API_URL}`, welcomeApi);
108112

109113
const SessionOauthStrategy = (req: Request, res: Response, next: NextFunction) => {
110114
if (req.isAuthenticated()) {
@@ -113,7 +117,7 @@ const SessionOauthStrategy = (req: Request, res: Response, next: NextFunction) =
113117
passport.authenticate('oauth-bearer', { session: true })(req, res, next);
114118
};
115119

116-
app.get(`${API_URL}/checklogin`, SessionOauthStrategy, async (req, res, next) => {
120+
const checkLogin = async (req: Request, res: Response, next: NextFunction) => {
117121
try {
118122
if (req.user) {
119123
return res.status(200).send('OK');
@@ -122,9 +126,11 @@ app.get(`${API_URL}/checklogin`, SessionOauthStrategy, async (req, res, next) =>
122126
} catch (error) {
123127
next(error);
124128
}
125-
});
129+
};
130+
131+
app.get(`${API_URL}/checklogin`, SessionOauthStrategy, checkLogin);
126132

127-
app.post(`${API_URL}/logout`, async (req, res, next) => {
133+
const logout = async (req: Request, res: Response, next: NextFunction) => {
128134
req.logout({ keepSessionInfo: false }, (err) => {
129135
if (err) {
130136
Logger.error(err);
@@ -135,7 +141,9 @@ app.post(`${API_URL}/logout`, async (req, res, next) => {
135141
Logger.info(req.session);
136142
// await prisma.sessions.delete({ where: { sid: req.session.id } });
137143
res.clearCookie(SESSION_KEY).send();
138-
});
144+
};
145+
146+
app.post(`${API_URL}/logout`, logout);
139147

140148
export const configure = (_app: typeof app) => {
141149
/**

src/prisma.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PrismaPg } from '@prisma/adapter-pg';
12
import { Prisma, PrismaClient } from '@prisma/client';
23

34
const options: Prisma.PrismaClientOptions & {
@@ -23,7 +24,11 @@ if (process.env.LOG) {
2324
}
2425
];
2526
}
26-
const prisma = new PrismaClient(options);
27+
28+
const connectionString = `${process.env.DATABASE_URL}`;
29+
30+
const adapter = new PrismaPg({ connectionString });
31+
const prisma = new PrismaClient({ ...options, adapter: adapter });
2732
prisma.$connect();
2833

2934
if (process.env.LOG) {

0 commit comments

Comments
 (0)