api : add api position api group and api users

This commit is contained in:
lukman
2024-07-26 17:44:54 +08:00
parent 4e55c7b061
commit ea7a2ba98c
30 changed files with 267 additions and 29 deletions

View File

@@ -1,7 +1,8 @@
import { NextRequest } from "next/server";
import { API_INDEX_GROUP } from "./api_index";
type Method = "GET" | "POST";
export async function apiGroup(req: Request, method: Method) {
export async function apiGroup(req: NextRequest, method: Method) {
const { searchParams } = new URL(req.url);
const path = searchParams.get("path");
const act = API_INDEX_GROUP.find((v) => v.path === path && v.method === method);

View File

@@ -1,5 +1,5 @@
import { getOneGroup } from "./get/getOneGroup";
import { listGroup } from "./get/listGroup";
import { listGroups } from "./get/listGroup";
import { createGroup } from "./post/createGroup";
import { deleteGroup } from "./post/deleteGroup";
import { updateGroup } from "./post/updateGroup";
@@ -8,7 +8,7 @@ export const API_INDEX_GROUP = [
{
path: "list-group",
method: "GET",
bin: listGroup,
bin: listGroups,
},
{
path: "create-group",

View File

@@ -1,12 +1,13 @@
import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function getOneGroup(req: Request): Promise<Response> {
export async function getOneGroup(req: NextRequest): Promise<Response> {
try {
// const groupId = req.params.id;
const groupId = "clz0v4kce0009e6mukfhzmyzb";
const searchParams = req.nextUrl.searchParams
const groupId = searchParams.get('groupId');
const getOne = await prisma.group.findUnique({
where: {
id: groupId,
id: String(groupId),
},
select: {
id: true,

View File

@@ -1,10 +1,15 @@
import { prisma } from "@/module/_global";
import { NextRequest } from "next/server";
export async function listGroup(req: Request): Promise<Response> {
export async function listGroups(req: NextRequest): Promise<Response> {
try {
const searchParams = req.nextUrl.searchParams
const villaId = searchParams.get('villageId');
const groups = await prisma.group.findMany({
where: {
isActive: true,
idVillage: String(villaId),
},
select: {
id: true,