diff --git a/.gitignore b/.gitignore index 439b47f..aaf2b40 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules .env .vercel + diff --git a/dist/app.js b/dist/app.js deleted file mode 100644 index f19212f..0000000 --- a/dist/app.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const express_1 = __importDefault(require("express")); -const cors_1 = __importDefault(require("cors")); -const cookie_parser_1 = __importDefault(require("cookie-parser")); -const http_status_1 = __importDefault(require("http-status")); -const globalErrorHandler_1 = __importDefault(require("./app/middlewares/globalErrorHandler")); -const routes_1 = __importDefault(require("./app/routes")); -const app = (0, express_1.default)(); -app.use((0, cors_1.default)()); -app.use(express_1.default.json()); -app.use((0, cookie_parser_1.default)()); -app.use('/api/v1', routes_1.default); -app.use(globalErrorHandler_1.default); -app.use((req, res, next) => { - res.status(http_status_1.default.NOT_FOUND).json({ - success: false, - message: "Oops! It looks like this page doesn't exist.", - error: { - path: req.originalUrl, - error: `The requested URL was not found on this server.`, - suggestion: 'Double-check the URL', - }, - }); -}); -app.get('/', (req, res) => { - res.send('Hello World!'); -}); -exports.default = app; diff --git a/dist/app/errors/HTTPError.js b/dist/app/errors/HTTPError.js deleted file mode 100644 index 143227c..0000000 --- a/dist/app/errors/HTTPError.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.HTTPError = void 0; -class HTTPError extends Error { - constructor(statusCode, message, stack = '') { - super(message); - this.name = this.constructor.name; - this.statusCode = statusCode; - this.stack = stack; - if (stack) { - this.stack = stack; - } - else { - Error.captureStackTrace(this, this.constructor); - } - } -} -exports.HTTPError = HTTPError; diff --git a/dist/app/interfaces/common.js b/dist/app/interfaces/common.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/app/interfaces/common.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/app/interfaces/file.js b/dist/app/interfaces/file.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/app/interfaces/file.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/app/interfaces/paginationSorting.js b/dist/app/interfaces/paginationSorting.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/app/interfaces/paginationSorting.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/app/middlewares/authGuard.js b/dist/app/middlewares/authGuard.js deleted file mode 100644 index 7427223..0000000 --- a/dist/app/middlewares/authGuard.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const jwtHelper_1 = require("../../helpers/jwtHelper"); -const config_1 = __importDefault(require("../../config/config")); -const HTTPError_1 = require("../errors/HTTPError"); -const http_status_1 = __importDefault(require("http-status")); -const authGuard = (...roles) => { - return (req, _res, next) => { - const token = req.headers.authorization; - if (!token) { - throw new HTTPError_1.HTTPError(http_status_1.default.UNAUTHORIZED, 'You are not authorized'); - } - try { - const verifiedUser = jwtHelper_1.jwtHelpers.verifyToken(token, config_1.default.jwt.jwt_secret); - if (roles.length && !roles.includes(verifiedUser.role)) { - throw new HTTPError_1.HTTPError(http_status_1.default.UNAUTHORIZED, "You don't have the permission"); - } - req.user = verifiedUser; - next(); - } - catch (error) { - next(error); - } - }; -}; -exports.default = authGuard; diff --git a/dist/app/middlewares/globalErrorHandler.js b/dist/app/middlewares/globalErrorHandler.js deleted file mode 100644 index c0e3142..0000000 --- a/dist/app/middlewares/globalErrorHandler.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const http_status_1 = __importDefault(require("http-status")); -const globalErrorHandler = (err, _req, res, _next) => { - console.dir('Came to global error handler'); - console.log(err.name); - res.status(http_status_1.default.INTERNAL_SERVER_ERROR).json({ - success: false, - message: err.message || 'Something went wrong', - error: err, - }); -}; -exports.default = globalErrorHandler; diff --git a/dist/app/middlewares/validateRequest.js b/dist/app/middlewares/validateRequest.js deleted file mode 100644 index 56bd3ab..0000000 --- a/dist/app/middlewares/validateRequest.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.validateRequest = void 0; -const validateRequest = (schema) => { - return (req, _res, next) => __awaiter(void 0, void 0, void 0, function* () { - try { - yield schema.parseAsync(req); - next(); - } - catch (error) { - next(error); - } - }); -}; -exports.validateRequest = validateRequest; diff --git a/dist/app/modules/admin/admin.ValidationSchema.js b/dist/app/modules/admin/admin.ValidationSchema.js deleted file mode 100644 index d4d612d..0000000 --- a/dist/app/modules/admin/admin.ValidationSchema.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.adminValidationSchemas = void 0; -const zod_1 = require("zod"); -const update = zod_1.z.object({ - body: zod_1.z.object({ - name: zod_1.z.string().optional(), - contactNumber: zod_1.z.string().optional(), - }), -}); -exports.adminValidationSchemas = { - update, -}; diff --git a/dist/app/modules/admin/admin.constants.js b/dist/app/modules/admin/admin.constants.js deleted file mode 100644 index 1ecf53a..0000000 --- a/dist/app/modules/admin/admin.constants.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.validParams = exports.searchableFields = void 0; -exports.searchableFields = ['name', 'email']; -exports.validParams = ['q', 'name', 'email']; diff --git a/dist/app/modules/admin/admin.controller.js b/dist/app/modules/admin/admin.controller.js deleted file mode 100644 index c4d3d97..0000000 --- a/dist/app/modules/admin/admin.controller.js +++ /dev/null @@ -1,81 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.AdminController = void 0; -const sendResponse_1 = require("../../../shared/sendResponse"); -const http_status_1 = __importDefault(require("http-status")); -const admin_service_1 = require("./admin.service"); -const catchAsync_1 = __importDefault(require("../../../shared/catchAsync")); -const filterValidQueryParams_1 = require("../../../shared/filterValidQueryParams"); -const admin_constants_1 = require("./admin.constants"); -const appConstants_1 = require("../../../shared/appConstants"); -const getAllAdmin = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const validQueryParams = (0, filterValidQueryParams_1.filterValidQueryParams)(req.query, admin_constants_1.validParams); - const paginationAndSortingQueryParams = (0, filterValidQueryParams_1.filterValidQueryParams)(req.query, appConstants_1.paginationAndSortingParams); - const result = yield admin_service_1.AdminService.getAllAdminFomDB(validQueryParams, paginationAndSortingQueryParams); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Admin data fetched!', - meta: result.meta, - data: result.result, - }); -})); -const getSingleAdmin = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const { id } = req.params; - const result = yield admin_service_1.AdminService.getSingleAdminFromDB(id); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Admin data fetched successfully!', - data: result, - }); -})); -const updateAdmin = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const { id } = req.params; - const result = yield admin_service_1.AdminService.updateAdminIntoDB(id, req.body); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Admin data updated successfully!', - data: result, - }); -})); -const deleteAdmin = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const { id } = req.params; - const result = yield admin_service_1.AdminService.deleteAdminFromDB(id); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Admin data deleted successfully!', - data: result, - }); -})); -const softDeleteAdmin = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const { id } = req.params; - const result = yield admin_service_1.AdminService.softDeleteAdminFromDB(id); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Admin data deleted!', - data: result, - }); -})); -exports.AdminController = { - getAllAdmin, - getSingleAdmin, - updateAdmin, - deleteAdmin, - softDeleteAdmin, -}; diff --git a/dist/app/modules/admin/admin.interface.js b/dist/app/modules/admin/admin.interface.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/app/modules/admin/admin.interface.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/app/modules/admin/admin.routes.js b/dist/app/modules/admin/admin.routes.js deleted file mode 100644 index ca889f3..0000000 --- a/dist/app/modules/admin/admin.routes.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.AdminRoutes = void 0; -const express_1 = __importDefault(require("express")); -const admin_controller_1 = require("./admin.controller"); -const validateRequest_1 = require("../../middlewares/validateRequest"); -const admin_ValidationSchema_1 = require("./admin.ValidationSchema"); -const authGuard_1 = __importDefault(require("../../middlewares/authGuard")); -const client_1 = require("@prisma/client"); -const router = express_1.default.Router(); -router.get('/', (0, authGuard_1.default)(client_1.UserRole.ADMIN, client_1.UserRole.SUPER_ADMIN), admin_controller_1.AdminController.getAllAdmin); -router.get('/:id', admin_controller_1.AdminController.getSingleAdmin); -router.patch('/:id', (0, validateRequest_1.validateRequest)(admin_ValidationSchema_1.adminValidationSchemas.update), admin_controller_1.AdminController.updateAdmin); -router.delete('/:id', admin_controller_1.AdminController.deleteAdmin); -router.delete('/soft/:id', admin_controller_1.AdminController.softDeleteAdmin); -exports.AdminRoutes = router; diff --git a/dist/app/modules/admin/admin.service.js b/dist/app/modules/admin/admin.service.js deleted file mode 100644 index 771493d..0000000 --- a/dist/app/modules/admin/admin.service.js +++ /dev/null @@ -1,149 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __rest = (this && this.__rest) || function (s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.AdminService = void 0; -const client_1 = require("@prisma/client"); -const prismaClient_1 = __importDefault(require("../../../shared/prismaClient")); -const paginationHelpers_1 = require("../../../helpers/paginationHelpers"); -const admin_constants_1 = require("./admin.constants"); -const getAllAdminFomDB = (queryParams, paginationAndSortingQueryParams) => __awaiter(void 0, void 0, void 0, function* () { - const { q } = queryParams, otherQueryParams = __rest(queryParams, ["q"]); - const { limit, skip, page, sortBy, sortOrder } = (0, paginationHelpers_1.generatePaginateAndSortOptions)(Object.assign({}, paginationAndSortingQueryParams)); - const conditions = []; - // filtering out the soft deleted users - conditions.push({ - isDeleted: false, - }); - //@ searching - if (q) { - const searchConditions = admin_constants_1.searchableFields.map((field) => ({ - [field]: { contains: q, mode: 'insensitive' }, - })); - conditions.push({ OR: searchConditions }); - } - //@ filtering with exact value - if (Object.keys(otherQueryParams).length > 0) { - const filterData = Object.keys(otherQueryParams).map((key) => ({ - [key]: otherQueryParams[key], - })); - conditions.push(...filterData); - } - const result = yield prismaClient_1.default.admin.findMany({ - where: { AND: conditions }, - skip, - take: limit, - orderBy: { - [sortBy]: sortOrder, - }, - }); - const total = yield prismaClient_1.default.admin.count({ - where: { AND: conditions }, - }); - return { - meta: { - page, - limit, - total, - }, - result, - }; -}); -const getSingleAdminFromDB = (id) => __awaiter(void 0, void 0, void 0, function* () { - return yield prismaClient_1.default.admin.findUniqueOrThrow({ - where: { - id, - isDeleted: false, - }, - }); -}); -const updateAdminIntoDB = (id, data) => __awaiter(void 0, void 0, void 0, function* () { - yield prismaClient_1.default.admin.findUniqueOrThrow({ - where: { - id, - isDeleted: false, - }, - }); - return yield prismaClient_1.default.admin.update({ - where: { - id, - }, - data, - }); -}); -const deleteAdminFromDB = (id) => __awaiter(void 0, void 0, void 0, function* () { - yield prismaClient_1.default.admin.findUniqueOrThrow({ - where: { - id, - isDeleted: false, - }, - }); - return yield prismaClient_1.default.$transaction((trClient) => __awaiter(void 0, void 0, void 0, function* () { - const deletedAdmin = yield trClient.admin.delete({ - where: { - id, - }, - }); - yield trClient.user.delete({ - where: { - email: deletedAdmin.email, - }, - }); - return deletedAdmin; - })); -}); -const softDeleteAdminFromDB = (id) => __awaiter(void 0, void 0, void 0, function* () { - yield prismaClient_1.default.admin.findUniqueOrThrow({ - where: { - id, - isDeleted: false, - }, - }); - return yield prismaClient_1.default.$transaction((trClient) => __awaiter(void 0, void 0, void 0, function* () { - const adminDeletedData = yield trClient.admin.update({ - where: { - id, - }, - data: { - isDeleted: true, - }, - }); - yield trClient.user.update({ - where: { - email: adminDeletedData.email, - }, - data: { - status: client_1.UserStatus.DELETED, - }, - }); - return adminDeletedData; - })); -}); -exports.AdminService = { - getAllAdminFomDB, - getSingleAdminFromDB, - updateAdminIntoDB, - deleteAdminFromDB, - softDeleteAdminFromDB, -}; diff --git a/dist/app/modules/auth/auth.controller.js b/dist/app/modules/auth/auth.controller.js deleted file mode 100644 index 21cc12f..0000000 --- a/dist/app/modules/auth/auth.controller.js +++ /dev/null @@ -1,83 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.authController = void 0; -const http_status_1 = __importDefault(require("http-status")); -const catchAsync_1 = __importDefault(require("../../../shared/catchAsync")); -const sendResponse_1 = require("../../../shared/sendResponse"); -const auth_services_1 = require("./auth.services"); -const loginUser = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const result = yield auth_services_1.authServices.loginUser(req.body); - const { refreshToken } = result; - res.cookie('refreshToken', refreshToken, { - secure: false, - httpOnly: true, - }); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Logged in successfully!', - data: { - accessToken: result.accessToken, - passwordChangeRequired: result.passwordChangeRequired, - }, - }); -})); -const refreshToken = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const { refreshToken } = req.cookies; - const result = yield auth_services_1.authServices.refreshToken(refreshToken); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Access token generated successfully!', - data: result, - }); -})); -const changePassword = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const user = req.user; - const payload = req.body; - const result = yield auth_services_1.authServices.changePassword(user, payload); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Password changed successfully!', - data: result, - }); -})); -const forgotPassword = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const result = yield auth_services_1.authServices.forgotPassword(req.body); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Check your email to reset your password', - data: null, - }); -})); -const resetPassword = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const token = req.headers.authorization || ''; - const result = yield auth_services_1.authServices.resetPassword(token, req.body); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.OK, - success: true, - message: 'Password reset successfully!', - data: result, - }); -})); -exports.authController = { - loginUser, - refreshToken, - changePassword, - forgotPassword, - resetPassword, -}; diff --git a/dist/app/modules/auth/auth.routes.js b/dist/app/modules/auth/auth.routes.js deleted file mode 100644 index f515221..0000000 --- a/dist/app/modules/auth/auth.routes.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.authRoutes = void 0; -const express_1 = __importDefault(require("express")); -const auth_controller_1 = require("./auth.controller"); -const authGuard_1 = __importDefault(require("../../middlewares/authGuard")); -const client_1 = require("@prisma/client"); -const router = express_1.default.Router(); -router.post('/login', auth_controller_1.authController.loginUser); -router.post('/refresh-token', auth_controller_1.authController.refreshToken); -router.post('/change-password', (0, authGuard_1.default)(client_1.UserRole.SUPER_ADMIN, client_1.UserRole.ADMIN, client_1.UserRole.AUTHOR, client_1.UserRole.MODERATOR), auth_controller_1.authController.changePassword); -router.post('/forgot-password', auth_controller_1.authController.forgotPassword); -router.post('/reset-password', auth_controller_1.authController.resetPassword); -exports.authRoutes = router; diff --git a/dist/app/modules/auth/auth.services.js b/dist/app/modules/auth/auth.services.js deleted file mode 100644 index 9389d9e..0000000 --- a/dist/app/modules/auth/auth.services.js +++ /dev/null @@ -1,181 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.authServices = void 0; -const bcrypt = __importStar(require("bcrypt")); -const client_1 = require("@prisma/client"); -const prismaClient_1 = __importDefault(require("../../../shared/prismaClient")); -const jwtHelper_1 = require("../../../helpers/jwtHelper"); -const config_1 = __importDefault(require("../../../config/config")); -const emailSender_1 = __importDefault(require("./emailSender")); -const path_1 = __importDefault(require("path")); -const fs_1 = __importDefault(require("fs")); -const HTTPError_1 = require("../../errors/HTTPError"); -const http_status_1 = __importDefault(require("http-status")); -const loginUser = (payload) => __awaiter(void 0, void 0, void 0, function* () { - const userData = yield prismaClient_1.default.user.findUniqueOrThrow({ - where: { - email: payload.email, - status: client_1.UserStatus.ACTIVE, - }, - }); - const isCorrectPassword = yield bcrypt.compare(payload.password, userData.password); - if (!isCorrectPassword) { - throw new Error('Password is incorrect!'); - } - const accessToken = jwtHelper_1.jwtHelpers.generateToken({ - email: userData.email, - role: userData.role, - }, config_1.default.jwt.jwt_secret, config_1.default.jwt.expires_in); - const refreshToken = jwtHelper_1.jwtHelpers.generateToken({ - email: userData.email, - role: userData.role, - }, config_1.default.jwt.refresh_token_secret, config_1.default.jwt.refresh_token_expires_in); - return { - accessToken, - refreshToken, - passwordChangeRequired: userData.passwordChangeRequired, - }; -}); -const refreshToken = (token) => __awaiter(void 0, void 0, void 0, function* () { - let decodedData; - try { - decodedData = jwtHelper_1.jwtHelpers.verifyToken(token, config_1.default.jwt.refresh_token_secret); - } - catch (err) { - throw new Error('You are not authorized!'); - } - const userData = yield prismaClient_1.default.user.findUniqueOrThrow({ - where: { - email: decodedData.email, - status: client_1.UserStatus.ACTIVE, - }, - }); - const accessToken = jwtHelper_1.jwtHelpers.generateToken({ - email: userData.email, - role: userData.role, - }, config_1.default.jwt.jwt_secret, config_1.default.jwt.expires_in); - return { - accessToken, - passwordChangeRequired: userData.passwordChangeRequired, - }; -}); -const changePassword = (user, payload) => __awaiter(void 0, void 0, void 0, function* () { - //@ checking if the user exist - const userData = yield prismaClient_1.default.user.findUniqueOrThrow({ - where: { - email: user.email, - status: client_1.UserStatus.ACTIVE, - }, - }); - //@ checking if the provided old password is correct - const isCorrectPassword = yield bcrypt.compare(payload.oldPassword, userData.password); - if (!isCorrectPassword) { - throw new Error('Password is incorrect!'); - } - //@ hashing the new password - const hashedPassword = yield bcrypt.hash(payload.newPassword, 10); - //@ updating the password and also changing the passwordChangeRequired to false - yield prismaClient_1.default.user.update({ - where: { - email: userData.email, - }, - data: { - password: hashedPassword, - passwordChangeRequired: false, - }, - }); - return { - message: 'Password change successfully', - }; -}); -const forgotPassword = (_a) => __awaiter(void 0, [_a], void 0, function* ({ email }) { - //@ checking if the user exist - const userData = yield prismaClient_1.default.user.findUniqueOrThrow({ - where: { - email: email, - status: client_1.UserStatus.ACTIVE, - }, - }); - //@ creating a short time token - const resetPasswordToken = jwtHelper_1.jwtHelpers.generateToken({ - email: userData.email, - role: userData.role, - }, config_1.default.jwt.reset_password_token_secret, config_1.default.jwt.reset_token_expires_in); - //@ generating a link to send via email - let link = `${config_1.default.reset_pass_link}?userId=${userData.id}&token=${resetPasswordToken}`; - //@ read HTML template file - const htmlFilePath = path_1.default.join(process.cwd(), '/src/templates/reset_pass_template.html'); - const htmlTemplate = fs_1.default.readFileSync(htmlFilePath, 'utf8'); - const htmlContent = htmlTemplate.replace('{{resetPasswordLink}}', link); - yield (0, emailSender_1.default)(userData.email, htmlContent); -}); -const resetPassword = (token, payload) => __awaiter(void 0, void 0, void 0, function* () { - //@ checking if the user exist - yield prismaClient_1.default.user.findUniqueOrThrow({ - where: { - id: payload.id, - status: client_1.UserStatus.ACTIVE, - }, - }); - //@ verifying token - const isValidToken = jwtHelper_1.jwtHelpers.verifyToken(token, config_1.default.jwt.reset_password_token_secret); - if (!isValidToken) { - throw new HTTPError_1.HTTPError(http_status_1.default.FORBIDDEN, 'Invalid Token'); - } - //@ hashing the new password - const hashedPassword = yield bcrypt.hash(payload.password, 10); - //@ updating the password and also changing the passwordChangeRequired to false - yield prismaClient_1.default.user.update({ - where: { - id: payload.id, - }, - data: { - password: hashedPassword, - }, - }); - return { - message: 'Password changed successfully', - }; -}); -exports.authServices = { - loginUser, - refreshToken, - changePassword, - forgotPassword, - resetPassword, -}; diff --git a/dist/app/modules/auth/emailSender.js b/dist/app/modules/auth/emailSender.js deleted file mode 100644 index 1541753..0000000 --- a/dist/app/modules/auth/emailSender.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const nodemailer_1 = __importDefault(require("nodemailer")); -const config_1 = __importDefault(require("../../../config/config")); -const emailSender = (receiverEmail, html) => __awaiter(void 0, void 0, void 0, function* () { - const transporter = nodemailer_1.default.createTransport({ - host: 'smtp.gmail.com', - port: 587, - secure: false, // Use `true` for port 465, `false` for all other ports - auth: { - user: config_1.default.sender_email, - pass: config_1.default.app_password, - }, - }); - // async..await is not allowed in global scope, must use a wrapper - // send mail with defined transport object - const info = yield transporter.sendMail({ - from: '"Prisma Blog" ', // sender address - to: receiverEmail, // list of receivers - subject: 'Reset Password Link', // Subject line - // text: 'Hello world?', // plain text body - html, // html body - }); - console.log('Message sent: %s', info.messageId); -}); -exports.default = emailSender; diff --git a/dist/app/modules/user/user.constant.js b/dist/app/modules/user/user.constant.js deleted file mode 100644 index 2e15549..0000000 --- a/dist/app/modules/user/user.constant.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.validParams = exports.searchableFields = void 0; -exports.searchableFields = ['name', 'email']; -exports.validParams = ['q', 'email', 'isActive']; diff --git a/dist/app/modules/user/user.controller.js b/dist/app/modules/user/user.controller.js deleted file mode 100644 index 932301b..0000000 --- a/dist/app/modules/user/user.controller.js +++ /dev/null @@ -1,41 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.userController = void 0; -const sendResponse_1 = require("../../../shared/sendResponse"); -const http_status_1 = __importDefault(require("http-status")); -const catchAsync_1 = __importDefault(require("../../../shared/catchAsync")); -const user_service_1 = require("./user.service"); -const createAdmin = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const result = yield user_service_1.userService.createAdmin(req); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.CREATED, - success: true, - message: 'Admin Created Successfully!', - data: result, - }); -})); -const createAuthor = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { - const result = yield user_service_1.userService.createAuthor(req); - (0, sendResponse_1.sendResponse)(res, { - statusCode: http_status_1.default.CREATED, - success: true, - message: 'Author Created Successfully!', - data: result, - }); -})); -exports.userController = { - createAdmin, - createAuthor, -}; diff --git a/dist/app/modules/user/user.interface.js b/dist/app/modules/user/user.interface.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/app/modules/user/user.interface.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/app/modules/user/user.routes.js b/dist/app/modules/user/user.routes.js deleted file mode 100644 index cc6c159..0000000 --- a/dist/app/modules/user/user.routes.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.userRoutes = void 0; -const express_1 = __importDefault(require("express")); -const user_controller_1 = require("./user.controller"); -const fileUploader_1 = require("../../../helpers/fileUploader"); -const user_validationSchema_1 = require("./user.validationSchema"); -const router = express_1.default.Router(); -router.post('/create-admin', -// authGuard(UserRole.SUPER_ADMIN, UserRole.ADMIN), -fileUploader_1.fileUploader.upload.single('file'), (req, res, next) => { - req.body = user_validationSchema_1.userValidationSchema.createAdminSchema.parse(JSON.parse(req.body.data)); - return user_controller_1.userController.createAdmin(req, res, next); -}); -router.post('/create-author', fileUploader_1.fileUploader.upload.single('file'), (req, res, next) => { - req.body = user_validationSchema_1.userValidationSchema.createAuthorSchema.parse(JSON.parse(req.body.data)); - return user_controller_1.userController.createAuthor(req, res, next); -}); -exports.userRoutes = router; diff --git a/dist/app/modules/user/user.service.js b/dist/app/modules/user/user.service.js deleted file mode 100644 index b0b598c..0000000 --- a/dist/app/modules/user/user.service.js +++ /dev/null @@ -1,79 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.userService = void 0; -const client_1 = require("@prisma/client"); -const bcrypt_1 = __importDefault(require("bcrypt")); -const prismaClient_1 = __importDefault(require("../../../shared/prismaClient")); -const fileUploader_1 = require("../../../helpers/fileUploader"); -const meilisearch_1 = __importDefault(require("../../../shared/meilisearch")); -const s3Uploader_1 = __importDefault(require("../../../helpers/s3Uploader")); -const meiliDoctorIndex = meilisearch_1.default.index('doctors'); -const meiliAuthorIndex = meilisearch_1.default.index('authors'); -const createAdmin = (req) => __awaiter(void 0, void 0, void 0, function* () { - if (req.file) { - const uploadedFileUrl = yield (0, s3Uploader_1.default)(req.file); - // const uploadedFile = await fileUploader.saveToCloudinary(req.file); - // req.body.admin.profilePhoto = uploadedFile?.secure_url; - req.body.admin.profilePhoto = uploadedFileUrl; - } - const hashedPassword = yield bcrypt_1.default.hash(req.body.password, 10); - const userData = { - email: req.body.admin.email, - password: hashedPassword, - role: client_1.UserRole.ADMIN, - }; - const result = yield prismaClient_1.default.$transaction((txClient) => __awaiter(void 0, void 0, void 0, function* () { - yield txClient.user.create({ - data: userData, - }); - const newAdmin = yield txClient.admin.create({ - data: req.body.admin, - }); - const { id, name, email, profilePhoto } = newAdmin; - // await meiliDoctorIndex.addDocuments([{ id, name, email, profilePhoto }]); - return newAdmin; - })); - return result; -}); -const createAuthor = (req) => __awaiter(void 0, void 0, void 0, function* () { - if (req.file) { - const uploadedFile = yield fileUploader_1.fileUploader.saveToCloudinary(req.file); - req.body.author.profilePhoto = uploadedFile === null || uploadedFile === void 0 ? void 0 : uploadedFile.secure_url; - } - const hashedPassword = yield bcrypt_1.default.hash(req.body.password, 10); - const userData = { - email: req.body.author.email, - password: hashedPassword, - role: client_1.UserRole.AUTHOR, - }; - const result = yield prismaClient_1.default.$transaction((txClient) => __awaiter(void 0, void 0, void 0, function* () { - yield txClient.user.create({ - data: userData, - }); - const newAuthor = yield txClient.author.create({ - data: req.body.author, - }); - const { id, name, email, profilePhoto, contactNumber } = newAuthor; - yield meiliAuthorIndex.addDocuments([ - { id, name, email, profilePhoto, contactNumber }, - ]); - return newAuthor; - })); - return result; -}); -exports.userService = { - createAdmin, - createAuthor, -}; diff --git a/dist/app/modules/user/user.validationSchema.js b/dist/app/modules/user/user.validationSchema.js deleted file mode 100644 index 263ca96..0000000 --- a/dist/app/modules/user/user.validationSchema.js +++ /dev/null @@ -1,25 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.userValidationSchema = void 0; -const zod_1 = require("zod"); -const createAdminSchema = zod_1.z.object({ - password: zod_1.z.string({ required_error: 'Password is required' }), - admin: zod_1.z.object({ - name: zod_1.z.string({ required_error: 'Name is required' }), - email: zod_1.z.string({ required_error: 'Email is required' }), - contactNumber: zod_1.z.string({ required_error: 'Contact number is required' }), - }), -}); -const createAuthorSchema = zod_1.z.object({ - password: zod_1.z.string({ required_error: 'Password is required' }), - author: zod_1.z.object({ - name: zod_1.z.string({ required_error: 'Name is required' }), - email: zod_1.z.string({ required_error: 'Email is required' }), - contactNumber: zod_1.z.string({ required_error: 'Contact number is required' }), - gender: zod_1.z.string({ required_error: 'Gender is required' }), - }), -}); -exports.userValidationSchema = { - createAdminSchema, - createAuthorSchema, -}; diff --git a/dist/app/routes/index.js b/dist/app/routes/index.js deleted file mode 100644 index 9a1f711..0000000 --- a/dist/app/routes/index.js +++ /dev/null @@ -1,26 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const express_1 = __importDefault(require("express")); -const user_routes_1 = require("../modules/user/user.routes"); -const admin_routes_1 = require("../modules/admin/admin.routes"); -const auth_routes_1 = require("../modules/auth/auth.routes"); -const router = express_1.default.Router(); -const moduleRoutes = [ - { - path: '/user', - route: user_routes_1.userRoutes, - }, - { - path: '/admin', - route: admin_routes_1.AdminRoutes, - }, - { - path: '/auth', - route: auth_routes_1.authRoutes, - }, -]; -moduleRoutes.forEach((route) => router.use(route.path, route.route)); -exports.default = router; diff --git a/dist/config/awsConfig.js b/dist/config/awsConfig.js deleted file mode 100644 index 9d6b400..0000000 --- a/dist/config/awsConfig.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const client_s3_1 = require("@aws-sdk/client-s3"); -// Create an S3 client -const s3Client = new client_s3_1.S3Client([ - { - region: process.env.AWS_REGION, - credentials: { - accessKeyId: process.env.AWS_ACCESS_KEY_ID, - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, - }, - }, -]); -exports.default = s3Client; diff --git a/dist/config/config.js b/dist/config/config.js deleted file mode 100644 index b724b18..0000000 --- a/dist/config/config.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const dotenv_1 = __importDefault(require("dotenv")); -const path_1 = __importDefault(require("path")); -dotenv_1.default.config({ path: path_1.default.join(process.cwd(), '.env') }); -exports.default = { - env: process.env.NODE_ENV, - port: process.env.PORT, - jwt: { - jwt_secret: process.env.JWT_SECRET, - expires_in: process.env.EXPIRES_IN, - refresh_token_secret: process.env.REFRESH_TOKEN_SECRET, - refresh_token_expires_in: process.env.REFRESH_TOKEN_EXPIRES_IN, - reset_password_token_secret: process.env.RESET_TOKEN_SECRET, - reset_token_expires_in: process.env.RESET_TOKEN_EXPIRES_IN, - }, - reset_pass_link: process.env.RESET_PASS_LINK, - sender_email: process.env.SENDER_EMAIL, - app_password: process.env.APP_PASSWORD, - cloudinary_api_key: process.env.CLOUDINARY_API_KEY, - cloudinary_api_secret: process.env.CLOUDINARY_API_SECRET, - aws_access_key_id: process.env.AWS_ACCESS_KEY_ID, - aws_secret_access_key: process.env.AWS_SECRET_ACCESS_KEY, - aws_region: process.env.AWS_REGION, - aws_bucket_name: process.env.AWS_BUCKET_NAME, -}; diff --git a/dist/helpers/fileUploader.js b/dist/helpers/fileUploader.js deleted file mode 100644 index 9bf28b5..0000000 --- a/dist/helpers/fileUploader.js +++ /dev/null @@ -1,47 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.fileUploader = void 0; -const multer_1 = __importDefault(require("multer")); -const path_1 = __importDefault(require("path")); -const cloudinary_1 = require("cloudinary"); -const fs_1 = __importDefault(require("fs")); -const config_1 = __importDefault(require("../config/config")); -const storage = multer_1.default.diskStorage({ - destination: function (_req, _file, cb) { - cb(null, path_1.default.join(process.cwd(), '/uploads')); - }, - filename: function (req, file, cb) { - // Remove spaces, add a hyphen, and append a timestamp - const sanitizedFilename = file.originalname.replace(/\s+/g, '-'); - const timestamp = Date.now(); - const filename = `${sanitizedFilename}-${timestamp}${path_1.default.extname(file.originalname)}`; - cb(null, filename); - }, -}); -// const upload = multer({ storage: multer.memoryStorage() }); -const upload = (0, multer_1.default)({ storage }); -cloudinary_1.v2.config({ - cloud_name: 'mizan-ph', - api_key: config_1.default.cloudinary_api_key, - api_secret: config_1.default.cloudinary_api_secret, -}); -const saveToCloudinary = (file) => { - return new Promise((resolve, reject) => { - cloudinary_1.v2.uploader.upload(file.path, { public_id: file.originalname }, (error, result) => { - fs_1.default.unlinkSync(file.path); - if (error) { - reject(error); - } - else { - resolve(result); - } - }); - }); -}; -exports.fileUploader = { - upload, - saveToCloudinary, -}; diff --git a/dist/helpers/jwtHelper.js b/dist/helpers/jwtHelper.js deleted file mode 100644 index 34ff8c2..0000000 --- a/dist/helpers/jwtHelper.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.jwtHelpers = void 0; -const jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); -const generateToken = (payload, secret, expiresIn) => { - const token = jsonwebtoken_1.default.sign(payload, secret, { - algorithm: 'HS256', - expiresIn, - }); - return token; -}; -const verifyToken = (token, secret) => { - return jsonwebtoken_1.default.verify(token, secret); -}; -exports.jwtHelpers = { - generateToken, - verifyToken, -}; diff --git a/dist/helpers/paginationHelpers.js b/dist/helpers/paginationHelpers.js deleted file mode 100644 index 25adcaa..0000000 --- a/dist/helpers/paginationHelpers.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.generatePaginateAndSortOptions = void 0; -const generatePaginateAndSortOptions = (paginateAndSortOptions) => { - const page = Number(paginateAndSortOptions.page) || 1; - const limit = Number(paginateAndSortOptions.limit) || 10; - const skip = (Number(page) - 1) * limit; - const sortBy = paginateAndSortOptions.sortBy || 'createdAt'; - const sortOrder = paginateAndSortOptions.sortOrder || 'desc'; - return { - page, - limit, - skip, - sortBy, - sortOrder, - }; -}; -exports.generatePaginateAndSortOptions = generatePaginateAndSortOptions; diff --git a/dist/helpers/s3Uploader.js b/dist/helpers/s3Uploader.js deleted file mode 100644 index e06bef9..0000000 --- a/dist/helpers/s3Uploader.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const client_s3_1 = require("@aws-sdk/client-s3"); -const awsConfig_1 = __importDefault(require("../config/awsConfig")); -const config_1 = __importDefault(require("../config/config")); -const fs_1 = __importDefault(require("fs")); -const uploadImageS3 = (file) => __awaiter(void 0, void 0, void 0, function* () { - console.log(file); - const fileBuffer = fs_1.default.readFileSync(file.path); - // console.log(fileBuffer); - // Upload file to S3 - const params = { - Bucket: config_1.default.aws_bucket_name, - Key: file.filename, - Body: fileBuffer, - }; - try { - const result = yield awsConfig_1.default.send(new client_s3_1.PutObjectCommand(params)); - const uploadUrl = `https://${config_1.default.aws_bucket_name}.s3.${config_1.default.aws_region}.amazonaws.com/${file.filename}`; - // console.log({ result, uploadUrl }); - return uploadUrl; - } - catch (err) { - console.error(err); - } -}); -exports.default = uploadImageS3; diff --git a/dist/server.js b/dist/server.js deleted file mode 100644 index 6488629..0000000 --- a/dist/server.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const app_1 = __importDefault(require("./app")); -const config_1 = __importDefault(require("./config/config")); -let server; -function main() { - return __awaiter(this, void 0, void 0, function* () { - server = app_1.default.listen(config_1.default.port, () => { - console.log(`🚀 Server ready at: http://localhost:${config_1.default.port} and the process id is ${process.pid}`); - }); - }); -} -const exitHandler = () => { - if (server) { - server.close(() => { - console.info('Server is shutting down'); - process.exit(1); - }); - } - else { - process.exit(1); - } -}; -const unexpectedErrorHandler = (error) => { - console.log(error); - exitHandler(); -}; -process.on('uncaughtException', unexpectedErrorHandler); -process.on('unhandledRejection', unexpectedErrorHandler); -/* -this will get fired upon stopping server by pressing ctrl + c -process.on('SIGINT', () => { - console.log('SIGINT signal received'); - unexpectedErrorHandler('SIGINT signal received'); -}); -*/ -process.on('SIGTERM', () => { - console.info('SIGTERM signal received'); - unexpectedErrorHandler('SIGTERM signal received'); -}); -main(); diff --git a/dist/shared/appConstants.js b/dist/shared/appConstants.js deleted file mode 100644 index bd707a9..0000000 --- a/dist/shared/appConstants.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.paginationAndSortingParams = void 0; -exports.paginationAndSortingParams = [ - 'page', - 'limit', - 'sortBy', - 'sortOrder', -]; diff --git a/dist/shared/catchAsync.js b/dist/shared/catchAsync.js deleted file mode 100644 index c040ed5..0000000 --- a/dist/shared/catchAsync.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const catchAsync = (controller) => { - return (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { - try { - yield controller(req, res, next); - } - catch (error) { - next(error); - } - }); -}; -exports.default = catchAsync; diff --git a/dist/shared/filterValidQueryParams.js b/dist/shared/filterValidQueryParams.js deleted file mode 100644 index 4649271..0000000 --- a/dist/shared/filterValidQueryParams.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.filterValidQueryParams = void 0; -const filterValidQueryParams = (params, validParams) => { - const filteredParams = {}; - for (const key of validParams) { - if (Object.hasOwnProperty.call(params, key) && params[key]) { - filteredParams[key] = params[key]; - } - } - return filteredParams; -}; -exports.filterValidQueryParams = filterValidQueryParams; diff --git a/dist/shared/meilisearch.js b/dist/shared/meilisearch.js deleted file mode 100644 index f752197..0000000 --- a/dist/shared/meilisearch.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.deleteResourceFromMeili = void 0; -const meilisearch_1 = require("meilisearch"); -const meiliClient = new meilisearch_1.MeiliSearch({ - host: 'http://localhost:7700', - apiKey: 'aSampleMasterKey', -}); -const deleteResourceFromMeili = (indexKey, id) => __awaiter(void 0, void 0, void 0, function* () { - const index = meiliClient.index(indexKey); - try { - yield index.deleteDocument(id); - console.log(`Resource with ID ${id} deleted successfully from MeiliSearch.`); - } - catch (error) { - console.error('Error deleting resource from MeiliSearch:', error); - } -}); -exports.deleteResourceFromMeili = deleteResourceFromMeili; -exports.default = meiliClient; diff --git a/dist/shared/prismaClient.js b/dist/shared/prismaClient.js deleted file mode 100644 index 6edd4ed..0000000 --- a/dist/shared/prismaClient.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const client_1 = require("@prisma/client"); -let prisma = new client_1.PrismaClient(); -exports.default = prisma; diff --git a/dist/shared/sendResponse.js b/dist/shared/sendResponse.js deleted file mode 100644 index 7c23b60..0000000 --- a/dist/shared/sendResponse.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.sendResponse = void 0; -const sendResponse = (res, jsonData) => { - res.status(jsonData.statusCode).json({ - success: jsonData.success, - message: jsonData.message, - meta: jsonData.meta || null || undefined, - data: jsonData.data || null || undefined, - }); -}; -exports.sendResponse = sendResponse;