Align shop item functionality with database schema
Update API endpoints and dashboard form to use the `enabled` column instead of `available` to resolve a database schema mismatch. This also includes adding `category` and `item_data` to the API payload and improving error reporting for shop item creation and updates. Replit-Commit-Author: Agent Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: c573fbd6-0ec0-4669-a499-27b140fa044c Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/oWFvNCu Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
1202d411f1
commit
4e9873d76a
3 changed files with 14 additions and 13 deletions
4
.replit
4
.replit
|
|
@ -21,10 +21,6 @@ externalPort = 80
|
|||
localPort = 8080
|
||||
externalPort = 8080
|
||||
|
||||
[[ports]]
|
||||
localPort = 41927
|
||||
externalPort = 3000
|
||||
|
||||
[workflows]
|
||||
runButton = "Project"
|
||||
|
||||
|
|
|
|||
|
|
@ -2359,7 +2359,7 @@
|
|||
<div class="item-row">
|
||||
<div style="font-size:1.5rem">${ITEM_TYPES[item.item_type]?.emoji || '🎁'}</div>
|
||||
<div class="item-info">
|
||||
<div class="item-name">${item.name} ${!item.available ? '<span style="color:var(--warning);font-size:0.75rem">(Disabled)</span>' : ''}</div>
|
||||
<div class="item-name">${item.name} ${!item.enabled ? '<span style="color:var(--warning);font-size:0.75rem">(Disabled)</span>' : ''}</div>
|
||||
<div class="item-desc">${item.price.toLocaleString()} XP | Stock: ${item.stock ?? 'Unlimited'}${item.level_required > 0 ? ' | Level ' + item.level_required : ''}</div>
|
||||
</div>
|
||||
<div class="item-actions">
|
||||
|
|
@ -2386,7 +2386,7 @@
|
|||
document.getElementById('shopItemStock').value = item?.stock ?? '';
|
||||
document.getElementById('shopItemLevelReq').value = item?.level_required || 0;
|
||||
document.getElementById('shopItemPrestigeReq').value = item?.prestige_required || 0;
|
||||
document.getElementById('shopItemEnabled').checked = item?.available !== false;
|
||||
document.getElementById('shopItemEnabled').checked = item?.enabled !== false;
|
||||
document.getElementById('shopModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
|
|
@ -2414,7 +2414,7 @@
|
|||
stock: stockVal === '' || stockVal === '-1' ? null : parseInt(stockVal),
|
||||
level_required: parseInt(document.getElementById('shopItemLevelReq').value) || 0,
|
||||
prestige_required: parseInt(document.getElementById('shopItemPrestigeReq').value) || 0,
|
||||
available: document.getElementById('shopItemEnabled').checked
|
||||
enabled: document.getElementById('shopItemEnabled').checked
|
||||
};
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -929,7 +929,7 @@ function createWebServer(discordClient, supabase, options = {}) {
|
|||
return res.status(403).json({ error: 'No admin access' });
|
||||
}
|
||||
|
||||
const { name, item_type, description, price, stock, level_required, prestige_required, available } = req.body;
|
||||
const { name, item_type, description, price, stock, level_required, prestige_required, enabled, category, item_data } = req.body;
|
||||
|
||||
try {
|
||||
const itemData = {
|
||||
|
|
@ -937,11 +937,13 @@ function createWebServer(discordClient, supabase, options = {}) {
|
|||
name,
|
||||
item_type: item_type || 'cosmetic',
|
||||
description: description || null,
|
||||
category: category || null,
|
||||
price: price || 100,
|
||||
stock: stock || null,
|
||||
item_data: item_data || null,
|
||||
level_required: level_required || 0,
|
||||
prestige_required: prestige_required || 0,
|
||||
available: available !== false,
|
||||
enabled: enabled !== false,
|
||||
created_at: new Date().toISOString()
|
||||
};
|
||||
|
||||
|
|
@ -952,7 +954,7 @@ function createWebServer(discordClient, supabase, options = {}) {
|
|||
res.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Failed to create shop item:', error);
|
||||
res.status(500).json({ error: 'Failed to create shop item' });
|
||||
res.status(500).json({ error: 'Failed to create shop item', details: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -973,7 +975,7 @@ function createWebServer(discordClient, supabase, options = {}) {
|
|||
return res.status(403).json({ error: 'No admin access' });
|
||||
}
|
||||
|
||||
const { name, item_type, description, price, stock, level_required, prestige_required, available } = req.body;
|
||||
const { name, item_type, description, price, stock, level_required, prestige_required, enabled, category, item_data } = req.body;
|
||||
|
||||
try {
|
||||
const { error } = await supabase
|
||||
|
|
@ -982,11 +984,14 @@ function createWebServer(discordClient, supabase, options = {}) {
|
|||
name,
|
||||
item_type: item_type || 'cosmetic',
|
||||
description: description || null,
|
||||
category: category || null,
|
||||
price: price || 100,
|
||||
stock: stock || null,
|
||||
item_data: item_data || null,
|
||||
level_required: level_required || 0,
|
||||
prestige_required: prestige_required || 0,
|
||||
available: available !== false
|
||||
enabled: enabled !== false,
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
.eq('id', itemId)
|
||||
.eq('guild_id', guildId);
|
||||
|
|
@ -996,7 +1001,7 @@ function createWebServer(discordClient, supabase, options = {}) {
|
|||
res.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Failed to update shop item:', error);
|
||||
res.status(500).json({ error: 'Failed to update shop item' });
|
||||
res.status(500).json({ error: 'Failed to update shop item', details: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue