[deploy] add register module backend
Some checks failed
Deploy Discord Bot / deploy (push) Failing after 20s
Some checks failed
Deploy Discord Bot / deploy (push) Failing after 20s
This commit is contained in:
@@ -543,6 +543,82 @@ router.delete('/reactionroles/:id', requireAuth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/register/forms', requireAuth, async (req, res) => {
|
||||
const guildId = typeof req.query.guildId === 'string' ? req.query.guildId : undefined;
|
||||
if (!guildId) return res.status(400).json({ error: 'guildId required' });
|
||||
const forms = await context.register.listForms(guildId);
|
||||
res.json({ forms });
|
||||
});
|
||||
|
||||
router.post('/register/forms', requireAuth, async (req, res) => {
|
||||
const guildId = typeof req.body.guildId === 'string' ? req.body.guildId : undefined;
|
||||
if (!guildId) return res.status(400).json({ error: 'guildId required' });
|
||||
const data = req.body || {};
|
||||
const form = await context.register.saveForm({
|
||||
guildId,
|
||||
name: data.name || 'Formular',
|
||||
description: data.description || '',
|
||||
reviewChannelId: data.reviewChannelId || undefined,
|
||||
notifyRoleIds: Array.isArray(data.notifyRoleIds) ? data.notifyRoleIds : typeof data.notifyRoleIds === 'string' ? data.notifyRoleIds.split(',').map((s: string) => s.trim()).filter(Boolean) : [],
|
||||
isActive: data.isActive !== false,
|
||||
fields: Array.isArray(data.fields) ? data.fields : []
|
||||
});
|
||||
res.json({ form });
|
||||
});
|
||||
|
||||
router.put('/register/forms/:id', requireAuth, async (req, res) => {
|
||||
const guildId = typeof req.body.guildId === 'string' ? req.body.guildId : undefined;
|
||||
const id = req.params.id;
|
||||
if (!guildId) return res.status(400).json({ error: 'guildId required' });
|
||||
const data = req.body || {};
|
||||
const form = await context.register.saveForm({
|
||||
id,
|
||||
guildId,
|
||||
name: data.name || 'Formular',
|
||||
description: data.description || '',
|
||||
reviewChannelId: data.reviewChannelId || undefined,
|
||||
notifyRoleIds: Array.isArray(data.notifyRoleIds) ? data.notifyRoleIds : typeof data.notifyRoleIds === 'string' ? data.notifyRoleIds.split(',').map((s: string) => s.trim()).filter(Boolean) : [],
|
||||
isActive: data.isActive !== false,
|
||||
fields: Array.isArray(data.fields) ? data.fields : []
|
||||
});
|
||||
res.json({ form });
|
||||
});
|
||||
|
||||
router.delete('/register/forms/:id', requireAuth, async (req, res) => {
|
||||
const guildId = typeof req.body.guildId === 'string' ? req.body.guildId : undefined;
|
||||
const id = req.params.id;
|
||||
if (!guildId) return res.status(400).json({ error: 'guildId required' });
|
||||
const ok = await context.register.deleteForm(guildId, id);
|
||||
if (!ok) return res.status(404).json({ error: 'not found' });
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.post('/register/forms/:id/panel', requireAuth, async (req, res) => {
|
||||
const guildId = typeof req.body.guildId === 'string' ? req.body.guildId : undefined;
|
||||
const id = req.params.id;
|
||||
if (!guildId) return res.status(400).json({ error: 'guildId required' });
|
||||
const channelId = typeof req.body.channelId === 'string' ? req.body.channelId : undefined;
|
||||
const message = typeof req.body.message === 'string' ? req.body.message : undefined;
|
||||
const msgId = await context.register.sendPanel(guildId, id, channelId, message);
|
||||
if (!msgId) return res.status(400).json({ error: 'panel failed' });
|
||||
res.json({ ok: true, messageId: msgId });
|
||||
});
|
||||
|
||||
router.get('/register/apps', requireAuth, async (req, res) => {
|
||||
const guildId = typeof req.query.guildId === 'string' ? req.query.guildId : undefined;
|
||||
const status = typeof req.query.status === 'string' ? req.query.status : undefined;
|
||||
const formId = typeof req.query.formId === 'string' ? req.query.formId : undefined;
|
||||
if (!guildId) return res.status(400).json({ error: 'guildId required' });
|
||||
const apps = await context.register.listApplications(guildId, status, formId);
|
||||
res.json({ applications: apps });
|
||||
});
|
||||
|
||||
router.get('/register/apps/:id', requireAuth, async (req, res) => {
|
||||
const app = await context.register.getApplication(req.params.id);
|
||||
if (!app) return res.status(404).json({ error: 'not found' });
|
||||
res.json({ application: app });
|
||||
});
|
||||
|
||||
router.get('/automations', requireAuth, async (req, res) => {
|
||||
const guildId = typeof req.query.guildId === 'string' ? req.query.guildId : undefined;
|
||||
if (!guildId) return res.status(400).json({ error: 'guildId required' });
|
||||
@@ -700,9 +776,11 @@ router.post('/settings', requireAuth, async (req, res) => {
|
||||
eventsEnabled,
|
||||
birthdayEnabled,
|
||||
birthdayConfig,
|
||||
reactionRolesEnabled,
|
||||
reactionRolesConfig
|
||||
} = req.body;
|
||||
reactionRolesEnabled,
|
||||
reactionRolesConfig,
|
||||
registerEnabled,
|
||||
registerConfig
|
||||
} = req.body;
|
||||
if (!guildId) return res.status(400).json({ error: 'guildId required' });
|
||||
const normalizeArray = (val: any) =>
|
||||
Array.isArray(val)
|
||||
@@ -798,6 +876,22 @@ router.post('/settings', requireAuth, async (req, res) => {
|
||||
channelId: reactionRolesConfig?.channelId ?? existingReactionRoles.channelId
|
||||
};
|
||||
|
||||
const parsedRegister = {
|
||||
enabled:
|
||||
registerConfig?.enabled ??
|
||||
(typeof registerEnabled === 'string' ? registerEnabled === 'true' : registerEnabled ?? (current as any).registerEnabled),
|
||||
reviewChannelId: registerConfig?.reviewChannelId ?? (current as any).registerConfig?.reviewChannelId,
|
||||
notifyRoleIds:
|
||||
Array.isArray(registerConfig?.notifyRoleIds) && registerConfig?.notifyRoleIds.length
|
||||
? registerConfig.notifyRoleIds
|
||||
: typeof registerConfig?.notifyRoleIds === 'string'
|
||||
? registerConfig.notifyRoleIds
|
||||
.split(',')
|
||||
.map((s: string) => s.trim())
|
||||
.filter(Boolean)
|
||||
: (current as any).registerConfig?.notifyRoleIds || []
|
||||
};
|
||||
|
||||
const updated = await settingsStore.set(guildId, {
|
||||
welcomeChannelId: welcomeChannelId ?? undefined,
|
||||
logChannelId: logChannelId ?? undefined,
|
||||
@@ -817,7 +911,9 @@ router.post('/settings', requireAuth, async (req, res) => {
|
||||
birthdayEnabled: parsedBirthday.enabled,
|
||||
birthdayConfig: parsedBirthday,
|
||||
reactionRolesEnabled: parsedReactionRoles.enabled,
|
||||
reactionRolesConfig: parsedReactionRoles
|
||||
reactionRolesConfig: parsedReactionRoles,
|
||||
registerEnabled: parsedRegister.enabled,
|
||||
registerConfig: parsedRegister
|
||||
});
|
||||
// Live update logging target
|
||||
context.logging = new LoggingService(updated.logChannelId);
|
||||
|
||||
Reference in New Issue
Block a user