updated docs
This commit is contained in:
20
web_services/web-controllers/app/api/menu/route.ts
Normal file
20
web_services/web-controllers/app/api/menu/route.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST() {
|
||||
async function retrieveAvailableApplication(): Promise<string[]> {
|
||||
return new Promise((resolve) => {
|
||||
const mockList = [
|
||||
"management/account/tenant/something",
|
||||
"management/account/tenant/somethingSecond",
|
||||
"building/parts/tenant/something",
|
||||
];
|
||||
resolve(mockList);
|
||||
});
|
||||
}
|
||||
|
||||
const availableApplications = await retrieveAvailableApplication();
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
data: availableApplications,
|
||||
});
|
||||
}
|
||||
15
web_services/web-controllers/app/api/pages/route.ts
Normal file
15
web_services/web-controllers/app/api/pages/route.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(): Promise<NextResponse> {
|
||||
async function retrievePageToRender(): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
resolve("superUserTenantSomething");
|
||||
});
|
||||
}
|
||||
|
||||
const pageToRender = await retrievePageToRender();
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
data: pageToRender,
|
||||
});
|
||||
}
|
||||
138
web_services/web-controllers/app/api/tst/[...id]/route.ts
Normal file
138
web_services/web-controllers/app/api/tst/[...id]/route.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
import { NextResponse, NextRequest } from "next/server";
|
||||
|
||||
interface APiData {
|
||||
uuid: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
phoneNumber: string;
|
||||
country: string;
|
||||
description: string;
|
||||
isDeleted: boolean;
|
||||
isConfirmed: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
function generateMockData(volume: number) : APiData[] {
|
||||
const data : APiData[] = [];
|
||||
for (let i = 0; i < volume; i++) {
|
||||
data.push({
|
||||
uuid: i.toString(),
|
||||
firstName: "test-" + i,
|
||||
lastName: "test-" + i,
|
||||
email: "test-" + i,
|
||||
phoneNumber: "test-" + i,
|
||||
country: "test-" + i,
|
||||
description: "test-" + i,
|
||||
isDeleted: false,
|
||||
isConfirmed: false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
const apiMockData: APiData[] = generateMockData(10);
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string[] }> }
|
||||
) {
|
||||
const id = (await params).id[0];
|
||||
const data = apiMockData.find((item) => item.uuid === id);
|
||||
if (!data) {
|
||||
return NextResponse.json({
|
||||
status: 404,
|
||||
data: {
|
||||
message: "Not Found",
|
||||
},
|
||||
});
|
||||
}
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string[] }> }
|
||||
) {
|
||||
const id = (await params).id[0];
|
||||
const body = await request.json();
|
||||
const idFound = apiMockData.find((item) => item.uuid === id);
|
||||
|
||||
if (!idFound) {
|
||||
return NextResponse.json({
|
||||
status: 404,
|
||||
data: {
|
||||
message: "Not Found",
|
||||
},
|
||||
});
|
||||
}
|
||||
apiMockData.splice(apiMockData.indexOf(idFound as any), 1);
|
||||
apiMockData.push({
|
||||
...idFound,
|
||||
firstName: body.name || idFound.firstName,
|
||||
description: body.description || idFound.description,
|
||||
uuid: id,
|
||||
isDeleted: false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
data: {
|
||||
...idFound,
|
||||
firstName: body.name,
|
||||
description: body.description,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string[] }> }
|
||||
) {
|
||||
const id = (await params).id[0];
|
||||
const data = apiMockData.find((item) => item.uuid === id);
|
||||
if (!data) {
|
||||
return NextResponse.json({
|
||||
status: 404,
|
||||
data: {
|
||||
message: "Not Found",
|
||||
},
|
||||
});
|
||||
}
|
||||
apiMockData.splice(apiMockData.indexOf(data as any), 1);
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
data: apiMockData.length,
|
||||
});
|
||||
}
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string[] }> }
|
||||
) {
|
||||
const id = (await params).id[0];
|
||||
const body = await request.json();
|
||||
const data = apiMockData.find((item) => item.uuid === id);
|
||||
if (!data) {
|
||||
return NextResponse.json({
|
||||
status: 404,
|
||||
data: {
|
||||
message: "Not Found",
|
||||
},
|
||||
});
|
||||
}
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
data: {
|
||||
...data,
|
||||
firstName: body.name || data.firstName,
|
||||
},
|
||||
});
|
||||
}
|
||||
139
web_services/web-controllers/app/api/tst/route.ts
Normal file
139
web_services/web-controllers/app/api/tst/route.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import { NextResponse, NextRequest } from "next/server";
|
||||
import { randomUUID } from "crypto";
|
||||
interface APiData {
|
||||
"Users.uuid": string;
|
||||
"Users.firstName": string;
|
||||
"Users.lastName": string;
|
||||
"Users.email": string;
|
||||
"Users.phoneNumber": string;
|
||||
"Users.country": string;
|
||||
"Users.description": string;
|
||||
"Users.isDeleted": boolean;
|
||||
"Users.isConfirmed": boolean;
|
||||
"Users.createdAt": Date;
|
||||
"Users.updatedAt": Date;
|
||||
}
|
||||
|
||||
function generateMockData(volume: number): APiData[] {
|
||||
const data: APiData[] = [];
|
||||
|
||||
for (let i = 0; i < volume; i++) {
|
||||
data.push({
|
||||
"Users.uuid": randomUUID(),
|
||||
"Users.firstName": "test-name-" + i,
|
||||
"Users.lastName": "test-lastName-" + i,
|
||||
"Users.email": "test-email-" + i,
|
||||
"Users.phoneNumber": "test-phoneNumber-" + i,
|
||||
"Users.country": "test-country-" + i,
|
||||
"Users.description": "test-description-" + i,
|
||||
"Users.isDeleted": Math.random() > 0.5,
|
||||
"Users.isConfirmed": Math.random() > 0.5,
|
||||
"Users.createdAt": new Date(),
|
||||
"Users.updatedAt": new Date(),
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
interface RequestParams {
|
||||
page: number;
|
||||
size: number;
|
||||
orderField: string[];
|
||||
orderType: string[];
|
||||
query: Record<string, any>;
|
||||
}
|
||||
|
||||
const apiMockData: APiData[] = generateMockData(108);
|
||||
|
||||
interface PaginationRequest {
|
||||
page: number;
|
||||
size: number;
|
||||
orderField: string[];
|
||||
orderType: string[];
|
||||
query: Record<string, any>;
|
||||
}
|
||||
|
||||
interface PaginationResponse {
|
||||
onPage: number;
|
||||
onPageCount: number;
|
||||
totalPage: number;
|
||||
totalCount: number;
|
||||
next: boolean;
|
||||
back: boolean;
|
||||
}
|
||||
|
||||
interface DataResponse<T> {
|
||||
data: T[];
|
||||
pagination: PaginationResponse;
|
||||
}
|
||||
interface NextApiResponse<T> {
|
||||
status: number;
|
||||
data: DataResponse<T>;
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest
|
||||
): Promise<NextResponse<NextApiResponse<APiData>>> {
|
||||
const pagination: PaginationRequest = await request.json();
|
||||
|
||||
const ceilLength = Math.ceil(apiMockData.length / pagination.size);
|
||||
const isNext = pagination.page < ceilLength;
|
||||
const isBack = pagination.page > 1;
|
||||
const sliceIfPaginationCorrect =
|
||||
pagination.page <= ceilLength ? pagination.page : ceilLength;
|
||||
const sliceParams = [
|
||||
(pagination.page - 1) * pagination.size,
|
||||
sliceIfPaginationCorrect * pagination.size,
|
||||
];
|
||||
const orderField = pagination.orderField;
|
||||
const orderType = pagination.orderType;
|
||||
const query = pagination.query;
|
||||
|
||||
const filteredData = apiMockData.filter((item) => {
|
||||
return Object.keys(query).every((key) => {
|
||||
return item[key as keyof APiData] === query[key];
|
||||
});
|
||||
});
|
||||
if (orderField && orderType) {
|
||||
for (let i = 0; i < orderField.length; i++) {
|
||||
const field = orderField[i];
|
||||
const order = orderType[i];
|
||||
if (order === "asc") {
|
||||
filteredData.sort((a, b) => {
|
||||
if (a[field as keyof APiData] < b[field as keyof APiData]) {
|
||||
return -1;
|
||||
}
|
||||
if (a[field as keyof APiData] > b[field as keyof APiData]) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
filteredData.sort((a, b) => {
|
||||
if (a[field as keyof APiData] < b[field as keyof APiData]) {
|
||||
return 1;
|
||||
}
|
||||
if (a[field as keyof APiData] > b[field as keyof APiData]) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
data: {
|
||||
data: filteredData.slice(...sliceParams),
|
||||
pagination: {
|
||||
onPage: pagination.page,
|
||||
onPageCount: pagination.size,
|
||||
totalPage: ceilLength,
|
||||
totalCount: apiMockData.length,
|
||||
next: isNext,
|
||||
back: isBack,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user