Add api: Users
This commit is contained in:
@@ -130,7 +130,7 @@ const get_single_order_from_db = async (req: Request) => {
|
|||||||
|
|
||||||
const create_order_into_db = async (req: Request) => {
|
const create_order_into_db = async (req: Request) => {
|
||||||
const payload = req?.body;
|
const payload = req?.body;
|
||||||
console.log(payload);
|
|
||||||
payload.status = "INITIATED";
|
payload.status = "INITIATED";
|
||||||
payload.paymentType = "COD";
|
payload.paymentType = "COD";
|
||||||
|
|
||||||
@@ -153,7 +153,6 @@ const create_order_into_db = async (req: Request) => {
|
|||||||
const update_order_into_db = async (req: Request) => {
|
const update_order_into_db = async (req: Request) => {
|
||||||
// define your own login here
|
// define your own login here
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
console.log(user);
|
|
||||||
if (user?.role !== "ADMIN") {
|
if (user?.role !== "ADMIN") {
|
||||||
throw new AppError("You are not authorized to perform this action", 403);
|
throw new AppError("You are not authorized to perform this action", 403);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const update_profile_into_db = async (req: Request) => {
|
|||||||
const user = req?.user as JwtPayloadType;
|
const user = req?.user as JwtPayloadType;
|
||||||
const payload = req?.body;
|
const payload = req?.body;
|
||||||
const file = req?.file;
|
const file = req?.file;
|
||||||
console.log(payload);
|
|
||||||
// check file and upload to cloud
|
// check file and upload to cloud
|
||||||
if (file) {
|
if (file) {
|
||||||
const cloudRes = await uploadCloud(file);
|
const cloudRes = await uploadCloud(file);
|
||||||
|
|||||||
@@ -1,29 +1,34 @@
|
|||||||
|
|
||||||
import { Request } from "express";
|
import { Request } from "express";
|
||||||
import { prisma } from "../../lib/prisma.js";
|
import { prisma } from "../../lib/prisma.js";
|
||||||
import paginationHelper from "../../utils/pagination_helper.js";
|
import paginationHelper from "../../utils/pagination_helper.js";
|
||||||
|
|
||||||
const get_all_users_from_db = async (req: Request) => {
|
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
|
// define your own login here
|
||||||
const result = await prisma.profile.findMany({
|
const result = await prisma.profile.findMany({
|
||||||
take: limit,
|
take: limit,
|
||||||
skip,
|
skip,
|
||||||
|
where: andCondition,
|
||||||
select: {
|
select: {
|
||||||
account: {
|
account: {
|
||||||
select: {
|
select: {
|
||||||
isSubscribe: true,
|
isSubscribe: true,
|
||||||
email: true,
|
email: true,
|
||||||
|
},
|
||||||
}
|
|
||||||
},
|
},
|
||||||
shopName: true,
|
shopName: true,
|
||||||
id: true,
|
id: true,
|
||||||
status:true
|
status: true,
|
||||||
|
},
|
||||||
}
|
|
||||||
});
|
});
|
||||||
const usersCount = await prisma.profile.count();
|
const usersCount = await prisma.profile.count();
|
||||||
return { result, usersCount, page, limit, skip };
|
return { result, usersCount, page, limit, skip };
|
||||||
@@ -32,7 +37,7 @@ const get_all_users_from_db = async (req: Request) => {
|
|||||||
const get_single_users_from_db = async (req: Request) => {
|
const get_single_users_from_db = async (req: Request) => {
|
||||||
// define your own login here
|
// define your own login here
|
||||||
const { id } = req.params as { id: string };
|
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;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,4 +68,3 @@ export const users_service = {
|
|||||||
update_users_into_db,
|
update_users_into_db,
|
||||||
delete_users_from_db,
|
delete_users_from_db,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
export const usersSwaggerDocs = {
|
export const usersSwaggerDocs = {
|
||||||
"/api/users": {
|
"/api/users": {
|
||||||
post: {
|
post: {
|
||||||
@@ -35,6 +34,12 @@
|
|||||||
required: false,
|
required: false,
|
||||||
schema: { type: "number" },
|
schema: { type: "number" },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "search",
|
||||||
|
in: "query",
|
||||||
|
required: false,
|
||||||
|
schema: { type: "string" },
|
||||||
|
},
|
||||||
],
|
],
|
||||||
responses: {
|
responses: {
|
||||||
200: { description: "users fetched successfully" },
|
200: { description: "users fetched successfully" },
|
||||||
@@ -105,6 +110,3 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user