feat: add Service api with interface
This commit is contained in:
parent
ab7a02bcca
commit
a440f954ad
35 changed files with 1027 additions and 23 deletions
50
package/config/api/Sale/Transaction/AddProducts/page.tsx
Normal file
50
package/config/api/Sale/Transaction/AddProducts/page.tsx
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { AddProductsOutputInterface } from "@interfaces/OutputInterfaces/Sale/AddProductsOutputInterfae";
|
||||
import { AddProductsResponseInterface } from "@interfaces/ResponseInterfaces/Sale/AddProductsResponseInterface";
|
||||
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 AddProducts(ae_object: AddProductsOutputInterface) {
|
||||
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({
|
||||
idTransaction: ae_object.idTransaction ?? '',
|
||||
storeNumber: ae_object.storeNumber ?? '',
|
||||
idSubsidiary: ae_object.idSubsidiary ?? 0,
|
||||
clientNit: ae_object.clientNit ?? '',
|
||||
idUser: ae_object.idUser ?? '',
|
||||
localDate: ae_object.localDate ?? '',
|
||||
pos: ae_object.pos ?? '',
|
||||
products: ae_object.products.map(item => ({
|
||||
sku: item.sku ?? '',
|
||||
value: item.value ?? 0,
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
let data: AddProductsResponseInterface = await FetchData(BASE_URL_SALE, 'addProducts', options)
|
||||
|
||||
if (data.correct) {
|
||||
return data.object
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
export default AddProducts
|
||||
63
package/config/api/Sale/Transaction/EndSale/page.tsx
Normal file
63
package/config/api/Sale/Transaction/EndSale/page.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { EndSaleOutputInterface } from "@interfaces/OutputInterfaces/Sale/EndSaleOutputInterface";
|
||||
import { EndSaleResponseInterface } from "@interfaces/ResponseInterfaces/Sale/EndSaleResponseInterface";
|
||||
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 EndSale(ae_object: EndSaleOutputInterface) {
|
||||
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({
|
||||
idTransaction: ae_object.idTransaction ?? '',
|
||||
storeNumber: ae_object.storeNumber ?? '',
|
||||
idSubsidiary: ae_object.idSubsidiary ?? 0,
|
||||
idUser: ae_object.idUser ?? '',
|
||||
localDate: ae_object.localDate ?? '',
|
||||
pos: ae_object.pos ?? '',
|
||||
comment: ae_object.comment ?? '',
|
||||
payment: ae_object.payment.map((item) => ({
|
||||
type: item.type ?? '',
|
||||
approvalCode: item.approvalCode ?? '',
|
||||
receiptNumber: item.receiptNumber ?? '',
|
||||
value: item.value ?? 0,
|
||||
cardNumber: item.cardNumber ?? '',
|
||||
cardType: item.cardType ?? '',
|
||||
comment: item.comment ?? '',
|
||||
})),
|
||||
infoPos: {
|
||||
addressPos: ae_object.infoPos.addressPos ?? '',
|
||||
codeMunPos: ae_object.infoPos.codeMunPos ?? '',
|
||||
nameMunPos: ae_object.infoPos.nameMunPos ?? '',
|
||||
codeDepPos: ae_object.infoPos.codeDepPos ?? '',
|
||||
nameDepPos: ae_object.infoPos.nameDepPos ?? '',
|
||||
pos: ae_object.infoPos.pos ?? '',
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
let data : EndSaleResponseInterface = await FetchData(BASE_URL_SALE, 'endSale', options)
|
||||
|
||||
if (data.correct) {
|
||||
return data.object
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
export default EndSale
|
||||
44
package/config/api/Sale/Transaction/GetSale/page.tsx
Normal file
44
package/config/api/Sale/Transaction/GetSale/page.tsx
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { GetSaleOutputInterface } from "@interfaces/OutputInterfaces/Sale/GetSaleOutputInterface";
|
||||
import { GetSaleResponseInterface } from "@interfaces/ResponseInterfaces/Sale/GetSaleResponseInterface";
|
||||
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 GetSale(ae_object: GetSaleOutputInterface) {
|
||||
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({
|
||||
idTransaction: ae_object.idTransaction ?? '',
|
||||
storeNumber: ae_object.storeNumber ?? 0,
|
||||
idSubsidiary: ae_object.idSubsidiary ?? '',
|
||||
idUser: ae_object.idUser ?? '',
|
||||
pos: ae_object.pos ?? '',
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
let data: GetSaleResponseInterface = await FetchData(BASE_URL_SALE, 'addProducts', options)
|
||||
|
||||
if (data.correct) {
|
||||
return data.object
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
export default GetSale
|
||||
55
package/config/api/Sale/Transaction/StartSale/page.tsx
Normal file
55
package/config/api/Sale/Transaction/StartSale/page.tsx
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue