Skip to content

Commit

Permalink
Merge pull request #40 from Northeastern-Electric-Racing/#12-CRUD-get…
Browse files Browse the repository at this point in the history
…-all-nodes

#12-getAllNodes
  • Loading branch information
Peyton-McKee authored Sep 27, 2023
2 parents 0e89b6c + 55de3db commit 8850baa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions scylla-server/src/services/nodes.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import prisma from '../prisma/prisma-client';
import { ResponseFunction } from '../utils/message-maps.utils';

/**
* CRUD operation to get all systems with ResponseFunction type
* @returns Promise<string> contianing all the nodes in the db
*/
export const getAllNodes: ResponseFunction = async () => {
const data = await prisma.node.findMany();
return JSON.stringify(data);
};
2 changes: 2 additions & 0 deletions scylla-server/src/utils/message-maps.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAllDataTypes } from '../services/dataTypes.services';
import { getAllDrivers } from '../services/driver.services';
import { getAllSystems } from '../services/systems.services';
import { getAllNodes } from '../services/nodes.services';

export type ResponseFunction = (data?: JSON) => Promise<string>;

Expand All @@ -13,5 +14,6 @@ export const createClientMessageMap = (): Map<string, ResponseFunction> => {
clientMessageMap.set('getAllSystems', getAllSystems);
clientMessageMap.set('getAllDataTypes', getAllDataTypes);
clientMessageMap.set('getAllDrivers', getAllDrivers);
clientMessageMap.set('getAllNodes', getAllNodes);
return clientMessageMap;
};
15 changes: 15 additions & 0 deletions scylla-server/tests/nodes-services.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, test, expect } from 'vitest';
import { getAllNodes } from '../src/services/nodes.services';

describe('Node', () => {
test('Get All Nodes Works', async () => {
const expected = [];
const result = await getAllNodes();

// Parse result to a JavaScript object from the JSON string
const parsedResult = JSON.parse(result);

// Use toEqual to compare parsedResult with the expected array
expect(parsedResult).toEqual(expected);
});
});

0 comments on commit 8850baa

Please sign in to comment.