├── logs └── winston │ ├── errors │ ├── phu-2023-17-06-17-error.log │ ├── phu-2023-17-06-21-error.log │ ├── phu-2023-18-06-10-error.log │ ├── phu-2023-18-06-19-error.log │ ├── phu-2023-18-06-20-error.log │ ├── phu-2023-18-06-21-error.log │ ├── phu-2023-18-06-07-error.log │ ├── phu-2023-18-06-09-error.log │ ├── phu-2023-18-06-08-error.log │ ├── phu-2023-17-06-16-error.log │ └── .e94f1ce02758f7c5d122d50a8ac7d9a84f2279f7-audit.json │ └── successes │ ├── phu-2023-17-06-17-success.log │ ├── phu-2023-18-06-10-success.log │ ├── phu-2023-17-06-21-success.log │ ├── phu-2023-18-06-21-success.log │ ├── phu-2023-17-06-16-success.log │ ├── phu-2023-18-06-20-success.log │ ├── phu-2023-18-06-19-success.log │ ├── phu-2023-18-06-07-success.log │ ├── .d0ded42ce3edcdfabaa88d9fcc4398bf83df5241-audit.json │ ├── phu-2023-18-06-09-success.log │ └── phu-2023-18-06-08-success.log ├── .gitignore ├── .eslintignore ├── .prettierrc ├── .husky └── pre-commit ├── dist ├── interfaces │ ├── common.js │ ├── error.js │ └── pagination.js ├── app │ ├── modules │ │ ├── cow │ │ │ ├── cow.interface.js │ │ │ ├── cow.route.js │ │ │ ├── cow.constants.js │ │ │ ├── cow.model.js │ │ │ ├── cow.validation.js │ │ │ ├── cow.controller.js │ │ │ └── cow.service.js │ │ ├── order │ │ │ ├── order.interface.js │ │ │ ├── order.validation.js │ │ │ ├── order.model.js │ │ │ ├── order.route.js │ │ │ ├── order.controller.js │ │ │ └── order.service.js │ │ └── user │ │ │ ├── user.interface.js │ │ │ ├── user.constants.js │ │ │ ├── user.model.js │ │ │ ├── user.route.js │ │ │ ├── user.validation.js │ │ │ ├── user.service.js │ │ │ └── user.controller.js │ ├── routes │ │ └── index.js │ └── middlewares │ │ ├── validateRequest.js │ │ └── globalErrorHandler.js ├── constants │ └── pagination.js ├── shared │ ├── pick.js │ ├── sendResponse.js │ ├── catchAsync.js │ └── logger.js ├── errors │ ├── ApiError.js │ ├── handleCastError.js │ ├── handleValidationError.js │ └── handleZodError.js ├── helpers │ └── paginationHelper.js ├── config │ └── index.js ├── app.js └── server.js ├── src ├── constants │ └── pagination.ts ├── interfaces │ ├── error.ts │ ├── pagination.ts │ └── common.ts ├── app │ ├── modules │ │ ├── order │ │ │ ├── order.interface.ts │ │ │ ├── order.validation.ts │ │ │ ├── order.route.ts │ │ │ ├── order.model.ts │ │ │ ├── order.controller.ts │ │ │ └── order.service.ts │ │ ├── user │ │ │ ├── user.constants.ts │ │ │ ├── user.interface.ts │ │ │ ├── user.route.ts │ │ │ ├── user.model.ts │ │ │ ├── user.service.ts │ │ │ ├── user.validation.ts │ │ │ └── user.controller.ts │ │ └── cow │ │ │ ├── cow.route.ts │ │ │ ├── cow.constants.ts │ │ │ ├── cow.interface.ts │ │ │ ├── cow.model.ts │ │ │ ├── cow.validation.ts │ │ │ ├── cow.controller.ts │ │ │ └── cow.service.ts │ ├── routes │ │ └── index.ts │ └── middlewares │ │ ├── validateRequest.ts │ │ └── globalErrorHandler.ts ├── shared │ ├── catchAsync.ts │ ├── pick.ts │ ├── sendResponse.ts │ └── logger.ts ├── config │ └── index.ts ├── errors │ ├── ApiError.ts │ ├── handleCastError.ts │ ├── handleZodError.ts │ └── handleValidationError.ts ├── helpers │ └── paginationHelper.ts ├── app.ts └── server.ts ├── .vscode └── settings.json ├── vercel.json ├── .eslintrc ├── LICENCE ├── readme.md └── tsconfig.json /logs/winston/errors/phu-2023-17-06-17-error.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-17-06-21-error.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-18-06-10-error.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-18-06-19-error.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-18-06-20-error.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | .vercel 4 | .gitignore -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | .env 4 | .eslingnore -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "singleQuote": true, 4 | "arrowParens": "avoid" 5 | } 6 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | # husky 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /dist/interfaces/common.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /dist/interfaces/error.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /dist/interfaces/pagination.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /src/constants/pagination.ts: -------------------------------------------------------------------------------- 1 | export const paginationFields = ['page', 'limit', 'sortBy', 'sortOrder']; 2 | // pagination -------------------------------------------------------------------------------- /dist/app/modules/cow/cow.interface.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /dist/app/modules/order/order.interface.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /dist/app/modules/user/user.interface.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /src/interfaces/error.ts: -------------------------------------------------------------------------------- 1 | export type IGenericErrorMessage = { 2 | path: string | number; 3 | message: string; 4 | }; 5 | // error -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-18-06-21-error.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 21:8:23 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.57:27017 2 | -------------------------------------------------------------------------------- /src/interfaces/pagination.ts: -------------------------------------------------------------------------------- 1 | export type IPaginationOptions = { 2 | page?: number; 3 | limit?: number; 4 | sortBy?: string; 5 | sortOrder?: 'asc' | 'desc'; 6 | }; 7 | //pagination -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-17-06-17-success.log: -------------------------------------------------------------------------------- 1 | Sat Jun 17 2023 17:5:43 } [PH] info: 🛢Database is connected successfully 2 | Sat Jun 17 2023 17:5:43 } [PH] info: Application listening on port 5000 3 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-18-06-10-success.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 10:2:12 } [PH] info: 🛢Database is connected successfully 2 | Sun Jun 18 2023 10:2:12 } [PH] info: Application listening on port 5000 3 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.codeActionsOnSave": { 3 | "source.fixAll.eslint": "explicit", 4 | "source.fixAll.tslint": "explicit", 5 | "source.organizeImports": "explicit" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-17-06-21-success.log: -------------------------------------------------------------------------------- 1 | Sat Jun 17 2023 21:56:56 } [PH] info: 🛢Database is connected successfully 2 | Sat Jun 17 2023 21:56:56 } [PH] info: Application listening on port 5000 3 | -------------------------------------------------------------------------------- /dist/constants/pagination.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.paginationFields = void 0; 4 | exports.paginationFields = ['page', 'limit', 'sortBy', 'sortOrder']; 5 | -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-18-06-07-error.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 7:46:6 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 2 | Sun Jun 18 2023 7:49:8 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 3 | -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-18-06-09-error.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 9:24:26 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 2 | Sun Jun 18 2023 9:26:3 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 3 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "builds": [ 4 | { 5 | "src": "dist/server.js", 6 | "use": "@vercel/node" 7 | } 8 | ], 9 | "routes": [ 10 | { 11 | "src": "/(.*)", 12 | "dest": "dist/server.js" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/app/modules/order/order.interface.ts: -------------------------------------------------------------------------------- 1 | import mongoose, { Model } from "mongoose"; 2 | 3 | export type IOrder = { 4 | cow: mongoose.Types.ObjectId; 5 | buyer: mongoose.Types.ObjectId; 6 | status: string; 7 | } 8 | 9 | export type OrderModel = Model>; 10 | -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-18-06-08-error.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 8:7:53 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 2 | Sun Jun 18 2023 8:45:3 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 3 | Sun Jun 18 2023 8:46:9 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 4 | -------------------------------------------------------------------------------- /dist/shared/pick.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const pick = (obj, keys) => { 4 | const finalObj = {}; 5 | for (const key of keys) { 6 | if (obj && Object.hasOwnProperty.call(obj, key)) { 7 | finalObj[key] = obj[key]; 8 | } 9 | } 10 | return finalObj; 11 | }; 12 | exports.default = pick; 13 | -------------------------------------------------------------------------------- /src/interfaces/common.ts: -------------------------------------------------------------------------------- 1 | import { IGenericErrorMessage } from './error'; 2 | // common ts 3 | export type IGenericResponse = { 4 | meta: { 5 | page: number; 6 | limit: number; 7 | total: number; 8 | }; 9 | data: T; 10 | }; 11 | 12 | export type IGenericErrorResponse = { 13 | statusCode: number; 14 | message: string; 15 | errorMessages: IGenericErrorMessage[]; 16 | }; 17 | -------------------------------------------------------------------------------- /src/shared/catchAsync.ts: -------------------------------------------------------------------------------- 1 | import { NextFunction, Request, RequestHandler, Response } from 'express'; 2 | 3 | const catchAsync = 4 | (fn: RequestHandler) => 5 | async (req: Request, res: Response, next: NextFunction): Promise => { 6 | try { 7 | await fn(req, res, next); 8 | } catch (error) { 9 | next(error); 10 | } 11 | }; 12 | 13 | export default catchAsync; 14 | -------------------------------------------------------------------------------- /src/shared/pick.ts: -------------------------------------------------------------------------------- 1 | const pick = , k extends keyof T>( 2 | obj: T, 3 | keys: k[] 4 | ): Partial => { 5 | const finalObj: Partial = {}; 6 | 7 | for (const key of keys) { 8 | if (obj && Object.hasOwnProperty.call(obj, key)) { 9 | finalObj[key] = obj[key]; 10 | } 11 | } 12 | return finalObj; 13 | }; 14 | 15 | export default pick; 16 | -------------------------------------------------------------------------------- /src/config/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | import dotenv from 'dotenv'; 3 | import path from 'path'; 4 | // index js 5 | dotenv.config({ path: path.join(process.cwd(), '.env') }); 6 | 7 | export default { 8 | env: process.env.NODE_ENV, 9 | port: process.env.PORT, 10 | database_url: process.env.DATABASE_URL, 11 | // default_student_pass: process.env.DEFAULT_STUDENT_PASS, 12 | }; 13 | -------------------------------------------------------------------------------- /src/app/modules/user/user.constants.ts: -------------------------------------------------------------------------------- 1 | export const userSearchableFields = [ 2 | 'id', 3 | 'phoneNumber', 4 | 'role', 5 | 'fisrtName', 6 | 'lastName', 7 | 'budget', 8 | 'income', 9 | ]; 10 | 11 | export const userFilterableFields = [ 12 | 'searchTerm', 13 | 'id', 14 | 'phoneNumber', 15 | 'role', 16 | 'name.fisrtName', 17 | 'name.lastName', 18 | 'budget', 19 | 'income', 20 | ]; 21 | -------------------------------------------------------------------------------- /src/app/modules/order/order.validation.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod'; 2 | 3 | const addOrderZodSchema = z.object({ 4 | body: z.object({ 5 | cow: z.string({ 6 | required_error: 'Cow Referance id is required', 7 | }), 8 | buyer: z.string({ 9 | required_error: 'Buyer Referance id is required', 10 | }), 11 | }), 12 | }); 13 | 14 | export const OrderValidation = { 15 | addOrderZodSchema, 16 | }; 17 | -------------------------------------------------------------------------------- /src/errors/ApiError.ts: -------------------------------------------------------------------------------- 1 | class ApiError extends Error { 2 | statusCode: number; 3 | // api error 4 | constructor(statusCode: number, message: string | undefined, stack = '') { 5 | super(message); 6 | this.statusCode = statusCode; 7 | if (stack) { 8 | this.stack = stack; 9 | } else { 10 | Error.captureStackTrace(this, this.constructor); 11 | } 12 | } 13 | } 14 | 15 | export default ApiError; 16 | -------------------------------------------------------------------------------- /logs/winston/errors/phu-2023-17-06-16-error.log: -------------------------------------------------------------------------------- 1 | Sat Jun 17 2023 16:29:14 } [PH] error: Failed to connect database bad auth : Authentication failed. 2 | Sat Jun 17 2023 16:34:44 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 3 | Sat Jun 17 2023 16:52:10 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 4 | Sat Jun 17 2023 16:55:46 } [PH] error: Failed to connect database connect ETIMEDOUT 3.6.254.147:27017 5 | -------------------------------------------------------------------------------- /dist/errors/ApiError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | class ApiError extends Error { 4 | constructor(statusCode, message, stack = '') { 5 | super(message); 6 | this.statusCode = statusCode; 7 | if (stack) { 8 | this.stack = stack; 9 | } 10 | else { 11 | Error.captureStackTrace(this, this.constructor); 12 | } 13 | } 14 | } 15 | exports.default = ApiError; 16 | -------------------------------------------------------------------------------- /dist/errors/handleCastError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const handleCastError = (error) => { 4 | const errors = [ 5 | { 6 | path: error.path, 7 | message: 'Invalid Id', 8 | }, 9 | ]; 10 | const statusCode = 400; 11 | return { 12 | statusCode, 13 | message: 'Cast Error', 14 | errorMessages: errors, 15 | }; 16 | }; 17 | exports.default = handleCastError; 18 | -------------------------------------------------------------------------------- /dist/shared/sendResponse.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const sendReponse = (res, data) => { 4 | const responseData = { 5 | statusCode: data.statusCode, 6 | success: data.success, 7 | message: data.message || null, 8 | meta: data.meta || null || undefined, 9 | data: data.data || null, 10 | }; 11 | res.status(data.statusCode).json(responseData); 12 | }; 13 | exports.default = sendReponse; 14 | -------------------------------------------------------------------------------- /src/errors/handleCastError.ts: -------------------------------------------------------------------------------- 1 | import mongoose from 'mongoose'; 2 | import { IGenericErrorMessage } from '../interfaces/error'; 3 | //handle cast error 4 | const handleCastError = (error: mongoose.Error.CastError) => { 5 | const errors: IGenericErrorMessage[] = [ 6 | { 7 | path: error.path, 8 | message: 'Invalid Id', 9 | }, 10 | ]; 11 | 12 | const statusCode = 400; 13 | return { 14 | statusCode, 15 | message: 'Cast Error', 16 | errorMessages: errors, 17 | }; 18 | }; 19 | 20 | export default handleCastError; 21 | -------------------------------------------------------------------------------- /src/app/modules/order/order.route.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import validateRequest from '../../middlewares/validateRequest'; 3 | import { OrderValidation } from './order.validation'; 4 | import { OrderController } from './order.controller'; 5 | const router = express.Router(); 6 | 7 | // router.get('/', CowController.getAllCows); 8 | router.post( 9 | '/', 10 | validateRequest(OrderValidation.addOrderZodSchema), 11 | OrderController.cowOrder 12 | ); 13 | 14 | router.get("/", OrderController.getAllOrders) 15 | 16 | export const OrderRoutes = router; 17 | -------------------------------------------------------------------------------- /src/app/modules/order/order.model.ts: -------------------------------------------------------------------------------- 1 | import { Schema, model } from 'mongoose'; 2 | import { IOrder, OrderModel } from './order.interface'; 3 | 4 | const orderSchema = new Schema( 5 | { 6 | cow: { 7 | type: Schema.Types.ObjectId, 8 | ref: 'Cow', 9 | }, 10 | buyer: { 11 | type: Schema.Types.ObjectId, 12 | ref: 'User', 13 | }, 14 | }, 15 | { 16 | timestamps: true, 17 | toJSON: { 18 | virtuals: true, 19 | }, 20 | } 21 | ); 22 | 23 | export const Order = model('Order', orderSchema); 24 | -------------------------------------------------------------------------------- /src/app/modules/user/user.interface.ts: -------------------------------------------------------------------------------- 1 | import { Model } from 'mongoose'; 2 | 3 | export type IUser = { 4 | phoneNumber: string; 5 | role: 'seller' | 'buyer'; 6 | password: string; 7 | name: { 8 | firstName: string; 9 | lastName: string; 10 | }; 11 | address: string; 12 | budget: number; 13 | income: number; 14 | }; 15 | 16 | export type UserModel = Model>; 17 | 18 | export type IUserFilters = { 19 | searchTerm?: string; 20 | id?: string; 21 | price?: string; 22 | contactNo?: string; 23 | location?: string; 24 | }; -------------------------------------------------------------------------------- /dist/app/modules/user/user.constants.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.userFilterableFields = exports.userSearchableFields = void 0; 4 | exports.userSearchableFields = [ 5 | 'id', 6 | 'phoneNumber', 7 | 'role', 8 | 'fisrtName', 9 | 'lastName', 10 | 'budget', 11 | 'income', 12 | ]; 13 | exports.userFilterableFields = [ 14 | 'searchTerm', 15 | 'id', 16 | 'phoneNumber', 17 | 'role', 18 | 'name.fisrtName', 19 | 'name.lastName', 20 | 'budget', 21 | 'income', 22 | ]; 23 | -------------------------------------------------------------------------------- /dist/app/modules/order/order.validation.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.OrderValidation = void 0; 4 | const zod_1 = require("zod"); 5 | const addOrderZodSchema = zod_1.z.object({ 6 | body: zod_1.z.object({ 7 | cow: zod_1.z.string({ 8 | required_error: 'Cow Referance id is required', 9 | }), 10 | buyer: zod_1.z.string({ 11 | required_error: 'Buyer Referance id is required', 12 | }), 13 | }), 14 | }); 15 | exports.OrderValidation = { 16 | addOrderZodSchema, 17 | }; 18 | -------------------------------------------------------------------------------- /dist/app/modules/order/order.model.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Order = void 0; 4 | const mongoose_1 = require("mongoose"); 5 | const orderSchema = new mongoose_1.Schema({ 6 | cow: { 7 | type: mongoose_1.Schema.Types.ObjectId, 8 | ref: 'Cow', 9 | }, 10 | buyer: { 11 | type: mongoose_1.Schema.Types.ObjectId, 12 | ref: 'User', 13 | }, 14 | }, { 15 | timestamps: true, 16 | toJSON: { 17 | virtuals: true, 18 | }, 19 | }); 20 | exports.Order = (0, mongoose_1.model)('Order', orderSchema); 21 | -------------------------------------------------------------------------------- /src/app/routes/index.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { CowRoutes } from '../modules/cow/cow.route'; 3 | import { OrderRoutes } from '../modules/order/order.route'; 4 | import { UserRoutes } from '../modules/user/user.route'; 5 | 6 | const router = express.Router(); 7 | 8 | const moduleRoutes = [ 9 | { 10 | path: '/', 11 | route: UserRoutes, 12 | }, 13 | { 14 | path: '/cows', 15 | route: CowRoutes, 16 | }, 17 | { 18 | path: '/orders', 19 | route: OrderRoutes, 20 | }, 21 | ]; 22 | 23 | moduleRoutes.forEach(route => router.use(route.path, route.route)); 24 | export default router; 25 | -------------------------------------------------------------------------------- /dist/errors/handleValidationError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const handleValidationError = (error) => { 4 | const errors = Object.values(error.errors).map((el) => { 5 | return { 6 | path: el === null || el === void 0 ? void 0 : el.path, 7 | message: el === null || el === void 0 ? void 0 : el.message, 8 | }; 9 | }); 10 | const statusCode = 400; 11 | return { 12 | statusCode, 13 | message: 'Validation Error', 14 | errorMessages: errors, 15 | }; 16 | }; 17 | exports.default = handleValidationError; 18 | -------------------------------------------------------------------------------- /dist/errors/handleZodError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const handleZodError = (error) => { 4 | const errors = error.issues.map((issue) => { 5 | return { 6 | path: issue === null || issue === void 0 ? void 0 : issue.path[issue.path.length - 1], 7 | message: issue === null || issue === void 0 ? void 0 : issue.message, 8 | }; 9 | }); 10 | const statusCode = 400; 11 | return { 12 | statusCode, 13 | message: 'Validation Error', 14 | errorMessages: errors, 15 | }; 16 | }; 17 | exports.default = handleZodError; 18 | -------------------------------------------------------------------------------- /dist/helpers/paginationHelper.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.paginationHelpers = void 0; 4 | const calculatePagination = (options) => { 5 | const page = Number(options.page || 1); 6 | const limit = Number(options.limit || 10); 7 | const skip = (page - 1) * limit; 8 | const sortBy = options.sortBy || 'createdAt'; 9 | const sortOrder = options.sortOrder || 'desc'; 10 | return { 11 | page, 12 | limit, 13 | skip, 14 | sortBy, 15 | sortOrder, 16 | }; 17 | }; 18 | exports.paginationHelpers = { 19 | calculatePagination, 20 | }; 21 | -------------------------------------------------------------------------------- /src/app/middlewares/validateRequest.ts: -------------------------------------------------------------------------------- 1 | import { NextFunction, Request, Response } from 'express'; 2 | import { AnyZodObject, ZodEffects } from 'zod'; 3 | // Validate Requests 4 | const validateRequest = 5 | (schema: AnyZodObject | ZodEffects) => 6 | async (req: Request, res: Response, next: NextFunction): Promise => { 7 | try { 8 | await schema.parseAsync({ 9 | body: req.body, 10 | query: req.query, 11 | params: req.params, 12 | cookies: req.cookies, 13 | }); 14 | return next(); 15 | } catch (error) { 16 | next(error); 17 | } 18 | }; 19 | 20 | export default validateRequest; 21 | -------------------------------------------------------------------------------- /dist/config/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | // index js 6 | Object.defineProperty(exports, "__esModule", { value: true }); 7 | /* eslint-disable no-undef */ 8 | const dotenv_1 = __importDefault(require("dotenv")); 9 | const path_1 = __importDefault(require("path")); 10 | dotenv_1.default.config({ path: path_1.default.join(process.cwd(), '.env') }); 11 | exports.default = { 12 | env: process.env.NODE_ENV, 13 | port: process.env.PORT, 14 | database_url: process.env.DATABASE_URL, 15 | // default_student_pass: process.env.DEFAULT_STUDENT_PASS, 16 | }; 17 | -------------------------------------------------------------------------------- /src/errors/handleZodError.ts: -------------------------------------------------------------------------------- 1 | import { ZodError, ZodIssue } from 'zod'; 2 | import { IGenericErrorResponse } from '../interfaces/common'; 3 | import { IGenericErrorMessage } from '../interfaces/error'; 4 | // Handel zod error 5 | const handleZodError = (error: ZodError): IGenericErrorResponse => { 6 | const errors: IGenericErrorMessage[] = error.issues.map((issue: ZodIssue) => { 7 | return { 8 | path: issue?.path[issue.path.length - 1], 9 | message: issue?.message, 10 | }; 11 | }); 12 | 13 | const statusCode = 400; 14 | 15 | return { 16 | statusCode, 17 | message: 'Validation Error', 18 | errorMessages: errors, 19 | }; 20 | }; 21 | 22 | export default handleZodError; 23 | -------------------------------------------------------------------------------- /src/app/modules/cow/cow.route.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import validateRequest from '../../middlewares/validateRequest'; 3 | import { CowController } from './cow.controller'; 4 | import { CowValidation } from './cow.validation'; 5 | const router = express.Router(); 6 | 7 | router.get('/', CowController.getAllCows); 8 | router.post( 9 | '/', 10 | validateRequest(CowValidation.addCowZodSchema), 11 | CowController.addCow 12 | ); 13 | router.get('/:id', CowController.getSingleCow); 14 | 15 | router.patch( 16 | '/:id', 17 | validateRequest(CowValidation.updateCowZodSchema), 18 | CowController.updateCow 19 | ); 20 | router.delete('/:id', CowController.deleteCow); 21 | 22 | export const CowRoutes = router; 23 | -------------------------------------------------------------------------------- /src/shared/sendResponse.ts: -------------------------------------------------------------------------------- 1 | import { Response } from 'express'; 2 | 3 | type IApiReponse = { 4 | statusCode: number; 5 | success: boolean; 6 | message?: string | null; 7 | meta?: { 8 | page: number; 9 | limit: number; 10 | total: number; 11 | }; 12 | data?: T | null; 13 | }; 14 | 15 | const sendReponse = (res: Response, data: IApiReponse): void => { 16 | const responseData: IApiReponse = { 17 | statusCode: data.statusCode, 18 | success: data.success, 19 | message: data.message || null, 20 | meta: data.meta || null || undefined, 21 | data: data.data || null, 22 | }; 23 | 24 | res.status(data.statusCode).json(responseData); 25 | }; 26 | 27 | export default sendReponse; 28 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "@typescript-eslint/parser", 3 | "parserOptions": { 4 | "ecmaVersion": 12, 5 | "sourceType": "module" 6 | }, 7 | "plugins": ["@typescript-eslint"], 8 | "extends": [ 9 | "eslint:recommended", 10 | "plugin:@typescript-eslint/recommended", 11 | "prettier" 12 | ], 13 | "rules": { 14 | "no-unused-vars": "error", 15 | "prefer-const": "error", 16 | "no-unused-expressions": "error", 17 | "no-undef": "error", 18 | "no-console": "warn", 19 | "@typescript-eslint/consistent-type-definitions": ["error", "type"] 20 | }, 21 | "env": { 22 | "browser": true, 23 | "es2021": true, 24 | "node":true 25 | }, 26 | "globals": { 27 | "process":"readonly" 28 | } 29 | } 30 | // eslintrc -------------------------------------------------------------------------------- /src/app/modules/user/user.route.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import validateRequest from '../../middlewares/validateRequest'; 3 | import { UserController } from './user.controller'; 4 | import { UserValidation } from './user.validation'; 5 | const router = express.Router(); 6 | 7 | router.get('/users/:id', UserController.getSingleUser); 8 | router.get('/users/', UserController.getAllUsers); 9 | 10 | router.patch( 11 | '/users/:id', 12 | validateRequest(UserValidation.updateUserZodSchema), 13 | UserController.updateUser 14 | ); 15 | router.delete('/users/:id', UserController.deleteUser); 16 | 17 | router.post( 18 | '/auth/signup', 19 | validateRequest(UserValidation.createUserZodSchema), 20 | UserController.createUser 21 | ); 22 | 23 | export const UserRoutes = router; 24 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-18-06-21-success.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 21:0:15 } [PH] info: 🛢Database is connected successfully 2 | Sun Jun 18 2023 21:0:16 } [PH] info: Application listening on port 5000 3 | Sun Jun 18 2023 21:1:40 } [PH] info: 🛢Database is connected successfully 4 | Sun Jun 18 2023 21:1:40 } [PH] info: Application listening on port 5000 5 | Sun Jun 18 2023 21:2:53 } [PH] info: 🛢Database is connected successfully 6 | Sun Jun 18 2023 21:2:53 } [PH] info: Application listening on port 5000 7 | Sun Jun 18 2023 21:3:2 } [PH] info: 🛢Database is connected successfully 8 | Sun Jun 18 2023 21:3:2 } [PH] info: Application listening on port 5000 9 | Sun Jun 18 2023 21:12:45 } [PH] info: 🛢Database is connected successfully 10 | Sun Jun 18 2023 21:12:45 } [PH] info: Application listening on port 5000 11 | -------------------------------------------------------------------------------- /src/errors/handleValidationError.ts: -------------------------------------------------------------------------------- 1 | import mongoose from 'mongoose'; 2 | import { IGenericErrorResponse } from '../interfaces/common'; 3 | import { IGenericErrorMessage } from '../interfaces/error'; 4 | // Handle Validation Erros 5 | const handleValidationError = ( 6 | error: mongoose.Error.ValidationError 7 | ): IGenericErrorResponse => { 8 | const errors: IGenericErrorMessage[] = Object.values(error.errors).map( 9 | (el: mongoose.Error.ValidatorError | mongoose.Error.CastError) => { 10 | return { 11 | path: el?.path, 12 | message: el?.message, 13 | }; 14 | } 15 | ); 16 | const statusCode = 400; 17 | return { 18 | statusCode, 19 | message: 'Validation Error', 20 | errorMessages: errors, 21 | }; 22 | }; 23 | 24 | export default handleValidationError; 25 | -------------------------------------------------------------------------------- /src/helpers/paginationHelper.ts: -------------------------------------------------------------------------------- 1 | import { SortOrder } from 'mongoose'; 2 | // pagination Helper 3 | type IOptions = { 4 | page?: number; 5 | limit?: number; 6 | sortBy?: string; 7 | sortOrder?: SortOrder; 8 | }; 9 | 10 | type IOptionsResult = { 11 | page: number; 12 | limit: number; 13 | skip: number; 14 | sortBy: string; 15 | sortOrder: SortOrder; 16 | }; 17 | 18 | const calculatePagination = (options: IOptions): IOptionsResult => { 19 | const page = Number(options.page || 1); 20 | const limit = Number(options.limit || 10); 21 | const skip = (page - 1) * limit; 22 | 23 | const sortBy = options.sortBy || 'createdAt'; 24 | const sortOrder = options.sortOrder || 'desc'; 25 | 26 | return { 27 | page, 28 | limit, 29 | skip, 30 | sortBy, 31 | sortOrder, 32 | }; 33 | }; 34 | 35 | export const paginationHelpers = { 36 | calculatePagination, 37 | }; 38 | -------------------------------------------------------------------------------- /dist/app/modules/order/order.route.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.OrderRoutes = void 0; 7 | const express_1 = __importDefault(require("express")); 8 | const validateRequest_1 = __importDefault(require("../../middlewares/validateRequest")); 9 | const order_validation_1 = require("./order.validation"); 10 | const order_controller_1 = require("./order.controller"); 11 | const router = express_1.default.Router(); 12 | // router.get('/', CowController.getAllCows); 13 | router.post('/', (0, validateRequest_1.default)(order_validation_1.OrderValidation.addOrderZodSchema), order_controller_1.OrderController.cowOrder); 14 | router.get("/", order_controller_1.OrderController.getAllOrders); 15 | exports.OrderRoutes = router; 16 | -------------------------------------------------------------------------------- /src/app.ts: -------------------------------------------------------------------------------- 1 | import cors from 'cors'; 2 | import express, { Application, NextFunction, Request, Response } from 'express'; 3 | import httpStatus from 'http-status'; 4 | import globalErrorHandler from './app/middlewares/globalErrorHandler'; 5 | import routes from './app/routes'; 6 | const app: Application = express(); 7 | 8 | app.use(cors()); 9 | 10 | //parser 11 | app.use(express.json()); 12 | app.use(express.urlencoded({ extended: true })); 13 | 14 | app.use('/api/v1', routes); 15 | 16 | 17 | //global error handler 18 | app.use(globalErrorHandler); 19 | 20 | //handle not found 21 | app.use((req: Request, res: Response, next: NextFunction) => { 22 | res.status(httpStatus.NOT_FOUND).json({ 23 | success: false, 24 | message: 'Not Found', 25 | errorMessages: [ 26 | { 27 | path: req.originalUrl, 28 | message: 'API Not Found', 29 | }, 30 | ], 31 | }); 32 | next(); 33 | }); 34 | 35 | export default app; 36 | -------------------------------------------------------------------------------- /dist/app/routes/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const express_1 = __importDefault(require("express")); 7 | const cow_route_1 = require("../modules/cow/cow.route"); 8 | const order_route_1 = require("../modules/order/order.route"); 9 | const user_route_1 = require("../modules/user/user.route"); 10 | const router = express_1.default.Router(); 11 | const moduleRoutes = [ 12 | { 13 | path: '/', 14 | route: user_route_1.UserRoutes, 15 | }, 16 | { 17 | path: '/cows', 18 | route: cow_route_1.CowRoutes, 19 | }, 20 | { 21 | path: '/orders', 22 | route: order_route_1.OrderRoutes, 23 | }, 24 | ]; 25 | moduleRoutes.forEach(route => router.use(route.path, route.route)); 26 | exports.default = router; 27 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-17-06-16-success.log: -------------------------------------------------------------------------------- 1 | Sat Jun 17 2023 16:37:58 } [PH] info: 🛢Database is connected successfully 2 | Sat Jun 17 2023 16:37:58 } [PH] info: Application listening on port 5000 3 | Sat Jun 17 2023 16:50:46 } [PH] info: 🛢Database is connected successfully 4 | Sat Jun 17 2023 16:50:49 } [PH] info: 🛢Database is connected successfully 5 | Sat Jun 17 2023 16:50:49 } [PH] info: Application listening on port 5000 6 | Sat Jun 17 2023 16:53:0 } [PH] info: 🛢Database is connected successfully 7 | Sat Jun 17 2023 16:53:0 } [PH] info: Application listening on port 5000 8 | Sat Jun 17 2023 16:53:37 } [PH] info: 🛢Database is connected successfully 9 | Sat Jun 17 2023 16:53:37 } [PH] info: Application listening on port 5000 10 | Sat Jun 17 2023 16:53:40 } [PH] info: 🛢Database is connected successfully 11 | Sat Jun 17 2023 16:53:40 } [PH] info: Application listening on port 5000 12 | Sat Jun 17 2023 16:57:12 } [PH] info: 🛢Database is connected successfully 13 | Sat Jun 17 2023 16:57:12 } [PH] info: Application listening on port 5000 14 | -------------------------------------------------------------------------------- /dist/shared/catchAsync.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | const catchAsync = (fn) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { 13 | try { 14 | yield fn(req, res, next); 15 | } 16 | catch (error) { 17 | next(error); 18 | } 19 | }); 20 | exports.default = catchAsync; 21 | -------------------------------------------------------------------------------- /src/app/modules/user/user.model.ts: -------------------------------------------------------------------------------- 1 | import { Schema, model } from 'mongoose'; 2 | import { IUser, UserModel } from './user.interface'; 3 | 4 | const userSchema = new Schema( 5 | { 6 | phoneNumber: { 7 | type: String, 8 | required: true, 9 | unique: true, 10 | }, 11 | role: { 12 | type: String, 13 | required: true, 14 | }, 15 | password: { 16 | type: String, 17 | required: true, 18 | }, 19 | name: { 20 | firstName: { 21 | type: String, 22 | required: true, 23 | }, 24 | lastName: { 25 | type: String, 26 | required: true, 27 | }, 28 | }, 29 | address: { 30 | type: String, 31 | required: true, 32 | }, 33 | budget: { 34 | type: Number, 35 | required: true, 36 | }, 37 | income: { 38 | type: Number, 39 | required: true, 40 | }, 41 | }, 42 | { 43 | timestamps: true, 44 | toJSON: { 45 | virtuals: true, 46 | }, 47 | } 48 | ); 49 | 50 | export const User = model('User', userSchema); -------------------------------------------------------------------------------- /dist/app/modules/cow/cow.route.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.CowRoutes = void 0; 7 | const express_1 = __importDefault(require("express")); 8 | const validateRequest_1 = __importDefault(require("../../middlewares/validateRequest")); 9 | const cow_controller_1 = require("./cow.controller"); 10 | const cow_validation_1 = require("./cow.validation"); 11 | const router = express_1.default.Router(); 12 | router.get('/', cow_controller_1.CowController.getAllCows); 13 | router.post('/', (0, validateRequest_1.default)(cow_validation_1.CowValidation.addCowZodSchema), cow_controller_1.CowController.addCow); 14 | router.get('/:id', cow_controller_1.CowController.getSingleCow); 15 | router.patch('/:id', (0, validateRequest_1.default)(cow_validation_1.CowValidation.updateCowZodSchema), cow_controller_1.CowController.updateCow); 16 | router.delete('/:id', cow_controller_1.CowController.deleteCow); 17 | exports.CowRoutes = router; 18 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-18-06-20-success.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 20:38:27 } [PH] info: 🛢Database is connected successfully 2 | Sun Jun 18 2023 20:38:27 } [PH] info: Application listening on port 5000 3 | Sun Jun 18 2023 20:50:23 } [PH] info: 🛢Database is connected successfully 4 | Sun Jun 18 2023 20:50:23 } [PH] info: Application listening on port 5000 5 | Sun Jun 18 2023 20:51:59 } [PH] info: 🛢Database is connected successfully 6 | Sun Jun 18 2023 20:51:59 } [PH] info: Application listening on port 5000 7 | Sun Jun 18 2023 20:54:58 } [PH] info: 🛢Database is connected successfully 8 | Sun Jun 18 2023 20:54:58 } [PH] info: Application listening on port 5000 9 | Sun Jun 18 2023 20:55:29 } [PH] info: 🛢Database is connected successfully 10 | Sun Jun 18 2023 20:55:29 } [PH] info: Application listening on port 5000 11 | Sun Jun 18 2023 20:56:28 } [PH] info: 🛢Database is connected successfully 12 | Sun Jun 18 2023 20:56:28 } [PH] info: Application listening on port 5000 13 | Sun Jun 18 2023 20:57:0 } [PH] info: 🛢Database is connected successfully 14 | Sun Jun 18 2023 20:57:0 } [PH] info: Application listening on port 5000 15 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Hazrat Ali 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/app/modules/cow/cow.constants.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ICowBreed, 3 | ICowCategory, 4 | ICowLabel, 5 | ICowLocation, 6 | } from './cow.interface'; 7 | // Cow Constants 8 | export const CowLocation: ICowLocation[] = [ 9 | 'Dhaka', 10 | 'Chattogram', 11 | 'Rajshahi', 12 | 'Khulna', 13 | 'Barishal', 14 | 'Sylhet', 15 | 'Rangpur', 16 | 'Mymensingh', 17 | ]; 18 | 19 | export const CowBreed: ICowBreed[] = [ 20 | 'Brahman', 21 | 'Nellore', 22 | 'Sahiwal', 23 | 'Gir', 24 | 'Indigenous', 25 | 'Tharparkar', 26 | 'Kankrej', 27 | ]; 28 | 29 | export const CowLabel: ICowLabel[] = ['for sale', 'sold out']; 30 | 31 | export const CowCategory: ICowCategory[] = ['Dairy', 'Beef', 'Dual Purpose']; 32 | 33 | export const cowSearchableFields = [ 34 | "searchTerm", 35 | 'name', 36 | // 'age', 37 | // 'price', 38 | 'location', 39 | 'breed', 40 | // 'weight', 41 | 'label', 42 | 'category', 43 | ]; 44 | 45 | export const cowFilterableFields = [ 46 | 'searchTerm', 47 | 'name', 48 | 'age', 49 | 'price', 50 | 'location', 51 | 'breed', 52 | 'weight', 53 | 'label', 54 | 'category', 55 | "minPrice", 56 | "maxPrice", 57 | ]; 58 | -------------------------------------------------------------------------------- /dist/app/modules/user/user.model.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.User = void 0; 4 | const mongoose_1 = require("mongoose"); 5 | const userSchema = new mongoose_1.Schema({ 6 | phoneNumber: { 7 | type: String, 8 | required: true, 9 | unique: true, 10 | }, 11 | role: { 12 | type: String, 13 | required: true, 14 | }, 15 | password: { 16 | type: String, 17 | required: true, 18 | }, 19 | name: { 20 | firstName: { 21 | type: String, 22 | required: true, 23 | }, 24 | lastName: { 25 | type: String, 26 | required: true, 27 | }, 28 | }, 29 | address: { 30 | type: String, 31 | required: true, 32 | }, 33 | budget: { 34 | type: Number, 35 | required: true, 36 | }, 37 | income: { 38 | type: Number, 39 | required: true, 40 | }, 41 | }, { 42 | timestamps: true, 43 | toJSON: { 44 | virtuals: true, 45 | }, 46 | }); 47 | exports.User = (0, mongoose_1.model)('User', userSchema); 48 | -------------------------------------------------------------------------------- /src/server.ts: -------------------------------------------------------------------------------- 1 | import { Server } from 'http'; 2 | import mongoose from 'mongoose'; 3 | import app from './app'; 4 | import config from './config/index'; 5 | // import { errorlogger, logger } from './shared/logger'; 6 | // server js 7 | process.on('uncaughtException', error => { 8 | console.log(error); 9 | process.exit(1); 10 | }); 11 | 12 | let server: Server; 13 | 14 | async function bootstrap() { 15 | try { 16 | await mongoose.connect(config.database_url as string); 17 | console.log(`🛢Database is connected successfully`); 18 | 19 | server = app.listen(config.port, () => { 20 | console.log(`Application listening on port ${config.port}`); 21 | }); 22 | } catch (err) { 23 | console.log('Failed to connect database', err); 24 | } 25 | 26 | process.on('unhandledRejection', error => { 27 | if (server) { 28 | server.close(() => { 29 | console.log(error); 30 | process.exit(1); 31 | }); 32 | } else { 33 | process.exit(1); 34 | } 35 | }); 36 | } 37 | 38 | bootstrap(); 39 | 40 | process.on('SIGTERM', () => { 41 | console.log('SIGTERM is received'); 42 | if (server) { 43 | server.close(); 44 | } 45 | }); 46 | -------------------------------------------------------------------------------- /dist/app/modules/user/user.route.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.UserRoutes = void 0; 7 | const express_1 = __importDefault(require("express")); 8 | const validateRequest_1 = __importDefault(require("../../middlewares/validateRequest")); 9 | const user_controller_1 = require("./user.controller"); 10 | const user_validation_1 = require("./user.validation"); 11 | const router = express_1.default.Router(); 12 | router.get('/users/:id', user_controller_1.UserController.getSingleUser); 13 | router.get('/users/', user_controller_1.UserController.getAllUsers); 14 | router.patch('/users/:id', (0, validateRequest_1.default)(user_validation_1.UserValidation.updateUserZodSchema), user_controller_1.UserController.updateUser); 15 | router.delete('/users/:id', user_controller_1.UserController.deleteUser); 16 | router.post('/auth/signup', (0, validateRequest_1.default)(user_validation_1.UserValidation.createUserZodSchema), user_controller_1.UserController.createUser); 17 | exports.UserRoutes = router; 18 | -------------------------------------------------------------------------------- /src/app/modules/cow/cow.interface.ts: -------------------------------------------------------------------------------- 1 | import { Model, Types } from 'mongoose'; 2 | 3 | export type ICowLocation = 4 | | 'Dhaka' 5 | | 'Chattogram' 6 | | 'Barishal' 7 | | 'Rajshahi' 8 | | 'Khulna' 9 | | 'Sylhet' 10 | | 'Rangpur' 11 | | 'Mymensingh'; 12 | 13 | export type ICowBreed = 14 | | 'Brahman' 15 | | 'Nellore' 16 | | 'Sahiwal' 17 | | 'Gir' 18 | | 'Indigenous' 19 | | 'Tharparkar' 20 | | 'Kankrej'; 21 | 22 | export type ICowLabel = 'for sale' | 'sold out'; 23 | 24 | export type ICowCategory = 'Dairy' | 'Beef' | 'Dual Purpose'; 25 | 26 | export type ICow = { 27 | name: string; 28 | age: number; 29 | price: number; 30 | location: ICowLocation; 31 | breed: ICowBreed; 32 | weight: number; 33 | label: ICowLabel; 34 | category: ICowCategory; 35 | seller?: Types.ObjectId; 36 | }; 37 | 38 | export type CowModel = Model>; 39 | 40 | export type ICowFilters = { 41 | searchTerm?: string; 42 | name?: string; 43 | age?: number; 44 | price?: number; 45 | location?: ICowLocation; 46 | breed?: ICowBreed; 47 | weight?: number; 48 | label?: ICowLabel; 49 | category?: ICowCategory; 50 | seller?: Types.ObjectId; 51 | }; 52 | -------------------------------------------------------------------------------- /dist/app/modules/cow/cow.constants.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.cowFilterableFields = exports.cowSearchableFields = exports.CowCategory = exports.CowLabel = exports.CowBreed = exports.CowLocation = void 0; 4 | exports.CowLocation = [ 5 | 'Dhaka', 6 | 'Chattogram', 7 | 'Rajshahi', 8 | 'Khulna', 9 | 'Barishal', 10 | 'Sylhet', 11 | 'Rangpur', 12 | 'Mymensingh', 13 | ]; 14 | exports.CowBreed = [ 15 | 'Brahman', 16 | 'Nellore', 17 | 'Sahiwal', 18 | 'Gir', 19 | 'Indigenous', 20 | 'Tharparkar', 21 | 'Kankrej', 22 | ]; 23 | exports.CowLabel = ['for sale', 'sold out']; 24 | exports.CowCategory = ['Dairy', 'Beef', 'Dual Purpose']; 25 | exports.cowSearchableFields = [ 26 | "searchTerm", 27 | 'name', 28 | // 'age', 29 | // 'price', 30 | 'location', 31 | 'breed', 32 | // 'weight', 33 | 'label', 34 | 'category', 35 | ]; 36 | exports.cowFilterableFields = [ 37 | 'searchTerm', 38 | 'name', 39 | 'age', 40 | 'price', 41 | 'location', 42 | 'breed', 43 | 'weight', 44 | 'label', 45 | 'category', 46 | "minPrice", 47 | "maxPrice", 48 | ]; 49 | -------------------------------------------------------------------------------- /src/app/modules/order/order.controller.ts: -------------------------------------------------------------------------------- 1 | import { Request, RequestHandler, Response } from 'express'; 2 | import httpStatus from 'http-status'; 3 | import catchAsync from '../../../shared/catchAsync'; 4 | import sendResponse from '../../../shared/sendResponse'; 5 | import { IOrder } from './order.interface'; 6 | import { OrderService } from './order.service'; 7 | 8 | const cowOrder: RequestHandler = catchAsync( 9 | async (req: Request, res: Response) => { 10 | const cow: IOrder = req.body; 11 | 12 | const result = await OrderService.cowOrder(cow); 13 | 14 | sendResponse(res, { 15 | statusCode: httpStatus.OK, 16 | success: true, 17 | message: 'Cow Ordered successfully!', 18 | data: result, 19 | }); 20 | } 21 | ); 22 | 23 | const getAllOrders: RequestHandler = catchAsync( 24 | async (req: Request, res: Response) => { 25 | const result = await OrderService.getAllOrders(); 26 | 27 | sendResponse(res, { 28 | statusCode: httpStatus.OK, 29 | success: true, 30 | message: 'All Orders fetched successfully!', 31 | data: result, 32 | }); 33 | 34 | } 35 | ); 36 | 37 | 38 | export const OrderController = { 39 | cowOrder, 40 | getAllOrders, 41 | }; 42 | -------------------------------------------------------------------------------- /dist/app/middlewares/validateRequest.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | const validateRequest = (schema) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { 13 | try { 14 | yield schema.parseAsync({ 15 | body: req.body, 16 | query: req.query, 17 | params: req.params, 18 | cookies: req.cookies, 19 | }); 20 | return next(); 21 | } 22 | catch (error) { 23 | next(error); 24 | } 25 | }); 26 | exports.default = validateRequest; 27 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-18-06-19-success.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 19:19:51 } [PH] info: 🛢Database is connected successfully 2 | Sun Jun 18 2023 19:19:51 } [PH] info: Application listening on port 5000 3 | Sun Jun 18 2023 19:29:30 } [PH] info: 🛢Database is connected successfully 4 | Sun Jun 18 2023 19:29:30 } [PH] info: Application listening on port 5000 5 | Sun Jun 18 2023 19:36:34 } [PH] info: 🛢Database is connected successfully 6 | Sun Jun 18 2023 19:36:34 } [PH] info: Application listening on port 5000 7 | Sun Jun 18 2023 19:37:40 } [PH] info: 🛢Database is connected successfully 8 | Sun Jun 18 2023 19:37:40 } [PH] info: Application listening on port 5000 9 | Sun Jun 18 2023 19:38:20 } [PH] info: 🛢Database is connected successfully 10 | Sun Jun 18 2023 19:38:20 } [PH] info: Application listening on port 5000 11 | Sun Jun 18 2023 19:39:34 } [PH] info: 🛢Database is connected successfully 12 | Sun Jun 18 2023 19:39:34 } [PH] info: Application listening on port 5000 13 | Sun Jun 18 2023 19:39:40 } [PH] info: 🛢Database is connected successfully 14 | Sun Jun 18 2023 19:39:40 } [PH] info: Application listening on port 5000 15 | Sun Jun 18 2023 19:40:35 } [PH] info: 🛢Database is connected successfully 16 | Sun Jun 18 2023 19:40:35 } [PH] info: Application listening on port 5000 17 | -------------------------------------------------------------------------------- /dist/app.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const cors_1 = __importDefault(require("cors")); 7 | const express_1 = __importDefault(require("express")); 8 | const http_status_1 = __importDefault(require("http-status")); 9 | const globalErrorHandler_1 = __importDefault(require("./app/middlewares/globalErrorHandler")); 10 | const routes_1 = __importDefault(require("./app/routes")); 11 | const app = (0, express_1.default)(); 12 | app.use((0, cors_1.default)()); 13 | //parser 14 | app.use(express_1.default.json()); 15 | app.use(express_1.default.urlencoded({ extended: true })); 16 | app.use('/api/v1', routes_1.default); 17 | //global error handler 18 | app.use(globalErrorHandler_1.default); 19 | //handle not found 20 | app.use((req, res, next) => { 21 | res.status(http_status_1.default.NOT_FOUND).json({ 22 | success: false, 23 | message: 'Not Found', 24 | errorMessages: [ 25 | { 26 | path: req.originalUrl, 27 | message: 'API Not Found', 28 | }, 29 | ], 30 | }); 31 | next(); 32 | }); 33 | exports.default = app; 34 | -------------------------------------------------------------------------------- /src/app/modules/cow/cow.model.ts: -------------------------------------------------------------------------------- 1 | import { Schema, model } from 'mongoose'; 2 | import { CowBreed, CowCategory, CowLabel, CowLocation } from './cow.constants'; 3 | import { CowModel, ICow } from './cow.interface'; 4 | 5 | const cowSchema = new Schema( 6 | { 7 | name: { 8 | type: String, 9 | required: true, 10 | }, 11 | age: { 12 | type: Number, 13 | required: true, 14 | }, 15 | price: { 16 | type: Number, 17 | required: true, 18 | }, 19 | location: { 20 | type: String, 21 | enum: CowLocation, 22 | required: true, 23 | }, 24 | breed: { 25 | type: String, 26 | required: true, 27 | enum: CowBreed, 28 | }, 29 | weight: { 30 | type: Number, 31 | required: true, 32 | }, 33 | label: { 34 | type: String, 35 | required: true, 36 | enum: CowLabel, 37 | }, 38 | category: { 39 | type: String, 40 | required: true, 41 | enum: CowCategory, 42 | }, 43 | seller: { 44 | type: Schema.Types.ObjectId, 45 | ref: 'User', 46 | required: true, 47 | }, 48 | }, 49 | { 50 | timestamps: true, 51 | toJSON: { 52 | virtuals: true, 53 | }, 54 | } 55 | ); 56 | 57 | export const Cow = model('Cow', cowSchema); 58 | -------------------------------------------------------------------------------- /dist/app/modules/cow/cow.model.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Cow = void 0; 4 | const mongoose_1 = require("mongoose"); 5 | const cow_constants_1 = require("./cow.constants"); 6 | const cowSchema = new mongoose_1.Schema({ 7 | name: { 8 | type: String, 9 | required: true, 10 | }, 11 | age: { 12 | type: Number, 13 | required: true, 14 | }, 15 | price: { 16 | type: Number, 17 | required: true, 18 | }, 19 | location: { 20 | type: String, 21 | enum: cow_constants_1.CowLocation, 22 | required: true, 23 | }, 24 | breed: { 25 | type: String, 26 | required: true, 27 | enum: cow_constants_1.CowBreed, 28 | }, 29 | weight: { 30 | type: Number, 31 | required: true, 32 | }, 33 | label: { 34 | type: String, 35 | required: true, 36 | enum: cow_constants_1.CowLabel, 37 | }, 38 | category: { 39 | type: String, 40 | required: true, 41 | enum: cow_constants_1.CowCategory, 42 | }, 43 | seller: { 44 | type: mongoose_1.Schema.Types.ObjectId, 45 | ref: 'User', 46 | required: true, 47 | }, 48 | }, { 49 | timestamps: true, 50 | toJSON: { 51 | virtuals: true, 52 | }, 53 | }); 54 | exports.Cow = (0, mongoose_1.model)('Cow', cowSchema); 55 | -------------------------------------------------------------------------------- /src/app/modules/user/user.service.ts: -------------------------------------------------------------------------------- 1 | import httpStatus from 'http-status'; 2 | import ApiError from '../../../errors/ApiError'; 3 | import { IUser } from './user.interface'; 4 | import { User } from './user.model'; 5 | 6 | const createUser = async (user: IUser): Promise => { 7 | if (!user.income) { 8 | user.income = 0; 9 | } 10 | 11 | const createdUser = await User.create(user); 12 | 13 | if (!createdUser) { 14 | throw new ApiError(400, 'Failed to create user'); 15 | } 16 | return createdUser; 17 | }; 18 | 19 | const getAllUsers = async (): Promise => { 20 | 21 | const result = await User.find() 22 | return result; 23 | }; 24 | 25 | const getSingleUser = async (id: string): Promise => { 26 | const result = await User.findById(id); 27 | return result; 28 | }; 29 | 30 | const updateUser = async ( 31 | id: string, 32 | payload: Partial 33 | ): Promise => { 34 | const isExist = await User.findOne({ _id: id }); 35 | 36 | if (!isExist) { 37 | throw new ApiError(httpStatus.NOT_FOUND, 'User not found !'); 38 | } 39 | 40 | const result = await User.findByIdAndUpdate(id, payload, { 41 | new: true, 42 | }); 43 | return result; 44 | }; 45 | 46 | const deleteUser = async (id: string): Promise => { 47 | const result = await User.findByIdAndDelete(id); 48 | return result; 49 | }; 50 | 51 | export const UserService = { 52 | createUser, 53 | getAllUsers, 54 | getSingleUser, 55 | updateUser, 56 | deleteUser, 57 | }; 58 | -------------------------------------------------------------------------------- /src/app/modules/user/user.validation.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod'; 2 | 3 | const createUserZodSchema = z.object({ 4 | body: z.object({ 5 | phoneNumber: z.string({ 6 | required_error: 'Phone number is required', 7 | }), 8 | role: z.enum(["seller", "buyer"],{ 9 | required_error: 'Role is required', 10 | }), 11 | password: z.string({ 12 | required_error: 'Password is required', 13 | }), 14 | name: z.object({ 15 | firstName: z.string({ 16 | required_error: 'First name is required', 17 | }), 18 | lastName: z.string({ 19 | required_error: 'Last name is required', 20 | }), 21 | }), 22 | address: z.string({ 23 | required_error: 'Address is required', 24 | }), 25 | budget: z.number({ 26 | required_error: 'Budget is required', 27 | }), 28 | income: z.number().optional(), 29 | }), 30 | }); 31 | 32 | const updateUserZodSchema = z.object({ 33 | body: z.object({ 34 | phoneNumber: z.string({ 35 | required_error: 'Phone number is required', 36 | }).optional(), 37 | role: z.enum(['seller', 'buyer'], { 38 | required_error: 'Role is required', 39 | }).optional(), 40 | password: z.string({ 41 | required_error: 'Password is required', 42 | }).optional(), 43 | name: z.object({ 44 | firstName: z.string({ 45 | required_error: 'First name is required', 46 | }).optional(), 47 | lastName: z.string({ 48 | required_error: 'Last name is required', 49 | }).optional(), 50 | }), 51 | address: z.string({ 52 | required_error: 'Address is required', 53 | }).optional(), 54 | budget: z.number({ 55 | required_error: 'Budget is required', 56 | }).optional(), 57 | income: z.number().optional(), 58 | }), 59 | }); 60 | 61 | export const UserValidation = { 62 | createUserZodSchema, 63 | updateUserZodSchema, 64 | }; 65 | -------------------------------------------------------------------------------- /dist/shared/logger.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // /* eslint-disable no-undef */ 3 | // import path from 'path'; 4 | // import { createLogger, format, transports } from 'winston'; 5 | // import DailyRotateFile from 'winston-daily-rotate-file'; 6 | // const { combine, timestamp, label, printf } = format; 7 | // //Customm Log Format 8 | // const myFormat = printf(({ level, message, label, timestamp }) => { 9 | // const date = new Date(timestamp); 10 | // const hour = date.getHours(); 11 | // const minutes = date.getMinutes(); 12 | // const seconds = date.getSeconds(); 13 | // return `${date.toDateString()} ${hour}:${minutes}:${seconds} } [${label}] ${level}: ${message}`; 14 | // }); 15 | // const logger = createLogger({ 16 | // level: 'info', 17 | // format: combine(label({ label: 'PH' }), timestamp(), myFormat), 18 | // transports: [ 19 | // new transports.Console(), 20 | // new DailyRotateFile({ 21 | // filename: path.join( 22 | // process.cwd(), 23 | // 'logs', 24 | // 'winston', 25 | // 'successes', 26 | // 'phu-%DATE%-success.log' 27 | // ), 28 | // datePattern: 'YYYY-DD-MM-HH', 29 | // zippedArchive: true, 30 | // maxSize: '20m', 31 | // maxFiles: '14d', 32 | // }), 33 | // ], 34 | // }); 35 | // const errorlogger = createLogger({ 36 | // level: 'error', 37 | // format: combine(label({ label: 'PH' }), timestamp(), myFormat), 38 | // transports: [ 39 | // new transports.Console(), 40 | // new DailyRotateFile({ 41 | // filename: path.join( 42 | // process.cwd(), 43 | // 'logs', 44 | // 'winston', 45 | // 'errors', 46 | // 'phu-%DATE%-error.log' 47 | // ), 48 | // datePattern: 'YYYY-DD-MM-HH', 49 | // zippedArchive: true, 50 | // maxSize: '20m', 51 | // maxFiles: '14d', 52 | // }), 53 | // ], 54 | // }); 55 | // export { logger, errorlogger }; 56 | -------------------------------------------------------------------------------- /src/shared/logger.ts: -------------------------------------------------------------------------------- 1 | // /* eslint-disable no-undef */ 2 | // import path from 'path'; 3 | // import { createLogger, format, transports } from 'winston'; 4 | // import DailyRotateFile from 'winston-daily-rotate-file'; 5 | // const { combine, timestamp, label, printf } = format; 6 | 7 | // //Customm Log Format 8 | 9 | // const myFormat = printf(({ level, message, label, timestamp }) => { 10 | // const date = new Date(timestamp); 11 | // const hour = date.getHours(); 12 | // const minutes = date.getMinutes(); 13 | // const seconds = date.getSeconds(); 14 | // return `${date.toDateString()} ${hour}:${minutes}:${seconds} } [${label}] ${level}: ${message}`; 15 | // }); 16 | 17 | // const logger = createLogger({ 18 | // level: 'info', 19 | // format: combine(label({ label: 'PH' }), timestamp(), myFormat), 20 | // transports: [ 21 | // new transports.Console(), 22 | // new DailyRotateFile({ 23 | // filename: path.join( 24 | // process.cwd(), 25 | // 'logs', 26 | // 'winston', 27 | // 'successes', 28 | // 'phu-%DATE%-success.log' 29 | // ), 30 | // datePattern: 'YYYY-DD-MM-HH', 31 | // zippedArchive: true, 32 | // maxSize: '20m', 33 | // maxFiles: '14d', 34 | // }), 35 | // ], 36 | // }); 37 | 38 | // const errorlogger = createLogger({ 39 | // level: 'error', 40 | // format: combine(label({ label: 'PH' }), timestamp(), myFormat), 41 | // transports: [ 42 | // new transports.Console(), 43 | // new DailyRotateFile({ 44 | // filename: path.join( 45 | // process.cwd(), 46 | // 'logs', 47 | // 'winston', 48 | // 'errors', 49 | // 'phu-%DATE%-error.log' 50 | // ), 51 | // datePattern: 'YYYY-DD-MM-HH', 52 | // zippedArchive: true, 53 | // maxSize: '20m', 54 | // maxFiles: '14d', 55 | // }), 56 | // ], 57 | // }); 58 | 59 | // export { logger, errorlogger }; 60 | -------------------------------------------------------------------------------- /dist/app/modules/order/order.controller.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __importDefault = (this && this.__importDefault) || function (mod) { 12 | return (mod && mod.__esModule) ? mod : { "default": mod }; 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | exports.OrderController = void 0; 16 | const http_status_1 = __importDefault(require("http-status")); 17 | const catchAsync_1 = __importDefault(require("../../../shared/catchAsync")); 18 | const sendResponse_1 = __importDefault(require("../../../shared/sendResponse")); 19 | const order_service_1 = require("./order.service"); 20 | const cowOrder = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 21 | const cow = req.body; 22 | const result = yield order_service_1.OrderService.cowOrder(cow); 23 | (0, sendResponse_1.default)(res, { 24 | statusCode: http_status_1.default.OK, 25 | success: true, 26 | message: 'Cow Ordered successfully!', 27 | data: result, 28 | }); 29 | })); 30 | const getAllOrders = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 31 | const result = yield order_service_1.OrderService.getAllOrders(); 32 | (0, sendResponse_1.default)(res, { 33 | statusCode: http_status_1.default.OK, 34 | success: true, 35 | message: 'All Orders fetched successfully!', 36 | data: result, 37 | }); 38 | })); 39 | exports.OrderController = { 40 | cowOrder, 41 | getAllOrders, 42 | }; 43 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Hazrat Ali 2 | 3 | ### Online Cow Selling Backend for Eid Ul Adha 4 | 5 | 6 | This project is a simple backend project for a cow hut. It is a simple project that allows a user to add cows to the cow hut, and get the status of the cow hut. Seller can also sell cows from the cow hut app. and buyer can buy cows from the cow hut app. 7 | 8 | ### All The Application Routes are given below: 9 | 10 | #### User 11 | - https://assigment-3-cow-hut.vercel.app/api/v1/auth/signup (POST) - For create a new user 12 | - https://assigment-3-cow-hut.vercel.app/api/v1/users (GET) - For get all the users 13 | - https://assigment-3-cow-hut.vercel.app/api/v1/users/6177a5b87d32123f08d2f5d4 (GET) - For get a single user 14 | - https://assigment-3-cow-hut.vercel.app/api/v1/users/6177a5b87d32123f08d2f5d4 (PATCH) - For update a single user 15 | - https://assigment-3-cow-hut.vercel.app/api/v1/users/6177a5b87d32123f08d2f5d4 (DELETE) - For delete a single user 16 | 17 | #### Cows 18 | 19 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows (POST) - For create a new cow 20 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows (GET) - For get all the cows aslo can filter by location, maxPrice , minPrice, and search by name search term etc 21 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows/6177a5b87d32123f08d2f5d4 (Single GET) - For get a single cow 22 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows/6177a5b87d32123f08d2f5d4 (PATCH) - For update a single cow 23 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows/6177a5b87d32123f08d2f5d4 (DELETE) Include an id that is saved in your database 24 | 25 | ### Pagination and Filtering routes of Cows 26 | 27 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows?page=1&limit=10 28 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows?sortBy=price&sortOrder=asc 29 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows?minPrice=20000&maxPrice=70000 30 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows?location=Chattogram 31 | - https://assigment-3-cow-hut.vercel.app/api/v1/cows?searchTerm=Cha 32 | 33 | #### Orders 34 | 35 | - https://assigment-3-cow-hut.vercel.app/api/v1/orders (POST) - For create a new order (buyer can buy a cow) 36 | - https://assigment-3-cow-hut.vercel.app/api/v1/orders (GET) - For get all the orders 37 | 38 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-18-06-07-success.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 7:38:24 } [PH] info: 🛢Database is connected successfully 2 | Sun Jun 18 2023 7:38:24 } [PH] info: Application listening on port 5000 3 | Sun Jun 18 2023 7:45:31 } [PH] info: 🛢Database is connected successfully 4 | Sun Jun 18 2023 7:45:31 } [PH] info: Application listening on port 5000 5 | Sun Jun 18 2023 7:46:57 } [PH] info: 🛢Database is connected successfully 6 | Sun Jun 18 2023 7:46:57 } [PH] info: Application listening on port 5000 7 | Sun Jun 18 2023 7:47:23 } [PH] info: 🛢Database is connected successfully 8 | Sun Jun 18 2023 7:47:23 } [PH] info: Application listening on port 5000 9 | Sun Jun 18 2023 7:47:39 } [PH] info: 🛢Database is connected successfully 10 | Sun Jun 18 2023 7:47:39 } [PH] info: Application listening on port 5000 11 | Sun Jun 18 2023 7:50:21 } [PH] info: 🛢Database is connected successfully 12 | Sun Jun 18 2023 7:50:21 } [PH] info: Application listening on port 5000 13 | Sun Jun 18 2023 7:50:25 } [PH] info: 🛢Database is connected successfully 14 | Sun Jun 18 2023 7:50:25 } [PH] info: Application listening on port 5000 15 | Sun Jun 18 2023 7:50:28 } [PH] info: 🛢Database is connected successfully 16 | Sun Jun 18 2023 7:50:28 } [PH] info: Application listening on port 5000 17 | Sun Jun 18 2023 7:50:32 } [PH] info: 🛢Database is connected successfully 18 | Sun Jun 18 2023 7:50:32 } [PH] info: Application listening on port 5000 19 | Sun Jun 18 2023 7:51:17 } [PH] info: 🛢Database is connected successfully 20 | Sun Jun 18 2023 7:51:17 } [PH] info: Application listening on port 5000 21 | Sun Jun 18 2023 7:52:35 } [PH] info: 🛢Database is connected successfully 22 | Sun Jun 18 2023 7:52:36 } [PH] info: Application listening on port 5000 23 | Sun Jun 18 2023 7:54:7 } [PH] info: 🛢Database is connected successfully 24 | Sun Jun 18 2023 7:54:7 } [PH] info: Application listening on port 5000 25 | Sun Jun 18 2023 7:59:4 } [PH] info: 🛢Database is connected successfully 26 | Sun Jun 18 2023 7:59:4 } [PH] info: Application listening on port 5000 27 | Sun Jun 18 2023 7:59:16 } [PH] info: 🛢Database is connected successfully 28 | Sun Jun 18 2023 7:59:16 } [PH] info: Application listening on port 5000 29 | Sun Jun 18 2023 7:59:43 } [PH] info: 🛢Database is connected successfully 30 | Sun Jun 18 2023 7:59:43 } [PH] info: Application listening on port 5000 31 | -------------------------------------------------------------------------------- /dist/app/modules/user/user.validation.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.UserValidation = void 0; 4 | const zod_1 = require("zod"); 5 | const createUserZodSchema = zod_1.z.object({ 6 | body: zod_1.z.object({ 7 | phoneNumber: zod_1.z.string({ 8 | required_error: 'Phone number is required', 9 | }), 10 | role: zod_1.z.enum(["seller", "buyer"], { 11 | required_error: 'Role is required', 12 | }), 13 | password: zod_1.z.string({ 14 | required_error: 'Password is required', 15 | }), 16 | name: zod_1.z.object({ 17 | firstName: zod_1.z.string({ 18 | required_error: 'First name is required', 19 | }), 20 | lastName: zod_1.z.string({ 21 | required_error: 'Last name is required', 22 | }), 23 | }), 24 | address: zod_1.z.string({ 25 | required_error: 'Address is required', 26 | }), 27 | budget: zod_1.z.number({ 28 | required_error: 'Budget is required', 29 | }), 30 | income: zod_1.z.number().optional(), 31 | }), 32 | }); 33 | const updateUserZodSchema = zod_1.z.object({ 34 | body: zod_1.z.object({ 35 | phoneNumber: zod_1.z.string({ 36 | required_error: 'Phone number is required', 37 | }).optional(), 38 | role: zod_1.z.enum(['seller', 'buyer'], { 39 | required_error: 'Role is required', 40 | }).optional(), 41 | password: zod_1.z.string({ 42 | required_error: 'Password is required', 43 | }).optional(), 44 | name: zod_1.z.object({ 45 | firstName: zod_1.z.string({ 46 | required_error: 'First name is required', 47 | }).optional(), 48 | lastName: zod_1.z.string({ 49 | required_error: 'Last name is required', 50 | }).optional(), 51 | }), 52 | address: zod_1.z.string({ 53 | required_error: 'Address is required', 54 | }).optional(), 55 | budget: zod_1.z.number({ 56 | required_error: 'Budget is required', 57 | }).optional(), 58 | income: zod_1.z.number().optional(), 59 | }), 60 | }); 61 | exports.UserValidation = { 62 | createUserZodSchema, 63 | updateUserZodSchema, 64 | }; 65 | -------------------------------------------------------------------------------- /dist/server.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __importDefault = (this && this.__importDefault) || function (mod) { 12 | return (mod && mod.__esModule) ? mod : { "default": mod }; 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | const mongoose_1 = __importDefault(require("mongoose")); 16 | const app_1 = __importDefault(require("./app")); 17 | const index_1 = __importDefault(require("./config/index")); 18 | // import { errorlogger, logger } from './shared/logger'; 19 | process.on('uncaughtException', error => { 20 | console.log(error); 21 | process.exit(1); 22 | }); 23 | let server; 24 | function bootstrap() { 25 | return __awaiter(this, void 0, void 0, function* () { 26 | try { 27 | yield mongoose_1.default.connect(index_1.default.database_url); 28 | console.log(`🛢Database is connected successfully`); 29 | server = app_1.default.listen(index_1.default.port, () => { 30 | console.log(`Application listening on port ${index_1.default.port}`); 31 | }); 32 | } 33 | catch (err) { 34 | console.log('Failed to connect database', err); 35 | } 36 | process.on('unhandledRejection', error => { 37 | if (server) { 38 | server.close(() => { 39 | console.log(error); 40 | process.exit(1); 41 | }); 42 | } 43 | else { 44 | process.exit(1); 45 | } 46 | }); 47 | }); 48 | } 49 | bootstrap(); 50 | process.on('SIGTERM', () => { 51 | console.log('SIGTERM is received'); 52 | if (server) { 53 | server.close(); 54 | } 55 | }); 56 | -------------------------------------------------------------------------------- /src/app/modules/cow/cow.validation.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod'; 2 | import { CowBreed, CowCategory, CowLabel, CowLocation } from './cow.constants'; 3 | 4 | const addCowZodSchema = z.object({ 5 | body: z.object({ 6 | name: z.string({ 7 | required_error: 'Name is required', 8 | }), 9 | age: z.number({ 10 | required_error: 'Age is required', 11 | }), 12 | price: z.number({ 13 | required_error: 'Price is required', 14 | }), 15 | location: z.enum([...CowLocation] as [string, ...string[]], { 16 | required_error: 'Location is required', 17 | }), 18 | breed: z.enum([...CowBreed] as [string, ...string[]], { 19 | required_error: 'Breed is required', 20 | }), 21 | weight: z.number({ 22 | required_error: 'Weight is required', 23 | }), 24 | label: z.enum([...CowLabel] as [string, ...string[]], { 25 | required_error: 'Label is required', 26 | }), 27 | category: z.enum([...CowCategory] as [string, ...string[]], { 28 | required_error: 'Category is required', 29 | }), 30 | seller: z.string({ 31 | required_error: 'Seller Referance is required', 32 | }), 33 | }), 34 | }); 35 | 36 | const updateCowZodSchema = z.object({ 37 | body: z.object({ 38 | name: z.string({ 39 | required_error: 'Name is required', 40 | }).optional(), 41 | age: z.number({ 42 | required_error: 'Age is required', 43 | }).optional(), 44 | price: z.number({ 45 | required_error: 'Price is required', 46 | }).optional(), 47 | location: z.enum([...CowLocation] as [string, ...string[]], { 48 | required_error: 'Location is required', 49 | }).optional(), 50 | breed: z.enum([...CowBreed] as [string, ...string[]], { 51 | required_error: 'Breed is required', 52 | }).optional(), 53 | weight: z.number({ 54 | required_error: 'Weight is required', 55 | }).optional(), 56 | label: z.enum([...CowLabel] as [string, ...string[]], { 57 | required_error: 'Label is required', 58 | }).optional(), 59 | category: z.enum([...CowCategory] as [string, ...string[]], { 60 | required_error: 'Category is required', 61 | }).optional(), 62 | seller: z.string({ 63 | required_error: 'Seller Referance is required', 64 | }).optional(), 65 | }), 66 | }); 67 | 68 | export const CowValidation = { 69 | addCowZodSchema, 70 | updateCowZodSchema, 71 | }; 72 | -------------------------------------------------------------------------------- /src/app/modules/user/user.controller.ts: -------------------------------------------------------------------------------- 1 | import { Request, RequestHandler, Response } from 'express'; 2 | import httpStatus from 'http-status'; 3 | import catchAsync from '../../../shared/catchAsync'; 4 | import sendResponse from '../../../shared/sendResponse'; 5 | import { IUser } from './user.interface'; 6 | import { UserService } from './user.service'; 7 | 8 | const createUser: RequestHandler = catchAsync( 9 | async (req: Request, res: Response) => { 10 | // const { user } = req.body; 11 | // console.log(req.body); 12 | 13 | const user: IUser = req.body; 14 | 15 | const result = await UserService.createUser(user); 16 | 17 | sendResponse(res, { 18 | statusCode: httpStatus.OK, 19 | success: true, 20 | message: 'user created successfully!', 21 | data: result, 22 | }); 23 | } 24 | ); 25 | 26 | const getAllUsers = catchAsync(async (req: Request, res: Response) => { 27 | 28 | const result = await UserService.getAllUsers(); 29 | 30 | const message = 31 | result.length > 0 32 | ? 'User retrieved successfully !' 33 | : 'No user founded'; 34 | 35 | sendResponse(res, { 36 | statusCode: httpStatus.OK, 37 | success: true, 38 | message: message, 39 | data: result, 40 | }); 41 | }); 42 | 43 | 44 | const getSingleUser = catchAsync(async (req: Request, res: Response) => { 45 | const id = req.params.id; 46 | 47 | const result = await UserService.getSingleUser(id); 48 | 49 | sendResponse(res, { 50 | statusCode: httpStatus.OK, 51 | success: true, 52 | message: 'User retrieved successfully !', 53 | data: result, 54 | }); 55 | }); 56 | 57 | 58 | const updateUser = catchAsync(async (req: Request, res: Response) => { 59 | const id = req.params.id; 60 | const updatedData = req.body; 61 | 62 | const result = await UserService.updateUser(id, updatedData); 63 | 64 | sendResponse(res, { 65 | statusCode: httpStatus.OK, 66 | success: true, 67 | message: 'User updated successfully !', 68 | data: result, 69 | }); 70 | }); 71 | 72 | 73 | const deleteUser = catchAsync(async (req: Request, res: Response) => { 74 | const id = req.params.id; 75 | 76 | const result = await UserService.deleteUser(id); 77 | 78 | sendResponse(res, { 79 | statusCode: httpStatus.OK, 80 | success: true, 81 | message: 'User deleted successfully !', 82 | data: result, 83 | }); 84 | }); 85 | 86 | export const UserController = { 87 | createUser, 88 | getAllUsers, 89 | getSingleUser, 90 | updateUser, 91 | deleteUser, 92 | }; 93 | -------------------------------------------------------------------------------- /dist/app/modules/user/user.service.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __importDefault = (this && this.__importDefault) || function (mod) { 12 | return (mod && mod.__esModule) ? mod : { "default": mod }; 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | exports.UserService = void 0; 16 | const http_status_1 = __importDefault(require("http-status")); 17 | const ApiError_1 = __importDefault(require("../../../errors/ApiError")); 18 | const user_model_1 = require("./user.model"); 19 | const createUser = (user) => __awaiter(void 0, void 0, void 0, function* () { 20 | if (!user.income) { 21 | user.income = 0; 22 | } 23 | const createdUser = yield user_model_1.User.create(user); 24 | if (!createdUser) { 25 | throw new ApiError_1.default(400, 'Failed to create user'); 26 | } 27 | return createdUser; 28 | }); 29 | const getAllUsers = () => __awaiter(void 0, void 0, void 0, function* () { 30 | const result = yield user_model_1.User.find(); 31 | return result; 32 | }); 33 | const getSingleUser = (id) => __awaiter(void 0, void 0, void 0, function* () { 34 | const result = yield user_model_1.User.findById(id); 35 | return result; 36 | }); 37 | const updateUser = (id, payload) => __awaiter(void 0, void 0, void 0, function* () { 38 | const isExist = yield user_model_1.User.findOne({ _id: id }); 39 | if (!isExist) { 40 | throw new ApiError_1.default(http_status_1.default.NOT_FOUND, 'User not found !'); 41 | } 42 | const result = yield user_model_1.User.findByIdAndUpdate(id, payload, { 43 | new: true, 44 | }); 45 | return result; 46 | }); 47 | const deleteUser = (id) => __awaiter(void 0, void 0, void 0, function* () { 48 | const result = yield user_model_1.User.findByIdAndDelete(id); 49 | return result; 50 | }); 51 | exports.UserService = { 52 | createUser, 53 | getAllUsers, 54 | getSingleUser, 55 | updateUser, 56 | deleteUser, 57 | }; 58 | -------------------------------------------------------------------------------- /src/app/middlewares/globalErrorHandler.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | /* eslint-disable no-console */ 3 | /* eslint-disable no-unused-expressions */ 4 | import { ErrorRequestHandler, NextFunction, Request, Response } from 'express'; 5 | import config from '../../config'; 6 | import ApiError from '../../errors/ApiError'; 7 | import handleValidationError from '../../errors/handleValidationError'; 8 | 9 | import { ZodError } from 'zod'; 10 | import handleCastError from '../../errors/handleCastError'; 11 | import handleZodError from '../../errors/handleZodError'; 12 | import { IGenericErrorMessage } from '../../interfaces/error'; 13 | // import { errorlogger } from '../../shared/logger'; 14 | 15 | const globalErrorHandler: ErrorRequestHandler = ( 16 | error, 17 | req: Request, 18 | res: Response, 19 | next: NextFunction 20 | ) => { 21 | config.env === 'development' 22 | ? console.log(`🐱‍🏍 globalErrorHandler ~~`, { error }) 23 | : console.log(`🐱‍🏍 globalErrorHandler ~~`, error); 24 | 25 | let statusCode = 500; 26 | let message = 'Something went wrong !'; 27 | let errorMessages: IGenericErrorMessage[] = []; 28 | 29 | if (error?.name === 'ValidationError') { 30 | const simplifiedError = handleValidationError(error); 31 | statusCode = simplifiedError.statusCode; 32 | message = simplifiedError.message; 33 | errorMessages = simplifiedError.errorMessages; 34 | } else if (error instanceof ZodError) { 35 | const simplifiedError = handleZodError(error); 36 | statusCode = simplifiedError.statusCode; 37 | message = simplifiedError.message; 38 | errorMessages = simplifiedError.errorMessages; 39 | } else if (error?.name === 'CastError') { 40 | const simplifiedError = handleCastError(error); 41 | statusCode = simplifiedError.statusCode; 42 | message = simplifiedError.message; 43 | errorMessages = simplifiedError.errorMessages; 44 | } else if (error instanceof ApiError) { 45 | statusCode = error?.statusCode; 46 | message = error.message; 47 | errorMessages = error?.message 48 | ? [ 49 | { 50 | path: '', 51 | message: error?.message, 52 | }, 53 | ] 54 | : []; 55 | } else if (error instanceof Error) { 56 | message = error?.message; 57 | errorMessages = error?.message 58 | ? [ 59 | { 60 | path: '', 61 | message: error?.message, 62 | }, 63 | ] 64 | : []; 65 | } 66 | 67 | res.status(statusCode).json({ 68 | success: false, 69 | message, 70 | errorMessages, 71 | stack: config.env !== 'production' ? error?.stack : undefined, 72 | }); 73 | }; 74 | 75 | export default globalErrorHandler; 76 | -------------------------------------------------------------------------------- /src/app/modules/cow/cow.controller.ts: -------------------------------------------------------------------------------- 1 | import { Request, RequestHandler, Response } from 'express'; 2 | import httpStatus from 'http-status'; 3 | import catchAsync from '../../../shared/catchAsync'; 4 | import pick from '../../../shared/pick'; 5 | import sendResponse from '../../../shared/sendResponse'; 6 | import { ICow } from './cow.interface'; 7 | import { CowService } from './cow.service'; 8 | import { paginationFields } from '../../../constants/pagination'; 9 | import { cowFilterableFields } from './cow.constants'; 10 | // cow controller 11 | const addCow: RequestHandler = catchAsync( 12 | async (req: Request, res: Response) => { 13 | 14 | const cow: ICow = req.body; 15 | 16 | const result = await CowService.addCow(cow); 17 | 18 | sendResponse(res, { 19 | statusCode: httpStatus.OK, 20 | success: true, 21 | message: 'Cow added successfully!', 22 | data: result, 23 | }); 24 | } 25 | ); 26 | 27 | const getAllCows = catchAsync(async (req: Request, res: Response) => { 28 | const filters = pick(req.query, cowFilterableFields); 29 | const paginationOptions = pick(req.query, paginationFields); 30 | 31 | const result = await CowService.getAllCows(filters, paginationOptions); 32 | 33 | const message = 34 | result.data.length > 0 ? 'Cow retrieved successfully !' : 'No cow founded'; 35 | 36 | sendResponse(res, { 37 | statusCode: httpStatus.OK, 38 | success: true, 39 | message: message, 40 | meta: result.meta, 41 | data: result.data, 42 | }); 43 | }); 44 | 45 | const getSingleCow = catchAsync(async (req: Request, res: Response) => { 46 | const id = req.params.id; 47 | 48 | const result = await CowService.getSingleCow(id); 49 | 50 | sendResponse(res, { 51 | statusCode: httpStatus.OK, 52 | success: true, 53 | message: 'Cow retrieved successfully !', 54 | data: result, 55 | }); 56 | }); 57 | 58 | const updateCow = catchAsync(async (req: Request, res: Response) => { 59 | const id = req.params.id; 60 | const updatedData = req.body; 61 | 62 | const result = await CowService.updateCow(id, updatedData); 63 | 64 | sendResponse(res, { 65 | statusCode: httpStatus.OK, 66 | success: true, 67 | message: 'Cow updated successfully !', 68 | data: result, 69 | }); 70 | }); 71 | 72 | const deleteCow = catchAsync(async (req: Request, res: Response) => { 73 | const id = req.params.id; 74 | 75 | const result = await CowService.deleteCow(id); 76 | 77 | sendResponse(res, { 78 | statusCode: httpStatus.OK, 79 | success: true, 80 | message: 'Cow deleted successfully !', 81 | data: result, 82 | }); 83 | }); 84 | 85 | export const CowController = { 86 | addCow, 87 | getAllCows, 88 | getSingleCow, 89 | updateCow, 90 | deleteCow 91 | }; 92 | -------------------------------------------------------------------------------- /dist/app/modules/cow/cow.validation.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.CowValidation = void 0; 4 | const zod_1 = require("zod"); 5 | const cow_constants_1 = require("./cow.constants"); 6 | const addCowZodSchema = zod_1.z.object({ 7 | body: zod_1.z.object({ 8 | name: zod_1.z.string({ 9 | required_error: 'Name is required', 10 | }), 11 | age: zod_1.z.number({ 12 | required_error: 'Age is required', 13 | }), 14 | price: zod_1.z.number({ 15 | required_error: 'Price is required', 16 | }), 17 | location: zod_1.z.enum([...cow_constants_1.CowLocation], { 18 | required_error: 'Location is required', 19 | }), 20 | breed: zod_1.z.enum([...cow_constants_1.CowBreed], { 21 | required_error: 'Breed is required', 22 | }), 23 | weight: zod_1.z.number({ 24 | required_error: 'Weight is required', 25 | }), 26 | label: zod_1.z.enum([...cow_constants_1.CowLabel], { 27 | required_error: 'Label is required', 28 | }), 29 | category: zod_1.z.enum([...cow_constants_1.CowCategory], { 30 | required_error: 'Category is required', 31 | }), 32 | seller: zod_1.z.string({ 33 | required_error: 'Seller Referance is required', 34 | }), 35 | }), 36 | }); 37 | const updateCowZodSchema = zod_1.z.object({ 38 | body: zod_1.z.object({ 39 | name: zod_1.z.string({ 40 | required_error: 'Name is required', 41 | }).optional(), 42 | age: zod_1.z.number({ 43 | required_error: 'Age is required', 44 | }).optional(), 45 | price: zod_1.z.number({ 46 | required_error: 'Price is required', 47 | }).optional(), 48 | location: zod_1.z.enum([...cow_constants_1.CowLocation], { 49 | required_error: 'Location is required', 50 | }).optional(), 51 | breed: zod_1.z.enum([...cow_constants_1.CowBreed], { 52 | required_error: 'Breed is required', 53 | }).optional(), 54 | weight: zod_1.z.number({ 55 | required_error: 'Weight is required', 56 | }).optional(), 57 | label: zod_1.z.enum([...cow_constants_1.CowLabel], { 58 | required_error: 'Label is required', 59 | }).optional(), 60 | category: zod_1.z.enum([...cow_constants_1.CowCategory], { 61 | required_error: 'Category is required', 62 | }).optional(), 63 | seller: zod_1.z.string({ 64 | required_error: 'Seller Referance is required', 65 | }).optional(), 66 | }), 67 | }); 68 | exports.CowValidation = { 69 | addCowZodSchema, 70 | updateCowZodSchema, 71 | }; 72 | -------------------------------------------------------------------------------- /src/app/modules/order/order.service.ts: -------------------------------------------------------------------------------- 1 | import httpStatus from 'http-status'; 2 | import mongoose from 'mongoose'; 3 | import ApiError from '../../../errors/ApiError'; 4 | import { Cow } from '../cow/cow.model'; 5 | import { User } from '../user/user.model'; 6 | import { IOrder } from './order.interface'; 7 | import { Order } from './order.model'; 8 | 9 | const cowOrder = async (data: IOrder): Promise => { 10 | const session = await mongoose.startSession(); 11 | try { 12 | // Simulate the transaction process 13 | const { cow, buyer } = data; 14 | session.startTransaction(); 15 | 16 | const buyerUser = await User.findOne({ 17 | _id: buyer, 18 | role: 'buyer', 19 | }); 20 | const AvailableCow = await Cow.findOne({ _id: cow, label: 'for sale' }); 21 | 22 | if (!buyerUser) { 23 | throw new ApiError(httpStatus.BAD_REQUEST, "Buyer doesn't exist !"); 24 | } 25 | 26 | if (!AvailableCow) { 27 | throw new ApiError( 28 | httpStatus.BAD_REQUEST, 29 | 'Cow is not available for sale' 30 | ); 31 | } 32 | 33 | if (AvailableCow.price > buyerUser?.budget) { 34 | throw new ApiError(httpStatus.BAD_REQUEST, 'Buyer budget is not enough'); 35 | } 36 | 37 | const updatedBuyer = await User.findByIdAndUpdate( 38 | buyer, 39 | { budget: buyerUser.budget - AvailableCow.price }, 40 | { new: true } 41 | ); 42 | if (!updatedBuyer) { 43 | throw new ApiError( 44 | httpStatus.BAD_REQUEST, 45 | "Failed to update buyer's budget" 46 | ); 47 | } 48 | 49 | const seller = await User.findOne({ 50 | _id: AvailableCow.seller, 51 | role: 'seller', 52 | }); 53 | 54 | if (!seller) { 55 | throw new ApiError(httpStatus.BAD_REQUEST, "Seller doesn't exist !"); 56 | } 57 | 58 | const updatedSeller = await User.findByIdAndUpdate( 59 | AvailableCow.seller, 60 | { income: seller.income + AvailableCow.price }, 61 | { new: true } 62 | ); 63 | 64 | if (!updatedSeller) { 65 | throw new ApiError( 66 | httpStatus.BAD_REQUEST, 67 | "Failed to update seller's income" 68 | ); 69 | } 70 | 71 | const updatedCow = await Cow.findByIdAndUpdate( 72 | cow, 73 | { label: 'sold out' }, 74 | { new: true } 75 | ); 76 | 77 | if (!updatedCow) { 78 | throw new ApiError( 79 | httpStatus.BAD_REQUEST, 80 | "Failed to update cow's status" 81 | ); 82 | } 83 | 84 | const order = new Order({ cow, buyer }); 85 | 86 | await order.save({ session }); 87 | await session.commitTransaction(); 88 | session.endSession(); 89 | 90 | return order; 91 | } catch (error) { 92 | await session.abortTransaction(); 93 | session.endSession(); 94 | throw error; 95 | } 96 | }; 97 | 98 | const getAllOrders = async (): Promise => { 99 | const orders = await Order.find().populate('cow').populate('buyer'); 100 | return orders; 101 | }; 102 | 103 | export const OrderService = { 104 | cowOrder, 105 | getAllOrders, 106 | }; 107 | -------------------------------------------------------------------------------- /dist/app/middlewares/globalErrorHandler.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const config_1 = __importDefault(require("../../config")); 7 | const ApiError_1 = __importDefault(require("../../errors/ApiError")); 8 | const handleValidationError_1 = __importDefault(require("../../errors/handleValidationError")); 9 | const zod_1 = require("zod"); 10 | const handleCastError_1 = __importDefault(require("../../errors/handleCastError")); 11 | const handleZodError_1 = __importDefault(require("../../errors/handleZodError")); 12 | // import { errorlogger } from '../../shared/logger'; 13 | const globalErrorHandler = (error, req, res, next) => { 14 | config_1.default.env === 'development' 15 | ? console.log(`🐱‍🏍 globalErrorHandler ~~`, { error }) 16 | : console.log(`🐱‍🏍 globalErrorHandler ~~`, error); 17 | let statusCode = 500; 18 | let message = 'Something went wrong !'; 19 | let errorMessages = []; 20 | if ((error === null || error === void 0 ? void 0 : error.name) === 'ValidationError') { 21 | const simplifiedError = (0, handleValidationError_1.default)(error); 22 | statusCode = simplifiedError.statusCode; 23 | message = simplifiedError.message; 24 | errorMessages = simplifiedError.errorMessages; 25 | } 26 | else if (error instanceof zod_1.ZodError) { 27 | const simplifiedError = (0, handleZodError_1.default)(error); 28 | statusCode = simplifiedError.statusCode; 29 | message = simplifiedError.message; 30 | errorMessages = simplifiedError.errorMessages; 31 | } 32 | else if ((error === null || error === void 0 ? void 0 : error.name) === 'CastError') { 33 | const simplifiedError = (0, handleCastError_1.default)(error); 34 | statusCode = simplifiedError.statusCode; 35 | message = simplifiedError.message; 36 | errorMessages = simplifiedError.errorMessages; 37 | } 38 | else if (error instanceof ApiError_1.default) { 39 | statusCode = error === null || error === void 0 ? void 0 : error.statusCode; 40 | message = error.message; 41 | errorMessages = (error === null || error === void 0 ? void 0 : error.message) 42 | ? [ 43 | { 44 | path: '', 45 | message: error === null || error === void 0 ? void 0 : error.message, 46 | }, 47 | ] 48 | : []; 49 | } 50 | else if (error instanceof Error) { 51 | message = error === null || error === void 0 ? void 0 : error.message; 52 | errorMessages = (error === null || error === void 0 ? void 0 : error.message) 53 | ? [ 54 | { 55 | path: '', 56 | message: error === null || error === void 0 ? void 0 : error.message, 57 | }, 58 | ] 59 | : []; 60 | } 61 | res.status(statusCode).json({ 62 | success: false, 63 | message, 64 | errorMessages, 65 | stack: config_1.default.env !== 'production' ? error === null || error === void 0 ? void 0 : error.stack : undefined, 66 | }); 67 | }; 68 | exports.default = globalErrorHandler; 69 | -------------------------------------------------------------------------------- /logs/winston/errors/.e94f1ce02758f7c5d122d50a8ac7d9a84f2279f7-audit.json: -------------------------------------------------------------------------------- 1 | { 2 | "keep": { 3 | "days": true, 4 | "amount": 14 5 | }, 6 | "auditLog": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\.e94f1ce02758f7c5d122d50a8ac7d9a84f2279f7-audit.json", 7 | "files": [ 8 | { 9 | "date": 1686997750073, 10 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-17-06-16-error.log", 11 | "hash": "53f766b931376a6564cbd2ee184bc523714e78c9c5b3bcfb2d04e68ce7c7155e" 12 | }, 13 | { 14 | "date": 1686999920780, 15 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-17-06-17-error.log", 16 | "hash": "94b767bcb02c80505dbffc838797926101dcfe69c592fa08ee50c776ce803fa3" 17 | }, 18 | { 19 | "date": 1687017384531, 20 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-17-06-21-error.log", 21 | "hash": "eaf8bf48c8230cb40e79455cff1b86aaf9431a0022e94948fd9b27ea63ebde15" 22 | }, 23 | { 24 | "date": 1687052302963, 25 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-18-06-07-error.log", 26 | "hash": "eb068228e4b4566f5a3fa4567b27cf4365f42649e5470acb5936c5f8861967c6" 27 | }, 28 | { 29 | "date": 1687053619521, 30 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-18-06-08-error.log", 31 | "hash": "7d24da6b18e259c1f21e2b20900d8aa0cdfedd8ec56a5ade72febc2dce6a8bc2" 32 | }, 33 | { 34 | "date": 1687057680371, 35 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-18-06-09-error.log", 36 | "hash": "f0d7db14c4f4bade6848b7587cab2e4bd0d7eb6ec5d7f4637834d82ce7f459f1" 37 | }, 38 | { 39 | "date": 1687060878533, 40 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-18-06-10-error.log", 41 | "hash": "0cf4c7eaa4769820a4cb920c6f4460b0744160fe3e0320621ee5addc0cdd0a40" 42 | }, 43 | { 44 | "date": 1687094388229, 45 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-18-06-19-error.log", 46 | "hash": "12660b6efd1d50e6cc1caa3e4c6a84eb623659a5429138f39065db73148d84c7" 47 | }, 48 | { 49 | "date": 1687099084208, 50 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-18-06-20-error.log", 51 | "hash": "ff589319fd9b531310453a1f7facdd632fa14cb2fca143f0bffe536d5ff41ad9" 52 | }, 53 | { 54 | "date": 1687100414950, 55 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\errors\\phu-2023-18-06-21-error.log", 56 | "hash": "5506f8b763bf4e07d2b5abdf3689f06e0528f52e249636014e503962dafb807c" 57 | } 58 | ], 59 | "hashType": "sha256" 60 | } -------------------------------------------------------------------------------- /logs/winston/successes/.d0ded42ce3edcdfabaa88d9fcc4398bf83df5241-audit.json: -------------------------------------------------------------------------------- 1 | { 2 | "keep": { 3 | "days": true, 4 | "amount": 14 5 | }, 6 | "auditLog": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\.d0ded42ce3edcdfabaa88d9fcc4398bf83df5241-audit.json", 7 | "files": [ 8 | { 9 | "date": 1686997750059, 10 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-17-06-16-success.log", 11 | "hash": "77863d3091e4235e8e9e8416a9e18e51ed2ca60bbb029ec15200d3c19a7c0a85" 12 | }, 13 | { 14 | "date": 1686999920770, 15 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-17-06-17-success.log", 16 | "hash": "ea3fcc90203282f2a4201b9a49f2debcce8d1d7687758c1f6c66aaac9963e8c8" 17 | }, 18 | { 19 | "date": 1687017384513, 20 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-17-06-21-success.log", 21 | "hash": "a7fbccb90b18a355805eef6370ba6082548eaa4a9e92baf8c670f2a39874670e" 22 | }, 23 | { 24 | "date": 1687052302927, 25 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-18-06-07-success.log", 26 | "hash": "615267d7eb4e8bd30b6bd4bcad2ba27bcfa34a7e12d1f922bc62e96deb3b031b" 27 | }, 28 | { 29 | "date": 1687053619515, 30 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-18-06-08-success.log", 31 | "hash": "8722dc27d83cab8cb2e4fa90615d56f9093bb10b8b29a6dd2228e7dfe775a647" 32 | }, 33 | { 34 | "date": 1687057680365, 35 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-18-06-09-success.log", 36 | "hash": "3a2624866f24794b650d9f38d4cd7d16cb979fcd8d38379d417ba1b408521dcb" 37 | }, 38 | { 39 | "date": 1687060878524, 40 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-18-06-10-success.log", 41 | "hash": "ca1ef298d5958708b15d26f501cbdf31e9f6f6ce420cdda86fd6036deff4e764" 42 | }, 43 | { 44 | "date": 1687094388198, 45 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-18-06-19-success.log", 46 | "hash": "c8e3b501df335979c2aa392d8b0664168d851688f4c1d30202d61fe51c8248f7" 47 | }, 48 | { 49 | "date": 1687099084048, 50 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-18-06-20-success.log", 51 | "hash": "0e7227f51e711aa010bba94f2144bfe0c18b1bed9777ac9cb855dcb2d40c02a9" 52 | }, 53 | { 54 | "date": 1687100414942, 55 | "name": "E:\\Next-Level-Web-Development\\Mission 3 Be A NoSQL Backend Braniac\\assignment-3\\logs\\winston\\successes\\phu-2023-18-06-21-success.log", 56 | "hash": "8a2630d2298e98b26467413b27c9f343f5d4c4b5d2bc0eeb345d180b5e198159" 57 | } 58 | ], 59 | "hashType": "sha256" 60 | } -------------------------------------------------------------------------------- /src/app/modules/cow/cow.service.ts: -------------------------------------------------------------------------------- 1 | import httpStatus from 'http-status'; 2 | import { SortOrder } from 'mongoose'; 3 | import ApiError from '../../../errors/ApiError'; 4 | import { paginationHelpers } from '../../../helpers/paginationHelper'; 5 | import { IGenericResponse } from '../../../interfaces/common'; 6 | import { IPaginationOptions } from '../../../interfaces/pagination'; 7 | import { User } from '../user/user.model'; 8 | import { cowSearchableFields } from './cow.constants'; 9 | import { ICow, ICowFilters } from './cow.interface'; 10 | import { Cow } from './cow.model'; 11 | 12 | const addCow = async (cow: ICow): Promise => { 13 | const user = await User.findOne({ 14 | _id: cow.seller, 15 | role: 'seller', 16 | }); 17 | if (!user) { 18 | throw new ApiError(httpStatus.NOT_FOUND, 'Seller not found !'); 19 | } 20 | const addedCow = await Cow.create(cow); 21 | 22 | if (!addedCow) { 23 | throw new ApiError(400, 'Failed to add cow'); 24 | } 25 | return addedCow; 26 | }; 27 | 28 | const getAllCows = async ( 29 | filters: ICowFilters, 30 | paginationOptions: IPaginationOptions 31 | ): Promise> => { 32 | const { searchTerm, ...filtersData } = filters; 33 | const { page, limit, skip, sortBy, sortOrder } = 34 | paginationHelpers.calculatePagination(paginationOptions); 35 | 36 | const andConditions = []; 37 | 38 | if (searchTerm) { 39 | andConditions.push({ 40 | $or: cowSearchableFields.map(field => ({ 41 | [field]: { 42 | $regex: searchTerm, 43 | $options: typeof searchTerm === 'string' ? 'i' : undefined, 44 | }, 45 | })), 46 | }); 47 | } 48 | 49 | if (Object.keys(filtersData).length) { 50 | andConditions.push({ 51 | $and: Object.entries(filtersData).map(([field, value]) => { 52 | if (field === 'minPrice') { 53 | return { price: { $gte: value } }; 54 | } else if (field === 'maxPrice') { 55 | return { price: { $lte: value } }; 56 | } 57 | return { 58 | [field]: value, 59 | }; 60 | }), 61 | }); 62 | } 63 | 64 | 65 | const sortConditions: { [key: string]: SortOrder } = {}; 66 | 67 | if (sortBy && sortOrder) { 68 | sortConditions[sortBy] = sortOrder; 69 | } 70 | const whereConditions = 71 | andConditions.length > 0 ? { $and: andConditions } : {}; 72 | 73 | const result = await Cow.find(whereConditions) 74 | .sort(sortConditions) 75 | .skip(skip) 76 | .limit(limit); 77 | 78 | const total = await Cow.countDocuments(whereConditions); 79 | 80 | return { 81 | meta: { 82 | page, 83 | limit, 84 | total, 85 | }, 86 | data: result, 87 | }; 88 | }; 89 | 90 | const getSingleCow = async (id: string): Promise => { 91 | const result = await Cow.findById(id); 92 | return result; 93 | }; 94 | 95 | const updateCow = async ( 96 | id: string, 97 | payload: Partial 98 | ): Promise => { 99 | const isExist = await Cow.findOne({ _id: id }); 100 | 101 | if (!isExist) { 102 | throw new ApiError(httpStatus.NOT_FOUND, 'Cow not found !'); 103 | } 104 | 105 | const result = await Cow.findByIdAndUpdate(id, payload, { 106 | new: true, 107 | }); 108 | return result; 109 | }; 110 | 111 | const deleteCow = async (id: string): Promise => { 112 | const result = await Cow.findByIdAndDelete(id); 113 | return result; 114 | }; 115 | 116 | export const CowService = { 117 | addCow, 118 | getAllCows, 119 | getSingleCow, 120 | updateCow, 121 | deleteCow, 122 | }; 123 | -------------------------------------------------------------------------------- /dist/app/modules/user/user.controller.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __importDefault = (this && this.__importDefault) || function (mod) { 12 | return (mod && mod.__esModule) ? mod : { "default": mod }; 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | exports.UserController = void 0; 16 | const http_status_1 = __importDefault(require("http-status")); 17 | const catchAsync_1 = __importDefault(require("../../../shared/catchAsync")); 18 | const sendResponse_1 = __importDefault(require("../../../shared/sendResponse")); 19 | const user_service_1 = require("./user.service"); 20 | const createUser = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 21 | // const { user } = req.body; 22 | // console.log(req.body); 23 | const user = req.body; 24 | const result = yield user_service_1.UserService.createUser(user); 25 | (0, sendResponse_1.default)(res, { 26 | statusCode: http_status_1.default.OK, 27 | success: true, 28 | message: 'user created successfully!', 29 | data: result, 30 | }); 31 | })); 32 | const getAllUsers = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 33 | const result = yield user_service_1.UserService.getAllUsers(); 34 | const message = result.length > 0 35 | ? 'User retrieved successfully !' 36 | : 'No user founded'; 37 | (0, sendResponse_1.default)(res, { 38 | statusCode: http_status_1.default.OK, 39 | success: true, 40 | message: message, 41 | data: result, 42 | }); 43 | })); 44 | const getSingleUser = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 45 | const id = req.params.id; 46 | const result = yield user_service_1.UserService.getSingleUser(id); 47 | (0, sendResponse_1.default)(res, { 48 | statusCode: http_status_1.default.OK, 49 | success: true, 50 | message: 'User retrieved successfully !', 51 | data: result, 52 | }); 53 | })); 54 | const updateUser = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 55 | const id = req.params.id; 56 | const updatedData = req.body; 57 | const result = yield user_service_1.UserService.updateUser(id, updatedData); 58 | (0, sendResponse_1.default)(res, { 59 | statusCode: http_status_1.default.OK, 60 | success: true, 61 | message: 'User updated successfully !', 62 | data: result, 63 | }); 64 | })); 65 | const deleteUser = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 66 | const id = req.params.id; 67 | const result = yield user_service_1.UserService.deleteUser(id); 68 | (0, sendResponse_1.default)(res, { 69 | statusCode: http_status_1.default.OK, 70 | success: true, 71 | message: 'User deleted successfully !', 72 | data: result, 73 | }); 74 | })); 75 | exports.UserController = { 76 | createUser, 77 | getAllUsers, 78 | getSingleUser, 79 | updateUser, 80 | deleteUser, 81 | }; 82 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-18-06-09-success.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 9:10:10 } [PH] info: 🛢Database is connected successfully 2 | Sun Jun 18 2023 9:10:10 } [PH] info: Application listening on port 5000 3 | Sun Jun 18 2023 9:12:5 } [PH] info: 🛢Database is connected successfully 4 | Sun Jun 18 2023 9:12:5 } [PH] info: Application listening on port 5000 5 | Sun Jun 18 2023 9:13:18 } [PH] info: 🛢Database is connected successfully 6 | Sun Jun 18 2023 9:13:18 } [PH] info: Application listening on port 5000 7 | Sun Jun 18 2023 9:14:44 } [PH] info: 🛢Database is connected successfully 8 | Sun Jun 18 2023 9:14:44 } [PH] info: Application listening on port 5000 9 | Sun Jun 18 2023 9:14:50 } [PH] info: 🛢Database is connected successfully 10 | Sun Jun 18 2023 9:14:50 } [PH] info: Application listening on port 5000 11 | Sun Jun 18 2023 9:15:17 } [PH] info: 🛢Database is connected successfully 12 | Sun Jun 18 2023 9:15:17 } [PH] info: Application listening on port 5000 13 | Sun Jun 18 2023 9:15:52 } [PH] info: 🛢Database is connected successfully 14 | Sun Jun 18 2023 9:15:52 } [PH] info: Application listening on port 5000 15 | Sun Jun 18 2023 9:16:5 } [PH] info: 🛢Database is connected successfully 16 | Sun Jun 18 2023 9:16:5 } [PH] info: Application listening on port 5000 17 | Sun Jun 18 2023 9:17:35 } [PH] info: 🛢Database is connected successfully 18 | Sun Jun 18 2023 9:17:35 } [PH] info: Application listening on port 5000 19 | Sun Jun 18 2023 9:17:44 } [PH] info: 🛢Database is connected successfully 20 | Sun Jun 18 2023 9:17:44 } [PH] info: Application listening on port 5000 21 | Sun Jun 18 2023 9:23:50 } [PH] info: 🛢Database is connected successfully 22 | Sun Jun 18 2023 9:23:50 } [PH] info: Application listening on port 5000 23 | Sun Jun 18 2023 9:23:56 } [PH] info: 🛢Database is connected successfully 24 | Sun Jun 18 2023 9:23:56 } [PH] info: Application listening on port 5000 25 | Sun Jun 18 2023 9:25:19 } [PH] info: 🛢Database is connected successfully 26 | Sun Jun 18 2023 9:25:19 } [PH] info: Application listening on port 5000 27 | Sun Jun 18 2023 9:25:30 } [PH] info: 🛢Database is connected successfully 28 | Sun Jun 18 2023 9:25:30 } [PH] info: Application listening on port 5000 29 | Sun Jun 18 2023 9:26:16 } [PH] info: 🛢Database is connected successfully 30 | Sun Jun 18 2023 9:26:16 } [PH] info: Application listening on port 5000 31 | Sun Jun 18 2023 9:29:24 } [PH] info: 🛢Database is connected successfully 32 | Sun Jun 18 2023 9:29:24 } [PH] info: Application listening on port 5000 33 | Sun Jun 18 2023 9:29:30 } [PH] info: 🛢Database is connected successfully 34 | Sun Jun 18 2023 9:29:30 } [PH] info: Application listening on port 5000 35 | Sun Jun 18 2023 9:30:56 } [PH] info: 🛢Database is connected successfully 36 | Sun Jun 18 2023 9:30:56 } [PH] info: Application listening on port 5000 37 | Sun Jun 18 2023 9:34:3 } [PH] info: 🛢Database is connected successfully 38 | Sun Jun 18 2023 9:34:3 } [PH] info: Application listening on port 5000 39 | Sun Jun 18 2023 9:34:8 } [PH] info: 🛢Database is connected successfully 40 | Sun Jun 18 2023 9:34:8 } [PH] info: Application listening on port 5000 41 | Sun Jun 18 2023 9:37:1 } [PH] info: 🛢Database is connected successfully 42 | Sun Jun 18 2023 9:37:1 } [PH] info: Application listening on port 5000 43 | Sun Jun 18 2023 9:40:15 } [PH] info: 🛢Database is connected successfully 44 | Sun Jun 18 2023 9:40:15 } [PH] info: Application listening on port 5000 45 | Sun Jun 18 2023 9:54:19 } [PH] info: 🛢Database is connected successfully 46 | Sun Jun 18 2023 9:54:19 } [PH] info: Application listening on port 5000 47 | Sun Jun 18 2023 9:54:32 } [PH] info: 🛢Database is connected successfully 48 | Sun Jun 18 2023 9:54:32 } [PH] info: Application listening on port 5000 49 | Sun Jun 18 2023 9:54:58 } [PH] info: 🛢Database is connected successfully 50 | Sun Jun 18 2023 9:54:58 } [PH] info: Application listening on port 5000 51 | -------------------------------------------------------------------------------- /dist/app/modules/cow/cow.controller.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __importDefault = (this && this.__importDefault) || function (mod) { 12 | return (mod && mod.__esModule) ? mod : { "default": mod }; 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | exports.CowController = void 0; 16 | const http_status_1 = __importDefault(require("http-status")); 17 | const catchAsync_1 = __importDefault(require("../../../shared/catchAsync")); 18 | const pick_1 = __importDefault(require("../../../shared/pick")); 19 | const sendResponse_1 = __importDefault(require("../../../shared/sendResponse")); 20 | const cow_service_1 = require("./cow.service"); 21 | const pagination_1 = require("../../../constants/pagination"); 22 | const cow_constants_1 = require("./cow.constants"); 23 | const addCow = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 24 | const cow = req.body; 25 | const result = yield cow_service_1.CowService.addCow(cow); 26 | (0, sendResponse_1.default)(res, { 27 | statusCode: http_status_1.default.OK, 28 | success: true, 29 | message: 'Cow added successfully!', 30 | data: result, 31 | }); 32 | })); 33 | const getAllCows = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 34 | const filters = (0, pick_1.default)(req.query, cow_constants_1.cowFilterableFields); 35 | const paginationOptions = (0, pick_1.default)(req.query, pagination_1.paginationFields); 36 | const result = yield cow_service_1.CowService.getAllCows(filters, paginationOptions); 37 | const message = result.data.length > 0 ? 'Cow retrieved successfully !' : 'No cow founded'; 38 | (0, sendResponse_1.default)(res, { 39 | statusCode: http_status_1.default.OK, 40 | success: true, 41 | message: message, 42 | meta: result.meta, 43 | data: result.data, 44 | }); 45 | })); 46 | const getSingleCow = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 47 | const id = req.params.id; 48 | const result = yield cow_service_1.CowService.getSingleCow(id); 49 | (0, sendResponse_1.default)(res, { 50 | statusCode: http_status_1.default.OK, 51 | success: true, 52 | message: 'Cow retrieved successfully !', 53 | data: result, 54 | }); 55 | })); 56 | const updateCow = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 57 | const id = req.params.id; 58 | const updatedData = req.body; 59 | const result = yield cow_service_1.CowService.updateCow(id, updatedData); 60 | (0, sendResponse_1.default)(res, { 61 | statusCode: http_status_1.default.OK, 62 | success: true, 63 | message: 'Cow updated successfully !', 64 | data: result, 65 | }); 66 | })); 67 | const deleteCow = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { 68 | const id = req.params.id; 69 | const result = yield cow_service_1.CowService.deleteCow(id); 70 | (0, sendResponse_1.default)(res, { 71 | statusCode: http_status_1.default.OK, 72 | success: true, 73 | message: 'Cow deleted successfully !', 74 | data: result, 75 | }); 76 | })); 77 | exports.CowController = { 78 | addCow, 79 | getAllCows, 80 | getSingleCow, 81 | updateCow, 82 | deleteCow 83 | }; 84 | -------------------------------------------------------------------------------- /dist/app/modules/order/order.service.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __importDefault = (this && this.__importDefault) || function (mod) { 12 | return (mod && mod.__esModule) ? mod : { "default": mod }; 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | exports.OrderService = void 0; 16 | const http_status_1 = __importDefault(require("http-status")); 17 | const mongoose_1 = __importDefault(require("mongoose")); 18 | const ApiError_1 = __importDefault(require("../../../errors/ApiError")); 19 | const cow_model_1 = require("../cow/cow.model"); 20 | const user_model_1 = require("../user/user.model"); 21 | const order_model_1 = require("./order.model"); 22 | const cowOrder = (data) => __awaiter(void 0, void 0, void 0, function* () { 23 | const session = yield mongoose_1.default.startSession(); 24 | try { 25 | // Simulate the transaction process 26 | const { cow, buyer } = data; 27 | session.startTransaction(); 28 | const buyerUser = yield user_model_1.User.findOne({ 29 | _id: buyer, 30 | role: 'buyer', 31 | }); 32 | const AvailableCow = yield cow_model_1.Cow.findOne({ _id: cow, label: 'for sale' }); 33 | if (!buyerUser) { 34 | throw new ApiError_1.default(http_status_1.default.BAD_REQUEST, "Buyer doesn't exist !"); 35 | } 36 | if (!AvailableCow) { 37 | throw new ApiError_1.default(http_status_1.default.BAD_REQUEST, 'Cow is not available for sale'); 38 | } 39 | if (AvailableCow.price > (buyerUser === null || buyerUser === void 0 ? void 0 : buyerUser.budget)) { 40 | throw new ApiError_1.default(http_status_1.default.BAD_REQUEST, 'Buyer budget is not enough'); 41 | } 42 | const updatedBuyer = yield user_model_1.User.findByIdAndUpdate(buyer, { budget: buyerUser.budget - AvailableCow.price }, { new: true }); 43 | if (!updatedBuyer) { 44 | throw new ApiError_1.default(http_status_1.default.BAD_REQUEST, "Failed to update buyer's budget"); 45 | } 46 | const seller = yield user_model_1.User.findOne({ 47 | _id: AvailableCow.seller, 48 | role: 'seller', 49 | }); 50 | if (!seller) { 51 | throw new ApiError_1.default(http_status_1.default.BAD_REQUEST, "Seller doesn't exist !"); 52 | } 53 | const updatedSeller = yield user_model_1.User.findByIdAndUpdate(AvailableCow.seller, { income: seller.income + AvailableCow.price }, { new: true }); 54 | if (!updatedSeller) { 55 | throw new ApiError_1.default(http_status_1.default.BAD_REQUEST, "Failed to update seller's income"); 56 | } 57 | const updatedCow = yield cow_model_1.Cow.findByIdAndUpdate(cow, { label: 'sold out' }, { new: true }); 58 | if (!updatedCow) { 59 | throw new ApiError_1.default(http_status_1.default.BAD_REQUEST, "Failed to update cow's status"); 60 | } 61 | const order = new order_model_1.Order({ cow, buyer }); 62 | yield order.save({ session }); 63 | yield session.commitTransaction(); 64 | session.endSession(); 65 | return order; 66 | } 67 | catch (error) { 68 | yield session.abortTransaction(); 69 | session.endSession(); 70 | throw error; 71 | } 72 | }); 73 | const getAllOrders = () => __awaiter(void 0, void 0, void 0, function* () { 74 | const orders = yield order_model_1.Order.find().populate('cow').populate('buyer'); 75 | return orders; 76 | }); 77 | exports.OrderService = { 78 | cowOrder, 79 | getAllOrders, 80 | }; 81 | -------------------------------------------------------------------------------- /dist/app/modules/cow/cow.service.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __rest = (this && this.__rest) || function (s, e) { 12 | var t = {}; 13 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) 14 | t[p] = s[p]; 15 | if (s != null && typeof Object.getOwnPropertySymbols === "function") 16 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { 17 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) 18 | t[p[i]] = s[p[i]]; 19 | } 20 | return t; 21 | }; 22 | var __importDefault = (this && this.__importDefault) || function (mod) { 23 | return (mod && mod.__esModule) ? mod : { "default": mod }; 24 | }; 25 | Object.defineProperty(exports, "__esModule", { value: true }); 26 | exports.CowService = void 0; 27 | const http_status_1 = __importDefault(require("http-status")); 28 | const ApiError_1 = __importDefault(require("../../../errors/ApiError")); 29 | const paginationHelper_1 = require("../../../helpers/paginationHelper"); 30 | const user_model_1 = require("../user/user.model"); 31 | const cow_constants_1 = require("./cow.constants"); 32 | const cow_model_1 = require("./cow.model"); 33 | const addCow = (cow) => __awaiter(void 0, void 0, void 0, function* () { 34 | const user = yield user_model_1.User.findOne({ 35 | _id: cow.seller, 36 | role: 'seller', 37 | }); 38 | if (!user) { 39 | throw new ApiError_1.default(http_status_1.default.NOT_FOUND, 'Seller not found !'); 40 | } 41 | const addedCow = yield cow_model_1.Cow.create(cow); 42 | if (!addedCow) { 43 | throw new ApiError_1.default(400, 'Failed to add cow'); 44 | } 45 | return addedCow; 46 | }); 47 | const getAllCows = (filters, paginationOptions) => __awaiter(void 0, void 0, void 0, function* () { 48 | const { searchTerm } = filters, filtersData = __rest(filters, ["searchTerm"]); 49 | const { page, limit, skip, sortBy, sortOrder } = paginationHelper_1.paginationHelpers.calculatePagination(paginationOptions); 50 | const andConditions = []; 51 | if (searchTerm) { 52 | andConditions.push({ 53 | $or: cow_constants_1.cowSearchableFields.map(field => ({ 54 | [field]: { 55 | $regex: searchTerm, 56 | $options: typeof searchTerm === 'string' ? 'i' : undefined, 57 | }, 58 | })), 59 | }); 60 | } 61 | if (Object.keys(filtersData).length) { 62 | andConditions.push({ 63 | $and: Object.entries(filtersData).map(([field, value]) => { 64 | if (field === 'minPrice') { 65 | return { price: { $gte: value } }; 66 | } 67 | else if (field === 'maxPrice') { 68 | return { price: { $lte: value } }; 69 | } 70 | return { 71 | [field]: value, 72 | }; 73 | }), 74 | }); 75 | } 76 | const sortConditions = {}; 77 | if (sortBy && sortOrder) { 78 | sortConditions[sortBy] = sortOrder; 79 | } 80 | const whereConditions = andConditions.length > 0 ? { $and: andConditions } : {}; 81 | const result = yield cow_model_1.Cow.find(whereConditions) 82 | .sort(sortConditions) 83 | .skip(skip) 84 | .limit(limit); 85 | const total = yield cow_model_1.Cow.countDocuments(whereConditions); 86 | return { 87 | meta: { 88 | page, 89 | limit, 90 | total, 91 | }, 92 | data: result, 93 | }; 94 | }); 95 | const getSingleCow = (id) => __awaiter(void 0, void 0, void 0, function* () { 96 | const result = yield cow_model_1.Cow.findById(id); 97 | return result; 98 | }); 99 | const updateCow = (id, payload) => __awaiter(void 0, void 0, void 0, function* () { 100 | const isExist = yield cow_model_1.Cow.findOne({ _id: id }); 101 | if (!isExist) { 102 | throw new ApiError_1.default(http_status_1.default.NOT_FOUND, 'Cow not found !'); 103 | } 104 | const result = yield cow_model_1.Cow.findByIdAndUpdate(id, payload, { 105 | new: true, 106 | }); 107 | return result; 108 | }); 109 | const deleteCow = (id) => __awaiter(void 0, void 0, void 0, function* () { 110 | const result = yield cow_model_1.Cow.findByIdAndDelete(id); 111 | return result; 112 | }); 113 | exports.CowService = { 114 | addCow, 115 | getAllCows, 116 | getSingleCow, 117 | updateCow, 118 | deleteCow, 119 | }; 120 | -------------------------------------------------------------------------------- /logs/winston/successes/phu-2023-18-06-08-success.log: -------------------------------------------------------------------------------- 1 | Sun Jun 18 2023 8:0:20 } [PH] info: 🛢Database is connected successfully 2 | Sun Jun 18 2023 8:0:20 } [PH] info: Application listening on port 5000 3 | Sun Jun 18 2023 8:1:56 } [PH] info: 🛢Database is connected successfully 4 | Sun Jun 18 2023 8:1:56 } [PH] info: Application listening on port 5000 5 | Sun Jun 18 2023 8:5:23 } [PH] info: 🛢Database is connected successfully 6 | Sun Jun 18 2023 8:5:23 } [PH] info: Application listening on port 5000 7 | Sun Jun 18 2023 8:5:43 } [PH] info: 🛢Database is connected successfully 8 | Sun Jun 18 2023 8:5:43 } [PH] info: Application listening on port 5000 9 | Sun Jun 18 2023 8:8:28 } [PH] info: 🛢Database is connected successfully 10 | Sun Jun 18 2023 8:8:28 } [PH] info: Application listening on port 5000 11 | Sun Jun 18 2023 8:10:35 } [PH] info: 🛢Database is connected successfully 12 | Sun Jun 18 2023 8:10:35 } [PH] info: Application listening on port 5000 13 | Sun Jun 18 2023 8:11:0 } [PH] info: 🛢Database is connected successfully 14 | Sun Jun 18 2023 8:11:0 } [PH] info: Application listening on port 5000 15 | Sun Jun 18 2023 8:11:10 } [PH] info: 🛢Database is connected successfully 16 | Sun Jun 18 2023 8:11:10 } [PH] info: Application listening on port 5000 17 | Sun Jun 18 2023 8:11:13 } [PH] info: 🛢Database is connected successfully 18 | Sun Jun 18 2023 8:11:13 } [PH] info: Application listening on port 5000 19 | Sun Jun 18 2023 8:11:23 } [PH] info: 🛢Database is connected successfully 20 | Sun Jun 18 2023 8:11:23 } [PH] info: Application listening on port 5000 21 | Sun Jun 18 2023 8:12:54 } [PH] info: 🛢Database is connected successfully 22 | Sun Jun 18 2023 8:12:54 } [PH] info: Application listening on port 5000 23 | Sun Jun 18 2023 8:13:4 } [PH] info: 🛢Database is connected successfully 24 | Sun Jun 18 2023 8:13:4 } [PH] info: Application listening on port 5000 25 | Sun Jun 18 2023 8:14:40 } [PH] info: 🛢Database is connected successfully 26 | Sun Jun 18 2023 8:14:40 } [PH] info: Application listening on port 5000 27 | Sun Jun 18 2023 8:15:29 } [PH] info: 🛢Database is connected successfully 28 | Sun Jun 18 2023 8:15:29 } [PH] info: Application listening on port 5000 29 | Sun Jun 18 2023 8:15:33 } [PH] info: 🛢Database is connected successfully 30 | Sun Jun 18 2023 8:15:33 } [PH] info: Application listening on port 5000 31 | Sun Jun 18 2023 8:16:0 } [PH] info: 🛢Database is connected successfully 32 | Sun Jun 18 2023 8:16:0 } [PH] info: Application listening on port 5000 33 | Sun Jun 18 2023 8:16:12 } [PH] info: 🛢Database is connected successfully 34 | Sun Jun 18 2023 8:16:12 } [PH] info: Application listening on port 5000 35 | Sun Jun 18 2023 8:17:0 } [PH] info: 🛢Database is connected successfully 36 | Sun Jun 18 2023 8:17:0 } [PH] info: Application listening on port 5000 37 | Sun Jun 18 2023 8:17:6 } [PH] info: 🛢Database is connected successfully 38 | Sun Jun 18 2023 8:17:6 } [PH] info: Application listening on port 5000 39 | Sun Jun 18 2023 8:17:13 } [PH] info: 🛢Database is connected successfully 40 | Sun Jun 18 2023 8:17:13 } [PH] info: Application listening on port 5000 41 | Sun Jun 18 2023 8:17:22 } [PH] info: 🛢Database is connected successfully 42 | Sun Jun 18 2023 8:17:22 } [PH] info: Application listening on port 5000 43 | Sun Jun 18 2023 8:17:24 } [PH] info: 🛢Database is connected successfully 44 | Sun Jun 18 2023 8:17:24 } [PH] info: Application listening on port 5000 45 | Sun Jun 18 2023 8:17:50 } [PH] info: 🛢Database is connected successfully 46 | Sun Jun 18 2023 8:17:50 } [PH] info: Application listening on port 5000 47 | Sun Jun 18 2023 8:17:59 } [PH] info: 🛢Database is connected successfully 48 | Sun Jun 18 2023 8:17:59 } [PH] info: Application listening on port 5000 49 | Sun Jun 18 2023 8:18:26 } [PH] info: 🛢Database is connected successfully 50 | Sun Jun 18 2023 8:18:26 } [PH] info: Application listening on port 5000 51 | Sun Jun 18 2023 8:18:38 } [PH] info: 🛢Database is connected successfully 52 | Sun Jun 18 2023 8:18:38 } [PH] info: Application listening on port 5000 53 | Sun Jun 18 2023 8:19:15 } [PH] info: 🛢Database is connected successfully 54 | Sun Jun 18 2023 8:19:15 } [PH] info: Application listening on port 5000 55 | Sun Jun 18 2023 8:19:19 } [PH] info: 🛢Database is connected successfully 56 | Sun Jun 18 2023 8:19:19 } [PH] info: Application listening on port 5000 57 | Sun Jun 18 2023 8:19:22 } [PH] info: 🛢Database is connected successfully 58 | Sun Jun 18 2023 8:19:22 } [PH] info: Application listening on port 5000 59 | Sun Jun 18 2023 8:19:41 } [PH] info: 🛢Database is connected successfully 60 | Sun Jun 18 2023 8:19:41 } [PH] info: Application listening on port 5000 61 | Sun Jun 18 2023 8:22:0 } [PH] info: 🛢Database is connected successfully 62 | Sun Jun 18 2023 8:22:0 } [PH] info: Application listening on port 5000 63 | Sun Jun 18 2023 8:22:4 } [PH] info: 🛢Database is connected successfully 64 | Sun Jun 18 2023 8:22:4 } [PH] info: Application listening on port 5000 65 | Sun Jun 18 2023 8:22:8 } [PH] info: 🛢Database is connected successfully 66 | Sun Jun 18 2023 8:22:8 } [PH] info: Application listening on port 5000 67 | Sun Jun 18 2023 8:22:20 } [PH] info: 🛢Database is connected successfully 68 | Sun Jun 18 2023 8:22:20 } [PH] info: Application listening on port 5000 69 | Sun Jun 18 2023 8:22:29 } [PH] info: 🛢Database is connected successfully 70 | Sun Jun 18 2023 8:22:29 } [PH] info: Application listening on port 5000 71 | Sun Jun 18 2023 8:22:31 } [PH] info: 🛢Database is connected successfully 72 | Sun Jun 18 2023 8:22:31 } [PH] info: Application listening on port 5000 73 | Sun Jun 18 2023 8:22:37 } [PH] info: 🛢Database is connected successfully 74 | Sun Jun 18 2023 8:22:37 } [PH] info: Application listening on port 5000 75 | Sun Jun 18 2023 8:22:52 } [PH] info: 🛢Database is connected successfully 76 | Sun Jun 18 2023 8:22:52 } [PH] info: Application listening on port 5000 77 | Sun Jun 18 2023 8:23:3 } [PH] info: 🛢Database is connected successfully 78 | Sun Jun 18 2023 8:23:3 } [PH] info: Application listening on port 5000 79 | Sun Jun 18 2023 8:23:12 } [PH] info: 🛢Database is connected successfully 80 | Sun Jun 18 2023 8:23:12 } [PH] info: Application listening on port 5000 81 | Sun Jun 18 2023 8:23:21 } [PH] info: 🛢Database is connected successfully 82 | Sun Jun 18 2023 8:23:21 } [PH] info: Application listening on port 5000 83 | Sun Jun 18 2023 8:24:7 } [PH] info: 🛢Database is connected successfully 84 | Sun Jun 18 2023 8:24:7 } [PH] info: Application listening on port 5000 85 | Sun Jun 18 2023 8:36:14 } [PH] info: 🛢Database is connected successfully 86 | Sun Jun 18 2023 8:36:14 } [PH] info: Application listening on port 5000 87 | Sun Jun 18 2023 8:37:8 } [PH] info: 🛢Database is connected successfully 88 | Sun Jun 18 2023 8:37:8 } [PH] info: Application listening on port 5000 89 | Sun Jun 18 2023 8:37:13 } [PH] info: 🛢Database is connected successfully 90 | Sun Jun 18 2023 8:37:13 } [PH] info: Application listening on port 5000 91 | Sun Jun 18 2023 8:37:19 } [PH] info: 🛢Database is connected successfully 92 | Sun Jun 18 2023 8:37:19 } [PH] info: Application listening on port 5000 93 | Sun Jun 18 2023 8:43:1 } [PH] info: 🛢Database is connected successfully 94 | Sun Jun 18 2023 8:43:1 } [PH] info: Application listening on port 5000 95 | Sun Jun 18 2023 8:43:4 } [PH] info: 🛢Database is connected successfully 96 | Sun Jun 18 2023 8:43:4 } [PH] info: Application listening on port 5000 97 | Sun Jun 18 2023 8:43:12 } [PH] info: 🛢Database is connected successfully 98 | Sun Jun 18 2023 8:43:12 } [PH] info: Application listening on port 5000 99 | Sun Jun 18 2023 8:45:16 } [PH] info: 🛢Database is connected successfully 100 | Sun Jun 18 2023 8:45:16 } [PH] info: Application listening on port 5000 101 | Sun Jun 18 2023 8:45:20 } [PH] info: 🛢Database is connected successfully 102 | Sun Jun 18 2023 8:45:20 } [PH] info: Application listening on port 5000 103 | Sun Jun 18 2023 8:45:27 } [PH] info: 🛢Database is connected successfully 104 | Sun Jun 18 2023 8:45:27 } [PH] info: Application listening on port 5000 105 | Sun Jun 18 2023 8:45:33 } [PH] info: 🛢Database is connected successfully 106 | Sun Jun 18 2023 8:45:33 } [PH] info: Application listening on port 5000 107 | Sun Jun 18 2023 8:46:37 } [PH] info: 🛢Database is connected successfully 108 | Sun Jun 18 2023 8:46:37 } [PH] info: Application listening on port 5000 109 | Sun Jun 18 2023 8:47:42 } [PH] info: 🛢Database is connected successfully 110 | Sun Jun 18 2023 8:47:42 } [PH] info: Application listening on port 5000 111 | Sun Jun 18 2023 8:47:52 } [PH] info: 🛢Database is connected successfully 112 | Sun Jun 18 2023 8:47:52 } [PH] info: Application listening on port 5000 113 | Sun Jun 18 2023 8:47:56 } [PH] info: 🛢Database is connected successfully 114 | Sun Jun 18 2023 8:47:56 } [PH] info: Application listening on port 5000 115 | Sun Jun 18 2023 8:48:22 } [PH] info: 🛢Database is connected successfully 116 | Sun Jun 18 2023 8:48:22 } [PH] info: Application listening on port 5000 117 | Sun Jun 18 2023 8:48:26 } [PH] info: 🛢Database is connected successfully 118 | Sun Jun 18 2023 8:48:26 } [PH] info: Application listening on port 5000 119 | Sun Jun 18 2023 8:48:36 } [PH] info: 🛢Database is connected successfully 120 | Sun Jun 18 2023 8:48:36 } [PH] info: Application listening on port 5000 121 | Sun Jun 18 2023 8:48:46 } [PH] info: 🛢Database is connected successfully 122 | Sun Jun 18 2023 8:48:46 } [PH] info: Application listening on port 5000 123 | Sun Jun 18 2023 8:48:59 } [PH] info: 🛢Database is connected successfully 124 | Sun Jun 18 2023 8:48:59 } [PH] info: Application listening on port 5000 125 | Sun Jun 18 2023 8:49:2 } [PH] info: 🛢Database is connected successfully 126 | Sun Jun 18 2023 8:49:2 } [PH] info: Application listening on port 5000 127 | Sun Jun 18 2023 8:49:8 } [PH] info: 🛢Database is connected successfully 128 | Sun Jun 18 2023 8:49:8 } [PH] info: Application listening on port 5000 129 | Sun Jun 18 2023 8:49:18 } [PH] info: 🛢Database is connected successfully 130 | Sun Jun 18 2023 8:49:18 } [PH] info: Application listening on port 5000 131 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [ 3 | "src", 4 | "src/app/modules/academicFaculty/academicFaculty.constant.ts" 5 | ], // which files to compile 6 | "exclude": ["node_modules"], // which files to skip 7 | "compilerOptions": { 8 | /* Visit https://aka.ms/tsconfig to read more about this file */ 9 | 10 | /* Projects */ 11 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 12 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 13 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 14 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 15 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 16 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 17 | 18 | /* Language and Environment */ 19 | "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 20 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 21 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 22 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 23 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 24 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 25 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 26 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 27 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 28 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 29 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 30 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 31 | 32 | /* Modules */ 33 | "module": "commonjs" /* Specify what module code is generated. */, 34 | "rootDir": "./src" /* Specify the root folder within your source files. */, 35 | // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ 36 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 37 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 38 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 39 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 40 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 41 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 42 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 43 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 44 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 45 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 46 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 47 | // "resolveJsonModule": true, /* Enable importing .json files. */ 48 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 49 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 50 | 51 | /* JavaScript Support */ 52 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 53 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 54 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 55 | 56 | /* Emit */ 57 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 58 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 59 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 60 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 61 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 62 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 63 | "outDir": "./dist" /* Specify an output folder for all emitted files. */, 64 | // "removeComments": true, /* Disable emitting comments. */ 65 | // "noEmit": true, /* Disable emitting files from a compilation. */ 66 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 67 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 68 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 69 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 70 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 71 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 72 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 73 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 74 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 75 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 76 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 77 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 78 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 79 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 80 | 81 | /* Interop Constraints */ 82 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 83 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 84 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 85 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, 86 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 87 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 88 | 89 | /* Type Checking */ 90 | "strict": true /* Enable all strict type-checking options. */, 91 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 92 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 93 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 94 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 95 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 96 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 97 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 98 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 99 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 100 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 101 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 102 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 103 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 104 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 105 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 106 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 107 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 108 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 109 | 110 | /* Completeness */ 111 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 112 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 113 | } 114 | } 115 | --------------------------------------------------------------------------------