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,55 @@
import { StartSaleOutputInterface } from "@interfaces/OutputInterfaces/Sale/StartSaleOutputInterface";
import { StartSaleResponseInterface } from "@interfaces/ResponseInterfaces/Sale/StartSaleResponseInterface";
import { BASE_URL_SALE } from "@package/config/ApiPath";
import { FetchData } from "@package/config/FetchData";
import { ReturnService } from "@package/config/ReturnService"
import { BASE_URL_LANGUAGE } from "@utils/Constants"
import i18n from "@utils/language/i18n";
import { getKeyApi } from "@utils/Utilities"
async function StartSale(ae_object: StartSaleOutputInterface) {
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({
storeNumber: ae_object.storeNumber ?? '',
idSubsidiary: ae_object.idSubsidiary ?? 0,
idClient: ae_object.idClient ?? '',
clientDni: ae_object.clientDni ?? '',
idType: ae_object.idType ?? '',
idGroup: ae_object.idGroup ?? '',
invoiceName: ae_object.invoiceName ?? '',
invoiceTypeNit: ae_object.invoiceTypeNit ?? '',
invoiceNit: ae_object.invoiceNit ?? '',
invoiceDirection: ae_object.invoiceDirection ?? '',
invoiceCellPhone: ae_object.invoiceCellPhone ?? '',
invoiceEmail: ae_object.invoiceEmail ?? '',
idUser: ae_object.idUser ?? '',
localDate: ae_object.localDate ?? '',
pos: ae_object.pos ?? '',
})
}
let data : StartSaleResponseInterface = await FetchData(BASE_URL_SALE, 'addProducts', options)
if (data.correct) {
return data.object
}
return data
}
export default StartSale