feat: Implement updateFlowStatus mutation
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
63198a6569
commit
64011b5c4b
31
packages/backend/src/graphql/mutations/update-flow-status.ts
Normal file
31
packages/backend/src/graphql/mutations/update-flow-status.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import Context from '../../types/express/context';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
active: boolean;
|
||||
};
|
||||
|
||||
const updateFlowStatus = async (
|
||||
_parent: unknown,
|
||||
params: Params,
|
||||
context: Context
|
||||
) => {
|
||||
let flow = await context.currentUser
|
||||
.$relatedQuery('flows')
|
||||
.findOne({
|
||||
id: params.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
if (flow.active === params.active) {
|
||||
return flow;
|
||||
}
|
||||
|
||||
flow = await flow.$query().patchAndFetch({
|
||||
active: params.active,
|
||||
});
|
||||
|
||||
return flow;
|
||||
};
|
||||
|
||||
export default updateFlowStatus;
|
Reference in New Issue
Block a user