Update:PROFILE API's and create get users api's with pagination

This commit is contained in:
sharafat
2026-05-24 00:17:16 +06:00
parent d2b320f3b1
commit 1abecc9b8f
13 changed files with 327 additions and 8 deletions
@@ -0,0 +1,14 @@
-- CreateEnum
CREATE TYPE "ShopStatus" AS ENUM ('ACTIVE', 'SUSPENDED', 'DELETED');
-- AlterTable
ALTER TABLE "Profile" ADD COLUMN "status" "ShopStatus" NOT NULL DEFAULT 'ACTIVE';
-- CreateTable
CREATE TABLE "Users" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Users_pkey" PRIMARY KEY ("id")
);
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "ShopStatus" ADD VALUE 'INACTIVE';
+11 -6
View File
@@ -1,14 +1,19 @@
enum ShopStatus {
ACTIVE
SUSPENDED
DELETED
INACTIVE
}
model Profile { model Profile {
id String @id @default(uuid()) id String @id @default(uuid())
accountId String @unique accountId String @unique
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade) account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
shopName String shopName String
shopLogo String? shopLogo String?
contactNumber String? contactNumber String?
shopAddress String? shopAddress String?
shopMapLocation String? shopMapLocation String?
shopCategory String? shopCategory String?
status ShopStatus @default(ACTIVE)
} }
+7
View File
@@ -0,0 +1,7 @@
model Users {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
+1 -1
View File
@@ -13,7 +13,7 @@ export const profileSwaggerDocs = {
data: { data: {
type: "object", type: "object",
properties: { properties: {
fullName: { type: "string" }, shopName: { type: "string" },
}, },
}, },
file: { file: {
+10 -1
View File
@@ -1,6 +1,15 @@
import { z } from "zod"; import { z } from "zod";
const update_profile = z.object({ const update_profile = z.object({
fullName: z.string().optional(), shopName: z.string().optional(),
shopAddress: z.string().optional(),
shopPhone: z.string().optional(),
shopLocation: z.string().optional(),
shopImage: z.string().optional(),
shopMapLocation: z.string().optional(),
contactNumber: z.string().optional(),
shopCategory: z.string().optional(),
}); });
export const profile_validations = { export const profile_validations = {
+69
View File
@@ -0,0 +1,69 @@
import catchAsync from "../../utils/catch_async.js";
import manageResponse from "../../utils/manage_response.js";
import { users_service } from "./users.service.js";
const get_all_users = catchAsync(async (req, res) => {
const result = await users_service.get_all_users_from_db(req);
manageResponse(res, {
success: true,
statusCode: 200,
message: "All users fetched successfully.",
data: result,
meta: {},
});
});
const get_single_users = catchAsync(async (req, res) => {
const result = await users_service.get_single_users_from_db(req);
manageResponse(res, {
success: true,
statusCode: 200,
message: "Single users fetched successfully.",
data: result,
meta: {},
});
});
const create_users = catchAsync(async (req, res) => {
const result = await users_service.create_users_into_db(req);
manageResponse(res, {
success: true,
statusCode: 200,
message: "users created successfully.",
data: result,
meta: {},
});
});
const update_users = catchAsync(async (req, res) => {
const result = await users_service.update_users_into_db(req);
manageResponse(res, {
success: true,
statusCode: 200,
message: "users updated successfully.",
data: result,
meta: {},
});
});
const delete_users = catchAsync(async (req, res) => {
const result = await users_service.delete_users_from_db(req);
manageResponse(res, {
success: true,
statusCode: 200,
message: "users deleted successfully.",
data: result,
meta: {},
});
});
export const users_controller = {
get_all_users,
get_single_users,
create_users,
update_users,
delete_users,
};
+24
View File
@@ -0,0 +1,24 @@
import { Router } from "express";
import { users_controller } from "./users.controller.js";
import { users_validations } from "./users.validation.js";
import RequestValidator from "../../middlewares/request_validator.js";
const router = Router();
router.get("/", users_controller.get_all_users);
router.post(
"/",
RequestValidator(users_validations.create_users),
users_controller.create_users,
);
router.get("/:id", users_controller.get_single_users);
router.patch(
"/:id",
RequestValidator(users_validations.update_users),
users_controller.update_users,
);
router.delete("/:id", users_controller.delete_users);
export default router;
+65
View File
@@ -0,0 +1,65 @@
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);
// define your own login here
const result = await prisma.profile.findMany({
take:limit,
skip,
select:{
account:{
select:{
isSubscribe:true,
email:true,
}
},
shopName:true,
id:true,
status:true
}
});
return result;
};
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}});
return result;
};
const create_users_into_db = async (req: Request) => {
// define your own login here
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});
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}});
return result;
};
export const users_service = {
get_all_users_from_db,
get_single_users_from_db,
create_users_into_db,
update_users_into_db,
delete_users_from_db,
};
+110
View File
@@ -0,0 +1,110 @@
export const usersSwaggerDocs = {
"/api/users": {
post: {
tags: ["users"],
summary: "Create new users",
description: "",
requestBody: {
required: true,
content: {
"application/json": {
example: JSON.stringify({}), // put your request body
},
},
},
responses: {
201: { description: "users created successfully" },
500: { description: "Validation error or internal server error" },
},
},
get: {
tags: ["users"],
summary: "Get all users",
description: "",
parameters: [
{
name: "page",
in: "query",
required: false,
schema: { type: "number" },
},
{
name: "limit",
in: "query",
required: false,
schema: { type: "number" },
},
],
responses: {
200: { description: "users fetched successfully" },
401: { description: "unauthorized" },
},
},
},
"/api/users/{id}": {
get: {
tags: ["users"],
summary: "Get single users",
description: "",
parameters: [
{
name: "id",
in: "path",
required: true,
schema: { type: "string" },
},
],
responses: {
200: { description: "users fetched successfully" },
401: { description: "unauthorized" },
},
},
patch: {
tags: ["users"],
summary: "Update users",
description: "",
parameters: [
{
name: "id",
in: "path",
required: true,
schema: { type: "string" },
},
],
requestBody: {
required: true,
content: {
"application/json": {
example: JSON.stringify({}), // put your request body
},
},
},
responses: {
200: { description: "users updated successfully" },
500: { description: "Validation error or internal server error" },
},
},
delete: {
tags: ["users"],
summary: "Delete users",
description: "",
parameters: [
{
name: "id",
in: "path",
required: true,
schema: { type: "string" },
},
],
responses: {
200: { description: "users delete successfully" },
401: { description: "unauthorized" },
},
},
},
};
+10
View File
@@ -0,0 +1,10 @@
import { z } from "zod";
const create_users = z.object({});
const update_users = z.object({});
export const users_validations = {
create_users,
update_users,
};
+2
View File
@@ -5,10 +5,12 @@ import planRoute from "./app/modules/plan/plan.route.js";
import profileRoute from "./app/modules/profile/profile.route.js"; import profileRoute from "./app/modules/profile/profile.route.js";
import supportRoute from "./app/modules/support/support.route.js"; import supportRoute from "./app/modules/support/support.route.js";
import templateRoute from "./app/modules/template/template.route"; import templateRoute from "./app/modules/template/template.route";
import usersRoute from "./app/modules/users/users.route";
const appRouter = Router(); const appRouter = Router();
const moduleRoutes = [ const moduleRoutes = [
{ path: "/users", route: usersRoute },
{ path: "/template", route: templateRoute }, { path: "/template", route: templateRoute },
{ path: "/order", route: orderRoute }, { path: "/order", route: orderRoute },
{ path: "/support", route: supportRoute }, { path: "/support", route: supportRoute },
+2
View File
@@ -7,6 +7,7 @@ import { planSwaggerDocs } from "./app/modules/plan/plan.swagger.js";
import { profileSwaggerDocs } from "./app/modules/profile/profile.swagger.js"; import { profileSwaggerDocs } from "./app/modules/profile/profile.swagger.js";
import { supportSwaggerDocs } from "./app/modules/support/support.swagger.js"; import { supportSwaggerDocs } from "./app/modules/support/support.swagger.js";
import { templateSwaggerDocs } from "./app/modules/template/template.swagger"; import { templateSwaggerDocs } from "./app/modules/template/template.swagger";
import { usersSwaggerDocs } from "./app/modules/users/users.swagger";
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const __dirname = path.dirname(__filename);
@@ -26,6 +27,7 @@ export const swaggerOptions = {
...profileSwaggerDocs, ...profileSwaggerDocs,
...supportSwaggerDocs, ...supportSwaggerDocs,
...templateSwaggerDocs, ...templateSwaggerDocs,
...usersSwaggerDocs,
}, },
servers: servers:
configs.env === "production" configs.env === "production"