File tree Expand file tree Collapse file tree 7 files changed +39
-3
lines changed
apps/backend/src/api/routes
libraries/nestjs-libraries/src Expand file tree Collapse file tree 7 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,7 @@ export class IntegrationsController {
264264
265265 if ( accessToken ) {
266266 await this . _integrationService . createOrUpdateIntegration (
267+ ! ! integrationProvider . oneTimeToken ,
267268 getIntegration . organizationId ,
268269 getIntegration . name ,
269270 getIntegration . picture ! ,
@@ -345,6 +346,7 @@ export class IntegrationsController {
345346 }
346347
347348 return this . _integrationService . createOrUpdateIntegration (
349+ true ,
348350 org . id ,
349351 name ,
350352 picture ,
@@ -468,6 +470,7 @@ export class IntegrationsController {
468470 }
469471 }
470472 return this . _integrationService . createOrUpdateIntegration (
473+ ! ! integrationProvider . oneTimeToken ,
471474 org . id ,
472475 validName . trim ( ) ,
473476 picture ,
Original file line number Diff line number Diff line change @@ -93,7 +93,8 @@ export class IntegrationRepository {
9393 } ) ;
9494 }
9595
96- createOrUpdateIntegration (
96+ async createOrUpdateIntegration (
97+ oneTimeToken : boolean ,
9798 org : string ,
9899 name : string ,
99100 picture : string | undefined ,
@@ -118,7 +119,7 @@ export class IntegrationRepository {
118119 ] ) ,
119120 }
120121 : { } ;
121- return this . _integration . model . integration . upsert ( {
122+ const upsert = await this . _integration . model . integration . upsert ( {
122123 where : {
123124 organizationId_internalId : {
124125 internalId,
@@ -141,6 +142,7 @@ export class IntegrationRepository {
141142 ...postTimes ,
142143 organizationId : org ,
143144 refreshNeeded : false ,
145+ rootInternalId : internalId . split ( '_' ) . pop ( ) ,
144146 ...( customInstanceDetails ? { customInstanceDetails } : { } ) ,
145147 } ,
146148 update : {
@@ -164,6 +166,27 @@ export class IntegrationRepository {
164166 refreshNeeded : false ,
165167 } ,
166168 } ) ;
169+
170+ if ( oneTimeToken ) {
171+ await this . _integration . model . integration . updateMany ( {
172+ where : {
173+ id : {
174+ not : upsert . id ,
175+ } ,
176+ organizationId : org ,
177+ rootInternalId : internalId . split ( '_' ) . pop ( ) ,
178+ } ,
179+ data : {
180+ token,
181+ refreshToken,
182+ ...( expiresIn
183+ ? { tokenExpiration : new Date ( Date . now ( ) + expiresIn * 1000 ) }
184+ : { } ) ,
185+ } ,
186+ } ) ;
187+ }
188+
189+ return upsert ;
167190 }
168191
169192 needsToBeRefreshed ( ) {
@@ -497,6 +520,6 @@ export class IntegrationRepository {
497520 select : {
498521 postingTimes : true ,
499522 } ,
500- } )
523+ } ) ;
501524 }
502525}
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ export class IntegrationService {
4242 }
4343
4444 async createOrUpdateIntegration (
45+ oneTimeToken : boolean ,
4546 org : string ,
4647 name : string ,
4748 picture : string | undefined ,
@@ -61,6 +62,7 @@ export class IntegrationService {
6162 ? await this . storage . uploadSimple ( picture )
6263 : undefined ;
6364 return this . _integrationRepository . createOrUpdateIntegration (
65+ oneTimeToken ,
6466 org ,
6567 name ,
6668 uploadedPicture ,
@@ -164,6 +166,7 @@ export class IntegrationService {
164166 const { refreshToken, accessToken, expiresIn } = data ;
165167
166168 await this . createOrUpdateIntegration (
169+ ! ! provider . oneTimeToken ,
167170 integration . organizationId ,
168171 integration . name ,
169172 undefined ,
@@ -350,6 +353,7 @@ export class IntegrationService {
350353
351354 if ( accessToken ) {
352355 await this . createOrUpdateIntegration (
356+ ! ! integrationProvider . oneTimeToken ,
353357 getIntegration . organizationId ,
354358 getIntegration . name ,
355359 getIntegration . picture ! ,
Original file line number Diff line number Diff line change @@ -249,6 +249,7 @@ export class PostsService {
249249 }
250250
251251 await this . _integrationService . createOrUpdateIntegration (
252+ ! ! getIntegration . oneTimeToken ,
252253 integration . organizationId ,
253254 integration . name ,
254255 integration . picture ! ,
Original file line number Diff line number Diff line change @@ -287,7 +287,9 @@ model Integration {
287287 customer Customer ? @relation (fields : [customerId ] , references : [id ] )
288288 plugs Plugs []
289289 exisingPlugData ExisingPlugData []
290+ rootInternalId String ?
290291
292+ @@index ([rootInternalId ] )
291293 @@index ([updatedAt ] )
292294 @@index ([deletedAt ] )
293295 @@unique ([organizationId , internalId ] )
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import { PostPlug } from '@gitroom/helpers/decorators/post.plug';
1515export class LinkedinProvider extends SocialAbstract implements SocialProvider {
1616 identifier = 'linkedin' ;
1717 name = 'LinkedIn' ;
18+ oneTimeToken = true ;
19+
1820 isBetweenSteps = false ;
1921 scopes = [
2022 'openid' ,
Original file line number Diff line number Diff line change @@ -109,6 +109,7 @@ export interface SocialProvider
109109 } [ ]
110110 > ;
111111 name : string ;
112+ oneTimeToken ?: boolean ;
112113 isBetweenSteps : boolean ;
113114 scopes : string [ ] ;
114115 externalUrl ?: (
You can’t perform that action at this time.
0 commit comments