Spaces:
Running
Running
File size: 4,549 Bytes
6abfd9d | 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | import { Controller, Get, Query, Res, Logger } from "@nestjs/common";
import { Response } from "express";
import { IntegrationsService } from "./integrations.service";
@Controller("api/integrations")
export class IntegrationsController {
private readonly logger = new Logger(IntegrationsController.name);
constructor(private readonly integrationsService: IntegrationsService) {}
@Get("google/callback")
async googleCallback(
@Query("code") code: string,
@Query("state") state: string,
@Query("error") error: string,
@Res() res: Response,
) {
if (error) {
this.logger.warn(`Google OAuth error: ${error}`);
return res.redirect(`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=google_calendar&status=error`);
}
try {
const result = await this.integrationsService.handleOAuthCallback(code, state);
return res.redirect(
`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=${result.provider}&status=${result.success ? "connected" : "error"}`,
);
} catch (err: any) {
this.logger.error(`Google OAuth callback failed: ${err.message}`);
return res.redirect(
`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=google_calendar&status=error`,
);
}
}
@Get("outlook/callback")
async outlookCallback(
@Query("code") code: string,
@Query("state") state: string,
@Query("error") error: string,
@Res() res: Response,
) {
if (error) {
this.logger.warn(`Outlook OAuth error: ${error}`);
return res.redirect(`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=outlook&status=error`);
}
try {
const result = await this.integrationsService.handleOAuthCallback(code, state);
return res.redirect(
`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=${result.provider}&status=${result.success ? "connected" : "error"}`,
);
} catch (err: any) {
this.logger.error(`Outlook OAuth callback failed: ${err.message}`);
return res.redirect(
`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=outlook&status=error`,
);
}
}
@Get("zoom/callback")
async zoomCallback(
@Query("code") code: string,
@Query("state") state: string,
@Query("error") error: string,
@Res() res: Response,
) {
if (error) {
this.logger.warn(`Zoom OAuth error: ${error}`);
return res.redirect(`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=zoom&status=error`);
}
try {
const result = await this.integrationsService.handleOAuthCallback(code, state);
return res.redirect(
`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=${result.provider}&status=${result.success ? "connected" : "error"}`,
);
} catch (err: any) {
this.logger.error(`Zoom OAuth callback failed: ${err.message}`);
return res.redirect(
`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=zoom&status=error`,
);
}
}
@Get("riverside/callback")
async riversideCallback(
@Query("code") code: string,
@Query("state") state: string,
@Query("error") error: string,
@Res() res: Response,
) {
if (error) {
this.logger.warn(`Riverside OAuth error: ${error}`);
return res.redirect(`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=riverside&status=error`);
}
try {
const result = await this.integrationsService.handleOAuthCallback(code, state);
return res.redirect(
`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=${result.provider}&status=${result.success ? "connected" : "error"}`,
);
} catch (err: any) {
this.logger.error(`Riverside OAuth callback failed: ${err.message}`);
return res.redirect(
`${process.env.WEBAPP_URL || "http://localhost:3000"}/settings?integration=riverside&status=error`,
);
}
}
}
|