diff --git a/scylla-server/src/services/dataTypes.services.ts b/scylla-server/src/services/dataTypes.services.ts new file mode 100644 index 00000000..dbf63edb --- /dev/null +++ b/scylla-server/src/services/dataTypes.services.ts @@ -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); +}; diff --git a/scylla-server/src/utils/message-maps.utils.ts b/scylla-server/src/utils/message-maps.utils.ts index 4b6d322e..27848d81 100644 --- a/scylla-server/src/utils/message-maps.utils.ts +++ b/scylla-server/src/utils/message-maps.utils.ts @@ -1,3 +1,4 @@ +import { getAllDataTypes } from '../services/dataTypes.services'; import { getAllSystems } from '../services/systems.services'; export type ResponseFunction = (data: JSON) => Promise; @@ -18,5 +19,6 @@ export const createServerMessageMap = (): Map => { export const createClientMessageMap = (): Map => { const clientMessageMap = new Map(); clientMessageMap.set('getAllSystems', getAllSystems); + clientMessageMap.set('getAllDataTypes', getAllDataTypes); return clientMessageMap; }; diff --git a/scylla-server/tests/data-types.test.ts b/scylla-server/tests/data-types.test.ts deleted file mode 100644 index a4246987..00000000 --- a/scylla-server/tests/data-types.test.ts +++ /dev/null @@ -1,8 +0,0 @@ -import prisma from '../src/prisma/prisma-client'; - -describe('Data Type', () => { - test('Get All Data Types Works', async () => { - const allDataTypes = await prisma.dataType.findMany(); - expect(allDataTypes).toStrictEqual([]); - }); -}); diff --git a/scylla-server/tests/dataTypes-services.test.ts b/scylla-server/tests/dataTypes-services.test.ts new file mode 100644 index 00000000..36f0e8e9 --- /dev/null +++ b/scylla-server/tests/dataTypes-services.test.ts @@ -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); + }); +});