@optimatech88/titomeet-shared-lib 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/prisma/schema.prisma +12 -0
- package/src/auth/admin.middleware.ts +20 -0
- package/src/auth/auth.guard.ts +2 -0
- package/src/index.ts +3 -1
package/package.json
CHANGED
package/prisma/schema.prisma
CHANGED
|
@@ -80,6 +80,16 @@ enum EventStatus {
|
|
|
80
80
|
PUBLISHED
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
model EventCategory {
|
|
84
|
+
id String @id @default(cuid())
|
|
85
|
+
name String
|
|
86
|
+
description String?
|
|
87
|
+
events Event[]
|
|
88
|
+
|
|
89
|
+
createdAt DateTime @default(now())
|
|
90
|
+
updatedAt DateTime @updatedAt
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
model Event {
|
|
84
94
|
id String @id @default(cuid())
|
|
85
95
|
name String
|
|
@@ -99,6 +109,8 @@ model Event {
|
|
|
99
109
|
chat Chat? // Optional one-to-one relation
|
|
100
110
|
status EventStatus @default(DRAFT)
|
|
101
111
|
|
|
112
|
+
categories EventCategory[]
|
|
113
|
+
|
|
102
114
|
address Address @relation(fields: [addressId], references: [id])
|
|
103
115
|
addressId String
|
|
104
116
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import { UserRole, User } from '@prisma/client';
|
|
4
|
+
|
|
5
|
+
interface RequestWithUser extends Request {
|
|
6
|
+
user?: User;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class AdminMiddleware implements NestMiddleware {
|
|
11
|
+
use(req: RequestWithUser, res: Response, next: NextFunction) {
|
|
12
|
+
const user = req.user;
|
|
13
|
+
|
|
14
|
+
if (!user || !user.role?.includes(UserRole.ADMIN)) {
|
|
15
|
+
throw new UnauthorizedException('Access denied. Admins only.');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
next();
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/auth/auth.guard.ts
CHANGED
|
@@ -51,6 +51,7 @@ export class AuthGuard implements CanActivate {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
//optional auth guard
|
|
54
55
|
@Injectable()
|
|
55
56
|
export class OptionalAuthGuard implements CanActivate {
|
|
56
57
|
private prisma: PrismaClient;
|
|
@@ -94,3 +95,4 @@ export class OptionalAuthGuard implements CanActivate {
|
|
|
94
95
|
return type === 'Bearer' ? token : undefined;
|
|
95
96
|
}
|
|
96
97
|
}
|
|
98
|
+
|
package/src/index.ts
CHANGED