Skip to content

Commit

Permalink
feat: Add more _destroyAll() helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 19, 2023
1 parent 03db128 commit c686ae0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
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 {
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
28 changes: 26 additions & 2 deletions src/requests/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ export class UserClient {
return createUser(this.client, args);
}

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

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

async getByEmail(email: string): Promise<User | null> {
Expand Down Expand Up @@ -64,7 +74,7 @@ export async function createUser(
return response.insert_users_one.id;
}

export async function _destroyUser(
export async function _destroyUserByPK(
client: GraphQLClient,
userId: number,
): Promise<boolean> {
Expand All @@ -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

0 comments on commit c686ae0

Please sign in to comment.