Skip to content

Commit

Permalink
Merge pull request #3627 from uselagoon/feature/add_service_to_delete…
Browse files Browse the repository at this point in the history
…FactsFromSource

Adds service to deleteFactsFromSource
  • Loading branch information
tobybellwood authored Feb 6, 2024
2 parents ad08dbe + d368cd8 commit 7dfbaa4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
11 changes: 8 additions & 3 deletions services/api/src/resources/fact/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,26 +382,31 @@ export const deleteFact: ResolverFn = async (

export const deleteFactsFromSource: ResolverFn = async (
root,
{ input: { environment: environmentId, source } },
{ input: { environment: environmentId, source, service } },
{ sqlClientPool, hasPermission, userActivityLogger }
) => {
const environment = await environmentHelpers(
sqlClientPool
).getEnvironmentById(environmentId);

if(environment == null) {
throw new Error(`Unable to find environment with id: ${environmentId}`);
}

await hasPermission('fact', 'delete', {
project: environment.project
});

await query(sqlClientPool, Sql.deleteFactsFromSource(environmentId, source));
await query(sqlClientPool, Sql.deleteFactsFromSource(environmentId, source, service));

userActivityLogger(`User deleted facts`, {
project: '',
event: 'api:deleteFactsFromSource',
payload: {
data: {
environment: environmentId,
source
source,
service
}
}
});
Expand Down
17 changes: 12 additions & 5 deletions services/api/src/resources/fact/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ export const Sql = {
})
.del()
.toString(),
deleteFactsFromSource: (environment, source) =>
knex('environment_fact')
.where({ environment, source })
.del()
.toString(),
deleteFactsFromSource: (environment, source, service) => {
let query = knex('environment_fact')
.where({ environment, source });

if(service != null) {
query = query.andWhere("service", "=", service)
}

query = query.del();

return query.toString();
},
selectFactReferenceByDatabaseId: (id: number) =>
knex('environment_fact_reference')
.where({ id })
Expand Down
1 change: 1 addition & 0 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ const typeDefs = gql`
input DeleteFactsFromSourceInput {
environment: Int!
source: String!
service: String
}
type FactReference {
Expand Down

0 comments on commit 7dfbaa4

Please sign in to comment.