diff --git a/Discord/discordIndex.js b/Discord/discordIndex.js index 327369e..afd53d2 100644 --- a/Discord/discordIndex.js +++ b/Discord/discordIndex.js @@ -687,6 +687,34 @@ module.exports.sendProductPayment = async (params, id, type) => { files: fields }); + if ('configs' in serverData && 'publicBuyChannel' in serverData.configs && serverData.configs.publicBuyChannel ) { + let findChannelPublic = DiscordServer.channels.cache.find(c => c.id === serverData.configs.publicBuyChannel) + let fieldsPublic = { name: `Carrinho:`, value: `\n` } + let valorTotal = 0 + await carrinho.forEach(async(element,index) => { + var product = await serverData.products.find(product => product.productID == element) + valorTotal = valorTotal + parseInt(product.price) + fieldsPublic.value += `${index + 1} - ${product.productName}\n` + }); + let allfieldsPublic = [ { name: '\u200B', value: '\u200B' }, + { name: 'Cliente:', value: user.username, inline: true }, + { name: 'Valor total:', value: await functions.formatarMoeda(valorTotal), inline: true }, + fieldsPublic, + { name: 'Data e hora da compra', value: dataHoraFormatada }, + { name: '\u200B', value: '\u200B' }] + findChannelPublic.send({ + embeds: [ + new Discord.EmbedBuilder() + .setTitle(`🛍️ | Nova compra!`) + .setDescription(`Uma nova compra foi feita abaixo está os dados da compra:`) + .addFields(...allfieldsPublic) + .setAuthor({ name: "SDKApps", iconURL: `https://res.cloudinary.com/dgcnfudya/image/upload/v1711769157/vyzyvzxajoboweorxh9s.png`, url: 'https://discord.gg/sdkapps' }) + .setColor("#6E58C7") + .setFooter({ text: DiscordServer.name, iconURL: `https://cdn.discordapp.com/icons/${DiscordServer.id}/${DiscordServer.icon}.webp` }) + ], + }) + } + let analytics = await db.findOne({ colecao: "analytics", doc: serverData.id }) if (analytics.error == false) { diff --git a/index.js b/index.js index 5086b86..fda5646 100644 --- a/index.js +++ b/index.js @@ -577,8 +577,16 @@ app.post('/config/change', async (req, res) => { try { let server = await db.findOne({ colecao: "servers", doc: req.body.serverID }) if (server.error == false) { - let configs = server.configs + let configs = { + noticeChannel:null, + publicBuyChannel:null + } + if ('configs' in server) { + configs = server.configs + } + configs.publicBuyChannel configs.noticeChannel = req.body.noticeChannel + configs.publicBuyChannel = req.body.publicBuyChannel db.update('servers', req.body.serverID, { configs: configs }) @@ -733,7 +741,6 @@ app.use('/', stripeRoutes); //TODO PRODUTOS ROUTES const produtoRoutes = require('./stripe/productsRoutes.js'); - app.use('/', produtoRoutes); diff --git a/public/js/config.js b/public/js/config.js index 213ef6d..f8a6751 100644 --- a/public/js/config.js +++ b/public/js/config.js @@ -4,13 +4,21 @@ let serverID = location.pathname.replace('/server/config/', "") document.getElementById('save-configs').addEventListener('click', async () => { const opcoes = document.getElementById('bot-config-channel-list').querySelectorAll('option'); let channelID = null; - console.log(1); + await opcoes.forEach(option => { if (option.value === document.getElementById('bot-config-channel').value) { channelID = option.getAttribute('data-channel'); } }); - console.log(channelID); + + let channelIDBuy = null + const opcoesBuy = document.getElementById('bot-config-channel-buy-list').querySelectorAll('option'); + await opcoesBuy.forEach(option => { + if (option.value === document.getElementById('bot-config-channel-buy').value) { + channelIDBuy = option.getAttribute('data-channel'); + } + }); + let session = await fetch('/config/change', { method: 'POST', headers: { @@ -18,7 +26,8 @@ document.getElementById('save-configs').addEventListener('click', async () => { }, body: JSON.stringify({ serverID: serverID, - noticeChannel:channelID + noticeChannel:channelID, + publicBuyChannel:channelIDBuy }), }).then(response => { return response.json() }) if (session.success == true) { @@ -28,6 +37,11 @@ document.getElementById('save-configs').addEventListener('click', async () => { } }) +document.getElementById('cancel-configs').addEventListener('click',()=>{ + document.getElementById('bot-config-channel').value = '' + document.getElementById('bot-config-channel-buy').value = '' +}) + document.getElementById('changePaymentMethod').addEventListener('click', async () => { try { let session = await fetch('/subscription/update', { diff --git a/stripe/productsRoutes.js b/stripe/productsRoutes.js index f7d6614..79d1cb2 100644 --- a/stripe/productsRoutes.js +++ b/stripe/productsRoutes.js @@ -302,10 +302,9 @@ router.post('/product/estoqueAdd', async (req, res) => { }) res.status(200).json({ success: true, data: '' }) } else { - res.status(200).json({ success: false, data: '' }) + res.status(200).json({ success: true, data: '' }) } } catch (error) { - res.status(200).json({ success: false, data: '' }) console.log(error); } }) diff --git a/views/config.ejs b/views/config.ejs index aa4f3a2..c167108 100644 --- a/views/config.ejs +++ b/views/config.ejs @@ -36,7 +36,7 @@