forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build stripe integration on backend side (twentyhq#5246)
Adding stripe integration by making the server logic independent of the input fields: - query factories (remote server, foreign data wrapper, foreign table) to loop on fields and values without hardcoding the names of the fields - adding stripe input and type - add the logic to handle static schema. Simply creating a big object to store into the server Additional work: - rename username field to user. This is the input intended for postgres user mapping and we now need a matching by name --------- Co-authored-by: Thomas Trompette <thomast@twenty.com>
- Loading branch information
Showing
30 changed files
with
394 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 0 additions & 105 deletions
105
...ngine/api/graphql/workspace-query-builder/factories/foreign-data-wrapper-query.factory.ts
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
...pi/graphql/workspace-query-builder/factories/foreign-data-wrapper-server-query.factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { | ||
ForeignDataWrapperOptions, | ||
RemoteServerType, | ||
} from 'src/engine/metadata-modules/remote-server/remote-server.entity'; | ||
import { UserMappingOptions } from 'src/engine/metadata-modules/remote-server/types/user-mapping-options'; | ||
|
||
@Injectable() | ||
export class ForeignDataWrapperServerQueryFactory { | ||
createForeignDataWrapperServer( | ||
foreignDataWrapperId: string, | ||
foreignDataWrapperType: RemoteServerType, | ||
foreignDataWrapperOptions: ForeignDataWrapperOptions<RemoteServerType>, | ||
) { | ||
const options = this.buildQueryOptions(foreignDataWrapperOptions, false); | ||
|
||
return `CREATE SERVER "${foreignDataWrapperId}" FOREIGN DATA WRAPPER ${foreignDataWrapperType} OPTIONS (${options})`; | ||
} | ||
|
||
updateForeignDataWrapperServer({ | ||
foreignDataWrapperId, | ||
foreignDataWrapperOptions, | ||
}: { | ||
foreignDataWrapperId: string; | ||
foreignDataWrapperOptions: Partial< | ||
ForeignDataWrapperOptions<RemoteServerType> | ||
>; | ||
}) { | ||
const options = this.buildQueryOptions(foreignDataWrapperOptions, true); | ||
|
||
return `ALTER SERVER "${foreignDataWrapperId}" OPTIONS (${options})`; | ||
} | ||
|
||
createUserMapping( | ||
foreignDataWrapperId: string, | ||
userMappingOptions: UserMappingOptions, | ||
) { | ||
const options = this.buildQueryOptions(userMappingOptions, false); | ||
|
||
// CURRENT_USER works for now since we are using only one user. But if we switch to a user per workspace, we need to change this. | ||
return `CREATE USER MAPPING IF NOT EXISTS FOR CURRENT_USER SERVER "${foreignDataWrapperId}" OPTIONS (${options})`; | ||
} | ||
|
||
updateUserMapping( | ||
foreignDataWrapperId: string, | ||
userMappingOptions: Partial<UserMappingOptions>, | ||
) { | ||
const options = this.buildQueryOptions(userMappingOptions, true); | ||
|
||
// CURRENT_USER works for now since we are using only one user. But if we switch to a user per workspace, we need to change this. | ||
return `ALTER USER MAPPING FOR CURRENT_USER SERVER "${foreignDataWrapperId}" OPTIONS (${options})`; | ||
} | ||
|
||
private buildQueryOptions( | ||
options: | ||
| ForeignDataWrapperOptions<RemoteServerType> | ||
| Partial<ForeignDataWrapperOptions<RemoteServerType>> | ||
| UserMappingOptions | ||
| Partial<UserMappingOptions>, | ||
isUpdate: boolean, | ||
) { | ||
const prefix = isUpdate ? 'SET ' : ''; | ||
|
||
return Object.entries(options) | ||
.map(([key, value]) => `${prefix}${key} '${value}'`) | ||
.join(', '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.