Begin refactoring all integrations to separate integration pages by step

This commit is contained in:
Tuan Dang
2023-02-07 11:48:17 +07:00
parent 13838861fb
commit 5ea5887146
13 changed files with 258 additions and 184 deletions
@@ -40,14 +40,16 @@ export const oAuthExchange = async (
throw new Error("Failed to get environments")
}
const integrationDetails = await IntegrationService.handleOAuthExchange({
const integrationAuth = await IntegrationService.handleOAuthExchange({
workspaceId,
integration,
code,
environment: environments[0].slug,
});
return res.status(200).send(integrationDetails);
return res.status(200).send({
integrationAuth
});
} catch (err) {
Sentry.setUser({ email: req.user.email });
Sentry.captureException(err);
@@ -1,4 +1,5 @@
import { Request, Response } from 'express';
import { Types } from 'mongoose';
import * as Sentry from '@sentry/node';
import {
Integration,
@@ -16,20 +17,31 @@ import { eventPushSecrets } from '../../events';
* @returns
*/
export const createIntegration = async (req: Request, res: Response) => {
// TODO: make this more versatile
let integration;
try {
const {
integrationAuthId,
app,
appId,
isActive,
targetEnvironment,
owner
} = req.body;
// initialize new integration after saving integration access token
integration = await new Integration({
workspace: req.integrationAuth.workspace._id,
isActive: false,
app: null,
environment: req.integrationAuth.workspace?.environments[0].slug,
isActive,
app,
appId,
targetEnvironment,
integration: req.integrationAuth.integration,
integrationAuth: req.integrationAuth._id
integrationAuth: new Types.ObjectId(integrationAuthId)
}).save();
// TODO: run sync function
} catch (err) {
Sentry.setUser({ email: req.user.email });
Sentry.captureException(err);