Files
LogisicsApp_Client/src/services/archive/archivedClient.service.ts
m7amedez5511 538111d726 fix: resolve permission fallback bug, remove debug code, and cleanup duplication
Logic Errors
------------
- Sidebar: fix permissions fallback so a user with no permissions gets
  zero access instead of falling back to the full nav list
  (user?.permissions ?? [] instead of ?? navSections.flatMap(...))
- carMaintanance.service / UseCarsMaintanance: add pagination to the
  maintenance records fetch instead of loading the entire list at once
- api.ts: redact sensitive fields (password, token) before logging the
  request body in console.debug, to avoid leaking credentials/PII

Code Flow Problems
-------------------
- OrderFormModal: remove leftover console.log/debug statements and the
  redundant onClick handler on the submit button
- auth: remove the unused src/service/auth.service.ts (axios) and keep
  only src/services/auth.service.ts (fetch); fix useAuth.ts import path
  from
2026-07-19 14:57:48 +03:00

42 lines
1.8 KiB
TypeScript

import { get } from "../api";
import type {
ArchivedClientListResponse,
ArchivedClientResponse,
ArchivedClientOrdersResponse,
} from "@/src/types/client";
/** Building a query string to fetch archived clients with pagination */
function buildArchivedQuery(page: number, search: string): string {
return `?page=${page}&limit=10${search ? `&search=${encodeURIComponent(search)}` : ""}`;
}
export const archivedClientService = {
/** Fetching the archived client list, paginated */
getAll: (page: number, search: string, token: string | null) =>
get<ArchivedClientListResponse>(
`client/archived${buildArchivedQuery(page, search)}`,
token,
),
/** Get a single archived client by id (includes addresses) */
getById: (id: string, token: string | null) =>
get<ArchivedClientResponse>(`client/archived/${id}`, token),
/** Get soft-deleted orders belonging to a specific client */
getArchivedOrders: (clientId: string, page: number, token: string | null) =>
get<ArchivedClientOrdersResponse>(
`client/${clientId}/orders/archived?page=${page}&limit=10`,
token,
),
getAllUnwrapped: async (page, search, token) => {
const res = await archivedClientService.getAll(page, search, token);
return { items: res.data.data, total: res.data.meta.total, pages: res.data.meta.totalPages };
},
getByIdUnwrapped: async (id, token) => (await archivedClientService.getById(id, token)).data,
getArchivedOrdersUnwrapped: async (clientId, page, token) => {
const res = await archivedClientService.getArchivedOrders(clientId, page, token);
return { items: res.data.data, total: res.data.meta.total, pages: res.data.meta.totalPages };
},
// NOTE: delete/restore intentionally left out for now — mirrors
// archivedUser.service.ts, see ticket follow-up.
};