Add Oudelaa dashboard API integration
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled
هذا الالتزام موجود في:
97
oudelaa_dashboard/lib/api/admin-users.ts
Normal file
97
oudelaa_dashboard/lib/api/admin-users.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type {
|
||||
AdminCreatePayload,
|
||||
AdminUpdatePayload,
|
||||
ApiRole,
|
||||
ApiUser,
|
||||
PaginatedResponse,
|
||||
ProfileOverviewResponse,
|
||||
SuccessMessage,
|
||||
} from "@/types/api";
|
||||
|
||||
function normalizeUser(user: Partial<ApiUser> & { id?: string }) {
|
||||
return {
|
||||
...user,
|
||||
_id: user._id ?? user.id ?? "",
|
||||
} as ApiUser;
|
||||
}
|
||||
|
||||
function normalizeUsersResponse(response: PaginatedResponse<ApiUser>) {
|
||||
return {
|
||||
...response,
|
||||
items: Array.isArray(response.items) ? response.items.map((item) => normalizeUser(item)) : response.items,
|
||||
data: Array.isArray(response.data) ? response.data.map((item) => normalizeUser(item)) : response.data,
|
||||
};
|
||||
}
|
||||
|
||||
export async function listPlatformAdmins(page = 1, limit = 20) {
|
||||
const response = await fetchWithAuth<PaginatedResponse<ApiUser>>(
|
||||
apiEndpoints.users.admins({ page, limit }),
|
||||
);
|
||||
return normalizeUsersResponse(response);
|
||||
}
|
||||
|
||||
export async function getAdminUserById(userId: string) {
|
||||
const response = await fetchWithAuth<ApiUser>(apiEndpoints.users.byId(userId));
|
||||
return normalizeUser(response);
|
||||
}
|
||||
|
||||
export async function updateAdminUser(userId: string, payload: AdminUpdatePayload) {
|
||||
const response = await fetchWithAuth<ApiUser>(apiEndpoints.users.update(userId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
return normalizeUser(response);
|
||||
}
|
||||
|
||||
export async function updatePlatformAdmin(userId: string, payload: AdminUpdatePayload) {
|
||||
const response = await fetchWithAuth<ApiUser>(apiEndpoints.users.updateAdmin(userId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
return normalizeUser(response);
|
||||
}
|
||||
|
||||
export async function setAdminUserRole(userId: string, role: ApiRole) {
|
||||
const response = await fetchWithAuth<ApiUser>(apiEndpoints.users.setRole(userId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ role }),
|
||||
});
|
||||
return normalizeUser(response);
|
||||
}
|
||||
|
||||
export async function deleteAdminUser(userId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.users.remove(userId), { method: "DELETE" });
|
||||
}
|
||||
|
||||
export async function deletePlatformAdmin(userId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.users.removeAdmin(userId), { method: "DELETE" });
|
||||
}
|
||||
|
||||
export async function createAdminUser(payload: AdminCreatePayload) {
|
||||
const response = await fetchWithAuth<ApiUser>(apiEndpoints.users.createAdmin, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
return normalizeUser(response);
|
||||
}
|
||||
|
||||
export async function searchAdminUsers(params: Record<string, string | number | boolean | null | undefined>) {
|
||||
const response = await fetchWithAuth<PaginatedResponse<ApiUser>>(apiEndpoints.users.all(params));
|
||||
return normalizeUsersResponse(response);
|
||||
}
|
||||
|
||||
export async function discoverAdminUsers(params: Record<string, string | number | boolean | null | undefined>) {
|
||||
const response = await fetchWithAuth<PaginatedResponse<ApiUser>>(apiEndpoints.users.discover(params));
|
||||
return normalizeUsersResponse(response);
|
||||
}
|
||||
|
||||
export async function searchPlatformAdmins(params: Record<string, string | number | boolean | null | undefined>) {
|
||||
const response = await fetchWithAuth<PaginatedResponse<ApiUser>>(apiEndpoints.users.admins(params));
|
||||
return normalizeUsersResponse(response);
|
||||
}
|
||||
|
||||
export async function getProfileOverviewForSuperAdmin(userId: string) {
|
||||
return fetchWithAuth<ProfileOverviewResponse>(apiEndpoints.users.profileOverview(userId));
|
||||
}
|
||||
7
oudelaa_dashboard/lib/api/audit.ts
Normal file
7
oudelaa_dashboard/lib/api/audit.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type { AuditLogsResponse } from "@/types/api";
|
||||
|
||||
export async function listAuditLogs(params: Record<string, string | number | boolean | null | undefined> = {}) {
|
||||
return fetchWithAuth<AuditLogsResponse>(apiEndpoints.audit.logs(params));
|
||||
}
|
||||
34
oudelaa_dashboard/lib/api/auth.ts
Normal file
34
oudelaa_dashboard/lib/api/auth.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type { LoginResponse, SessionsResponse, SuccessMessage } from "@/types/api";
|
||||
|
||||
export async function loginDashboardUser(email: string, password: string) {
|
||||
return fetchWithAuth<LoginResponse>(apiEndpoints.auth.login, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ email, password }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function refreshDashboardUser(refreshToken: string) {
|
||||
return fetchWithAuth<LoginResponse>(apiEndpoints.auth.refresh, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ refreshToken }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function logoutDashboardUser(refreshToken: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.auth.logout, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ refreshToken }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function listSuperAdminSessions() {
|
||||
return fetchWithAuth<SessionsResponse>(apiEndpoints.auth.superAdminSessions);
|
||||
}
|
||||
|
||||
export async function revokeSuperAdminSession(sessionId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.auth.revokeSuperAdminSession(sessionId), {
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
15
oudelaa_dashboard/lib/api/comments.ts
Normal file
15
oudelaa_dashboard/lib/api/comments.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type { CommentsResponse, SuccessMessage } from "@/types/api";
|
||||
|
||||
export async function listModerationComments(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<CommentsResponse>(apiEndpoints.comments.moderation(params));
|
||||
}
|
||||
|
||||
export async function deleteAdminComment(commentId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.comments.adminDelete(commentId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
36
oudelaa_dashboard/lib/api/core.ts
Normal file
36
oudelaa_dashboard/lib/api/core.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { ApiIdentifier, PaginatedResponse } from "@/types/api";
|
||||
|
||||
export function getEntityId(entity?: ApiIdentifier | null) {
|
||||
if (!entity) return "";
|
||||
return entity._id ?? entity.id ?? "";
|
||||
}
|
||||
|
||||
export function getItems<T>(payload: PaginatedResponse<T> | T[] | undefined | null) {
|
||||
if (!payload) return [] as T[];
|
||||
if (Array.isArray(payload)) return payload;
|
||||
if (Array.isArray(payload.items)) return payload.items;
|
||||
if (Array.isArray(payload.data)) return payload.data;
|
||||
return [] as T[];
|
||||
}
|
||||
|
||||
export function getTotal<T>(payload: PaginatedResponse<T> | undefined | null) {
|
||||
if (!payload) return 0;
|
||||
if (typeof payload.pagination?.total === "number") return payload.pagination.total;
|
||||
if (typeof payload.total === "number") return payload.total;
|
||||
return getItems(payload).length;
|
||||
}
|
||||
|
||||
export function getPagination<T>(payload: PaginatedResponse<T> | undefined | null) {
|
||||
return payload?.pagination ?? null;
|
||||
}
|
||||
|
||||
export function toQueryString(params: Record<string, string | number | boolean | null | undefined>) {
|
||||
const search = new URLSearchParams();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value === undefined || value === null || value === "") return;
|
||||
search.set(key, String(value));
|
||||
});
|
||||
|
||||
return search.toString();
|
||||
}
|
||||
118
oudelaa_dashboard/lib/api/endpoints.ts
Normal file
118
oudelaa_dashboard/lib/api/endpoints.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
import { toQueryString } from "@/lib/api/core";
|
||||
|
||||
export const apiEndpoints = {
|
||||
health: "/",
|
||||
auth: {
|
||||
login: "/auth/login",
|
||||
refresh: "/auth/refresh",
|
||||
logout: "/auth/logout",
|
||||
superAdminLogin: "/auth/superadmin/login",
|
||||
superAdminRefresh: "/auth/superadmin/refresh",
|
||||
superAdminLogout: "/auth/superadmin/logout",
|
||||
superAdminSessions: "/auth/superadmin/sessions",
|
||||
revokeSuperAdminSession: (sessionId: string) => `/auth/superadmin/sessions/${sessionId}/revoke`,
|
||||
},
|
||||
users: {
|
||||
all: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/users/admin?${toQueryString(params)}`,
|
||||
byId: (userId: string) => `/users/admin/${userId}`,
|
||||
update: (userId: string) => `/users/admin/${userId}`,
|
||||
disable: (userId: string) => `/users/admin/${userId}/disable`,
|
||||
enable: (userId: string) => `/users/admin/${userId}/enable`,
|
||||
remove: (userId: string) => `/users/admin/${userId}`,
|
||||
setRole: (userId: string) => `/users/admin/${userId}/role`,
|
||||
admins: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/users/admin/admins?${toQueryString(params)}`,
|
||||
updateAdmin: (userId: string) => `/users/admin/admins/${userId}`,
|
||||
removeAdmin: (userId: string) => `/users/admin/admins/${userId}`,
|
||||
createAdmin: "/users/admin/create-admin",
|
||||
discover: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/users/admin/discover?${toQueryString(params)}`,
|
||||
profileOverview: (userId: string) => `/users/admin/${userId}/profile-overview`,
|
||||
},
|
||||
posts: {
|
||||
moderation: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/posts/admin/moderation?${toQueryString(params)}`,
|
||||
adminDelete: (postId: string) => `/posts/admin/${postId}`,
|
||||
},
|
||||
comments: {
|
||||
moderation: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/comments/admin?${toQueryString(params)}`,
|
||||
adminDelete: (commentId: string) => `/comments/admin/${commentId}`,
|
||||
},
|
||||
notifications: {
|
||||
superAdmin: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/notifications/superadmin?${toQueryString(params)}`,
|
||||
},
|
||||
reports: {
|
||||
superAdmin: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/reports/superadmin?${toQueryString(params)}`,
|
||||
updateStatus: (reportId: string) => `/reports/superadmin/${reportId}/status`,
|
||||
},
|
||||
marketplace: {
|
||||
home: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/marketplace/home?${toQueryString(params)}`,
|
||||
shopByAdminId: (adminId: string) => `/marketplace/shops/${adminId}`,
|
||||
adminShopProfile: "/marketplace/admin/shop-profile",
|
||||
adminMyShopProfile: "/marketplace/admin/shop-profile/me",
|
||||
adminCreateRepairShop: "/marketplace/admin/repair-shops",
|
||||
adminUpdateRepairShop: (repairShopId: string) => `/marketplace/admin/repair-shops/${repairShopId}`,
|
||||
adminDeleteRepairShop: (repairShopId: string) => `/marketplace/admin/repair-shops/${repairShopId}`,
|
||||
adminMyRepairShops: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/marketplace/admin/repair-shops/me?${toQueryString(params)}`,
|
||||
adminCreateInstrument: "/marketplace/admin/instruments",
|
||||
adminUpdateInstrument: (instrumentId: string) => `/marketplace/admin/instruments/${instrumentId}`,
|
||||
adminDeleteInstrument: (instrumentId: string) => `/marketplace/admin/instruments/${instrumentId}`,
|
||||
adminMyInstruments: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/marketplace/admin/instruments/me?${toQueryString(params)}`,
|
||||
adminCreateListing: "/marketplace/admin/listings",
|
||||
adminUpdateListing: (listingId: string) => `/marketplace/admin/listings/${listingId}`,
|
||||
adminDeleteListing: (listingId: string) => `/marketplace/admin/listings/${listingId}`,
|
||||
adminMyListings: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/marketplace/admin/listings/me?${toQueryString(params)}`,
|
||||
moderationListings: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/marketplace/superadmin/listings?${toQueryString(params)}`,
|
||||
superAdminCreateListing: (adminId: string) => `/marketplace/superadmin/admins/${adminId}/listings`,
|
||||
superAdminCreateInstrument: (adminId: string) => `/marketplace/superadmin/admins/${adminId}/instruments`,
|
||||
superAdminCreateRepairShop: (adminId: string) => `/marketplace/superadmin/admins/${adminId}/repair-shops`,
|
||||
superAdminUpdateShopProfile: (adminId: string) => `/marketplace/superadmin/admins/${adminId}/shop-profile`,
|
||||
moderationUpdateListingStatus: (listingId: string) => `/marketplace/superadmin/listings/${listingId}/status`,
|
||||
moderationDeleteListing: (listingId: string) => `/marketplace/superadmin/listings/${listingId}`,
|
||||
moderationRepairShops: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/marketplace/superadmin/repair-shops?${toQueryString(params)}`,
|
||||
moderationUpdateRepairShopStatus: (repairShopId: string) =>
|
||||
`/marketplace/superadmin/repair-shops/${repairShopId}/status`,
|
||||
moderationDeleteRepairShop: (repairShopId: string) => `/marketplace/superadmin/repair-shops/${repairShopId}`,
|
||||
},
|
||||
audit: {
|
||||
logs: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/audit/superadmin/logs?${toQueryString(params)}`,
|
||||
},
|
||||
superadmin: {
|
||||
session: "/superadmin/session",
|
||||
overview: "/superadmin/overview",
|
||||
charts: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/superadmin/charts?${toQueryString(params)}`,
|
||||
recentActivity: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/superadmin/recent-activity?${toQueryString(params)}`,
|
||||
reports: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/superadmin/reports?${toQueryString(params)}`,
|
||||
ops: "/superadmin/ops",
|
||||
cases: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/superadmin/cases?${toQueryString(params)}`,
|
||||
createCase: "/superadmin/cases",
|
||||
caseById: (caseId: string) => `/superadmin/cases/${caseId}`,
|
||||
bulkActions: "/superadmin/bulk-actions",
|
||||
settings: "/superadmin/settings",
|
||||
settingsHistory: (params: Record<string, string | number | boolean | null | undefined> = {}) =>
|
||||
`/superadmin/settings/history?${toQueryString(params)}`,
|
||||
restoreSettingsHistory: (historyId: string) => `/superadmin/settings/history/${historyId}/restore`,
|
||||
updatePostStatus: (postId: string) => `/superadmin/posts/${postId}/status`,
|
||||
deletePost: (postId: string) => `/superadmin/posts/${postId}`,
|
||||
restorePost: (postId: string) => `/superadmin/posts/${postId}/restore`,
|
||||
updateCommentStatus: (commentId: string) => `/superadmin/comments/${commentId}/status`,
|
||||
deleteComment: (commentId: string) => `/superadmin/comments/${commentId}`,
|
||||
restoreComment: (commentId: string) => `/superadmin/comments/${commentId}/restore`,
|
||||
updateUserStatus: (userId: string) => `/superadmin/users/${userId}/status`,
|
||||
},
|
||||
} as const;
|
||||
6
oudelaa_dashboard/lib/api/health.ts
Normal file
6
oudelaa_dashboard/lib/api/health.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
|
||||
export async function getHealth() {
|
||||
return fetchWithAuth<string | Record<string, unknown>>(apiEndpoints.health);
|
||||
}
|
||||
236
oudelaa_dashboard/lib/api/marketplace.ts
Normal file
236
oudelaa_dashboard/lib/api/marketplace.ts
Normal file
@@ -0,0 +1,236 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type {
|
||||
MarketplaceHomeResponse,
|
||||
MarketplaceListing,
|
||||
MarketplaceRepairShop,
|
||||
MarketplaceRepairShopResponse,
|
||||
MarketplaceResponse,
|
||||
MarketplaceShopProfile,
|
||||
SuccessMessage,
|
||||
} from "@/types/api";
|
||||
|
||||
type MarketplaceFormValue =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| File
|
||||
| null
|
||||
| undefined
|
||||
| Array<string | number | boolean | File>;
|
||||
|
||||
type MarketplaceFormPayload = Record<string, MarketplaceFormValue>;
|
||||
|
||||
function appendFormValue(formData: FormData, key: string, value: MarketplaceFormValue) {
|
||||
if (value === undefined || value === null || value === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((entry) => appendFormValue(formData, key, entry));
|
||||
return;
|
||||
}
|
||||
|
||||
if (value instanceof File) {
|
||||
formData.append(key, value);
|
||||
return;
|
||||
}
|
||||
|
||||
formData.append(key, String(value));
|
||||
}
|
||||
|
||||
function toMarketplaceFormData(payload: MarketplaceFormPayload) {
|
||||
const formData = new FormData();
|
||||
Object.entries(payload).forEach(([key, value]) => appendFormValue(formData, key, value));
|
||||
return formData;
|
||||
}
|
||||
|
||||
export async function getMarketplaceHome(params: Record<string, string | number | boolean | null | undefined> = {}) {
|
||||
return fetchWithAuth<MarketplaceHomeResponse>(apiEndpoints.marketplace.home(params));
|
||||
}
|
||||
|
||||
export async function getMarketplaceShopByAdminId(adminId: string) {
|
||||
return fetchWithAuth<MarketplaceShopProfile>(apiEndpoints.marketplace.shopByAdminId(adminId));
|
||||
}
|
||||
|
||||
export async function getAdminShopProfile() {
|
||||
return fetchWithAuth<MarketplaceShopProfile>(apiEndpoints.marketplace.adminMyShopProfile);
|
||||
}
|
||||
|
||||
export async function updateAdminShopProfile(payload: MarketplaceFormPayload) {
|
||||
return fetchWithAuth<MarketplaceShopProfile>(apiEndpoints.marketplace.adminShopProfile, {
|
||||
method: "PATCH",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function createAdminRepairShop(payload: MarketplaceFormPayload) {
|
||||
return fetchWithAuth<MarketplaceRepairShop>(apiEndpoints.marketplace.adminCreateRepairShop, {
|
||||
method: "POST",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateAdminRepairShop(repairShopId: string, payload: MarketplaceFormPayload) {
|
||||
return fetchWithAuth<MarketplaceRepairShop>(apiEndpoints.marketplace.adminUpdateRepairShop(repairShopId), {
|
||||
method: "PATCH",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteAdminRepairShop(repairShopId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.marketplace.adminDeleteRepairShop(repairShopId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function listAdminRepairShops(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceRepairShopResponse>(apiEndpoints.marketplace.adminMyRepairShops(params));
|
||||
}
|
||||
|
||||
export async function createAdminInstrument(payload: MarketplaceFormPayload) {
|
||||
return fetchWithAuth<MarketplaceListing>(apiEndpoints.marketplace.adminCreateInstrument, {
|
||||
method: "POST",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateAdminInstrument(instrumentId: string, payload: MarketplaceFormPayload) {
|
||||
return fetchWithAuth<MarketplaceListing>(apiEndpoints.marketplace.adminUpdateInstrument(instrumentId), {
|
||||
method: "PATCH",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteAdminInstrument(instrumentId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.marketplace.adminDeleteInstrument(instrumentId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function listAdminInstruments(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceResponse>(apiEndpoints.marketplace.adminMyInstruments(params));
|
||||
}
|
||||
|
||||
export async function createAdminListing(payload: MarketplaceFormPayload) {
|
||||
return fetchWithAuth<MarketplaceListing>(apiEndpoints.marketplace.adminCreateListing, {
|
||||
method: "POST",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateAdminListing(listingId: string, payload: MarketplaceFormPayload) {
|
||||
return fetchWithAuth<MarketplaceListing>(apiEndpoints.marketplace.adminUpdateListing(listingId), {
|
||||
method: "PATCH",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteAdminListing(listingId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.marketplace.adminDeleteListing(listingId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function listAdminListings(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceResponse>(apiEndpoints.marketplace.adminMyListings(params));
|
||||
}
|
||||
|
||||
export async function listModerationListings(params: Record<string, string | number | boolean | null | undefined> = {}) {
|
||||
return fetchWithAuth<MarketplaceResponse>(apiEndpoints.marketplace.moderationListings(params));
|
||||
}
|
||||
|
||||
export async function updateModerationListingStatus(
|
||||
listingId: string,
|
||||
isActive: boolean,
|
||||
reason?: string,
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceListing>(apiEndpoints.marketplace.moderationUpdateListingStatus(listingId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ isActive, reason }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteModerationListing(listingId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.marketplace.moderationDeleteListing(listingId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function listModerationRepairShops(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceRepairShopResponse>(apiEndpoints.marketplace.moderationRepairShops(params));
|
||||
}
|
||||
|
||||
export async function updateModerationRepairShopStatus(
|
||||
repairShopId: string,
|
||||
isActive: boolean,
|
||||
reason?: string,
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceRepairShop>(
|
||||
apiEndpoints.marketplace.moderationUpdateRepairShopStatus(repairShopId),
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ isActive, reason }),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteModerationRepairShop(repairShopId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.marketplace.moderationDeleteRepairShop(repairShopId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function createMarketplaceListingForSuperAdmin(
|
||||
adminId: string,
|
||||
payload: MarketplaceFormPayload,
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceListing>(apiEndpoints.marketplace.superAdminCreateListing(adminId), {
|
||||
method: "POST",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function createMarketplaceInstrumentForSuperAdmin(
|
||||
adminId: string,
|
||||
payload: MarketplaceFormPayload,
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceListing>(apiEndpoints.marketplace.superAdminCreateInstrument(adminId), {
|
||||
method: "POST",
|
||||
body: toMarketplaceFormData(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function createMarketplaceRepairShopForSuperAdmin(
|
||||
adminId: string,
|
||||
payload: MarketplaceFormPayload,
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceRepairShop>(
|
||||
apiEndpoints.marketplace.superAdminCreateRepairShop(adminId),
|
||||
{
|
||||
method: "POST",
|
||||
body: toMarketplaceFormData(payload),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateMarketplaceShopProfileForSuperAdmin(
|
||||
adminId: string,
|
||||
payload: MarketplaceFormPayload,
|
||||
) {
|
||||
return fetchWithAuth<MarketplaceShopProfile>(
|
||||
apiEndpoints.marketplace.superAdminUpdateShopProfile(adminId),
|
||||
{
|
||||
method: "PATCH",
|
||||
body: toMarketplaceFormData(payload),
|
||||
},
|
||||
);
|
||||
}
|
||||
9
oudelaa_dashboard/lib/api/notifications.ts
Normal file
9
oudelaa_dashboard/lib/api/notifications.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type { NotificationsResponse } from "@/types/api";
|
||||
|
||||
export async function listPlatformNotifications(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<NotificationsResponse>(apiEndpoints.notifications.superAdmin(params));
|
||||
}
|
||||
13
oudelaa_dashboard/lib/api/posts.ts
Normal file
13
oudelaa_dashboard/lib/api/posts.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type { PostsResponse, SuccessMessage } from "@/types/api";
|
||||
|
||||
export async function listModerationPosts(params: Record<string, string | number | boolean | null | undefined> = {}) {
|
||||
return fetchWithAuth<PostsResponse>(apiEndpoints.posts.moderation(params));
|
||||
}
|
||||
|
||||
export async function deleteAdminPost(postId: string) {
|
||||
return fetchWithAuth<SuccessMessage>(apiEndpoints.posts.adminDelete(postId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
20
oudelaa_dashboard/lib/api/reports.ts
Normal file
20
oudelaa_dashboard/lib/api/reports.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type { PlatformReport, ReportsResponse, ReportStatus } from "@/types/api";
|
||||
|
||||
export async function listPlatformReports(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<ReportsResponse>(apiEndpoints.reports.superAdmin(params));
|
||||
}
|
||||
|
||||
export async function updatePlatformReportStatus(
|
||||
reportId: string,
|
||||
status: ReportStatus,
|
||||
resolutionNote?: string,
|
||||
) {
|
||||
return fetchWithAuth<PlatformReport>(apiEndpoints.reports.updateStatus(reportId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ status, resolutionNote }),
|
||||
});
|
||||
}
|
||||
182
oudelaa_dashboard/lib/api/superadmin.ts
Normal file
182
oudelaa_dashboard/lib/api/superadmin.ts
Normal file
@@ -0,0 +1,182 @@
|
||||
import { apiEndpoints } from "@/lib/api/endpoints";
|
||||
import { fetchWithAuth } from "@/lib/auth/client";
|
||||
import type {
|
||||
ApiComment,
|
||||
ApiPost,
|
||||
ApiUser,
|
||||
CreateSuperAdminCasePayload,
|
||||
ModerationStatus,
|
||||
SuperAdminCase,
|
||||
SuperAdminCasesResponse,
|
||||
SuperAdminChartsResponse,
|
||||
SuperAdminOpsResponse,
|
||||
SuperAdminOverviewResponse,
|
||||
SuperAdminRecentActivityResponse,
|
||||
SuperAdminReportsResponse,
|
||||
SuperAdminSessionResponse,
|
||||
SuperAdminSettings,
|
||||
SuperAdminSettingsHistoryResponse,
|
||||
SuperAdminSettingsResponse,
|
||||
} from "@/types/api";
|
||||
|
||||
export async function getSuperAdminSession() {
|
||||
return fetchWithAuth<SuperAdminSessionResponse>(apiEndpoints.superadmin.session);
|
||||
}
|
||||
|
||||
export async function getSuperAdminOverview() {
|
||||
return fetchWithAuth<SuperAdminOverviewResponse>(apiEndpoints.superadmin.overview);
|
||||
}
|
||||
|
||||
export async function getSuperAdminCharts(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<SuperAdminChartsResponse>(apiEndpoints.superadmin.charts(params));
|
||||
}
|
||||
|
||||
export async function getSuperAdminRecentActivity(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<SuperAdminRecentActivityResponse>(apiEndpoints.superadmin.recentActivity(params));
|
||||
}
|
||||
|
||||
export async function getSuperAdminReports(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<SuperAdminReportsResponse>(apiEndpoints.superadmin.reports(params));
|
||||
}
|
||||
|
||||
export async function getSuperAdminOps() {
|
||||
return fetchWithAuth<SuperAdminOpsResponse>(apiEndpoints.superadmin.ops);
|
||||
}
|
||||
|
||||
export async function getSuperAdminCases(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<SuperAdminCasesResponse>(apiEndpoints.superadmin.cases(params));
|
||||
}
|
||||
|
||||
export async function createSuperAdminCase(payload: CreateSuperAdminCasePayload) {
|
||||
return fetchWithAuth<SuperAdminCase>(apiEndpoints.superadmin.createCase, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateSuperAdminCase(
|
||||
caseId: string,
|
||||
payload: Partial<SuperAdminCase> & { note?: string },
|
||||
) {
|
||||
return fetchWithAuth<SuperAdminCase>(apiEndpoints.superadmin.caseById(caseId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function performSuperAdminBulkAction(payload: {
|
||||
resourceType: string;
|
||||
targetIds: string[];
|
||||
action: string;
|
||||
reason?: string;
|
||||
priority?: string;
|
||||
assignToMe?: boolean;
|
||||
}) {
|
||||
return fetchWithAuth<Record<string, unknown>>(apiEndpoints.superadmin.bulkActions, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function getSuperAdminSettings() {
|
||||
return fetchWithAuth<SuperAdminSettingsResponse>(apiEndpoints.superadmin.settings);
|
||||
}
|
||||
|
||||
export async function getSuperAdminSettingsHistory(
|
||||
params: Record<string, string | number | boolean | null | undefined> = {},
|
||||
) {
|
||||
return fetchWithAuth<SuperAdminSettingsHistoryResponse>(
|
||||
apiEndpoints.superadmin.settingsHistory(params),
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateSuperAdminSettings(payload: Partial<SuperAdminSettings>) {
|
||||
return fetchWithAuth<SuperAdminSettingsResponse>(apiEndpoints.superadmin.settings, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function restoreSuperAdminSettingsHistory(historyId: string) {
|
||||
return fetchWithAuth<SuperAdminSettingsResponse>(
|
||||
apiEndpoints.superadmin.restoreSettingsHistory(historyId),
|
||||
{
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateSuperAdminPostStatus(postId: string, status: ModerationStatus, reason?: string) {
|
||||
return fetchWithAuth<ApiPost>(apiEndpoints.superadmin.updatePostStatus(postId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ status, reason }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteSuperAdminPost(postId: string) {
|
||||
return fetchWithAuth<Record<string, unknown>>(apiEndpoints.superadmin.deletePost(postId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function restoreSuperAdminPost(postId: string) {
|
||||
return fetchWithAuth<ApiPost>(apiEndpoints.superadmin.restorePost(postId), {
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateSuperAdminCommentStatus(
|
||||
commentId: string,
|
||||
status: ModerationStatus,
|
||||
reason?: string,
|
||||
) {
|
||||
return fetchWithAuth<ApiComment>(apiEndpoints.superadmin.updateCommentStatus(commentId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ status, reason }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteSuperAdminComment(commentId: string) {
|
||||
return fetchWithAuth<Record<string, unknown>>(apiEndpoints.superadmin.deleteComment(commentId), {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function restoreSuperAdminComment(commentId: string) {
|
||||
return fetchWithAuth<ApiComment>(apiEndpoints.superadmin.restoreComment(commentId), {
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateSuperAdminUserStatus(userId: string, isDisabled: boolean, reason?: string) {
|
||||
try {
|
||||
return await fetchWithAuth<ApiUser>(apiEndpoints.superadmin.updateUserStatus(userId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ isDisabled, reason }),
|
||||
});
|
||||
} catch (error) {
|
||||
const message = String(error);
|
||||
if (!message.includes("404")) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (isDisabled) {
|
||||
return fetchWithAuth<ApiUser>(apiEndpoints.users.disable(userId), {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ reason: reason ?? "Disabled by SuperAdmin dashboard" }),
|
||||
});
|
||||
}
|
||||
|
||||
return fetchWithAuth<ApiUser>(apiEndpoints.users.enable(userId), {
|
||||
method: "PATCH",
|
||||
});
|
||||
}
|
||||
}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم