Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-Santana-j committed May 27, 2024
1 parent 51d1198 commit 2b7346c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
33 changes: 21 additions & 12 deletions Discord/discordIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,25 @@ module.exports = (Discord, client) => {
}
}


if (interaction.customId && interaction.customId.includes('qntProduct')) {
if (!preCarrinhos[interaction.user.id]) {
preCarrinhos[interaction.user.id] = []
}
preCarrinhos[interaction.user.id].push({
product: interaction.customId.replace('qntProduct_', ""),
quantidade: interaction.values[0]
})
let value = await interaction.values[0]
let product = await interaction.customId.replace('qntProduct_', "")
let findCart = await preCarrinhos[interaction.user.id].find(element => element.product == product)
let findIndexCart = await preCarrinhos[interaction.user.id].findIndex(element => element.product == product)
preCarrinhos[interaction.user.id]
if (findCart) {
preCarrinhos[interaction.user.id][findIndexCart].quantidade = parseInt(value)
console.log(preCarrinhos[interaction.user.id][findIndexCart]);
}else{
preCarrinhos[interaction.user.id].push({
product: product,
quantidade: value
})
}

interaction.deferReply();
interaction.deleteReply()
}
Expand Down Expand Up @@ -354,6 +364,7 @@ module.exports = (Discord, client) => {
}

if (interaction.customId && interaction.customId.includes('confirm')) {
console.log(1);
try {
if (!carrinhos[interaction.user.id]) {
if (interaction.replied) {
Expand Down Expand Up @@ -383,7 +394,7 @@ module.exports = (Discord, client) => {
for (let index = 0; index < carrinho.length; index++) {
const element = carrinho[index];
let produto = await server.products.find(product => product.productID == element.product)
let price = null
let price = parseInt(produto.price)
// if (cupomOptions[interaction.user.id]) {
// let findCupom = serverData.cupons.find(cupom => cupom.code == cupomOptions[interaction.user.id])
// if (findCupom && findCupom.productRef == produto.productID) {
Expand All @@ -395,7 +406,7 @@ module.exports = (Discord, client) => {
// price = produto.priceID
// }

if (parseInt(produto.price) < 100) {
if (price < 100) {
isProduct1n = true
}

Expand All @@ -404,7 +415,7 @@ module.exports = (Discord, client) => {
quantity: parseInt(carrinho[index].quantidade),
})
let subtotal = (parseInt(price) * parseInt(carrinho[index].quantidade))
total = total + subtotal
total = parseInt(total) + parseInt( subtotal)
}
return {
lineItems: line_items,
Expand All @@ -415,7 +426,7 @@ module.exports = (Discord, client) => {


let getData = await getLineItemsAndPrice(carrinho, serverData)

console.log(getData);
if (!getData || !getData.lineItems || !getData.total) {
return
}
Expand Down Expand Up @@ -447,7 +458,7 @@ module.exports = (Discord, client) => {
content: getData.isProduct1n == true ? '⚠️ 1 ou mais produtos tem o valor inferior a 1 real no pix para cobrir as taxas do cartão temos que reajustar o valor para no minimo 1 real' : '',
embeds: [
new Discord.EmbedBuilder()
.setColor('personalize' in server && 'colorDest' in server.personalize ? server.personalize.colorDest : '#6E58C7')
.setColor('personalize' in serverData && 'colorDest' in serverData.personalize ? serverData.personalize.colorDest : '#6E58C7')
.setTitle(`💕 | Produto Criado!`)
.setDescription(`<@${interaction.user.id}> **Acesse o link abaixo para fazer o pagamento do seu produto.**`)
],
Expand Down Expand Up @@ -519,15 +530,13 @@ module.exports = (Discord, client) => {
})
}).catch((error) => {
console.error(error);
// Lidar com erros aqui
});
} catch (error) {
console.log(error);
}
}
} catch (error) {
console.log(error);

}
}

Expand Down
4 changes: 2 additions & 2 deletions public/css/chatLive.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#chat-containner {
z-index: 99999999;
position: fixed;
padding: 1em 1em 0.5em 1em;
padding: 1em ;
width: 24em;
height: 34em;
right: 2em;
Expand Down Expand Up @@ -97,7 +97,7 @@

#chat-mensages-content {
width: 100%;
height: 75%;
height: 100%;
overflow: auto;
display: flex;
flex-direction: column;
Expand Down
24 changes: 20 additions & 4 deletions public/js/chatLive.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function init(params) {
doc.docChanges().forEach((change, index) => {
let data = change.doc.data()
if (change.type === "removed" && change.doc.id && change.doc.id.includes(userID)) {
var parentElement = document.getElementById("chat-up-containner");
var parentElement = document.getElementById("chat-containner");
while (parentElement.firstChild) {
parentElement.removeChild(parentElement.firstChild);
}
Expand Down Expand Up @@ -67,6 +67,7 @@ async function init(params) {
let dateForm = `${String(date.getDate()).padStart(2, '0')}/${String(date.getMonth() + 1).padStart(2, '0')}/${date.getFullYear()}`;
if (change.doc.id && change.doc.id.includes(userID)) {
ticketProt = change.doc.id

data.mensages.forEach((element,index)=>{
countMensages++
if (chatIsOpen == false) {
Expand Down Expand Up @@ -104,10 +105,25 @@ async function init(params) {
}

async function sendMensage() {

let content = document.getElementById('chat-input-mensage').value

if (content.trim().length <= 0) {
errorNotify('Digite algo antes...')
return
}

if (!ticketProt) {
errorNotify('Você não tem nenhum ticket aberto!')
return
}

let ticket = await db.collection("tickets").doc(ticketProt).get()
ticket = await ticket.data()
let content = document.getElementById('chat-input-mensage').value
if (!ticket) {
errorNotify('Erro ao obter o ticket!')
return
}

document.getElementById('chat-input-mensage').value = ''
let session = await fetch('/send/discordMensage', {
method: 'POST',
Expand Down Expand Up @@ -149,7 +165,7 @@ document.getElementById('chat-top-close').addEventListener('click', () => {
document.getElementById('chat-icon-containner').addEventListener('click', () => {
let chatContainner = document.getElementById('chat-containner')
if (chatContainner.style.display == "none") {
chatContainner.style.display = "block"
chatContainner.style.display = "flex"
chatIsOpen = true
countMensages = 0
let conte = document.getElementById('chat-mensages-content')
Expand Down

0 comments on commit 2b7346c

Please sign in to comment.