api : add api users
This commit is contained in:
47
api.http
47
api.http
@@ -118,4 +118,49 @@ Content-Type: application/json
|
||||
// USERS
|
||||
|
||||
###
|
||||
GET http://localhost:3000/api/user/get?path=get-all-users&roleID=dev&positionID=null&villageID=null&groupID=null HTTP/1.1
|
||||
GET http://localhost:3000/api/user/get?path=get-all-users&roleID=dev&villageID=121212&groupID=2&positionID=clz24bff70001w01in64dd9ea HTTP/1.1
|
||||
|
||||
###
|
||||
GET http://localhost:3000/api/user/get?path=get-one-users&userID=devAmalia HTTP/1.1
|
||||
|
||||
###
|
||||
POST http://localhost:3000/api/user/post?path=create-users HTTP/1.1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"idUserRole": "user",
|
||||
"idVillage": "121212",
|
||||
"idGroup": "2",
|
||||
"idPosition": "clz24bff70001w01in64dd9ea",
|
||||
"nik": "53239236727329",
|
||||
"name": "coba user",
|
||||
"email": "cobauser@gmail.com",
|
||||
"phone": "07319031009",
|
||||
"gender": "M"
|
||||
}
|
||||
|
||||
###
|
||||
POST http://localhost:3000/api/user/post?path=update-users HTTP/1.1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"id": "clz6dq88e0001b3mlyl4vjaf8",
|
||||
"idUserRole": "user",
|
||||
"idVillage": "121212",
|
||||
"idGroup": "2",
|
||||
"idPosition": "clz24bff70001w01in64dd9ea",
|
||||
"nik": "53239236727329",
|
||||
"name": "coba user edit",
|
||||
"email": "cobauser@gmail.com",
|
||||
"phone": "07319031009",
|
||||
"gender": "M"
|
||||
}
|
||||
|
||||
###
|
||||
POST http://localhost:3000/api/user/post?path=delete-users HTTP/1.1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"id": "clz6dq88e0001b3mlyl4vjaf8"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { apiPosition } from "@/module/position";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
export async function GET(req: NextRequest) {
|
||||
return apiPosition(req, "GET");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { apiPosition } from "@/module/position";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
export async function POST(req: NextRequest) {
|
||||
return apiPosition(req, "POST");
|
||||
}
|
||||
|
||||
@@ -3,15 +3,20 @@ import { NextRequest } from "next/server";
|
||||
|
||||
export async function getAllUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const idGroup = searchParams.get('groupID');
|
||||
const idUserRole = searchParams.get('roleID');
|
||||
const idPosition = searchParams.get('positionID');
|
||||
const idVillage = searchParams.get('villageID');
|
||||
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idUserRole: String(searchParams.get("roleID")),
|
||||
idPosition: String(searchParams.get("positionID")),
|
||||
idVillage: String(searchParams.get("villageID")),
|
||||
idGroup: String(searchParams.get("groupID")),
|
||||
idUserRole: String(idUserRole),
|
||||
idPosition: idPosition,
|
||||
idVillage: idVillage,
|
||||
idGroup: idGroup,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -1,9 +1,28 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function getOneUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const idUser = searchParams.get("userID");
|
||||
|
||||
const users = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: String(idUser),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
nik: true,
|
||||
name: true,
|
||||
phone: true,
|
||||
email: true,
|
||||
gender: true,
|
||||
},
|
||||
});
|
||||
|
||||
return Response.json(users);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return Response.json({ message: "Internal Server Error", success: false }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,35 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function createUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
const data = await req.json();
|
||||
|
||||
const users = await prisma.user.create({
|
||||
data: {
|
||||
nik: data.nik,
|
||||
name: data.name,
|
||||
phone: data.phone,
|
||||
email: data.email,
|
||||
gender: data.gender,
|
||||
idGroup: data.idGroup,
|
||||
idVillage: data.idVillage,
|
||||
idPosition: data.idPosition,
|
||||
idUserRole: data.idUserRole,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
nik: true,
|
||||
name: true,
|
||||
phone: true,
|
||||
email: true,
|
||||
gender: true,
|
||||
},
|
||||
});
|
||||
|
||||
return Response.json(users, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return Response.json({ message: "Internal Server Error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,27 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function deleteUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
const data = await req.json();
|
||||
const update = await prisma.user.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
isActive: false,
|
||||
},
|
||||
});
|
||||
|
||||
return Response.json(
|
||||
{ success: true, message: "Sukses Delete User" },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return Response.json(
|
||||
{ message: "Internal Server Error", success: false },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,36 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function updateUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
const data = await req.json();
|
||||
|
||||
const updates = await prisma.user.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
nik: data.nik,
|
||||
name: data.name,
|
||||
phone: data.phone,
|
||||
email: data.email,
|
||||
gender: data.gender,
|
||||
idGroup: data.idGroup,
|
||||
idVillage: data.idVillage,
|
||||
idPosition: data.idPosition,
|
||||
idUserRole: data.idUserRole,
|
||||
},
|
||||
});
|
||||
|
||||
return Response.json(
|
||||
{ success: true, message: "Sukses Update User" },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return Response.json(
|
||||
{ message: "Internal Server Error", success: false },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user