This commit is contained in:
Stefan Pejcic
2024-11-07 19:03:37 +01:00
parent c6df945ed5
commit 09f9f9502d
2472 changed files with 620417 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import axios from "axios";
interface ILoginResponse {
jwt: string;
user: IUser;
}
interface IRole {
id: number | string;
name: string;
description: string;
type: string;
}
interface IUser {
id: number | string;
username: string;
email: string;
provider: string;
confirmed: boolean;
blocked: boolean;
role: IRole;
created_at: string;
updated_at: string;
}
export const AuthHelper = (apiUrl: string) => ({
login: async (identifier: string, password: string) => {
const url = `${apiUrl}/auth/local`;
return await axios.post<ILoginResponse>(url, {
identifier,
password,
});
},
me: async (token: string) => {
return await axios.get<IUser>(`${apiUrl}/users/me`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
},
});

View File

@@ -0,0 +1,2 @@
export * from "./auth";
export * from "./normalize";

View File

@@ -0,0 +1,50 @@
export const getValueProps = (data: any, imageUrl: string) => {
if (!data) {
return { fileList: [] };
}
return {
file: data.file,
fileList:
data.fileList ??
(Array.isArray(data) ? data : [...data]).map((item: any) => {
const file: any = {
name: item.name,
percent: item.percent,
size: item.size,
status: item.status,
type: item.mime || item.type,
uid: item.id,
};
if (item.url) {
file.url = `${imageUrl}${item.url}`;
}
return file;
}),
};
};
export const mediaUploadMapper = (params: any) => {
Object.keys(params).map((item) => {
if (params[item]) {
const param = params[item].fileList;
const isMediaField = Array.isArray(param);
if (isMediaField) {
const ids = [];
for (const item of param) {
if (item.response) {
for (const response of item.response) {
ids.push(response.id);
}
} else {
ids.push(item.uid);
}
}
params[item] = ids;
}
}
});
return params;
};