lapeh 1.0.10 → 1.0.12
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 +3 -1
- package/src/controllers/authController.ts +12 -12
- package/src/schema/auth-schema.ts +26 -26
- package/src/schema/user-schema.ts +0 -57
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lapeh",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Framework API Express yang siap pakai (Standardized)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"typescript",
|
|
34
34
|
"prisma",
|
|
35
35
|
"roby",
|
|
36
|
+
"roby-ajo",
|
|
37
|
+
"ajo-roby",
|
|
36
38
|
"roby-karti-s",
|
|
37
39
|
"lapeh"
|
|
38
40
|
],
|
|
@@ -26,7 +26,7 @@ export async function register(req: Request, res: Response) {
|
|
|
26
26
|
if (existing) {
|
|
27
27
|
sendError(res, 409, "Email already used", {
|
|
28
28
|
field: "email",
|
|
29
|
-
message: "Email
|
|
29
|
+
message: "Email is already registered, please use another email",
|
|
30
30
|
});
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
@@ -55,7 +55,7 @@ export async function register(req: Request, res: Response) {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
sendSuccess(res, 200, "
|
|
58
|
+
sendSuccess(res, 200, "Registration successful", {
|
|
59
59
|
id: user.id.toString(),
|
|
60
60
|
email: user.email,
|
|
61
61
|
name: user.name,
|
|
@@ -84,7 +84,7 @@ export async function login(req: Request, res: Response) {
|
|
|
84
84
|
if (!user) {
|
|
85
85
|
sendError(res, 401, "Email not registered", {
|
|
86
86
|
field: "email",
|
|
87
|
-
message: "Email
|
|
87
|
+
message: "Email is not registered, please register first",
|
|
88
88
|
});
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
@@ -92,7 +92,7 @@ export async function login(req: Request, res: Response) {
|
|
|
92
92
|
if (!ok) {
|
|
93
93
|
sendError(res, 401, "Invalid credentials", {
|
|
94
94
|
field: "password",
|
|
95
|
-
message: "
|
|
95
|
+
message: "The password you entered is incorrect",
|
|
96
96
|
});
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
@@ -124,7 +124,7 @@ export async function login(req: Request, res: Response) {
|
|
|
124
124
|
secret,
|
|
125
125
|
{ expiresIn: refreshExpiresInSeconds }
|
|
126
126
|
);
|
|
127
|
-
sendSuccess(res, 200, "Login
|
|
127
|
+
sendSuccess(res, 200, "Login successful", {
|
|
128
128
|
token,
|
|
129
129
|
refreshToken,
|
|
130
130
|
expiresIn: accessExpiresInSeconds,
|
|
@@ -166,7 +166,7 @@ export async function me(req: Request, res: Response) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
export async function logout(req: Request, res: Response) {
|
|
169
|
-
sendSuccess(res, 200, "Logout
|
|
169
|
+
sendSuccess(res, 200, "Logout successful", null);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
export async function refreshToken(req: Request, res: Response) {
|
|
@@ -243,7 +243,7 @@ export async function updateAvatar(req: Request, res: Response) {
|
|
|
243
243
|
path: string;
|
|
244
244
|
} | null;
|
|
245
245
|
if (!file) {
|
|
246
|
-
sendError(res, 400, "Avatar file
|
|
246
|
+
sendError(res, 400, "Avatar file is required");
|
|
247
247
|
return;
|
|
248
248
|
}
|
|
249
249
|
const userId = BigInt(payload.userId);
|
|
@@ -259,7 +259,7 @@ export async function updateAvatar(req: Request, res: Response) {
|
|
|
259
259
|
},
|
|
260
260
|
});
|
|
261
261
|
const { password, remember_token, ...rest } = updated as any;
|
|
262
|
-
sendSuccess(res, 200, "Avatar
|
|
262
|
+
sendSuccess(res, 200, "Avatar updated successfully", {
|
|
263
263
|
...rest,
|
|
264
264
|
id: updated.id.toString(),
|
|
265
265
|
});
|
|
@@ -289,7 +289,7 @@ export async function updatePassword(req: Request, res: Response) {
|
|
|
289
289
|
if (!ok) {
|
|
290
290
|
sendError(res, 401, "Invalid credentials", {
|
|
291
291
|
field: "currentPassword",
|
|
292
|
-
message: "
|
|
292
|
+
message: "Current password is incorrect",
|
|
293
293
|
});
|
|
294
294
|
return;
|
|
295
295
|
}
|
|
@@ -301,7 +301,7 @@ export async function updatePassword(req: Request, res: Response) {
|
|
|
301
301
|
updated_at: new Date(),
|
|
302
302
|
},
|
|
303
303
|
});
|
|
304
|
-
sendSuccess(res, 200, "Password
|
|
304
|
+
sendSuccess(res, 200, "Password updated successfully", null);
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
export async function updateProfile(req: Request, res: Response) {
|
|
@@ -327,7 +327,7 @@ export async function updateProfile(req: Request, res: Response) {
|
|
|
327
327
|
if (existing) {
|
|
328
328
|
sendError(res, 409, "Email already used", {
|
|
329
329
|
field: "email",
|
|
330
|
-
message: "Email
|
|
330
|
+
message: "Email is already registered, please use another email",
|
|
331
331
|
});
|
|
332
332
|
return;
|
|
333
333
|
}
|
|
@@ -340,7 +340,7 @@ export async function updateProfile(req: Request, res: Response) {
|
|
|
340
340
|
},
|
|
341
341
|
});
|
|
342
342
|
const { password, remember_token, ...rest } = updated as any;
|
|
343
|
-
sendSuccess(res, 200, "
|
|
343
|
+
sendSuccess(res, 200, "Profile updated successfully", {
|
|
344
344
|
...rest,
|
|
345
345
|
id: updated.id.toString(),
|
|
346
346
|
});
|
|
@@ -3,60 +3,60 @@ import z from "zod";
|
|
|
3
3
|
export const registerSchema = z
|
|
4
4
|
.object({
|
|
5
5
|
email: z
|
|
6
|
-
.string({ required_error: "Email
|
|
7
|
-
.email("
|
|
6
|
+
.string({ required_error: "Email is required" })
|
|
7
|
+
.email("Invalid email format"),
|
|
8
8
|
name: z
|
|
9
|
-
.string({ required_error: "
|
|
10
|
-
.min(1, "
|
|
9
|
+
.string({ required_error: "Name is required" })
|
|
10
|
+
.min(1, "Name is required"),
|
|
11
11
|
password: z
|
|
12
|
-
.string({ required_error: "Password
|
|
13
|
-
.min(4, "Password
|
|
12
|
+
.string({ required_error: "Password is required" })
|
|
13
|
+
.min(4, "Password must be at least 4 characters"),
|
|
14
14
|
confirmPassword: z
|
|
15
|
-
.string({ required_error: "
|
|
16
|
-
.min(4, "
|
|
15
|
+
.string({ required_error: "Confirm password is required" })
|
|
16
|
+
.min(4, "Confirm password must be at least 4 characters"),
|
|
17
17
|
})
|
|
18
18
|
.refine((data) => data.password === data.confirmPassword, {
|
|
19
19
|
path: ["confirmPassword"],
|
|
20
|
-
message: "
|
|
20
|
+
message: "Confirm password does not match",
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
export const loginSchema = z.object({
|
|
24
24
|
email: z
|
|
25
|
-
.string({ required_error: "Email
|
|
26
|
-
.email("
|
|
25
|
+
.string({ required_error: "Email is required" })
|
|
26
|
+
.email("Invalid email format"),
|
|
27
27
|
password: z
|
|
28
|
-
.string({ required_error: "Password
|
|
29
|
-
.min(4, "Password
|
|
28
|
+
.string({ required_error: "Password is required" })
|
|
29
|
+
.min(4, "Password must be at least 4 characters"),
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
export const refreshSchema = z.object({
|
|
33
33
|
refreshToken: z
|
|
34
|
-
.string({ required_error: "Refresh token
|
|
35
|
-
.min(1, "Refresh token
|
|
34
|
+
.string({ required_error: "Refresh token is required" })
|
|
35
|
+
.min(1, "Refresh token is required"),
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
export const updatePasswordSchema = z
|
|
39
39
|
.object({
|
|
40
40
|
currentPassword: z
|
|
41
|
-
.string({ required_error: "
|
|
42
|
-
.min(4, "
|
|
41
|
+
.string({ required_error: "Current password is required" })
|
|
42
|
+
.min(4, "Current password must be at least 4 characters"),
|
|
43
43
|
newPassword: z
|
|
44
|
-
.string({ required_error: "
|
|
45
|
-
.min(4, "
|
|
44
|
+
.string({ required_error: "New password is required" })
|
|
45
|
+
.min(4, "New password must be at least 4 characters"),
|
|
46
46
|
confirmPassword: z
|
|
47
|
-
.string({ required_error: "
|
|
48
|
-
.min(4, "
|
|
47
|
+
.string({ required_error: "Confirm password is required" })
|
|
48
|
+
.min(4, "Confirm password must be at least 4 characters"),
|
|
49
49
|
})
|
|
50
50
|
.refine((data) => data.newPassword === data.confirmPassword, {
|
|
51
51
|
path: ["confirmPassword"],
|
|
52
|
-
message: "
|
|
52
|
+
message: "Confirm password does not match",
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
export const updateProfileSchema = z.object({
|
|
56
56
|
name: z
|
|
57
|
-
.string({ required_error: "
|
|
58
|
-
.min(1, "
|
|
57
|
+
.string({ required_error: "Name is required" })
|
|
58
|
+
.min(1, "Name is required"),
|
|
59
59
|
email: z
|
|
60
|
-
.string({ required_error: "Email
|
|
61
|
-
.email("
|
|
60
|
+
.string({ required_error: "Email is required" })
|
|
61
|
+
.email("Invalid email format"),
|
|
62
62
|
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
|
|
3
|
-
export const createUserSchema = z
|
|
4
|
-
.object({
|
|
5
|
-
email: z
|
|
6
|
-
.string({ required_error: "Email wajib diisi" })
|
|
7
|
-
.email("Format email tidak valid"),
|
|
8
|
-
name: z
|
|
9
|
-
.string({ required_error: "Nama wajib diisi" })
|
|
10
|
-
.min(1, "Nama wajib diisi"),
|
|
11
|
-
password: z
|
|
12
|
-
.string({ required_error: "Password wajib diisi" })
|
|
13
|
-
.min(6, "Password minimal 6 karakter"),
|
|
14
|
-
confirmPassword: z
|
|
15
|
-
.string({ required_error: "Konfirmasi password wajib diisi" })
|
|
16
|
-
.min(4, "Konfirmasi password minimal 4 karakter"),
|
|
17
|
-
roleId: z.string().optional(),
|
|
18
|
-
permissionIds: z.array(z.string()).optional(),
|
|
19
|
-
})
|
|
20
|
-
.refine((data) => data.password === data.confirmPassword, {
|
|
21
|
-
path: ["confirmPassword"],
|
|
22
|
-
message: "Konfirmasi password tidak sama",
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const updateUserSchema = z
|
|
26
|
-
.object({
|
|
27
|
-
email: z
|
|
28
|
-
.string({ required_error: "Email wajib diisi" })
|
|
29
|
-
.email("Format email tidak valid")
|
|
30
|
-
.optional(),
|
|
31
|
-
name: z
|
|
32
|
-
.string({ required_error: "Nama wajib diisi" })
|
|
33
|
-
.min(1, "Nama wajib diisi")
|
|
34
|
-
.optional(),
|
|
35
|
-
password: z
|
|
36
|
-
.string({ required_error: "Password wajib diisi" })
|
|
37
|
-
.min(6, "Password minimal 6 karakter")
|
|
38
|
-
.optional(),
|
|
39
|
-
confirmPassword: z
|
|
40
|
-
.string({ required_error: "Konfirmasi password wajib diisi" })
|
|
41
|
-
.min(4, "Konfirmasi password minimal 4 karakter")
|
|
42
|
-
.optional(),
|
|
43
|
-
roleId: z.string().optional(),
|
|
44
|
-
permissionIds: z.array(z.string()).optional(),
|
|
45
|
-
})
|
|
46
|
-
.refine(
|
|
47
|
-
(data) => {
|
|
48
|
-
if (!data.password) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
return data.password === data.confirmPassword;
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
path: ["confirmPassword"],
|
|
55
|
-
message: "Konfirmasi password tidak sama",
|
|
56
|
-
}
|
|
57
|
-
);
|