feat: add shareConnection mutation
This commit is contained in:
@@ -19,6 +19,7 @@ import login from './mutations/login';
|
|||||||
import registerUser from './mutations/register-user.ee';
|
import registerUser from './mutations/register-user.ee';
|
||||||
import resetConnection from './mutations/reset-connection';
|
import resetConnection from './mutations/reset-connection';
|
||||||
import resetPassword from './mutations/reset-password.ee';
|
import resetPassword from './mutations/reset-password.ee';
|
||||||
|
import shareConnection from './mutations/share-connection.ee';
|
||||||
import updateAppAuthClient from './mutations/update-app-auth-client.ee';
|
import updateAppAuthClient from './mutations/update-app-auth-client.ee';
|
||||||
import updateAppConfig from './mutations/update-app-config.ee';
|
import updateAppConfig from './mutations/update-app-config.ee';
|
||||||
import updateConfig from './mutations/update-config.ee';
|
import updateConfig from './mutations/update-config.ee';
|
||||||
@@ -55,6 +56,7 @@ const mutationResolvers = {
|
|||||||
registerUser,
|
registerUser,
|
||||||
resetConnection,
|
resetConnection,
|
||||||
resetPassword,
|
resetPassword,
|
||||||
|
shareConnection,
|
||||||
updateAppAuthClient,
|
updateAppAuthClient,
|
||||||
updateAppConfig,
|
updateAppConfig,
|
||||||
updateConfig,
|
updateConfig,
|
||||||
|
@@ -0,0 +1,55 @@
|
|||||||
|
import Context from '../../types/express/context';
|
||||||
|
import Connection from '../../models/connection';
|
||||||
|
import SharedConnection from '../../models/shared-connection';
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
input: {
|
||||||
|
id: string;
|
||||||
|
roleIds: string[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const shareConnection = async (
|
||||||
|
_parent: unknown,
|
||||||
|
params: Params,
|
||||||
|
context: Context
|
||||||
|
) => {
|
||||||
|
const conditions = context.currentUser.can('update', 'Connection');
|
||||||
|
|
||||||
|
if (conditions.isCreator) return;
|
||||||
|
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
roleIds,
|
||||||
|
} = params.input;
|
||||||
|
|
||||||
|
const connection = await Connection
|
||||||
|
.query()
|
||||||
|
.findById(id)
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updatedConnection = await Connection.transaction(async (trx) => {
|
||||||
|
await connection.$relatedQuery('sharedConnections', trx).delete();
|
||||||
|
|
||||||
|
if (roleIds?.length) {
|
||||||
|
const sharedConnections = roleIds.map((roleId) => ({
|
||||||
|
roleId,
|
||||||
|
connectionId: connection.id,
|
||||||
|
}));
|
||||||
|
|
||||||
|
await SharedConnection.query().insert(sharedConnections);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await Connection
|
||||||
|
.query(trx)
|
||||||
|
.findById(id);
|
||||||
|
});
|
||||||
|
|
||||||
|
return updatedConnection;
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error('The connection sharing preferences could not be updated!');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default shareConnection;
|
@@ -84,6 +84,7 @@ type Mutation {
|
|||||||
registerUser(input: RegisterUserInput): User
|
registerUser(input: RegisterUserInput): User
|
||||||
resetConnection(input: ResetConnectionInput): Connection
|
resetConnection(input: ResetConnectionInput): Connection
|
||||||
resetPassword(input: ResetPasswordInput): Boolean
|
resetPassword(input: ResetPasswordInput): Boolean
|
||||||
|
shareConnection(input: ShareConnectionInput): Connection
|
||||||
updateAppAuthClient(input: UpdateAppAuthClientInput): AppAuthClient
|
updateAppAuthClient(input: UpdateAppAuthClientInput): AppAuthClient
|
||||||
updateAppConfig(input: UpdateAppConfigInput): AppConfig
|
updateAppConfig(input: UpdateAppConfigInput): AppConfig
|
||||||
updateConfig(input: JSONObject): JSONObject
|
updateConfig(input: JSONObject): JSONObject
|
||||||
@@ -812,6 +813,11 @@ input ExecutionFiltersInput {
|
|||||||
status: String
|
status: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input ShareConnectionInput {
|
||||||
|
id: String!
|
||||||
|
roleIds: [String]
|
||||||
|
}
|
||||||
|
|
||||||
schema {
|
schema {
|
||||||
query: Query
|
query: Query
|
||||||
mutation: Mutation
|
mutation: Mutation
|
||||||
|
@@ -11,7 +11,7 @@ class SharedConnection extends Base {
|
|||||||
|
|
||||||
static jsonSchema = {
|
static jsonSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['name', 'key'],
|
required: ['roleId', 'connectionId'],
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
id: { type: 'string', format: 'uuid' },
|
id: { type: 'string', format: 'uuid' },
|
||||||
|
Reference in New Issue
Block a user