mirror of
https://github.com/logto-io/logto.git
synced 2025-03-10 22:22:45 -05:00
chore: align routers return process of updating DB (#193)
* chore: align routers return process of updating DB * chore: align connector router output
This commit is contained in:
parent
67843f45db
commit
871789e763
3 changed files with 10 additions and 11 deletions
|
@ -32,4 +32,4 @@ export const insertConnector = buildInsertInto<CreateConnector, Connector>(pool,
|
|||
returning: true,
|
||||
});
|
||||
|
||||
export const updateConnector = buildUpdateWhere<CreateConnector>(pool, Connectors);
|
||||
export const updateConnector = buildUpdateWhere<CreateConnector, Connector>(pool, Connectors, true);
|
||||
|
|
|
@ -4,7 +4,7 @@ import { object, string } from 'zod';
|
|||
import { getConnectorInstances, getConnectorInstanceById } from '@/connectors';
|
||||
import { ConnectorInstance } from '@/connectors/types';
|
||||
import koaGuard from '@/middleware/koa-guard';
|
||||
import { findConnectorById, updateConnector } from '@/queries/connector';
|
||||
import { updateConnector } from '@/queries/connector';
|
||||
|
||||
import { AuthedRouter } from './types';
|
||||
|
||||
|
@ -48,9 +48,9 @@ export default function connectorRoutes<T extends AuthedRouter>(router: T) {
|
|||
params: { id },
|
||||
body: { enabled },
|
||||
} = ctx.guard;
|
||||
await findConnectorById(id);
|
||||
await updateConnector({ set: { enabled }, where: { id } });
|
||||
ctx.body = { enabled };
|
||||
const { metadata } = await getConnectorInstanceById(id);
|
||||
const connector = await updateConnector({ set: { enabled }, where: { id } });
|
||||
ctx.body = { ...connector, metadata };
|
||||
|
||||
return next();
|
||||
}
|
||||
|
@ -69,14 +69,14 @@ export default function connectorRoutes<T extends AuthedRouter>(router: T) {
|
|||
params: { id },
|
||||
body,
|
||||
} = ctx.guard;
|
||||
const connectorInstance = await getConnectorInstanceById(id);
|
||||
const { metadata, validateConfig } = await getConnectorInstanceById(id);
|
||||
|
||||
if (body.config) {
|
||||
await connectorInstance.validateConfig(body.config);
|
||||
await validateConfig(body.config);
|
||||
}
|
||||
|
||||
await updateConnector({ set: body, where: { id } });
|
||||
ctx.body = transpileConnectorInstance(await getConnectorInstanceById(id));
|
||||
const connector = await updateConnector({ set: body, where: { id } });
|
||||
ctx.body = { ...connector, metadata };
|
||||
|
||||
return next();
|
||||
}
|
||||
|
|
|
@ -97,11 +97,10 @@ export default function userRoutes<T extends AnonymousRouter>(router: T, provide
|
|||
|
||||
const { passwordEncrypted, passwordEncryptionSalt } = encryptUserPassword(userId, password);
|
||||
|
||||
await updateUserById(userId, {
|
||||
const user = await updateUserById(userId, {
|
||||
passwordEncryptionSalt,
|
||||
passwordEncrypted,
|
||||
});
|
||||
const user = await findUserById(userId);
|
||||
ctx.body = pick(user, ...userInfoSelectFields);
|
||||
return next();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue