♻️ refactor(account, order, plan, profile, support, email): restructure application modules and enhance error handling
Updated Docker configuration, refactored middleware for improved error handling, and restructured account, order, plan, profile, and support modules, including their routes, services, and validations. Enhanced email processing queues and utilities for token generation, pagination, and response management to streamline the application architecture and enhance maintainability.
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
import catchAsync from "../../utils/catch_async.js";
|
||||
import manageResponse from "../../utils/manage_response.js";
|
||||
import { profile_service } from "./profile.service.js";
|
||||
const update_profile = catchAsync(async (req, res) => {
|
||||
const result = await profile_service.update_profile_into_db(req);
|
||||
manageResponse(res, {
|
||||
success: true,
|
||||
statusCode: 200,
|
||||
message: "profile updated successfully.",
|
||||
data: result,
|
||||
});
|
||||
});
|
||||
export const profile_controller = {
|
||||
update_profile,
|
||||
};
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { Router } from "express";
|
||||
import RequestValidator from "../../middlewares/request_validator.js";
|
||||
import { profile_controller } from "./profile.controller.js";
|
||||
import { profile_validations } from "./profile.validation.js";
|
||||
import auth from "../../middlewares/auth.js";
|
||||
import uploader from "../../middlewares/uploader.js";
|
||||
const router = Router();
|
||||
router.patch("/", auth("USER"), uploader.single("file"), (req, res, next) => {
|
||||
req.body = JSON.parse(req?.body?.data);
|
||||
next();
|
||||
}, RequestValidator(profile_validations.update_profile), profile_controller.update_profile);
|
||||
export default router;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import uploadCloud from "../../utils/cloudinary.js";
|
||||
import { prisma } from "../../lib/prisma.js";
|
||||
const update_profile_into_db = async (req) => {
|
||||
const user = req?.user;
|
||||
const payload = req?.body;
|
||||
const file = req?.file;
|
||||
// check file and upload to cloud
|
||||
if (file) {
|
||||
const cloudRes = await uploadCloud(file);
|
||||
payload.profilePhoto = cloudRes?.secure_url;
|
||||
}
|
||||
const result = await prisma.profile.update({
|
||||
where: {
|
||||
accountId: user.accountId,
|
||||
},
|
||||
data: payload,
|
||||
});
|
||||
return result;
|
||||
};
|
||||
export const profile_service = {
|
||||
update_profile_into_db,
|
||||
};
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
export const profileSwaggerDocs = {
|
||||
"/api/profile": {
|
||||
patch: {
|
||||
tags: ["profile"],
|
||||
summary: "Update profile",
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
"multipart/form-data": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
data: {
|
||||
type: "object",
|
||||
properties: {
|
||||
fullName: { type: "string" },
|
||||
},
|
||||
},
|
||||
file: {
|
||||
type: "string",
|
||||
format: "binary",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: { description: "profile updated successfully" },
|
||||
500: { description: "Validation error or internal server error" },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { z } from "zod";
|
||||
const update_profile = z.object({
|
||||
fullName: z.string().optional(),
|
||||
});
|
||||
export const profile_validations = {
|
||||
update_profile,
|
||||
};
|
||||
Reference in New Issue
Block a user