Skip to content

Commit

Permalink
Merge pull request #29 from Northeastern-Electric-Racing/#9
Browse files Browse the repository at this point in the history
#9 - CRUD get all data types
  • Loading branch information
Peyton-McKee committed Sep 18, 2023
2 parents a1e3ccc + a2630bc commit 4ecd50f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
12 changes: 12 additions & 0 deletions scylla-server/src/services/dataTypes.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import prisma from '../prisma/prisma-client';
import { ResponseFunction } from '../utils/message-maps.utils';

/**
* CRUD operation to get all dataTypes
* @returns string containing all the dataTypes
*/

export const getAllDataTypes: ResponseFunction = async () => {
const data = await prisma.dataType.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,3 +1,4 @@
import { getAllDataTypes } from '../services/dataTypes.services';
import { getAllSystems } from '../services/systems.services';

export type ResponseFunction = (data: JSON) => Promise<string>;
Expand All @@ -18,5 +19,6 @@ export const createServerMessageMap = (): Map<string, ResponseFunction> => {
export const createClientMessageMap = (): Map<string, ResponseFunction> => {
const clientMessageMap = new Map<string, ResponseFunction>();
clientMessageMap.set('getAllSystems', getAllSystems);
clientMessageMap.set('getAllDataTypes', getAllDataTypes);
return clientMessageMap;
};
8 changes: 0 additions & 8 deletions scylla-server/tests/data-types.test.ts

This file was deleted.

15 changes: 15 additions & 0 deletions scylla-server/tests/dataTypes-services.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, test, expect } from 'vitest';
import { getAllDataTypes } from '../src/services/dataTypes.services';

describe('Data Type', () => {
test('Get All Data Types Works', async () => {
const expected = [];
const result = await getAllDataTypes();

// 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 4ecd50f

Please sign in to comment.