Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add more _destroyAll() helpers #132

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/requests/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@ export class FlowClient {
return publishFlow(this.client, args);
}

/**
* Only used in test environments
*/
async _destroy(flowId: string): Promise<boolean> {
return _destroyFlow(this.client, flowId);
}

/**
* Only used in test environments
*/
async _destroyAll(): Promise<boolean> {
return _destroyAllFlows(this.client);
}

async _destroyPublished(publishedFlowId: number): Promise<boolean> {
return _destroyPublishedFlow(this.client, publishedFlowId);
}
Expand Down Expand Up @@ -223,6 +233,20 @@ export async function _destroyFlow(
return Boolean(response.delete_flows_by_pk?.id);
}

export async function _destroyAllFlows(
client: GraphQLClient,
): Promise<boolean> {
const response: { deleteFlows: { affectedRows: string } } =
await client.request(gql`
mutation DestroyAllFlows {
deleteFlows: delete_flows(where: { id: { _is_null: false } }) {
affectedRows: affected_rows
}
}
`);
return Boolean(response.deleteFlows.affectedRows);
}

export async function _destroyPublishedFlow(
client: GraphQLClient,
publishedFlowId: number,
Expand Down
24 changes: 24 additions & 0 deletions src/requests/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,19 @@ export class TeamClient {
return removeMember(this.client, args);
}

/**
* Only used in test environments
*/
async _destroy(teamId: number): Promise<boolean> {
return _destroyTeam(this.client, teamId);
}

/**
* Only used in test environments
*/
async _destroyAll(): Promise<boolean> {
return _destroyAllTeams(this.client);
}
}

const defaultNotifyPersonalisation = {
Expand Down Expand Up @@ -145,6 +155,20 @@ export async function _destroyTeam(
return Boolean(response.delete_teams_by_pk?.id);
}

export async function _destroyAllTeams(
client: GraphQLClient,
): Promise<boolean> {
const response: { deleteTeams: { affectedRows: number } } =
await client.request(gql`
mutation DestroyAllTeams {
deleteTeams: delete_teams(where: { id: { _is_null: false } }) {
affectedRows: affected_rows
}
}
`);
return Boolean(response.deleteTeams.affectedRows);
}

export async function upsertMember(
client: GraphQLClient,
args: UpsertMember,
Expand Down
24 changes: 24 additions & 0 deletions src/requests/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ export class UserClient {
return createUser(this.client, args);
}

/**
* Only used in test environments
*/
async _destroy(userId: number): Promise<boolean> {
return _destroyUser(this.client, userId);
}

/**
* Only used in test environments
*/
async _destroyAll(): Promise<boolean> {
return _destroyAllUsers(this.client);
}

async getByEmail(email: string): Promise<User | null> {
return getByEmail(this.client, email);
}
Expand Down Expand Up @@ -82,6 +92,20 @@ export async function _destroyUser(
return Boolean(response.delete_users_by_pk?.id);
}

export async function _destroyAllUsers(
client: GraphQLClient,
): Promise<boolean> {
const response: { deleteUsers: { affectedRows: number } } =
await client.request(gql`
mutation DestroyAllUsers {
deleteUsers: delete_users(where: { id: { _is_null: false } }) {
affectedRows: affected_rows
}
}
`);
return Boolean(response.deleteUsers.affectedRows);
}

async function getByEmail(
client: GraphQLClient,
email: string,
Expand Down