From f224ff6bf0c1624d6d6e5b3ea3a2eb7382bad554 Mon Sep 17 00:00:00 2001 From: sharafat Date: Wed, 17 Jun 2026 22:01:03 +0600 Subject: [PATCH] Add api: Users --- src/app/modules/order/order.service.ts | 3 +- src/app/modules/profile/profile.service.ts | 1 - src/app/modules/users/users.service.ts | 48 ++++++++++++---------- src/app/modules/users/users.swagger.ts | 12 +++--- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/app/modules/order/order.service.ts b/src/app/modules/order/order.service.ts index e554f37..864b9ed 100644 --- a/src/app/modules/order/order.service.ts +++ b/src/app/modules/order/order.service.ts @@ -130,7 +130,7 @@ const get_single_order_from_db = async (req: Request) => { const create_order_into_db = async (req: Request) => { const payload = req?.body; - console.log(payload); + payload.status = "INITIATED"; payload.paymentType = "COD"; @@ -153,7 +153,6 @@ const create_order_into_db = async (req: Request) => { const update_order_into_db = async (req: Request) => { // define your own login here const user = req.user; - console.log(user); if (user?.role !== "ADMIN") { throw new AppError("You are not authorized to perform this action", 403); } diff --git a/src/app/modules/profile/profile.service.ts b/src/app/modules/profile/profile.service.ts index 5aaf758..b93e02d 100644 --- a/src/app/modules/profile/profile.service.ts +++ b/src/app/modules/profile/profile.service.ts @@ -7,7 +7,6 @@ const update_profile_into_db = async (req: Request) => { const user = req?.user as JwtPayloadType; const payload = req?.body; const file = req?.file; - console.log(payload); // check file and upload to cloud if (file) { const cloudRes = await uploadCloud(file); diff --git a/src/app/modules/users/users.service.ts b/src/app/modules/users/users.service.ts index c45dd3e..8404cb8 100644 --- a/src/app/modules/users/users.service.ts +++ b/src/app/modules/users/users.service.ts @@ -1,58 +1,63 @@ - import { Request } from "express"; import { prisma } from "../../lib/prisma.js"; import paginationHelper from "../../utils/pagination_helper.js"; const get_all_users_from_db = async (req: Request) => { - const {page,skip,limit}=paginationHelper(req.query); - + const { page, skip, limit } = paginationHelper(req.query); + const search = req.query.search as string; + const andCondition = {} as any; + if (search) { + andCondition.shopName = { + contains: search, + mode: "insensitive", + }; + } // define your own login here const result = await prisma.profile.findMany({ - take:limit, + take: limit, skip, - select:{ - account:{ - select:{ - isSubscribe:true, - email:true, - - } + where: andCondition, + select: { + account: { + select: { + isSubscribe: true, + email: true, + }, }, - shopName:true, - id:true, - status:true - - } + shopName: true, + id: true, + status: true, + }, }); const usersCount = await prisma.profile.count(); - return{ result,usersCount,page,limit,skip}; + return { result, usersCount, page, limit, skip }; }; const get_single_users_from_db = async (req: Request) => { // define your own login here const { id } = req.params as { id: string }; - const result = await prisma.account.findUnique({where:{id}}); + const result = await prisma.profile.findUnique({ where: { id } }); return result; }; const create_users_into_db = async (req: Request) => { // define your own login here - const result = await prisma.account.create({data:req.body}); + const result = await prisma.account.create({ data: req.body }); return result; }; const update_users_into_db = async (req: Request) => { // define your own login here const { id } = req.params as { id: string }; - const result = await prisma.account.update({where:{id},data:req.body}); + const result = await prisma.account.update({ where: { id }, data: req.body }); return result; }; const delete_users_from_db = async (req: Request) => { // define your own login here const { id } = req.params as { id: string }; - const result = await prisma.account.delete({where:{id}}); + const result = await prisma.account.delete({ where: { id } }); return result; }; @@ -63,4 +68,3 @@ export const users_service = { update_users_into_db, delete_users_from_db, }; - \ No newline at end of file diff --git a/src/app/modules/users/users.swagger.ts b/src/app/modules/users/users.swagger.ts index a951986..4672e12 100644 --- a/src/app/modules/users/users.swagger.ts +++ b/src/app/modules/users/users.swagger.ts @@ -1,5 +1,4 @@ - - export const usersSwaggerDocs = { +export const usersSwaggerDocs = { "/api/users": { post: { tags: ["users"], @@ -35,6 +34,12 @@ required: false, schema: { type: "number" }, }, + { + name: "search", + in: "query", + required: false, + schema: { type: "string" }, + }, ], responses: { 200: { description: "users fetched successfully" }, @@ -105,6 +110,3 @@ }, }, }; - - - \ No newline at end of file