slack integration reinstall

This commit is contained in:
Sheen Capadngan
2024-09-02 21:05:30 +08:00
parent 07fd489982
commit f509464947
2 changed files with 58 additions and 16 deletions
+38 -10
View File
@@ -21,7 +21,7 @@ import {
type TSlackServiceFactoryDep = {
slackIntegrationDAL: Pick<
TSlackIntegrationDALFactory,
"create" | "findOne" | "findById" | "updateById" | "deleteById"
"create" | "findOne" | "findById" | "updateById" | "deleteById" | "transaction"
>;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
projectDAL: Pick<TProjectDALFactory, "findById">;
@@ -62,15 +62,43 @@ export const slackServiceFactory = ({
plainText: Buffer.from(botAccessToken, "utf8")
});
await slackIntegrationDAL.create({
projectId,
teamId,
teamName,
slackUserId,
slackAppId,
slackBotId,
slackBotUserId,
encryptedBotAccessToken
await slackIntegrationDAL.transaction(async (tx) => {
const slackIntegration = await slackIntegrationDAL.findOne(
{
projectId
},
tx
);
if (slackIntegration) {
return slackIntegrationDAL.updateById(
slackIntegration.id,
{
teamId,
teamName,
slackUserId,
slackAppId,
slackBotId,
slackBotUserId,
encryptedBotAccessToken
},
tx
);
}
return slackIntegrationDAL.create(
{
projectId,
teamId,
teamName,
slackUserId,
slackAppId,
slackBotId,
slackBotUserId,
encryptedBotAccessToken
},
tx
);
});
};