fix: clone base db queries

This commit is contained in:
Ali BARIN
2023-08-03 19:07:01 +00:00
parent e4e3356dc9
commit 7ca37c412e
11 changed files with 13 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ const getApp = async (_parent: unknown, params: Params, context: Context) => {
if (context.currentUser) { if (context.currentUser) {
const connections = await connectionBaseQuery const connections = await connectionBaseQuery
.clone()
.select('connections.*') .select('connections.*')
.fullOuterJoinRelated('steps') .fullOuterJoinRelated('steps')
.where({ .where({

View File

@@ -26,12 +26,14 @@ const getConnectedApps = async (
let apps = await App.findAll(params.name); let apps = await App.findAll(params.name);
const connections = await connectionBaseQuery const connections = await connectionBaseQuery
.clone()
.select('connections.key') .select('connections.key')
.where({ draft: false }) .where({ draft: false })
.count('connections.id as count') .count('connections.id as count')
.groupBy('connections.key'); .groupBy('connections.key');
const flows = await flowBaseQuery const flows = await flowBaseQuery
.clone()
.withGraphJoined('steps') .withGraphJoined('steps')
.orderBy('created_at', 'desc'); .orderBy('created_at', 'desc');

View File

@@ -23,6 +23,7 @@ const getDynamicData = async (
const stepBaseQuery = conditions.isCreator ? userSteps : allSteps; const stepBaseQuery = conditions.isCreator ? userSteps : allSteps;
const step = await stepBaseQuery const step = await stepBaseQuery
.clone()
.withGraphFetched({ .withGraphFetched({
connection: true, connection: true,
flow: true, flow: true,

View File

@@ -21,6 +21,7 @@ const getDynamicFields = async (
const stepBaseQuery = conditions.isCreator ? userSteps : allSteps; const stepBaseQuery = conditions.isCreator ? userSteps : allSteps;
const step = await stepBaseQuery const step = await stepBaseQuery
.clone()
.withGraphFetched({ .withGraphFetched({
connection: true, connection: true,
flow: true, flow: true,

View File

@@ -19,6 +19,7 @@ const getExecutionSteps = async (
const executionBaseQuery = conditions.isCreator ? userExecutions : allExecutions; const executionBaseQuery = conditions.isCreator ? userExecutions : allExecutions;
const execution = await executionBaseQuery const execution = await executionBaseQuery
.clone()
.withSoftDeleted() .withSoftDeleted()
.findById(params.executionId) .findById(params.executionId)
.throwIfNotFound(); .throwIfNotFound();

View File

@@ -16,6 +16,7 @@ const getExecution = async (
const executionBaseQuery = conditions.isCreator ? userExecutions : allExecutions; const executionBaseQuery = conditions.isCreator ? userExecutions : allExecutions;
const execution = await executionBaseQuery const execution = await executionBaseQuery
.clone()
.withGraphFetched({ .withGraphFetched({
flow: { flow: {
steps: true, steps: true,

View File

@@ -29,6 +29,7 @@ const getExecutions = async (
`; `;
const executions = executionBaseQuery const executions = executionBaseQuery
.clone()
.joinRelated('executionSteps as execution_steps') .joinRelated('executionSteps as execution_steps')
.select('executions.*', raw(selectStatusStatement)) .select('executions.*', raw(selectStatusStatement))
.withSoftDeleted() .withSoftDeleted()

View File

@@ -12,6 +12,7 @@ const getFlow = async (_parent: unknown, params: Params, context: Context) => {
const baseQuery = conditions.isCreator ? userFlows : allFlows; const baseQuery = conditions.isCreator ? userFlows : allFlows;
const flow = await baseQuery const flow = await baseQuery
.clone()
.withGraphJoined('[steps.[connection]]') .withGraphJoined('[steps.[connection]]')
.orderBy('steps.position', 'asc') .orderBy('steps.position', 'asc')
.findOne({ 'flows.id': params.id }) .findOne({ 'flows.id': params.id })

View File

@@ -17,6 +17,7 @@ const getFlows = async (_parent: unknown, params: Params, context: Context) => {
const baseQuery = conditions.isCreator ? userFlows : allFlows; const baseQuery = conditions.isCreator ? userFlows : allFlows;
const flowsQuery = baseQuery const flowsQuery = baseQuery
.clone()
.joinRelated({ .joinRelated({
steps: true, steps: true,
}) })

View File

@@ -18,10 +18,12 @@ const getStepWithTestExecutions = async (
const stepBaseQuery = conditions.isCreator ? userSteps : allSteps; const stepBaseQuery = conditions.isCreator ? userSteps : allSteps;
const step = await stepBaseQuery const step = await stepBaseQuery
.clone()
.findOne({ 'steps.id': params.stepId }) .findOne({ 'steps.id': params.stepId })
.throwIfNotFound(); .throwIfNotFound();
const previousStepsWithCurrentStep = await stepBaseQuery const previousStepsWithCurrentStep = await stepBaseQuery
.clone()
.withGraphJoined('executionSteps') .withGraphJoined('executionSteps')
.where('flow_id', '=', step.flowId) .where('flow_id', '=', step.flowId)
.andWhere('position', '<', step.position) .andWhere('position', '<', step.position)

View File

@@ -19,6 +19,7 @@ const testConnection = async (
const connectionBaseQuery = conditions.isCreator ? userConnections : allConnections; const connectionBaseQuery = conditions.isCreator ? userConnections : allConnections;
let connection = await connectionBaseQuery let connection = await connectionBaseQuery
.clone()
.findOne({ .findOne({
id: params.id, id: params.id,
}) })