Skip to content

Commit

Permalink
fix: new ts issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tethik committed Oct 23, 2024
1 parent aaa47dd commit 8e9532d
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
7 changes: 6 additions & 1 deletion api/src/test-util/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { createApp } from "../app.js";
import { bootstrap } from "@gram/core/dist/bootstrap.js";
import { Pool } from "pg";

export async function createTestApp() {
export async function createTestApp(): Promise<{
pool: Pool;
app: any;
dal: any;
}> {
const dal = await bootstrap();
const app = await createApp(dal);
return { pool: dal.pool._pool, app, dal };
Expand Down
4 changes: 2 additions & 2 deletions core/src/data/controls/ControlDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class ControlDataService extends EventEmitter {

const result = await this.pool.runTransaction(async (client) => {
const res = await client.query(query, [modelId, ...ids]);
const result = res.rowCount > 0;
const result = res && res.rowCount !== null && res.rowCount > 0;

if (result) {
const suggestionIds = res.rows
Expand Down Expand Up @@ -257,7 +257,7 @@ export class ControlDataService extends EventEmitter {

const res = await this.pool.query(query, params);

if (res.rowCount > 0) {
if (res.rowCount !== null && res.rowCount > 0) {
this.emit("updated-for", {
modelId: res.rows[0].model_id,
componentId: res.rows[0].component_id,
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/flow/FlowDataService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe("FlowDataService implementation", () => {
expect(res.length).toEqual(0);
});

it("should not delete link when id does not exist", async () => {
it("should not delete flow when id does not exist", async () => {
const dataFlowId = randomUUID();
const originComponentId = randomUUID();
const summary = "GET /hello-world";
Expand Down
4 changes: 2 additions & 2 deletions core/src/data/flow/FlowDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class FlowDataService extends EventEmitter {
attributes,
id,
]);
if (res.rowCount > 0) {
if (res.rowCount !== null && res.rowCount > 0) {
this.emit("updated-for", {
modelId: res.rows[0].model_id,
dataFlowId: res.rows[0].data_flow_id,
Expand All @@ -125,7 +125,7 @@ export class FlowDataService extends EventEmitter {
DELETE FROM flows WHERE id = $1 RETURNING *
`;
const res = await this.pool.query(query, [id]);
if (res.rowCount > 0) {
if (res.rowCount !== null && res.rowCount > 0) {
this.emit("updated-for", {
modelId: res.rows[0].model_id,
dataFlowId: res.rows[0].data_flow_id,
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/mitigations/MitigationDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class MitigationDataService extends EventEmitter {

const res = await this.pool.query(query, [threatId, controlId]);

if (res.rowCount > 0) {
if (res.rowCount !== null && res.rowCount > 0) {
this.emit("updated-for", {
modelId: res.rows[0].model_id,
componentId: res.rows[0].component_id,
Expand Down
4 changes: 2 additions & 2 deletions core/src/data/models/ModelDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export class ModelDataService extends EventEmitter implements SearchProvider {
return res;
});

if (res.rowCount > 0) {
if (res.rowCount !== null && res.rowCount > 0) {
this.emit("updated-for", { modelId: id });
success = true;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ export class ModelDataService extends EventEmitter implements SearchProvider {

this.emit("updated-for", { modelId: id });

return res.rowCount > 0;
return res.rowCount !== null && res.rowCount > 0;
}

async setSystemId(modelId: string, systemId: string | null) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/notifications/NotificationDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class NotificationDataService {
WHERE id IN (${safeInString})`;

const res = await this.pool.query(query, [status]);
return res.rowCount > 0;
return res.rowCount !== null && res.rowCount > 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/reviews/ReviewDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export class ReviewDataService extends EventEmitter {

const res = await this.pool.query(query, params);

if (res.rowCount > 0) {
if (res.rowCount !== null && res.rowCount > 0) {
this.emit("updated-for", {
modelId,
});
Expand Down
4 changes: 2 additions & 2 deletions core/src/data/suggestions/SuggestionDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class SuggestionDataService extends EventEmitter {
this.pool.query(threatsQuery, [modelId, ...componentIds]),
this.pool.query(controlsQuery, [modelId, ...componentIds]),
])
).reduce((p, c) => p + c.rowCount, 0) > 0
).reduce((p, c) => p + c.rowCount!, 0) > 0
);
}

Expand Down Expand Up @@ -282,7 +282,7 @@ export class SuggestionDataService extends EventEmitter {
this.emit("updated-for", {
modelId,
});
return res.rowCount > 0;
return res.rowCount !== null && res.rowCount > 0;
}

async getById(modelId: string, suggestionId: SuggestionID) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/data/threats/ThreatDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class ThreatDataService extends EventEmitter {

const res = await this.pool.query(query, params);

if (res.rowCount > 0) {
if (res.rowCount !== null && res.rowCount > 0) {
this.emit("updated-for", {
modelId: res.rows[0].model_id,
componentId: res.rows[0].component_id,
Expand Down Expand Up @@ -268,7 +268,7 @@ export class ThreatDataService extends EventEmitter {
let suggestionIds: SuggestionID[] = [];

const res = await client.query(query, [modelId, ...ids]);
const result = res.rowCount > 0;
const result = res.rowCount !== null && res.rowCount > 0;

if (result) {
suggestionIds = res.rows
Expand Down

0 comments on commit 8e9532d

Please sign in to comment.