init project portal web

This commit is contained in:
Sweli Giri
2025-04-15 13:56:54 +07:00
parent 9a25243035
commit 8b15dcebf8
122 changed files with 13965 additions and 1 deletions

10
app/api/cookies/route.ts Normal file
View File

@ -0,0 +1,10 @@
import { NextResponse } from "next/server";
import { cookies } from "next/headers";
export async function GET() {
const cookieStore = cookies();
const credential = JSON.parse(cookieStore.get("credential")?.value || "");
return NextResponse.json({ credential });
}

55
app/api/login/route.ts Normal file
View File

@ -0,0 +1,55 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server';
export const POST = async (request: NextRequest) => {
// INTERPOLATING API URL OF BACKEND
const url: string = `${process.env.NEXT_PUBLIC_API_URL}/auth/login`
// GET REQUEST BODY
const {username, password} = await request.json();
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
data: JSON.stringify({
userName: username,
password,
})
})
if (response?.data ?? false) {
const token: string = response.data.data.token;
const expired = response.data.data.expired;
const data = {
username: response.data.data.username,
token
}
cookies().set({
name: 'credential',
value: JSON.stringify(data),
httpOnly: false,
sameSite: 'strict',
path: '/',
maxAge: expired
})
}
return NextResponse.json(response.data, { status: response.status });
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}

18
app/api/logout/route.ts Normal file
View File

@ -0,0 +1,18 @@
import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';
export const POST = async () => {
// Hapus cookie 'credential'
cookies().delete({
name: "credential",
httpOnly: false,
sameSite: 'strict',
path: '/',
maxAge: 0,
})
// Return a JSON response
return NextResponse.json({
message: 'Cookie deleted successfully.',
status: 'success',
}, { status: 200 });
};

View File

@ -0,0 +1,36 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server';
export const POST = async () => {
// INTERPOLATING API URL OF BACKEND
const url: string = `${process.env.NEXT_PUBLIC_API_URL}/usage_event/list`
const data = JSON.parse(cookies().get('credential')?.value ?? "")
const token = `Bearer ${data.token}`
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token
},
})
return NextResponse.json(response.data, { status: response.status });
} catch (error: any) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}

View File

@ -0,0 +1,58 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server';
export const POST = async (request: NextRequest) => {
// INTERPOLATING API URL OF BACKEND
const {
offerType,
offerName,
pricePlanCode,
remarks,
sourceFrom,
baseValidPeriod,
serviceType,
versionValidPeriod
} = await request.json();
const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/createpriceplan`
const data = JSON.parse(cookies().get('credential')?.value ?? "")
const token = `Bearer ${data.token}`
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token
},
data: JSON.stringify({
offerType,
offerName,
applyLevel: "S",
pricePlanCode,
remarks,
sourceFrom,
baseValidPeriod,
versionValidPeriod,
serviceType
})
})
return NextResponse.json(response.data, { status: response.status });
} catch (error: any) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}

View File

@ -0,0 +1,36 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server';
export const POST = async (request: NextRequest) => {
// INTERPOLATING API URL OF BACKEND
const {id} = await request.json();
const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/delete/${id}`
const data = JSON.parse(cookies().get('credential')?.value ?? "")
const token = `Bearer ${data.token}`
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token
},
})
return NextResponse.json(response.data, { status: response.status });
} catch (error: any) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}

View File

@ -0,0 +1,39 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server';
export const POST = async () => {
// INTERPOLATING API URL OF BACKEND
const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/getmenuList`
const data = JSON.parse(cookies().get('credential')?.value ?? "")
const token = `Bearer ${data.token}`
// console.log(token, 'cek token');
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token
},
})
return NextResponse.json(response.data, { status: response.status });
} catch (error: any) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}

View File

@ -0,0 +1,39 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server';
export const POST = async (request: NextRequest) => {
// INTERPOLATING API URL OF BACKEND
const {page, size, type} = await request.json();
let url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/list`
if(type) url += `/${type}`
url += `?page=${page}&size=${size}`
const data = JSON.parse(cookies().get('credential')?.value ?? "")
const token = `Bearer ${data.token}`
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token
},
})
return NextResponse.json(response.data, { status: response.status });
} catch (error: any) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}

View File

@ -0,0 +1,36 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server';
export const POST = async () => {
// INTERPOLATING API URL OF BACKEND
const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/getservtype`
const data = JSON.parse(cookies().get('credential')?.value ?? "")
const token = `Bearer ${data.token}`
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token
},
})
return NextResponse.json(response.data, { status: response.status });
} catch (error: any) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}

View File

@ -0,0 +1,36 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server';
export const POST = async () => {
// INTERPOLATING API URL OF BACKEND
const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/getalltype`
const data = JSON.parse(cookies().get('credential')?.value ?? "")
const token = `Bearer ${data.token}`
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token
},
})
return NextResponse.json(response.data, { status: response.status });
} catch (error: any) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}

View File

@ -0,0 +1,55 @@
import axios from 'axios';
import { cookies } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server';
export const POST = async (request: NextRequest) => {
// INTERPOLATING API URL OF BACKEND
const {
offerVerId,
offerType,
reId,
ratePlanName,
ratePlanCode,
remarks,
ratePlanType,
} = await request.json();
const url: string = `${process.env.NEXT_PUBLIC_API_URL}/priceplan/createpriceplan`
const data = JSON.parse(cookies().get('credential')?.value ?? "")
const token = `Bearer ${data.token}`
try {
// MAKE AN API REQUEST
/*
* - WE USE AXIOS INSTEAD OF FETCH
* - FETCH ALWAYS RETURNS "TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed"
* WHEN WE RUN "response.json()"
*/
const response = await axios(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token
},
data: JSON.stringify({
offerVerId,
offerType,
reId,
ratePlanName,
ratePlanCode,
remarks,
ratePlanType,
})
})
return NextResponse.json(response.data, { status: response.status });
} catch (error: any) {
if (axios.isAxiosError(error)) {
return NextResponse.json(error.response?.data || { message: 'Unknown error' }, { status: error.response?.status || 500 });
}
return NextResponse.json({ message: 'An unexpected error occurred' }, { status: 500 });
}
}