feat: add Service api with interface

This commit is contained in:
Luis Felipe Cadavid 2024-09-30 15:19:20 -05:00
parent ab7a02bcca
commit a440f954ad
35 changed files with 1027 additions and 23 deletions

View file

@ -0,0 +1,53 @@
import { GetCustomerOutputInterface } from "@interfaces/OutputInterfaces/Customer/GetCustomerOutputInterface";
import { CustomerResponseInterface } from "@interfaces/ResponseInterfaces/Customer/CustomerResponseInterface";
import { BASE_URL_CUSTOMER } from "@package/config/ApiPath";
import { FetchData } from "@package/config/FetchData";
import { ReturnService } from "@package/config/ReturnService"
import { BASE_URL_LANGUAGE } from "@package/utils/Constants";
import i18n from "@package/utils/language/i18n"
import { getKeyApi } from "@package/utils/Utilities"
async function GetCustomer(ae_object: GetCustomerOutputInterface) {
const token = getKeyApi()
if (token === '') {
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
}
const options: RequestInit = {
method: 'post',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
lng: BASE_URL_LANGUAGE
},
body: JSON.stringify({
id: ae_object.id ?? '',
idCompany: ae_object.idCompany ?? '',
idSubsidiary: ae_object.idSubsidiary ?? 0,
name: ae_object.name ?? '',
lastname: ae_object.lastname ?? '',
idTypeCustomer: ae_object.idTypeCustomer ?? '',
dni: ae_object.dni ?? '',
idGender: ae_object.idGender ?? '',
idMaritalStatus: ae_object.idMaritalStatus ?? '',
address: ae_object.address ?? '',
mail: ae_object.mail ?? '',
phone: ae_object.phone ?? '',
idUser: '',
status: ae_object.status ?? null,
size: ae_object.size ?? 1000,
page: ae_object.page ?? 0
})
}
const data: CustomerResponseInterface = await FetchData(BASE_URL_CUSTOMER, 'all', options)
if (data.correct) {
return data.object
}
return data
}
export { GetCustomer }

View file

@ -0,0 +1,52 @@
import { SaveCustomerOutputInteface } from "@interfaces/OutputInterfaces/Customer/SaveCustomerOutputInterface";
import { BASE_URL_CUSTOMER } from "@package/config/ApiPath";
import { FetchData } from "@package/config/FetchData";
import { ReturnService } from "@package/config/ReturnService";
import { BASE_URL_LANGUAGE } from "@package/utils/Constants";
import i18n from "@package/utils/language/i18n";
import { getKeyApi } from "@package/utils/Utilities"
async function SaveCustomer(ae_object: SaveCustomerOutputInteface) {
const token = getKeyApi()
if (token === '') {
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
}
const options: RequestInit = {
method: 'post',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
lng: BASE_URL_LANGUAGE
},
body: JSON.stringify({
id: ae_object.id ?? '',
idCompany: ae_object.idCompany ?? '',
idSubsidiary: ae_object.idSubsidiary ?? '',
name: ae_object.name ?? '',
secondName: ae_object.secondName ?? '',
firstSurname: ae_object.firstSurname ?? '',
secondSurname: ae_object.secondSurname ?? '',
idTypeCustomer: ae_object.idTypeCustomer ?? '',
dni: ae_object.dni ?? '',
idGender: ae_object.idGender ?? '',
idMaritalStatus: ae_object.idMaritalStatus ?? '',
address: ae_object.address ?? '',
mail: ae_object.mail ?? '',
phone: ae_object.phone ?? '',
idUser: ae_object.idUser ?? '',
status: ae_object.status ?? null
})
}
const data = await FetchData(BASE_URL_CUSTOMER,'save', options)
if (data.correct) {
return data.object
}
return data
}
export { SaveCustomer }

View file

@ -0,0 +1,48 @@
import { GetTypeDNIOutputInterface } from "@interfaces/OutputInterfaces/Customer/GetTypeDNIOutputInterface";
import { BASE_URL_CUSTOMER_TYPEDNI } from "@package/config/ApiPath";
import { FetchData } from "@package/config/FetchData";
import { ReturnService } from "@package/config/ReturnService"
import { BASE_URL_LANGUAGE } from "@package/utils/Constants";
import i18n from "@package/utils/language/i18n";
import { getKeyApi } from "@package/utils/Utilities"
async function GetTypeDni(ae_object: GetTypeDNIOutputInterface) {
const token = getKeyApi()
if (token === '') {
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
}
const options: RequestInit = {
method: 'post',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
lng: BASE_URL_LANGUAGE
},
body: JSON.stringify({
id: ae_object.id ?? '',
name: ae_object.name ?? '',
alias: ae_object.alias ?? '',
longitude: ae_object.longitude ?? '',
status: ae_object.status ?? null,
idMethodValidation: ae_object.idMethodValidation ?? '',
nameMethodValidation: ae_object.nameMethodValidation ?? '',
idUser: ae_object.idUser ?? '',
dataType: ae_object.dataType ?? '',
size: ae_object.size ?? 1000,
page: ae_object.page ?? 0
})
}
const data = await FetchData(BASE_URL_CUSTOMER_TYPEDNI, 'all', options)
if (data.correct) {
return data.object
}
return data
}
export { GetTypeDni }

