exp-node-server 1.1.7 → 2.0.0
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/README.md +82 -20
- package/dist/cli.js +525 -0
- package/package.json +29 -9
- package/templates/mongoose/.dockerignore +10 -0
- package/templates/mongoose/.env.example +56 -7
- package/templates/mongoose/.prettierignore +3 -0
- package/templates/mongoose/.prettierrc +7 -0
- package/templates/mongoose/Dockerfile +33 -0
- package/templates/mongoose/_gitignore +32 -0
- package/templates/mongoose/docker-compose.yml +21 -0
- package/templates/mongoose/eslint.config.js +35 -0
- package/templates/mongoose/package-lock.json +6377 -0
- package/templates/mongoose/package.json +49 -10
- package/templates/mongoose/readme.md +85 -0
- package/templates/mongoose/src/app/configs/index.ts +178 -26
- package/templates/mongoose/src/app/errors/zodError.ts +16 -16
- package/templates/mongoose/src/app/lib/db.ts +18 -0
- package/templates/mongoose/src/app/lib/logger.ts +12 -0
- package/templates/mongoose/src/app/middlewares/auth.ts +48 -44
- package/templates/mongoose/src/app/middlewares/global_error_handler.ts +59 -65
- package/templates/mongoose/src/app/middlewares/not_found_api.ts +7 -7
- package/templates/mongoose/src/app/middlewares/rate_limiter.ts +153 -0
- package/templates/mongoose/src/app/middlewares/request_validator.ts +11 -10
- package/templates/mongoose/src/app/middlewares/uploader.ts +17 -13
- package/templates/mongoose/src/app/modules/account/account.controller.ts +156 -0
- package/templates/mongoose/src/app/modules/account/account.interface.ts +65 -0
- package/templates/mongoose/src/app/modules/account/account.route.ts +101 -0
- package/templates/mongoose/src/app/modules/account/account.schema.ts +97 -0
- package/templates/mongoose/src/app/modules/account/account.service.ts +422 -0
- package/templates/mongoose/src/app/modules/account/account.swagger.ts +278 -0
- package/templates/mongoose/src/app/modules/account/account.validation.ts +63 -0
- package/templates/mongoose/src/app/modules/profile/profile.controller.ts +17 -0
- package/templates/mongoose/src/app/modules/profile/profile.interface.ts +7 -0
- package/templates/mongoose/src/app/modules/profile/profile.route.ts +28 -0
- package/templates/mongoose/src/app/modules/profile/profile.schema.ts +13 -0
- package/templates/mongoose/src/app/modules/profile/profile.service.ts +28 -0
- package/templates/mongoose/src/app/modules/profile/profile.swagger.ts +34 -0
- package/templates/mongoose/src/app/modules/profile/profile.validation.ts +8 -0
- package/templates/mongoose/src/app/passport-js/index.ts +87 -0
- package/templates/mongoose/src/app/passport-js/oauth-state.ts +150 -0
- package/templates/mongoose/src/app/passport-js/providers.ts +258 -0
- package/templates/mongoose/src/app/passport-js/social-account.ts +141 -0
- package/templates/mongoose/src/app/queues/agenda.ts +24 -0
- package/templates/mongoose/src/app/queues/email.queue.ts +53 -0
- package/templates/mongoose/src/app/queues/index.ts +13 -0
- package/templates/mongoose/src/app/templates/otpEmailTemplate.ts +185 -0
- package/templates/mongoose/src/app/templates/resetPasswordEmailTemplate.ts +157 -0
- package/templates/mongoose/src/app/types/error.d.ts +7 -7
- package/templates/mongoose/src/app/types/express.d.ts +11 -0
- package/templates/mongoose/src/app/types/passport-oauth1.d.ts +51 -0
- package/templates/mongoose/src/app/utils/JWT.ts +38 -18
- package/templates/mongoose/src/app/utils/app_error.ts +10 -10
- package/templates/mongoose/src/app/utils/auth_cookie.ts +27 -0
- package/templates/mongoose/src/app/utils/catch_async.ts +8 -8
- package/templates/mongoose/src/app/utils/cloudinary.ts +26 -59
- package/templates/mongoose/src/app/utils/mail_sender.ts +26 -92
- package/templates/mongoose/src/app/utils/manage_response.ts +19 -19
- package/templates/mongoose/src/app/utils/otp.ts +20 -0
- package/templates/mongoose/src/app/utils/session.ts +55 -0
- package/templates/mongoose/src/app.ts +73 -42
- package/templates/mongoose/src/routes.ts +13 -13
- package/templates/mongoose/src/server.ts +38 -18
- package/templates/mongoose/src/swaggerOptions.ts +23 -23
- package/templates/mongoose/tests/app.test.ts +97 -0
- package/templates/mongoose/tests/global-setup.ts +15 -0
- package/templates/mongoose/tests/helpers/fixtures.ts +42 -0
- package/templates/mongoose/tests/routes/account.test.ts +614 -0
- package/templates/mongoose/tests/routes/profile.test.ts +95 -0
- package/templates/mongoose/tests/routes/social.test.ts +310 -0
- package/templates/mongoose/tests/setup.ts +25 -0
- package/templates/mongoose/tsconfig.json +16 -20
- package/templates/mongoose/vitest.config.ts +43 -0
- package/templates/prisma/.dockerignore +2 -0
- package/templates/prisma/.env.example +62 -6
- package/templates/prisma/.prettierignore +3 -0
- package/templates/prisma/.prettierrc +7 -0
- package/templates/prisma/.projectrc.json +1 -1
- package/templates/prisma/Dockerfile +21 -7
- package/templates/prisma/_gitignore +35 -0
- package/templates/prisma/docker-compose.yml +8 -7
- package/templates/prisma/eslint.config.js +35 -0
- package/templates/prisma/package-lock.json +7327 -0
- package/templates/prisma/package.json +47 -9
- package/templates/prisma/prisma/schema/account.schema.prisma +92 -10
- package/templates/prisma/prisma/schema/profile.schema.prisma +8 -3
- package/templates/prisma/prisma/schema/schema.prisma +1 -2
- package/templates/prisma/prisma.config.ts +5 -5
- package/templates/prisma/readme.md +81 -0
- package/templates/prisma/src/app/configs/index.ts +175 -26
- package/templates/prisma/src/app/errors/zodError.ts +16 -16
- package/templates/prisma/src/app/lib/logger.ts +12 -0
- package/templates/prisma/src/app/lib/prisma.ts +4 -6
- package/templates/prisma/src/app/middlewares/auth.ts +37 -16
- package/templates/prisma/src/app/middlewares/global_error_handler.ts +42 -35
- package/templates/prisma/src/app/middlewares/not_found_api.ts +7 -7
- package/templates/prisma/src/app/middlewares/rate_limiter.ts +124 -0
- package/templates/prisma/src/app/middlewares/request_validator.ts +4 -3
- package/templates/prisma/src/app/middlewares/uploader.ts +17 -13
- package/templates/prisma/src/app/modules/account/account.controller.ts +74 -34
- package/templates/prisma/src/app/modules/account/account.route.ts +68 -22
- package/templates/prisma/src/app/modules/account/account.service.ts +329 -309
- package/templates/prisma/src/app/modules/account/account.swagger.ts +167 -76
- package/templates/prisma/src/app/modules/account/account.validation.ts +41 -19
- package/templates/prisma/src/app/modules/profile/profile.controller.ts +4 -4
- package/templates/prisma/src/app/modules/profile/profile.route.ts +18 -12
- package/templates/prisma/src/app/modules/profile/profile.service.ts +11 -18
- package/templates/prisma/src/app/modules/profile/profile.swagger.ts +11 -11
- package/templates/prisma/src/app/modules/profile/profile.validation.ts +2 -2
- package/templates/prisma/src/app/passport-js/index.ts +87 -0
- package/templates/prisma/src/app/passport-js/oauth-state.ts +150 -0
- package/templates/prisma/src/app/passport-js/providers.ts +263 -0
- package/templates/prisma/src/app/passport-js/social-account.ts +147 -0
- package/templates/prisma/src/app/queues/boss.ts +8 -0
- package/templates/prisma/src/app/queues/email.queue.ts +56 -0
- package/templates/prisma/src/app/queues/index.ts +14 -0
- package/templates/prisma/src/app/queues/maintenance.queue.ts +30 -0
- package/templates/prisma/src/app/templates/otpEmailTemplate.ts +185 -0
- package/templates/prisma/src/app/templates/resetPasswordEmailTemplate.ts +157 -0
- package/templates/prisma/src/app/types/error.d.ts +7 -7
- package/templates/prisma/src/app/types/express.d.ts +11 -0
- package/templates/prisma/src/app/types/passport-oauth1.d.ts +51 -0
- package/templates/prisma/src/app/utils/JWT.ts +36 -17
- package/templates/prisma/src/app/utils/app_error.ts +10 -10
- package/templates/prisma/src/app/utils/auth_cookie.ts +27 -0
- package/templates/prisma/src/app/utils/catch_async.ts +8 -8
- package/templates/prisma/src/app/utils/cloudinary.ts +26 -59
- package/templates/prisma/src/app/utils/mail_sender.ts +26 -92
- package/templates/prisma/src/app/utils/manage_response.ts +19 -19
- package/templates/prisma/src/app/utils/otp.ts +20 -0
- package/templates/prisma/src/app/utils/session.ts +57 -0
- package/templates/prisma/src/app.ts +73 -42
- package/templates/prisma/src/routes.ts +12 -10
- package/templates/prisma/src/server.ts +37 -19
- package/templates/prisma/src/swaggerOptions.ts +22 -26
- package/templates/prisma/tests/app.test.ts +86 -0
- package/templates/prisma/tests/helpers/fixtures.ts +35 -0
- package/templates/prisma/tests/helpers/prisma.ts +32 -0
- package/templates/prisma/tests/routes/account.test.ts +627 -0
- package/templates/prisma/tests/routes/profile.test.ts +91 -0
- package/templates/prisma/tests/routes/social.test.ts +317 -0
- package/templates/prisma/tests/setup.ts +10 -0
- package/templates/prisma/tsconfig.json +16 -23
- package/templates/prisma/vitest.config.ts +38 -0
- package/bin/cli.js +0 -41
- package/src/createProject.js +0 -61
- package/src/generateModule.js +0 -93
- package/src/utils/getProjectType.js +0 -13
- package/src/utils/mongoose/controllerGenerator.js +0 -70
- package/src/utils/mongoose/routeGenerator.js +0 -27
- package/src/utils/mongoose/schemaGenerator.js +0 -11
- package/src/utils/mongoose/serviceGenerator.js +0 -49
- package/src/utils/mongoose/swaggerGenerator.js +0 -112
- package/src/utils/mongoose/validationGenerator.js +0 -13
- package/src/utils/prisma/prismaSchemaGenerator.js +0 -10
- package/src/utils/prisma/prismaServiceGenerator.js +0 -47
- package/src/utils/routeInjector.js +0 -40
- package/src/utils/swaggerInjector.js +0 -52
- package/src/utils/validateModuleName.js +0 -17
- package/src/utils/validateProjectName.js +0 -15
- package/src/utils.js +0 -26
- package/templates/mongoose/src/app/errors/castError.ts +0 -23
- package/templates/mongoose/src/app/errors/duplicateError.ts +0 -26
- package/templates/mongoose/src/app/errors/validationError.ts +0 -25
- package/templates/mongoose/src/app/modules/auth/auth.controller.ts +0 -127
- package/templates/mongoose/src/app/modules/auth/auth.interface.ts +0 -24
- package/templates/mongoose/src/app/modules/auth/auth.route.ts +0 -46
- package/templates/mongoose/src/app/modules/auth/auth.schema.ts +0 -19
- package/templates/mongoose/src/app/modules/auth/auth.service.ts +0 -324
- package/templates/mongoose/src/app/modules/auth/auth.swagger.ts +0 -214
- package/templates/mongoose/src/app/modules/auth/auth.validation.ts +0 -37
- package/templates/mongoose/src/app/modules/user/user.controller.ts +0 -17
- package/templates/mongoose/src/app/modules/user/user.interface.ts +0 -15
- package/templates/mongoose/src/app/modules/user/user.route.ts +0 -20
- package/templates/mongoose/src/app/modules/user/user.schema.ts +0 -22
- package/templates/mongoose/src/app/modules/user/user.service.ts +0 -22
- package/templates/mongoose/src/app/modules/user/user.swagger.ts +0 -75
- package/templates/mongoose/src/app/modules/user/user.validation.ts +0 -18
- package/templates/mongoose/src/app/types/index.d.ts +0 -12
- package/templates/mongoose/src/app/utils/isAccountExist.ts +0 -31
- package/templates/prisma/src/app/types/index.d.ts +0 -12
- package/templates/prisma/src/app/utils/otpGenerator.ts +0 -29
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
export const authSwaggerDocs = {
|
|
2
|
-
"/api/auth/register": {
|
|
3
|
-
post: {
|
|
4
|
-
tags: ["Auth"],
|
|
5
|
-
summary: "Register a new user",
|
|
6
|
-
description: "Create a new user account with email, number, password, and name.",
|
|
7
|
-
requestBody: {
|
|
8
|
-
required: true,
|
|
9
|
-
content: {
|
|
10
|
-
"application/json": {
|
|
11
|
-
schema: {
|
|
12
|
-
type: "object",
|
|
13
|
-
required: ["email", "number", "password", "name"],
|
|
14
|
-
properties: {
|
|
15
|
-
email: { type: "string", example: "user@example.com" },
|
|
16
|
-
number: { type: "string", example: "+1234567890" },
|
|
17
|
-
password: { type: "string", example: "secret123" },
|
|
18
|
-
name: { type: "string", example: "John Doe" }
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
responses: {
|
|
25
|
-
201: { description: "User registered successfully" },
|
|
26
|
-
400: { description: "Validation error or user already exists" }
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
"/api/auth/login": {
|
|
32
|
-
post: {
|
|
33
|
-
tags: ["Auth"],
|
|
34
|
-
summary: "Login a user",
|
|
35
|
-
description: "Authenticate user with email and password.",
|
|
36
|
-
requestBody: {
|
|
37
|
-
required: true,
|
|
38
|
-
content: {
|
|
39
|
-
"application/json": {
|
|
40
|
-
schema: {
|
|
41
|
-
type: "object",
|
|
42
|
-
required: ["email", "password"],
|
|
43
|
-
properties: {
|
|
44
|
-
email: { type: "string", example: "user@example.com" },
|
|
45
|
-
password: { type: "string", example: "secret123" }
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
responses: {
|
|
52
|
-
200: { description: "User logged in successfully" },
|
|
53
|
-
401: { description: "Invalid credentials" }
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
"/api/auth/me": {
|
|
59
|
-
get: {
|
|
60
|
-
tags: ["Auth"],
|
|
61
|
-
summary: "Get logged-in user's profile",
|
|
62
|
-
description: "Fetch the authenticated user's profile details.",
|
|
63
|
-
security: [{ bearerAuth: [] }],
|
|
64
|
-
responses: {
|
|
65
|
-
200: { description: "Profile data retrieved successfully" },
|
|
66
|
-
401: { description: "Unauthorized" }
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
"/api/auth/refresh-token": {
|
|
72
|
-
post: {
|
|
73
|
-
tags: ["Auth"],
|
|
74
|
-
summary: "Refresh JWT token",
|
|
75
|
-
description: "Refresh the access token using a valid refresh token.",
|
|
76
|
-
responses: {
|
|
77
|
-
200: { description: "Token refreshed successfully" },
|
|
78
|
-
401: { description: "Invalid or expired refresh token" }
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
"/api/auth/change-password": {
|
|
84
|
-
post: {
|
|
85
|
-
tags: ["Auth"],
|
|
86
|
-
summary: "Change password (authenticated users)",
|
|
87
|
-
security: [{ bearerAuth: [] }],
|
|
88
|
-
requestBody: {
|
|
89
|
-
required: true,
|
|
90
|
-
content: {
|
|
91
|
-
"application/json": {
|
|
92
|
-
schema: {
|
|
93
|
-
type: "object",
|
|
94
|
-
required: ["oldPassword", "newPassword"],
|
|
95
|
-
properties: {
|
|
96
|
-
oldPassword: { type: "string", example: "oldPass123" },
|
|
97
|
-
newPassword: { type: "string", example: "newPass456" }
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
responses: {
|
|
104
|
-
200: { description: "Password changed successfully" },
|
|
105
|
-
400: { description: "Invalid old password or bad request" }
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
"/api/auth/forgot-password": {
|
|
111
|
-
post: {
|
|
112
|
-
tags: ["Auth"],
|
|
113
|
-
summary: "Request password reset",
|
|
114
|
-
requestBody: {
|
|
115
|
-
required: true,
|
|
116
|
-
content: {
|
|
117
|
-
"application/json": {
|
|
118
|
-
schema: {
|
|
119
|
-
type: "object",
|
|
120
|
-
required: ["email"],
|
|
121
|
-
properties: {
|
|
122
|
-
email: { type: "string", example: "user@example.com" }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
responses: {
|
|
129
|
-
200: { description: "Password reset link sent to email" },
|
|
130
|
-
404: { description: "User not found" }
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
"/api/auth/reset-password": {
|
|
136
|
-
post: {
|
|
137
|
-
tags: ["Auth"],
|
|
138
|
-
summary: "Reset password using token",
|
|
139
|
-
description: "Reset the user's password using a valid token sent to their email.",
|
|
140
|
-
requestBody: {
|
|
141
|
-
required: true,
|
|
142
|
-
content: {
|
|
143
|
-
"application/json": {
|
|
144
|
-
schema: {
|
|
145
|
-
type: "object",
|
|
146
|
-
required: ["token", "email", "newPassword"],
|
|
147
|
-
properties: {
|
|
148
|
-
token: { type: "string", example: "eyJhbGciOiJIUz..." },
|
|
149
|
-
email: { type: "string", example: "user@example.com" },
|
|
150
|
-
newPassword: { type: "string", example: "newSecret123" }
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
responses: {
|
|
157
|
-
200: { description: "Password reset successfully" },
|
|
158
|
-
400: { description: "Invalid or expired token" }
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
"/api/auth/verified-account": {
|
|
164
|
-
post: {
|
|
165
|
-
tags: ["Auth"],
|
|
166
|
-
summary: "Verify account using token",
|
|
167
|
-
description: "Verify a user's email account using a verification token.",
|
|
168
|
-
requestBody: {
|
|
169
|
-
required: true,
|
|
170
|
-
content: {
|
|
171
|
-
"application/json": {
|
|
172
|
-
schema: {
|
|
173
|
-
type: "object",
|
|
174
|
-
required: ["token"],
|
|
175
|
-
properties: {
|
|
176
|
-
token: { type: "string", example: "eyJhbGciOiJIUzI1NiIs..." }
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
responses: {
|
|
183
|
-
200: { description: "Account verified successfully" },
|
|
184
|
-
400: { description: "Invalid or expired token" }
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
"/api/auth/new-verification-link": {
|
|
190
|
-
post: {
|
|
191
|
-
tags: ["Auth"],
|
|
192
|
-
summary: "Request a new verification link",
|
|
193
|
-
description: "Send a new verification link to the user's email address.",
|
|
194
|
-
requestBody: {
|
|
195
|
-
required: true,
|
|
196
|
-
content: {
|
|
197
|
-
"application/json": {
|
|
198
|
-
schema: {
|
|
199
|
-
type: "object",
|
|
200
|
-
required: ["email"],
|
|
201
|
-
properties: {
|
|
202
|
-
email: { type: "string", example: "user@example.com" }
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
responses: {
|
|
209
|
-
200: { description: "Verification link resent successfully" },
|
|
210
|
-
404: { description: "User not found or already verified" }
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
// Zod schema matching TAccount / authSchema
|
|
4
|
-
const register_validation = z.object({
|
|
5
|
-
email: z.string({ message: "Email is required" }).email(),
|
|
6
|
-
password: z.string({ message: "Password is required" }),
|
|
7
|
-
name: z.string({ message: "Name is required" })
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const login_validation = z.object({
|
|
11
|
-
email: z.string({ message: "Email is required" }),
|
|
12
|
-
password: z.string({ message: "Email is required" })
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
const changePassword = z.object({
|
|
16
|
-
oldPassword: z.string({ message: "Old Password is required" }),
|
|
17
|
-
newPassword: z.string({ message: "New Password is required" })
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const forgotPassword = z.object({ email: z.string({ message: "Email is required" }) })
|
|
21
|
-
const resetPassword = z.object({
|
|
22
|
-
token: z.string(),
|
|
23
|
-
newPassword: z.string(),
|
|
24
|
-
email: z.string()
|
|
25
|
-
})
|
|
26
|
-
const verified_account = z.object({
|
|
27
|
-
token: z.string({ message: "Token is Required!!" })
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
export const auth_validation = {
|
|
31
|
-
register_validation,
|
|
32
|
-
login_validation,
|
|
33
|
-
changePassword,
|
|
34
|
-
forgotPassword,
|
|
35
|
-
resetPassword,
|
|
36
|
-
verified_account
|
|
37
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import catchAsync from "../../utils/catch_async";
|
|
2
|
-
import manageResponse from "../../utils/manage_response";
|
|
3
|
-
import { user_services } from "./user.service";
|
|
4
|
-
|
|
5
|
-
const update_profile = catchAsync(async (req, res) => {
|
|
6
|
-
const result = await user_services.update_profile_into_db(req);
|
|
7
|
-
manageResponse(res, {
|
|
8
|
-
success: true,
|
|
9
|
-
statusCode: 200,
|
|
10
|
-
message: "Profile update successful.",
|
|
11
|
-
data: result,
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export const user_controllers = {
|
|
16
|
-
update_profile,
|
|
17
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Types } from "mongoose"
|
|
2
|
-
|
|
3
|
-
export type TUser = {
|
|
4
|
-
name: string,
|
|
5
|
-
photo?: string,
|
|
6
|
-
address?: {
|
|
7
|
-
location?: string,
|
|
8
|
-
city?: string,
|
|
9
|
-
state?: string,
|
|
10
|
-
postCode?: string,
|
|
11
|
-
country?: string,
|
|
12
|
-
timeZone?: string
|
|
13
|
-
},
|
|
14
|
-
accountId?: Types.ObjectId
|
|
15
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Request, Response, Router } from "express";
|
|
2
|
-
import { user_controllers } from "./user.controller";
|
|
3
|
-
import uploader from "../../middlewares/uploader";
|
|
4
|
-
import { user_validations } from "./user.validation";
|
|
5
|
-
import auth from "../../middlewares/auth";
|
|
6
|
-
|
|
7
|
-
const userRoute = Router()
|
|
8
|
-
|
|
9
|
-
userRoute.patch(
|
|
10
|
-
"/update-profile",
|
|
11
|
-
auth("ADMIN","USER"),
|
|
12
|
-
uploader.single("image"),
|
|
13
|
-
(req: Request, res: Response, next: NextFunction) => {
|
|
14
|
-
req.body = user_validations.update_user.parse(JSON.parse(req?.body?.data))
|
|
15
|
-
user_controllers.update_profile(req, res, next)
|
|
16
|
-
},
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export default userRoute;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { model, Schema } from "mongoose";
|
|
2
|
-
import { TUser } from "./user.interface";
|
|
3
|
-
|
|
4
|
-
const user_schema = new Schema<TUser>({
|
|
5
|
-
name: { type: String, required: true },
|
|
6
|
-
photo: { type: String, required: false },
|
|
7
|
-
accountId: { type: String, required: false, ref: "account" },
|
|
8
|
-
address: {
|
|
9
|
-
location: { type: String },
|
|
10
|
-
city: { type: String },
|
|
11
|
-
state: { type: String },
|
|
12
|
-
postCode: { type: String },
|
|
13
|
-
country: { type: String },
|
|
14
|
-
timeZone: { type: String }
|
|
15
|
-
}
|
|
16
|
-
}, {
|
|
17
|
-
versionKey: false,
|
|
18
|
-
timestamps: true
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const User_Model = model("user", user_schema)
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Request } from "express"
|
|
2
|
-
import uploadCloud from "../../utils/cloudinary";
|
|
3
|
-
import { User_Model } from "./user.schema";
|
|
4
|
-
import { Account_Model } from "../auth/auth.schema";
|
|
5
|
-
|
|
6
|
-
const update_profile_into_db = async (req: Request) => {
|
|
7
|
-
// upload file and get link
|
|
8
|
-
if (req.file) {
|
|
9
|
-
const uploadedImage = await uploadCloud(req.file);
|
|
10
|
-
req.body.photo = uploadedImage?.secure_url;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const isExistUser = await Account_Model.findOne({ email: req?.user?.email }).lean()
|
|
14
|
-
const result = await User_Model.findOneAndUpdate({ accountId: isExistUser!._id }, req?.body)
|
|
15
|
-
return result
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export const user_services = {
|
|
21
|
-
update_profile_into_db
|
|
22
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export const userSwaggerDocs = {
|
|
2
|
-
"/api/user/update-profile": {
|
|
3
|
-
patch: {
|
|
4
|
-
tags: ["User"],
|
|
5
|
-
summary: "Update user profile",
|
|
6
|
-
description:
|
|
7
|
-
"Updates the authenticated user's profile information, including optional profile image upload. Accessible by both ADMIN and USER roles.",
|
|
8
|
-
security: [{ bearerAuth: [] }],
|
|
9
|
-
requestBody: {
|
|
10
|
-
required: true,
|
|
11
|
-
content: {
|
|
12
|
-
"multipart/form-data": {
|
|
13
|
-
schema: {
|
|
14
|
-
type: "object",
|
|
15
|
-
properties: {
|
|
16
|
-
image: {
|
|
17
|
-
type: "string",
|
|
18
|
-
format: "binary",
|
|
19
|
-
description: "Optional profile image file",
|
|
20
|
-
},
|
|
21
|
-
data: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description:
|
|
24
|
-
"JSON string containing user profile update data (validated by `user_validations.update_user`)",
|
|
25
|
-
example: JSON.stringify({
|
|
26
|
-
name: "John Doe",
|
|
27
|
-
email: "john.doe@example.com",
|
|
28
|
-
phone: "+8801787654321",
|
|
29
|
-
address: "Dhaka, Bangladesh",
|
|
30
|
-
}),
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
required: ["data"],
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
responses: {
|
|
39
|
-
200: {
|
|
40
|
-
description: "User profile updated successfully",
|
|
41
|
-
content: {
|
|
42
|
-
"application/json": {
|
|
43
|
-
schema: {
|
|
44
|
-
type: "object",
|
|
45
|
-
properties: {
|
|
46
|
-
message: { type: "string", example: "Profile updated successfully" },
|
|
47
|
-
data: {
|
|
48
|
-
type: "object",
|
|
49
|
-
properties: {
|
|
50
|
-
id: { type: "string", example: "64b2e1b9d1234f0012ab5678" },
|
|
51
|
-
name: { type: "string", example: "John Doe" },
|
|
52
|
-
email: { type: "string", example: "john.doe@example.com" },
|
|
53
|
-
phone: { type: "string", example: "+8801787654321" },
|
|
54
|
-
image: {
|
|
55
|
-
type: "string",
|
|
56
|
-
example: "/uploads/users/profile_64b2e1b9.png",
|
|
57
|
-
},
|
|
58
|
-
role: { type: "string", example: "USER" },
|
|
59
|
-
updatedAt: {
|
|
60
|
-
type: "string",
|
|
61
|
-
example: "2025-10-10T10:00:00Z",
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
400: { description: "Bad Request — Validation failed or invalid JSON format" },
|
|
71
|
-
401: { description: "Unauthorized — must be logged in as ADMIN or USER" },
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
const update_user = z.object({
|
|
4
|
-
name: z.string().optional(),
|
|
5
|
-
photo: z.string().optional(),
|
|
6
|
-
address: z.object({
|
|
7
|
-
location: z.string().optional(),
|
|
8
|
-
city: z.string().optional(),
|
|
9
|
-
state: z.string().optional(),
|
|
10
|
-
postCode: z.string().optional(),
|
|
11
|
-
country: z.string().optional(),
|
|
12
|
-
timeZone: z.string().optional(),
|
|
13
|
-
}).optional()
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
export const user_validations = {
|
|
17
|
-
update_user
|
|
18
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Account_Model } from "../modules/auth/auth.schema";
|
|
2
|
-
import { AppError } from "./app_error";
|
|
3
|
-
|
|
4
|
-
export const isAccountExist = async (email: string, populateField?: string) => {
|
|
5
|
-
let isExistAccount;
|
|
6
|
-
if (populateField) {
|
|
7
|
-
isExistAccount = await Account_Model.findOne({ email }).populate(
|
|
8
|
-
populateField,
|
|
9
|
-
);
|
|
10
|
-
} else {
|
|
11
|
-
isExistAccount = await Account_Model.findOne({ email });
|
|
12
|
-
}
|
|
13
|
-
// check account
|
|
14
|
-
if (!isExistAccount) {
|
|
15
|
-
throw new AppError("Account not found!!", 404);
|
|
16
|
-
}
|
|
17
|
-
if (isExistAccount.isDeleted) {
|
|
18
|
-
throw new AppError("Account deleted !!", 403);
|
|
19
|
-
}
|
|
20
|
-
if (isExistAccount.accountStatus == "INACTIVE") {
|
|
21
|
-
throw new AppError(
|
|
22
|
-
"Account is temporary suspend, contact us on support !!",
|
|
23
|
-
403,
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
if (isExistAccount.accountStatus == "SUSPENDED") {
|
|
27
|
-
throw new AppError("Account is suspended !!", 403);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return isExistAccount;
|
|
31
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export const otpGenerator = (): string => {
|
|
2
|
-
const upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
3
|
-
const lower = "abcdefghijklmnopqrstuvwxyz";
|
|
4
|
-
const numbers = "0123456789";
|
|
5
|
-
const symbols = "@#$%&*!?";
|
|
6
|
-
|
|
7
|
-
const allChars = upper + lower + numbers + symbols;
|
|
8
|
-
|
|
9
|
-
let otp = "";
|
|
10
|
-
|
|
11
|
-
// Ensure at least one character from each set
|
|
12
|
-
otp += upper[Math.floor(Math.random() * upper.length)];
|
|
13
|
-
otp += lower[Math.floor(Math.random() * lower.length)];
|
|
14
|
-
otp += numbers[Math.floor(Math.random() * numbers.length)];
|
|
15
|
-
otp += symbols[Math.floor(Math.random() * symbols.length)];
|
|
16
|
-
|
|
17
|
-
// Fill the rest randomly
|
|
18
|
-
for (let i = otp.length; i < 6; i++) {
|
|
19
|
-
otp += allChars[Math.floor(Math.random() * allChars.length)];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Shuffle to remove predictable order
|
|
23
|
-
otp = otp
|
|
24
|
-
.split("")
|
|
25
|
-
.sort(() => Math.random() - 0.5)
|
|
26
|
-
.join("");
|
|
27
|
-
|
|
28
|
-
return otp;
|
|
29
|
-
};
|