Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #52

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 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,18 @@ 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;
}
}

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

});
async function refound() {
Expand Down Expand Up @@ -2249,7 +2254,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 +2310,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 +2559,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
Loading