create-lyrajs 1.1.1 → 1.1.3
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
CHANGED
package/template/package.json
CHANGED
|
@@ -177,7 +177,7 @@ export class AuthController {
|
|
|
177
177
|
sameSite: "lax",
|
|
178
178
|
httpOnly: true,
|
|
179
179
|
secure: process.env.ENV === "production",
|
|
180
|
-
maxAge: securityConfig.jwt.token_expiration,
|
|
180
|
+
maxAge: securityConfig.jwt.token_expiration * 1000,
|
|
181
181
|
partitioned: false
|
|
182
182
|
})
|
|
183
183
|
|
|
@@ -6,7 +6,7 @@ import { User } from "@entity/User"
|
|
|
6
6
|
import { userRepository } from "@repository/UserRepository"
|
|
7
7
|
|
|
8
8
|
export class UserController {
|
|
9
|
-
static list = async (req: Request
|
|
9
|
+
static list = async (req: AuthenticatedRequest<Request>, res: Response, next: NextFunction): Promise<void> => {
|
|
10
10
|
try {
|
|
11
11
|
const users = (await userRepository.findAll()).map((user: User) => {
|
|
12
12
|
delete user?.password
|
|
@@ -18,7 +18,7 @@ export class UserController {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
static read = async (req: Request
|
|
21
|
+
static read = async (req: AuthenticatedRequest<Request>, res: Response, next: NextFunction) => {
|
|
22
22
|
try {
|
|
23
23
|
const { id } = req.params
|
|
24
24
|
const user = await userRepository.find(id)
|
|
@@ -29,7 +29,7 @@ export class UserController {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
static create = async (req: Request
|
|
32
|
+
static create = async (req: AuthenticatedRequest<Request>, res: Response, next: NextFunction) => {
|
|
33
33
|
try {
|
|
34
34
|
const { data }: { data: User } = req.body
|
|
35
35
|
|
|
@@ -83,11 +83,12 @@ export class UserController {
|
|
|
83
83
|
const { data }: { data: User } = req.body
|
|
84
84
|
const user = await userRepository.find(data.id)
|
|
85
85
|
if (!user) res.status(404).json({ message: "User not found" })
|
|
86
|
-
|
|
87
|
-
delete user?.email
|
|
88
|
-
user.updated_at = new Date()
|
|
86
|
+
if (!AccessControl.isOwner(req.user, user.id) && !AccessControl.hasRoleHigherThan(req.user, user.role)) throw new UnauthorizedException()
|
|
89
87
|
if (AccessControl.hasRoleHigherThan(req.user, user.role)) delete user.role
|
|
90
|
-
|
|
88
|
+
delete data?.password
|
|
89
|
+
delete data?.email
|
|
90
|
+
data.updated_at = new Date()
|
|
91
|
+
await userRepository.save(data)
|
|
91
92
|
res.status(200).json({ message: "Users updated successfully" })
|
|
92
93
|
} catch (error) {
|
|
93
94
|
next(error)
|
package/template/src/server.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { Config, SecurityConfig, LyraConsole, accessMiddleware, errorHandler, ht
|
|
|
9
9
|
|
|
10
10
|
dotenv.config()
|
|
11
11
|
|
|
12
|
+
process.env.TZ = process.env.TZ || "Europe/Paris"
|
|
13
|
+
|
|
12
14
|
const params = new Config().get("parameters")
|
|
13
15
|
const securityConfig = new SecurityConfig().getConfig()
|
|
14
16
|
|