Overrides
This commit is contained in:
parent
f2bbf45f85
commit
70b4015173
@ -92,14 +92,12 @@ func CreatePanel(ctx *gin.Context) {
|
||||
if premiumTier == premium.None {
|
||||
panels, err := dbclient.Client.Panel.GetByGuild(guildId)
|
||||
if err != nil {
|
||||
ctx.AbortWithStatusJSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
ctx.JSON(500, utils.ErrorJson(err))
|
||||
return
|
||||
}
|
||||
|
||||
if len(panels) >= freePanelLimit {
|
||||
ctx.AbortWithStatusJSON(402, utils.ErrorStr("You have exceeded your panel quota. Purchase premium to unlock more panels."))
|
||||
ctx.JSON(402, utils.ErrorStr("You have exceeded your panel quota. Purchase premium to unlock more panels."))
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -251,7 +249,7 @@ func (p *panelBody) doValidations(ctx *gin.Context, guildId uint64) bool {
|
||||
}
|
||||
|
||||
if !p.verifyTitle() {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
ctx.JSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "Panel titles must be between 1 - 80 characters in length",
|
||||
})
|
||||
@ -259,7 +257,7 @@ func (p *panelBody) doValidations(ctx *gin.Context, guildId uint64) bool {
|
||||
}
|
||||
|
||||
if !p.verifyContent() {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
ctx.JSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "Panel content must be between 1 - 4096 characters in length",
|
||||
})
|
||||
|
@ -236,15 +236,9 @@
|
||||
}
|
||||
|
||||
async function createPanel() {
|
||||
let mapped = Object.fromEntries(Object.entries(panelCreateData).map(([k, v]) => {
|
||||
if (v === "null") {
|
||||
return [k, null];
|
||||
} else {
|
||||
return [k, v];
|
||||
}
|
||||
}));
|
||||
setBlankStringsToNull(panelCreateData);
|
||||
|
||||
const res = await axios.post(`${API_URL}/api/${guildId}/panels`, mapped);
|
||||
const res = await axios.post(`${API_URL}/api/${guildId}/panels`, panelCreateData);
|
||||
if (res.status !== 200) {
|
||||
notifyError(res.data.error);
|
||||
return;
|
||||
@ -256,6 +250,7 @@
|
||||
|
||||
async function submitEdit(e) {
|
||||
let data = e.detail;
|
||||
setBlankStringsToNull(data);
|
||||
|
||||
const res = await axios.patch(`${API_URL}/api/${guildId}/panels/${data.panel_id}`, data);
|
||||
if (res.status !== 200) {
|
||||
@ -270,6 +265,17 @@
|
||||
await loadPanels();
|
||||
}
|
||||
|
||||
function setBlankStringsToNull(obj) {
|
||||
// Set all blank strings in the object, including nested objects, to null
|
||||
for (const key in obj) {
|
||||
if (obj[key] === "" || obj[key] === "null") {
|
||||
obj[key] = null;
|
||||
} else if (typeof obj[key] === "object") {
|
||||
setBlankStringsToNull(obj[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function submitMultiPanelEdit(e) {
|
||||
let data = e.detail;
|
||||
|
||||
|
@ -12,6 +12,12 @@ func ValueOrZero[T any](v *T) T {
|
||||
}
|
||||
}
|
||||
|
||||
func SetNilIfZero[T comparable](value **T) {
|
||||
if value != nil && *value != nil && **value == *new(T) {
|
||||
*value = nil
|
||||
}
|
||||
}
|
||||
|
||||
func Slice[T any](v ...T) []T {
|
||||
return v
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user