mirror of https://github.com/buster-so/buster.git
Refactor Slack integration update endpoint to support more flexible settings
Co-authored-by: dallin <dallin@buster.so>
This commit is contained in:
parent
ba01e881e6
commit
151662f300
|
@ -20,9 +20,13 @@ const OAuthCallbackSchema = z.object({
|
|||
state: z.string(),
|
||||
});
|
||||
|
||||
const UpdateDefaultChannelSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
id: z.string().min(1),
|
||||
const UpdateIntegrationSchema = z.object({
|
||||
defaultChannel: z
|
||||
.object({
|
||||
name: z.string().min(1),
|
||||
id: z.string().min(1),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
// Custom error class
|
||||
|
@ -317,10 +321,10 @@ export class SlackHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* PUT /api/v2/slack/integration/default-channel
|
||||
* Update default channel for Slack integration
|
||||
* PUT /api/v2/slack/integration
|
||||
* Update Slack integration settings
|
||||
*/
|
||||
async updateDefaultChannel(c: Context) {
|
||||
async updateIntegration(c: Context) {
|
||||
try {
|
||||
// Get service instance (lazy initialization)
|
||||
const slackOAuthService = this.getSlackOAuthService();
|
||||
|
@ -350,7 +354,7 @@ export class SlackHandler {
|
|||
|
||||
// Parse request body
|
||||
const body = await c.req.json();
|
||||
const parsed = UpdateDefaultChannelSchema.safeParse(body);
|
||||
const parsed = UpdateIntegrationSchema.safeParse(body);
|
||||
|
||||
if (!parsed.success) {
|
||||
throw new SlackError(
|
||||
|
@ -361,21 +365,19 @@ export class SlackHandler {
|
|||
}
|
||||
|
||||
// Get active integration
|
||||
const { getActiveIntegration, updateDefaultChannel } = await import(
|
||||
'./services/slack-helpers'
|
||||
);
|
||||
const { getActiveIntegration, updateIntegration } = await import('./services/slack-helpers');
|
||||
const integration = await getActiveIntegration(organizationGrant.organizationId);
|
||||
|
||||
if (!integration) {
|
||||
throw new SlackError('No active Slack integration found', 404, 'INTEGRATION_NOT_FOUND');
|
||||
}
|
||||
|
||||
// Update default channel
|
||||
await updateDefaultChannel(integration.id, parsed.data);
|
||||
// Update integration settings
|
||||
await updateIntegration(integration.id, parsed.data);
|
||||
|
||||
return c.json({
|
||||
message: 'Default channel updated successfully',
|
||||
defaultChannel: parsed.data,
|
||||
message: 'Integration updated successfully',
|
||||
...parsed.data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to update default channel:', error);
|
||||
|
|
|
@ -9,8 +9,8 @@ const app = new Hono()
|
|||
.get('/auth/callback', (c) => slackHandler.handleOAuthCallback(c))
|
||||
// Protected endpoints
|
||||
.get('/integration', requireAuth, (c) => slackHandler.getIntegration(c))
|
||||
.put('/integration', requireAuth, (c) => slackHandler.updateIntegration(c))
|
||||
.delete('/integration', requireAuth, (c) => slackHandler.removeIntegration(c))
|
||||
.put('/integration/default-channel', requireAuth, (c) => slackHandler.updateDefaultChannel(c))
|
||||
// Error handling
|
||||
.onError((e, c) => {
|
||||
if (e instanceof SlackError) {
|
||||
|
|
Loading…
Reference in New Issue