change routee
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* - Sends the raw JWT access token in the Authorization header
|
||||
* (the backend middleware expects the bare token, no "Bearer " prefix).
|
||||
* - Unwraps the response envelope { status, message, code, data }.
|
||||
* - On 401 tries a one-shot refresh via POST /v1/admin/token, then retries.
|
||||
* - On 401 tries a one-shot refresh via POST /api/v1/admin/token, then retries.
|
||||
* - Throws ApiError with a friendly, human-readable message.
|
||||
*/
|
||||
(function () {
|
||||
@@ -95,7 +95,7 @@
|
||||
const refreshToken = tokens.refresh;
|
||||
if (!refreshToken) return false;
|
||||
try {
|
||||
const response = await fetch("/v1/admin/token", {
|
||||
const response = await fetch("/api/v1/admin/token", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ refreshToken }),
|
||||
@@ -116,7 +116,7 @@
|
||||
/**
|
||||
* Perform an authenticated JSON request.
|
||||
* @param {string} method HTTP method
|
||||
* @param {string} path request path, e.g. /v1/admin/news
|
||||
* @param {string} path request path, e.g. /api/v1/admin/news
|
||||
* @param {{ body?: object, query?: object, formData?: FormData, retried?: boolean }} [options]
|
||||
*/
|
||||
async function request(method, path, options) {
|
||||
@@ -171,7 +171,7 @@
|
||||
function upload(file) {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
return request("POST", "/v1/admin/file", { formData });
|
||||
return request("POST", "/api/v1/admin/file", { formData });
|
||||
}
|
||||
|
||||
window.Api = {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
/** Sign in and store the token pair. */
|
||||
async function login(loginValue, password) {
|
||||
const pair = await Api.post("/v1/admin/login", {
|
||||
const pair = await Api.post("/api/v1/admin/login", {
|
||||
login: loginValue,
|
||||
password: password,
|
||||
});
|
||||
@@ -37,7 +37,7 @@
|
||||
const initialEl = document.getElementById("profile-initial");
|
||||
if (!nameEl) return;
|
||||
try {
|
||||
const profile = await Api.get("/v1/admin/get-profile");
|
||||
const profile = await Api.get("/api/v1/admin/get-profile");
|
||||
const fullName = (profile && profile.fullName) || "Admin";
|
||||
nameEl.textContent = fullName;
|
||||
if (avatarEl && profile && profile.avatar) {
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
"use strict";
|
||||
|
||||
const CARDS = [
|
||||
{ id: "stat-news", endpoint: "/v1/admin/news", listKey: "news" },
|
||||
{ id: "stat-categories", endpoint: "/v1/admin/categories", listKey: "categories" },
|
||||
{ id: "stat-banners", endpoint: "/v1/admin/banner", listKey: "banners" },
|
||||
{ id: "stat-static", endpoint: "/v1/admin/static", listKey: "statics" },
|
||||
{ id: "stat-currency", endpoint: "/v1/admin/currency", listKey: "currencies" },
|
||||
{ id: "stat-news", endpoint: "/api/v1/admin/news", listKey: "news" },
|
||||
{ id: "stat-categories", endpoint: "/api/v1/admin/categories", listKey: "categories" },
|
||||
{ id: "stat-banners", endpoint: "/api/v1/admin/banner", listKey: "banners" },
|
||||
{ id: "stat-static", endpoint: "/api/v1/admin/static", listKey: "statics" },
|
||||
{ id: "stat-currency", endpoint: "/api/v1/admin/currency", listKey: "currencies" },
|
||||
];
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
@@ -37,7 +37,7 @@
|
||||
const container = document.getElementById("latest-news");
|
||||
if (!container) return;
|
||||
try {
|
||||
const data = await Api.get("/v1/admin/news", { limit: 5, page: 1 });
|
||||
const data = await Api.get("/api/v1/admin/news", { limit: 5, page: 1 });
|
||||
const items = (data && data.news) || [];
|
||||
if (!items.length) {
|
||||
container.innerHTML =
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
window.Resources = {
|
||||
categories: {
|
||||
title: "Categories",
|
||||
endpoint: "/v1/admin/categories",
|
||||
endpoint: "/api/v1/admin/categories",
|
||||
listKey: "categories",
|
||||
searchable: true,
|
||||
statusToggle: true,
|
||||
@@ -36,19 +36,19 @@
|
||||
|
||||
"sub-categories": {
|
||||
title: "Sub-categories",
|
||||
endpoint: "/v1/admin/sub-categories",
|
||||
endpoint: "/api/v1/admin/sub-categories",
|
||||
listKey: "subCategory",
|
||||
searchable: true,
|
||||
statusToggle: true,
|
||||
// The list endpoint is scoped by category: GET /v1/admin/sub-categories/:categoryId
|
||||
// The list endpoint is scoped by category: GET /api/v1/admin/sub-categories/:categoryId
|
||||
parentFilter: {
|
||||
label: "Category",
|
||||
endpoint: "/v1/admin/categories",
|
||||
endpoint: "/api/v1/admin/categories",
|
||||
listKey: "categories",
|
||||
labelField: "name",
|
||||
},
|
||||
listUrl: (state) => "/v1/admin/sub-categories/" + state.parentId,
|
||||
getOneUrl: (id) => "/v1/admin/sub-categories/" + id + "/edit",
|
||||
listUrl: (state) => "/api/v1/admin/sub-categories/" + state.parentId,
|
||||
getOneUrl: (id) => "/api/v1/admin/sub-categories/" + id + "/edit",
|
||||
columns: [
|
||||
{ key: "Id", label: "ID", type: "id", sortKey: "id" },
|
||||
{ key: "name", label: "Name", type: "lang" },
|
||||
@@ -62,7 +62,7 @@
|
||||
type: "select",
|
||||
required: true,
|
||||
options: {
|
||||
endpoint: "/v1/admin/categories",
|
||||
endpoint: "/api/v1/admin/categories",
|
||||
listKey: "categories",
|
||||
valueField: "Id",
|
||||
labelField: "name",
|
||||
@@ -80,7 +80,7 @@
|
||||
|
||||
banners: {
|
||||
title: "Banners",
|
||||
endpoint: "/v1/admin/banner",
|
||||
endpoint: "/api/v1/admin/banner",
|
||||
listKey: "banners",
|
||||
searchable: true,
|
||||
columns: [
|
||||
@@ -119,7 +119,7 @@
|
||||
|
||||
news: {
|
||||
title: "News",
|
||||
endpoint: "/v1/admin/news",
|
||||
endpoint: "/api/v1/admin/news",
|
||||
listKey: "news",
|
||||
searchable: true,
|
||||
columns: [
|
||||
@@ -144,7 +144,7 @@
|
||||
|
||||
static: {
|
||||
title: "Static pages",
|
||||
endpoint: "/v1/admin/static",
|
||||
endpoint: "/api/v1/admin/static",
|
||||
listKey: "statics",
|
||||
searchable: true,
|
||||
columns: [
|
||||
@@ -184,7 +184,7 @@
|
||||
|
||||
currency: {
|
||||
title: "Currency",
|
||||
endpoint: "/v1/admin/currency",
|
||||
endpoint: "/api/v1/admin/currency",
|
||||
listKey: "currencies",
|
||||
searchable: true,
|
||||
columns: [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Settings page: single-record form backed by
|
||||
* GET /v1/admin/setting and POST /v1/admin/setting/:id.
|
||||
* GET /api/v1/admin/setting and POST /api/v1/admin/setting/:id.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const setting = await Api.get("/v1/admin/setting");
|
||||
const setting = await Api.get("/api/v1/admin/setting");
|
||||
if (setting) {
|
||||
settingId = setting.Id || 1;
|
||||
logoPath.value = setting.logoR || "";
|
||||
@@ -68,7 +68,7 @@
|
||||
errorEl.classList.add("hidden");
|
||||
UI.setLoading(submitButton, true);
|
||||
try {
|
||||
const saved = await Api.post("/v1/admin/setting/" + (settingId || 1), {
|
||||
const saved = await Api.post("/api/v1/admin/setting/" + (settingId || 1), {
|
||||
logoR: logoPath.value,
|
||||
phoneNumber: phoneInput.value.trim(),
|
||||
faxNumber: faxInput.value.trim(),
|
||||
|
||||
Reference in New Issue
Block a user