mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
feat: updateConnectorConfig (#168)
* feat: updateConnectorConfig * fix: throw RequestError * feat: template
This commit is contained in:
parent
6e9cabe50b
commit
59cd617b2b
2 changed files with 35 additions and 0 deletions
32
packages/core/src/connectors/utils.ts
Normal file
32
packages/core/src/connectors/utils.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { ConnectorConfig, ConnectorType } from '@logto/schemas';
|
||||
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import { findConnectorByIdAndType, updateConnector } from '@/queries/connector';
|
||||
|
||||
export const getConnectorConfig = async <T extends ConnectorConfig>(
|
||||
id: string,
|
||||
type: ConnectorType
|
||||
): Promise<T> => {
|
||||
const connector = await findConnectorByIdAndType(id, type);
|
||||
if (!connector) {
|
||||
throw new RequestError({
|
||||
code: 'entity.not_exists_with_id',
|
||||
name: 'connector',
|
||||
id,
|
||||
status: 404,
|
||||
});
|
||||
}
|
||||
|
||||
return connector.config as T;
|
||||
};
|
||||
|
||||
export const updateConnectorConfig = async <T extends ConnectorConfig>(
|
||||
id: string,
|
||||
type: ConnectorType,
|
||||
config: T
|
||||
): Promise<void> => {
|
||||
await updateConnector({
|
||||
where: { id, type },
|
||||
set: { config },
|
||||
});
|
||||
};
|
|
@ -3,6 +3,7 @@ import { sql } from 'slonik';
|
|||
|
||||
import { buildInsertInto } from '@/database/insert-into';
|
||||
import pool from '@/database/pool';
|
||||
import { buildUpdateWhere } from '@/database/update-where';
|
||||
import { convertToIdentifiers } from '@/database/utils';
|
||||
|
||||
const { table, fields } = convertToIdentifiers(Connectors);
|
||||
|
@ -17,3 +18,5 @@ export const findConnectorByIdAndType = async (id: string, type: ConnectorType)
|
|||
export const insertConnector = buildInsertInto<ConnectorUpdate, Connector>(pool, Connectors, {
|
||||
returning: true,
|
||||
});
|
||||
|
||||
export const updateConnector = buildUpdateWhere<ConnectorUpdate>(pool, Connectors);
|
||||
|
|
Loading…
Add table
Reference in a new issue