Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-Santana-j committed Dec 28, 2024
1 parent 9ec581a commit aef18df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
20 changes: 13 additions & 7 deletions Discord/discordIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -2142,15 +2142,16 @@ module.exports.sendProductPayment = async (params, id, type) => {
let carrinho = carrinhos[params.userID]
delete carrinhos[params.userID]
let result = await new Promise(async (resolve, reject) => {
let arrayEstoque = []
for (let [chave, element] of Object.entries(carrinho)) {
const produto = serverData.products.find(product => product.productID == element.product);
let typeProduct = 'typeProduct' in produto ? produto.typeProduct : 'normal'
switch (typeProduct) {
case 'single':
if (produto.estoque <= 0) {
resolve(false)
arrayEstoque.push(false)
} else {
resolve(true)
arrayEstoque.push(true)
}
break;
case 'subscription':
Expand All @@ -2161,14 +2162,20 @@ module.exports.sendProductPayment = async (params, id, type) => {
break;
case 'normal':
if (produto.estoque.length <= 0) {
resolve(false)
arrayEstoque.push(false)
} else {
resolve(true)
arrayEstoque.push(true)
}
break;
}
}

console.log(arrayEstoque);

if (arrayEstoque.includes(false)) {
resolve(false)
} else {
resolve(true)
}

});
async function refound() {
Expand Down Expand Up @@ -2249,7 +2256,6 @@ module.exports.sendProductPayment = async (params, id, type) => {

if (typeProduct == 'single') {
try {
numberProdsSingle += 1
let productSingleChannel = DiscordServer.channels.cache.find(c => c.topic === element.product)
let thread = await productSingleChannel.threads.create({
name: `Recebimento manual, ${user.username}`,
Expand Down Expand Up @@ -2306,7 +2312,6 @@ module.exports.sendProductPayment = async (params, id, type) => {

if (typeProduct == 'normal') {
try {
numberProdsNormal += 1
let itensCortados = await product.estoque.splice(0, requestedQuantity)
let itens = itensCortados.map(item => item.conteudo)
itens.forEach(item => {
Expand Down Expand Up @@ -2556,6 +2561,7 @@ module.exports.sendProductPayment = async (params, id, type) => {
} catch (error) {}
},5000)
} else {
console.log("ResultPaymentMessageError", result);
refound()
}
}
Expand Down
13 changes: 1 addition & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2142,19 +2142,10 @@ app.use((req, res, next) => {
});

//TODO------------Listen--------------
tem()
async function tem(params) {

client.on('ready', async () => {


})
}

cron.schedule('0 * * * *',async () => {
let hora = new Date().getHours()
console.log(hora);

try {
let firebaseDB = require("./Firebase/db.js")
let snapshot;
Expand All @@ -2173,7 +2164,6 @@ cron.schedule('0 * * * *',async () => {
snapshot = await query.get();

if (snapshot.empty) {
console.log('Nenhum documento encontrado com esse valor.');
break;
}

Expand Down Expand Up @@ -2204,9 +2194,8 @@ cron.schedule('0 * * * *',async () => {
})
});

// Atualiza o último documento para a próxima iteração
ultimoDocumento = snapshot.docs[snapshot.docs.length - 1];
} while (snapshot.size === 500); // Continua até não retornar mais 500 documentos
} while (snapshot.size === 500);

} catch (error) {
console.error('Erro ao buscar documentos:', error);
Expand Down

0 comments on commit aef18df

Please sign in to comment.