feat: fix linkedin connect for multiple accounts
This commit is contained in:
parent
1a3b52ac34
commit
4806b82c20
|
|
@ -264,6 +264,7 @@ export class IntegrationsController {
|
|||
|
||||
if (accessToken) {
|
||||
await this._integrationService.createOrUpdateIntegration(
|
||||
!!integrationProvider.oneTimeToken,
|
||||
getIntegration.organizationId,
|
||||
getIntegration.name,
|
||||
getIntegration.picture!,
|
||||
|
|
@ -345,6 +346,7 @@ export class IntegrationsController {
|
|||
}
|
||||
|
||||
return this._integrationService.createOrUpdateIntegration(
|
||||
true,
|
||||
org.id,
|
||||
name,
|
||||
picture,
|
||||
|
|
@ -468,6 +470,7 @@ export class IntegrationsController {
|
|||
}
|
||||
}
|
||||
return this._integrationService.createOrUpdateIntegration(
|
||||
!!integrationProvider.oneTimeToken,
|
||||
org.id,
|
||||
validName.trim(),
|
||||
picture,
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@ export class IntegrationRepository {
|
|||
});
|
||||
}
|
||||
|
||||
createOrUpdateIntegration(
|
||||
async createOrUpdateIntegration(
|
||||
oneTimeToken: boolean,
|
||||
org: string,
|
||||
name: string,
|
||||
picture: string | undefined,
|
||||
|
|
@ -118,7 +119,7 @@ export class IntegrationRepository {
|
|||
]),
|
||||
}
|
||||
: {};
|
||||
return this._integration.model.integration.upsert({
|
||||
const upsert = await this._integration.model.integration.upsert({
|
||||
where: {
|
||||
organizationId_internalId: {
|
||||
internalId,
|
||||
|
|
@ -141,6 +142,7 @@ export class IntegrationRepository {
|
|||
...postTimes,
|
||||
organizationId: org,
|
||||
refreshNeeded: false,
|
||||
rootInternalId: internalId.split('_').pop(),
|
||||
...(customInstanceDetails ? { customInstanceDetails } : {}),
|
||||
},
|
||||
update: {
|
||||
|
|
@ -164,6 +166,27 @@ export class IntegrationRepository {
|
|||
refreshNeeded: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (oneTimeToken) {
|
||||
await this._integration.model.integration.updateMany({
|
||||
where: {
|
||||
id: {
|
||||
not: upsert.id,
|
||||
},
|
||||
organizationId: org,
|
||||
rootInternalId: internalId.split('_').pop(),
|
||||
},
|
||||
data: {
|
||||
token,
|
||||
refreshToken,
|
||||
...(expiresIn
|
||||
? { tokenExpiration: new Date(Date.now() + expiresIn * 1000) }
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return upsert;
|
||||
}
|
||||
|
||||
needsToBeRefreshed() {
|
||||
|
|
@ -497,6 +520,6 @@ export class IntegrationRepository {
|
|||
select: {
|
||||
postingTimes: true,
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ export class IntegrationService {
|
|||
}
|
||||
|
||||
async createOrUpdateIntegration(
|
||||
oneTimeToken: boolean,
|
||||
org: string,
|
||||
name: string,
|
||||
picture: string | undefined,
|
||||
|
|
@ -61,6 +62,7 @@ export class IntegrationService {
|
|||
? await this.storage.uploadSimple(picture)
|
||||
: undefined;
|
||||
return this._integrationRepository.createOrUpdateIntegration(
|
||||
oneTimeToken,
|
||||
org,
|
||||
name,
|
||||
uploadedPicture,
|
||||
|
|
@ -164,6 +166,7 @@ export class IntegrationService {
|
|||
const { refreshToken, accessToken, expiresIn } = data;
|
||||
|
||||
await this.createOrUpdateIntegration(
|
||||
!!provider.oneTimeToken,
|
||||
integration.organizationId,
|
||||
integration.name,
|
||||
undefined,
|
||||
|
|
@ -350,6 +353,7 @@ export class IntegrationService {
|
|||
|
||||
if (accessToken) {
|
||||
await this.createOrUpdateIntegration(
|
||||
!!integrationProvider.oneTimeToken,
|
||||
getIntegration.organizationId,
|
||||
getIntegration.name,
|
||||
getIntegration.picture!,
|
||||
|
|
|
|||
|
|
@ -249,6 +249,7 @@ export class PostsService {
|
|||
}
|
||||
|
||||
await this._integrationService.createOrUpdateIntegration(
|
||||
!!getIntegration.oneTimeToken,
|
||||
integration.organizationId,
|
||||
integration.name,
|
||||
integration.picture!,
|
||||
|
|
|
|||
|
|
@ -287,7 +287,9 @@ model Integration {
|
|||
customer Customer? @relation(fields: [customerId], references: [id])
|
||||
plugs Plugs[]
|
||||
exisingPlugData ExisingPlugData[]
|
||||
rootInternalId String?
|
||||
|
||||
@@index([rootInternalId])
|
||||
@@index([updatedAt])
|
||||
@@index([deletedAt])
|
||||
@@unique([organizationId, internalId])
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import { PostPlug } from '@gitroom/helpers/decorators/post.plug';
|
|||
export class LinkedinProvider extends SocialAbstract implements SocialProvider {
|
||||
identifier = 'linkedin';
|
||||
name = 'LinkedIn';
|
||||
oneTimeToken = true;
|
||||
|
||||
isBetweenSteps = false;
|
||||
scopes = [
|
||||
'openid',
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ export interface SocialProvider
|
|||
}[]
|
||||
>;
|
||||
name: string;
|
||||
oneTimeToken?: boolean;
|
||||
isBetweenSteps: boolean;
|
||||
scopes: string[];
|
||||
externalUrl?: (
|
||||
|
|
|
|||
Loading…
Reference in New Issue