diff --git a/prisma/migrations/20260523173211_edit_profile/migration.sql b/prisma/migrations/20260523173211_edit_profile/migration.sql new file mode 100644 index 0000000..7f77fa8 --- /dev/null +++ b/prisma/migrations/20260523173211_edit_profile/migration.sql @@ -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") +); diff --git a/prisma/migrations/20260523174545_edit_the_profile_status/migration.sql b/prisma/migrations/20260523174545_edit_the_profile_status/migration.sql new file mode 100644 index 0000000..b45a2dc --- /dev/null +++ b/prisma/migrations/20260523174545_edit_the_profile_status/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "ShopStatus" ADD VALUE 'INACTIVE'; diff --git a/prisma/schema/profile.schema.prisma b/prisma/schema/profile.schema.prisma index b5959a9..26ef467 100644 --- a/prisma/schema/profile.schema.prisma +++ b/prisma/schema/profile.schema.prisma @@ -1,14 +1,19 @@ +enum ShopStatus { + ACTIVE + SUSPENDED + DELETED + INACTIVE +} + model Profile { - id String @id @default(uuid()) - accountId String @unique - account Account @relation(fields: [accountId], references: [id], onDelete: Cascade) + id String @id @default(uuid()) + accountId String @unique + account Account @relation(fields: [accountId], references: [id], onDelete: Cascade) shopName String shopLogo String? contactNumber String? shopAddress String? shopMapLocation String? shopCategory String? - + status ShopStatus @default(ACTIVE) } - - diff --git a/prisma/schema/users.prisma b/prisma/schema/users.prisma new file mode 100644 index 0000000..f5a0e8c --- /dev/null +++ b/prisma/schema/users.prisma @@ -0,0 +1,7 @@ + +model Users { + id String @id @default(uuid()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} + \ No newline at end of file diff --git a/src/app/modules/profile/profile.swagger.ts b/src/app/modules/profile/profile.swagger.ts index 5a93aee..4494f8d 100644 --- a/src/app/modules/profile/profile.swagger.ts +++ b/src/app/modules/profile/profile.swagger.ts @@ -13,7 +13,7 @@ export const profileSwaggerDocs = { data: { type: "object", properties: { - fullName: { type: "string" }, + shopName: { type: "string" }, }, }, file: { diff --git a/src/app/modules/profile/profile.validation.ts b/src/app/modules/profile/profile.validation.ts index b7ffb04..eb604d3 100644 --- a/src/app/modules/profile/profile.validation.ts +++ b/src/app/modules/profile/profile.validation.ts @@ -1,6 +1,15 @@ import { z } from "zod"; 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 = { diff --git a/src/app/modules/users/users.controller.ts b/src/app/modules/users/users.controller.ts new file mode 100644 index 0000000..d134055 --- /dev/null +++ b/src/app/modules/users/users.controller.ts @@ -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, +}; + \ No newline at end of file diff --git a/src/app/modules/users/users.route.ts b/src/app/modules/users/users.route.ts new file mode 100644 index 0000000..be8e7ab --- /dev/null +++ b/src/app/modules/users/users.route.ts @@ -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; + \ No newline at end of file diff --git a/src/app/modules/users/users.service.ts b/src/app/modules/users/users.service.ts new file mode 100644 index 0000000..2d135dc --- /dev/null +++ b/src/app/modules/users/users.service.ts @@ -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, +}; + \ No newline at end of file diff --git a/src/app/modules/users/users.swagger.ts b/src/app/modules/users/users.swagger.ts new file mode 100644 index 0000000..a951986 --- /dev/null +++ b/src/app/modules/users/users.swagger.ts @@ -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" }, + }, + }, + }, +}; + + + \ No newline at end of file diff --git a/src/app/modules/users/users.validation.ts b/src/app/modules/users/users.validation.ts new file mode 100644 index 0000000..2424e36 --- /dev/null +++ b/src/app/modules/users/users.validation.ts @@ -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, +}; diff --git a/src/routes.ts b/src/routes.ts index faf8148..e873c17 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -5,10 +5,12 @@ import planRoute from "./app/modules/plan/plan.route.js"; import profileRoute from "./app/modules/profile/profile.route.js"; import supportRoute from "./app/modules/support/support.route.js"; import templateRoute from "./app/modules/template/template.route"; +import usersRoute from "./app/modules/users/users.route"; const appRouter = Router(); const moduleRoutes = [ + { path: "/users", route: usersRoute }, { path: "/template", route: templateRoute }, { path: "/order", route: orderRoute }, { path: "/support", route: supportRoute }, diff --git a/src/swaggerOptions.ts b/src/swaggerOptions.ts index 3aa0273..34fd8ba 100644 --- a/src/swaggerOptions.ts +++ b/src/swaggerOptions.ts @@ -7,6 +7,7 @@ import { planSwaggerDocs } from "./app/modules/plan/plan.swagger.js"; import { profileSwaggerDocs } from "./app/modules/profile/profile.swagger.js"; import { supportSwaggerDocs } from "./app/modules/support/support.swagger.js"; import { templateSwaggerDocs } from "./app/modules/template/template.swagger"; +import { usersSwaggerDocs } from "./app/modules/users/users.swagger"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -26,6 +27,7 @@ export const swaggerOptions = { ...profileSwaggerDocs, ...supportSwaggerDocs, ...templateSwaggerDocs, + ...usersSwaggerDocs, }, servers: configs.env === "production"