View file

@ -0,0 +1,44 @@
import { SaveTypeDniOutputInterface } from "@interfaces/OutputInterfaces/Customer/SaveTypeDniOutputInterface";
import { BASE_URL_CUSTOMER_TYPEDNI } from "@package/config/ApiPath";
import { FetchData } from "@package/config/FetchData";
import { ReturnService } from "@package/config/ReturnService"
import { BASE_URL_LANGUAGE } from "@package/utils/Constants";
import i18n from "@package/utils/language/i18n"
import { getKeyApi } from "@package/utils/Utilities"
async function SaveTypeDni(ae_object: SaveTypeDniOutputInterface) {
const token = getKeyApi()
if (token === '') {
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
}
const options: RequestInit = {
method: 'post',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
lng: BASE_URL_LANGUAGE
},
body: JSON.stringify({
id: ae_object.id ?? '',
name: ae_object.name ?? '',
alias: ae_object.alias ?? '',
longitude: ae_object.longitude ?? 0,
status: ae_object.status ?? null,
idMethodValidation: ae_object.idMethodValidation ?? '',
idUser: ae_object.idUser ?? '',
dataType: ae_object.dataType ?? '',
})
}
const data = await FetchData(BASE_URL_CUSTOMER_TYPEDNI, 'save', options)
if (data.correct) {
return data.object
}
return data
}
export { SaveTypeDni }

View file

@ -0,0 +1,45 @@
import { GetTypeValidationOutputInrerface } from "@interfaces/OutputInterfaces/Customer/GetTypeValidationOutputInrerface"
import { BASE_URL_CUSTOMER_VALIDATION } from "@package/config/ApiPath"
import { FetchData } from "@package/config/FetchData"
import { ReturnService } from "@package/config/ReturnService"
import { BASE_URL_LANGUAGE } from "@package/utils/Constants"
import i18n from "@package/utils/language/i18n"
import { getKeyApi } from "@package/utils/Utilities"
async function GetTypeValidation(ae_object: GetTypeValidationOutputInrerface) {
const token = getKeyApi()
if (token === '') {
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
}
const options: RequestInit = {
method: 'post',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
lng: BASE_URL_LANGUAGE
},
body: JSON.stringify({
id: ae_object.id ?? '',
idCountry: ae_object.idCountry ?? '',
name: ae_object.name ?? '',
alias: ae_object.alias ?? '',
status: ae_object.status ?? null,
idUser: ae_object.idUser ?? '',
page: ae_object.page ?? 0,
size: ae_object.size ?? 1000
})
}
const data = await FetchData(BASE_URL_CUSTOMER_VALIDATION, 'all', options)
if (data.correct) {
return data.object
}
return data
}
export { GetTypeValidation }

View file

@ -0,0 +1,42 @@
import { SaveTypeValidationOutputInterface } from "@interfaces/OutputInterfaces/Customer/SaveTypeValidationOutputInterface"
import { BASE_URL_CUSTOMER_VALIDATION } from "@package/config/ApiPath"
import { FetchData } from "@package/config/FetchData"
import { ReturnService } from "@package/config/ReturnService"
import { BASE_URL_LANGUAGE } from "@package/utils/Constants"
import i18n from "@package/utils/language/i18n"
import { getKeyApi } from "@package/utils/Utilities"
async function SaveTypeValidation(ae_object: SaveTypeValidationOutputInterface) {
const token = getKeyApi()
if (token === '') {
return new ReturnService('', false, i18n.t('errorTokenAPI'), 102)
}
const options: RequestInit = {
method: 'post',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
lng: BASE_URL_LANGUAGE
},
body: JSON.stringify({
id: ae_object.id ?? '',
idCountry: ae_object.idCountry ?? '',
name: ae_object.name ?? '',
alias: ae_object.alias ?? '',
status: ae_object.status ?? null,
idUser: ae_object.idUser ?? ''
})
}
const data = await FetchData(BASE_URL_CUSTOMER_VALIDATION, 'save', options)
if (data.correct) {
return data.object
}
return data
}
export { SaveTypeValidation }