Skip to content

Commit

Permalink
Adds service to deleteFactsFromSource
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed Dec 17, 2023
1 parent e4ce695 commit ac5baae
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 @@ -48,11 +48,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 @@ -378,6 +378,7 @@ const typeDefs = gql`
input DeleteFactsFromSourceInput {
environment: Int!
source: String!
service: String
}
type FactReference {
Expand Down

0 comments on commit ac5baae

Please sign in to comment.