File size: 2,383 Bytes
e5c9966
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { Octokit } = require('@octokit/rest');
const { createEmbed } = require('../utils/embeds');
const { Colors } = require('../config');
const { stmts } = require('../database');
const fetch = require('node-fetch');

/**
 * usage: editdrop <id> <property> <new_value>
 * properties: title, description, status
 */
module.exports = {
    async execute(client, message, args) {
        if (args.length < 3) {
            return message.reply({ content: '❌ Usage: `editdrop <id> <title|description|status> <new value>`' });
        }

        const id = parseInt(args[0]);
        const property = args[1].toLowerCase();
        const newValue = args.slice(2).join(' ');

        if (isNaN(id)) return message.reply({ content: '❌ Invalid Drop ID. Must be a number.' });

        const drop = await stmts.getWebDrop(id);
        if (!drop) {
            return message.reply({ content: `❌ No drop found in database with ID: **${id}**` });
        }

        const validProps = ['title', 'description', 'status'];
        if (!validProps.includes(property)) {
            return message.reply({ content: `❌ Invalid property. Use: ${validProps.join(', ')}` });
        }

        try {
            // 1. Update Supabase
            const { db } = require('../database');
            await db.from('web_drops').update({ [property]: newValue }).eq('id', id);

            // 2. Send update request to Website Backend API
            const WEBSITE_API = process.env.WEBSITE_API_URL || 'http://localhost:3000/api/drops';
            
            try {
                // Mock request for now
                await fetch(`${WEBSITE_API}/${id}`, {
                    method: 'PATCH',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ [property]: newValue })
                }).catch(() => {});
            } catch (e) {}

            await message.reply({
                embeds: [createEmbed({
                    title: 'βœ… Drop Updated',
                    description: `Successfully updated Drop **#${id}**.\n\n**${property}** is now:\n> ${newValue}`,
                    color: Colors.SUCCESS
                })]
            });

        } catch (err) {
            console.error('[Edit Drop Error]', err);
            await message.reply({ content: `❌ Error updating drop: ${err.message}` });
        }
    }
};