ref: change auth setting in Login Screen
This commit is contained in:
parent
9d31ea245c
commit
12c90ff120
26 changed files with 1149 additions and 99 deletions
75
package/config/api/Admin/user/GetTypeUsers/page.tsx
Normal file
75
package/config/api/Admin/user/GetTypeUsers/page.tsx
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import { BASE_URL_ADMINISTRATION } from "@package/config/ApiPath"
|
||||
import { FetchData } from "@package/config/FetchData"
|
||||
import { ReturnService } from "@package/config/ReturnService"
|
||||
import { GRID_SIZE } from "@package/utils/Constants"
|
||||
import i18n from "@package/utils/language/i18n"
|
||||
import { getKeyApi } from "@package/utils/Utilities"
|
||||
|
||||
const BASE_URL_LANGUAGE = i18n.language
|
||||
|
||||
interface AeObject {
|
||||
id?: string;
|
||||
name?: string;
|
||||
idCompany?: string;
|
||||
idSubsidiary?: number;
|
||||
isActive?: boolean;
|
||||
size?: number;
|
||||
page?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a list of user types from the administration API.
|
||||
*
|
||||
* @param {AeObject} ae_object - The object containing parameters for the request.
|
||||
* @param {string} ae_object.id - The ID of the user type (optional).
|
||||
* @param {string} ae_object.name - The name of the user type (optional).
|
||||
* @param {string} ae_object.idCompany - The ID of the company (optional).
|
||||
* @param {string} ae_object.idSubsidiary - The ID of the subsidiary (optional).
|
||||
* @param {boolean} ae_object.isActive - The active status of the user type (optional, defaults to true).
|
||||
* @param {number} ae_object.size - The number of items per page (optional, defaults to GRID_SIZE).
|
||||
* @param {number} ae_object.page - The page number (optional, defaults to 0).
|
||||
* @returns {Promise<ReturnService>} A promise that resolves to a ReturnService object containing the result of the API call.
|
||||
*/
|
||||
async function GetTypeUsers(ae_object: AeObject): Promise<ReturnService<any>> {
|
||||
const token = getKeyApi()
|
||||
if (token === '') {
|
||||
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
|
||||
}
|
||||
|
||||
if (ae_object.size == null || ae_object.size <= 0) {
|
||||
ae_object.size = GRID_SIZE
|
||||
}
|
||||
if (ae_object.page == null || ae_object.page <= 0) {
|
||||
ae_object.page = 0
|
||||
}
|
||||
|
||||
const options = {
|
||||
method: 'post',
|
||||
mode: 'cors' as RequestMode,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + token,
|
||||
lng: BASE_URL_LANGUAGE
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: ae_object.id ?? '',
|
||||
name: ae_object.name ?? '',
|
||||
idCompany: ae_object.idCompany ?? '',
|
||||
idSubsidiary: ae_object.idSubsidiary ?? 0,
|
||||
isActive: ae_object.isActive ?? true,
|
||||
size: ae_object.size,
|
||||
page: ae_object.page
|
||||
})
|
||||
}
|
||||
|
||||
const data = await FetchData(BASE_URL_ADMINISTRATION, 'type-user/all', options)
|
||||
|
||||
let result = data;
|
||||
if (data.correct) {
|
||||
result = data.object as ReturnService<unknown>
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export { GetTypeUsers }
|
||||
78
package/config/api/Admin/user/GetUsers/page.tsx
Normal file
78
package/config/api/Admin/user/GetUsers/page.tsx
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import { BASE_URL_ADMINISTRATION } from "@package/config/ApiPath";
|
||||
import { FetchData } from "@package/config/FetchData";
|
||||
import { GRID_SIZE } from "@package/utils/Constants";
|
||||
import i18n from "@package/utils/language/i18n";
|
||||
import { getKeyApi } from "@package/utils/Utilities";
|
||||
|
||||
interface AeObject {
|
||||
size: number | null;
|
||||
page: number | null;
|
||||
type?: string;
|
||||
idSubsidiary?: number;
|
||||
idCompany?: number;
|
||||
name?: string;
|
||||
email?: string;
|
||||
isActive?: boolean | null;
|
||||
}
|
||||
|
||||
interface GetUsersResponse {
|
||||
correct: boolean;
|
||||
message: string;
|
||||
errorCode: number;
|
||||
object?: any;
|
||||
}
|
||||
|
||||
async function GetUsers(ae_object: AeObject): Promise<GetUsersResponse> {
|
||||
const token = getKeyApi();
|
||||
if (!token) {
|
||||
return { correct: false, message: i18n.t('errorTokenAPI'), errorCode: 102, object: null };
|
||||
}
|
||||
|
||||
if (ae_object.size === null || ae_object.size <= 0) {
|
||||
ae_object.size = GRID_SIZE;
|
||||
}
|
||||
if (ae_object.page === null || ae_object.page <= 0) {
|
||||
ae_object.page = 0;
|
||||
}
|
||||
|
||||
const options = {
|
||||
method: 'post',
|
||||
mode: 'cors' as RequestMode,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + token,
|
||||
lng: i18n.language,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
idType: ae_object.type ?? '',
|
||||
idSubsidiary: ae_object.idSubsidiary ?? 0,
|
||||
idCompany: ae_object.idCompany ?? 0,
|
||||
name: ae_object.name ?? '',
|
||||
mail: ae_object.email ?? '',
|
||||
isActive: ae_object.isActive ?? null,
|
||||
size: ae_object.size,
|
||||
page: ae_object.page,
|
||||
}),
|
||||
};
|
||||
|
||||
// Llamada a FetchData
|
||||
const response = await FetchData<any>(BASE_URL_ADMINISTRATION, 'user/all', options);
|
||||
|
||||
if (response.correct) {
|
||||
return {
|
||||
correct: true,
|
||||
message: "OK",
|
||||
errorCode: 0,
|
||||
object: response.object,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
correct: false,
|
||||
message: response.message,
|
||||
errorCode: response.errorCode,
|
||||
object: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { GetUsers };
|
||||
72
package/config/api/Admin/user/SaveUser/page.tsx
Normal file
72
package/config/api/Admin/user/SaveUser/page.tsx
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { BASE_URL_ADMINISTRATION } from "@package/config/ApiPath";
|
||||
import { FetchData } from "@package/config/FetchData";
|
||||
import { ReturnService } from "@package/config/ReturnService";
|
||||
import { DEFAULT_PASSWORD } from "@package/utils/Constants";
|
||||
import i18n from "@package/utils/language/i18n";
|
||||
import { encrypt, getKeyApi } from "@package/utils/Utilities";
|
||||
|
||||
const BASE_URL_LANGUAGE = i18n.language
|
||||
|
||||
interface UserObject {
|
||||
id?: string;
|
||||
idSubsidiary?: number;
|
||||
idCompany?: number;
|
||||
name?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
cellphone?: string;
|
||||
password?: string;
|
||||
type?: string;
|
||||
isActive?: boolean;
|
||||
isAdmin?: boolean;
|
||||
}
|
||||
|
||||
async function SaveUser(ae_object: UserObject) {
|
||||
const token = getKeyApi()
|
||||
if (token === '') {
|
||||
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
|
||||
}
|
||||
|
||||
if ((ae_object.id ?? '').trim().length <= 0 && (ae_object.password ?? '').trim().length <= 0) {
|
||||
ae_object.password = DEFAULT_PASSWORD
|
||||
}
|
||||
|
||||
if ((ae_object.password ?? '').trim().length > 0) {
|
||||
ae_object.password = encrypt(ae_object.password ?? '')
|
||||
}
|
||||
|
||||
const options = {
|
||||
method: 'post',
|
||||
mode: 'cors' as RequestMode,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + token,
|
||||
lng: BASE_URL_LANGUAGE
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: (ae_object.id ?? '').trim(),
|
||||
idSubsidiary: ae_object.idSubsidiary ?? 0,
|
||||
idCompany: ae_object.idCompany ?? 0,
|
||||
name: ae_object.name ?? '',
|
||||
lastName: ae_object.lastName ?? '',
|
||||
email: ae_object.email ?? '',
|
||||
cellphone: ae_object.cellphone ?? '',
|
||||
password: ae_object.password ?? '',
|
||||
idTypeUser: ae_object.type ?? '',
|
||||
isActive: ae_object.isActive ?? false,
|
||||
isAdmin: ae_object.isAdmin ?? false
|
||||
})
|
||||
}
|
||||
|
||||
const data = await FetchData(BASE_URL_ADMINISTRATION, 'user/save', options)
|
||||
|
||||
let result = data;
|
||||
if (data.correct) {
|
||||
result = data.object as ReturnService<unknown>
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
export { SaveUser }
|
||||
Loading…
Add table
Add a link
Reference in a new issue