From 3dcbcf40668be76e727b9f2542889d1e0ebdb11e Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 11:05:33 +0200 Subject: [PATCH 01/12] Code For Create Workspace POST Used The API contract to determine what response needs to be made when creating a workspace --- src/client/src/lib/services/workspaces.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/client/src/lib/services/workspaces.ts diff --git a/src/client/src/lib/services/workspaces.ts b/src/client/src/lib/services/workspaces.ts new file mode 100644 index 00000000..793be63a --- /dev/null +++ b/src/client/src/lib/services/workspaces.ts @@ -0,0 +1,18 @@ +import axios from 'axios'; + +// create workspace POST +export async function workspaces(name: string, organisationID: string, createdBy: string, users: string[], image: string): Promise { + try { + const response = await axios.post('http://localhost:3000/workspaces', { + name: name, + organisationID: organisationID, + createdBy: createdBy, + users: users, + image: image + }); + + return response.data; + } catch (error) { + throw new Error('Create Workspace Failed'); + } +} \ No newline at end of file From e71c0fd1e5a6d373328746cb759b69725ec97f5f Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 11:10:32 +0200 Subject: [PATCH 02/12] Code For Getting A Workspace Used The API contract to determine what response needs to be made when getting a workspace --- src/client/src/lib/services/workspaces.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/client/src/lib/services/workspaces.ts b/src/client/src/lib/services/workspaces.ts index 793be63a..2b012d44 100644 --- a/src/client/src/lib/services/workspaces.ts +++ b/src/client/src/lib/services/workspaces.ts @@ -15,4 +15,14 @@ export async function workspaces(name: string, organisationID: string, createdBy } catch (error) { throw new Error('Create Workspace Failed'); } +} + +// get Workspace GET +export async function getWorkspace(id: string): Promise { + try { + const response = await axios.get(`http://localhost:3000/workspaces/${id}`); + return response.data; + } catch (error) { + throw new Error('Get Workspace Failed'); + } } \ No newline at end of file From 96e854f11f8888179f0adb4e5a78801e1918463a Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 11:16:12 +0200 Subject: [PATCH 03/12] Code For Updating A Workspace Used The API contract to determine what response needs to be made when updating a workspace --- src/client/src/lib/services/workspaces.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/client/src/lib/services/workspaces.ts b/src/client/src/lib/services/workspaces.ts index 2b012d44..2636fd65 100644 --- a/src/client/src/lib/services/workspaces.ts +++ b/src/client/src/lib/services/workspaces.ts @@ -25,4 +25,24 @@ export async function getWorkspace(id: string): Promise { } catch (error) { throw new Error('Get Workspace Failed'); } +} + +export async function updateWorkspace( + id: string, + name: string, + organisationID: string, + users: string[], + image: string +): Promise { + try { + const response = await axios.put(`http://localhost:3000/workspaces/${id}`, { + name: name, + organisationID: organisationID, + users: users, + image: image + }); + return response.data; + } catch (error) { + throw new Error('Update Workspace Failed'); + } } \ No newline at end of file From ee10a11c0e64048320064b956e084a219df5c854 Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 11:19:36 +0200 Subject: [PATCH 04/12] Code For Deleting A Workspace Used The API contract to determine what response needs to be made when deleting a workspace --- src/client/src/lib/services/workspaces.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/client/src/lib/services/workspaces.ts b/src/client/src/lib/services/workspaces.ts index 2636fd65..224c4dd3 100644 --- a/src/client/src/lib/services/workspaces.ts +++ b/src/client/src/lib/services/workspaces.ts @@ -45,4 +45,13 @@ export async function updateWorkspace( } catch (error) { throw new Error('Update Workspace Failed'); } +} + +export async function deleteWorkspace(id: string): Promise { + try { + const response = await axios.delete(`http://localhost:3000/workspaces/${id}`); + return response.data.message; + } catch (error) { + throw new Error('Delete Workspace Failed'); + } } \ No newline at end of file From 375241a961f70f1978536032afc5338898265e40 Mon Sep 17 00:00:00 2001 From: Gini24mp Date: Sat, 22 Jun 2024 11:20:51 +0200 Subject: [PATCH 05/12] addition of notes to intergartion --- .../admin/modals/add/+AddWorkspace.svelte | 3 +- src/client/src/lib/store/index.ts | 1 + src/client/src/routes/student/+page.ts | 54 ++++++++++++++++ .../src/routes/student/module/study/+page.ts | 63 +++++++++++++++++++ 4 files changed, 119 insertions(+), 2 deletions(-) diff --git a/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte b/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte index fc9d99e9..271d5773 100644 --- a/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte +++ b/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte @@ -22,8 +22,7 @@ const name = formData.get('org_name')?.toString() ?? ''; console.log('This is the name parameter:', name); const userID = localStorage.getItem('userID') || 'non-existent'; - const image = - 'https://www.edarabia.com/wp-content/uploads/2013/08/university-of-pretoria-logo-south-africa.jpg'; + const image = 'https://www.edarabia.com/wp-content/uploads/2013/08/university-of-pretoria-logo-south-africa.jpg'; //console.log("User ID Add Org:", userID); try { const response = await organizations(name, userID, image); diff --git a/src/client/src/lib/store/index.ts b/src/client/src/lib/store/index.ts index ca5a5939..8de88366 100644 --- a/src/client/src/lib/store/index.ts +++ b/src/client/src/lib/store/index.ts @@ -23,6 +23,7 @@ export const file = writable(''); export const module = writable(''); export const user_details = writable({}); +export const module_details = writable({}); export const username = 'e241198014'; export const userInfo = writable({ diff --git a/src/client/src/routes/student/+page.ts b/src/client/src/routes/student/+page.ts index 8078dd82..c5effe1f 100644 --- a/src/client/src/routes/student/+page.ts +++ b/src/client/src/routes/student/+page.ts @@ -5,6 +5,60 @@ import { user_details } from '$lib/store'; export function load() { const details = get(user_details); console.log('User details:', details); + /** + * Note to intergration: + * now once the user logs in and the user details are stored in the store + * they should be as follows according to the api contract + * { + * "id": "60d21b4667d0d8992e610c85", + * "username": "a24125634", + * "name": "John", + * "surname": "Doe", + * "email": "johndoe@example.com", + * "role": "admin", + * "organisations": ["60d21b4967d0d8992e610c86"], + * "workspaces": ["60d21b4c67d0d8992e610c87"], + * "image": "https://example.com/images/johndoe.jpg", + * "createdAt": "2023-01-01T00:00:00.000Z", + * "updatedAt": "2023-01-01T00:00:00.000Z", + * "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" + * } + * + * Now what your job if is to take the workspaces array, "workspaces": ["60d21b4c67d0d8992e610c87"], + * and fectch the details if of every a workspace a student is apart of according to the contact this + * should be the infomation on the workspaces you get + * { + * "id": "60d21b4c67d0d8992e610c87", + * "name": "Development", + * "organisationId": "60d21b49667d0d8992e610c86", + * "createdBy": "60d21b4667d0d8992e610c85", + * "users": ["60d21b4667d0d8992e610c85"], + * "image": "https://example.com/images/development.jpg", + * "createdAt": "2023-01-01T00:00:00.000Z", + * "updatedAt": "2023-01-01T00:00:00.000Z" + * } + * + * now we only look to capture the name and id of the workspace and store it in and array as follows + * { + * modules: [ + * { + * module_name: 'Computer Graphics', + * module_id: '789123456' + * }, + * + * { + * module_name: 'Programming Languages', + * module_id: '789456123' + * } + * ] + * } + * + * please make sure that the how the return object is returned is not + * altered as it is used in later stages, this return object should then be stored in a store named + * module_details, it is advised that you console log the + * current respose just to see what it look s like then you make sure that your respose is the exact same + * + */ return { modules: [ { diff --git a/src/client/src/routes/student/module/study/+page.ts b/src/client/src/routes/student/module/study/+page.ts index e5cd084e..3d171b91 100644 --- a/src/client/src/routes/student/module/study/+page.ts +++ b/src/client/src/routes/student/module/study/+page.ts @@ -4,6 +4,69 @@ import two from '$lib/files/study-notes-two.pdf'; import three from '$lib/files/study-notes-three.pdf'; export function load() { + /** + * Note to intergration: + * in the previous step you captured the module details and the user details are still as below + * + * { + * "id": "60d21b4667d0d8992e610c85", + * "username": "a24125634", + * "name": "John", + * "surname": "Doe", + * "email": "johndoe@example.com", + * "role": "admin", + * "organisations": ["60d21b4967d0d8992e610c86"], + * "workspaces": ["60d21b4c67d0d8992e610c87"], + * "image": "https://example.com/images/johndoe.jpg", + * "createdAt": "2023-01-01T00:00:00.000Z", + * "updatedAt": "2023-01-01T00:00:00.000Z", + * "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" + * } + * + * the module details are as follows: + * + * { + * modules: [ + * { + * module_name: 'Computer Graphics', + * module_id: '789123456' + * }, + * + * { + * module_name: 'Programming Languages', + * module_id: '789456123' + * } + * ] + * } + * + * the infomation above is only true if the the previos steps have be correctly followed + * + * + * Now what your job if is to take the modules array, and get all the study material stored in the workspace/module :additional note WORKSPACE === MODULE + * + * now we only look to capture the title, descrtiption and link of the study material and store it in and array as follows + * { + * materials: [ + * { + * title: 'Introduction to Computer Networks', + * description: + * 'A foundational course covering the basics of computer networking, including network models, protocols, and architectures. (COS 332)', + * link: one + * }, + * { + * title: 'Advanced Networking Concepts', + * description: + * 'An in-depth exploration of advanced networking topics such as routing algorithms, network security, and wireless networks. (COS 332)', + * link: two + * }, + * ] + * } + * + * please make sure that the how the return object is returned is not + * altered as it is used in later stages, it is advised that you console log the + * current respose just to see what it look s like then you make sure that your respose is the exact same + * + */ return { materials: [ { From a90da0f8647f34f8a1819672fc55888ab159a740 Mon Sep 17 00:00:00 2001 From: Gini24mp Date: Sat, 22 Jun 2024 13:23:18 +0200 Subject: [PATCH 06/12] addition of prep for addition of the workspace --- .../admin/modals/add/+AddWorkspace.svelte | 47 +++++++------------ .../universal/auth/+SignInForm.svelte | 8 ++-- .../{+page.server.js => +page.server.ts} | 36 ++++++++++++++ 3 files changed, 59 insertions(+), 32 deletions(-) rename src/client/src/routes/admin/workspaces/{+page.server.js => +page.server.ts} (64%) diff --git a/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte b/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte index 271d5773..26678712 100644 --- a/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte +++ b/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte @@ -1,41 +1,30 @@ diff --git a/src/client/src/lib/components/universal/auth/+SignInForm.svelte b/src/client/src/lib/components/universal/auth/+SignInForm.svelte index f3059e93..a9e37e04 100644 --- a/src/client/src/lib/components/universal/auth/+SignInForm.svelte +++ b/src/client/src/lib/components/universal/auth/+SignInForm.svelte @@ -9,9 +9,11 @@ import '@fontsource/roboto'; // Function to store the access token in local storage - function storeAccessToken(token: string, id: string): void { + function storeAccessToken(token: string, id: string, organisationID: string): void { localStorage.setItem('accessToken', token); localStorage.setItem('userID', id); + localStorage.setItem('organisationID', organisationID); + console.log('This is the ID', id); console.log('User ID stored:', localStorage.getItem('userID')); @@ -38,8 +40,8 @@ console.log('Response:', response); - if (response && response.accessToken) { - storeAccessToken(response.accessToken, response.sub); + if (response && response.accessToken && response.organisations[0]) { + storeAccessToken(response.accessToken, response.sub , response.organisations[0]); } goto('/student'); } catch (error) { diff --git a/src/client/src/routes/admin/workspaces/+page.server.js b/src/client/src/routes/admin/workspaces/+page.server.ts similarity index 64% rename from src/client/src/routes/admin/workspaces/+page.server.js rename to src/client/src/routes/admin/workspaces/+page.server.ts index 53e8481f..1f448f5b 100644 --- a/src/client/src/routes/admin/workspaces/+page.server.js +++ b/src/client/src/routes/admin/workspaces/+page.server.ts @@ -7,6 +7,16 @@ async function addDetails(name, email, role) { console.log(role); } +async function addWorkspace(name, email, createdBy, image){ + console.log(name); + console.log(email); + console.log(createdBy); + console.log(image); + + //TODO: Based on the api contract you now have all the infomation to create a work space now just make the call; + +} + async function editDetails(name, email, role) { console.log(name); console.log(email); @@ -36,6 +46,32 @@ export const actions = { status: 200 }; }, + add: async ({ request }) => { + const formData = await request.formData(); + const name = formData.get('work_name'); + const email = formData.get('organisationId'); + const createdBy = formData.get('createdBy'); + const image = formData.get('image'); + + console.log(name); + console.log(email); + console.log(createdBy); + console.log(image); + + try { + await addWorkspace(name, email, createdBy, image); + + return { + status: 200 + }; + + } catch (error) { + console.log(error); + return { + status: 500 + } + } + }, edit: async ({ request }) => { const formData = await request.formData(); const name = formData.get('org_name'); From 9133f561362bdc88859dc62a94bd4da64c5e4ad8 Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 16:42:51 +0200 Subject: [PATCH 07/12] Code For Creating A Workspace Post Used The API contract to determine what response needs to be made when posting a workspace. --- src/client/src/lib/services/materials.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/client/src/lib/services/materials.ts diff --git a/src/client/src/lib/services/materials.ts b/src/client/src/lib/services/materials.ts new file mode 100644 index 00000000..263fb24b --- /dev/null +++ b/src/client/src/lib/services/materials.ts @@ -0,0 +1,18 @@ +import axios from 'axios'; + +export async function materials(type: boolean, workspace_id: string, lecturer_id: string, title: string, description: string, file_path: string) { + try { + const response = await axios.post('http://localhost:3000/student/module/study/material', { + type: type, + workspace_id: workspace_id, + lecturer_id: lecturer_id, + title: title, + description: description, + file_path: file_path + }); + + return response.data; + } catch (error) { + throw new Error('Create Material Failed'); + } +} \ No newline at end of file From b45826ab0f8634b51556b2e63f33af33980b0f13 Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 16:54:12 +0200 Subject: [PATCH 08/12] Code For Getting Lecture Material Used The API contract to determine what response needs to be made when getting lecture material. --- src/client/src/lib/services/materials.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/client/src/lib/services/materials.ts b/src/client/src/lib/services/materials.ts index 263fb24b..22c59e7f 100644 --- a/src/client/src/lib/services/materials.ts +++ b/src/client/src/lib/services/materials.ts @@ -15,4 +15,13 @@ export async function materials(type: boolean, workspace_id: string, lecturer_id } catch (error) { throw new Error('Create Material Failed'); } +} + +export async function getMaterial(id: string ): Promise { + try { + const response = await axios.get(`http://localhost:3000/study/material/${id}`); + return response.data; + } catch (error) { + throw new Error('Get Material Failed'); + } } \ No newline at end of file From c7ee60d660a00bb7ba7c7f7522c6eece4777ca0f Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 17:04:26 +0200 Subject: [PATCH 09/12] Updated Material Integration Changed endpoint and include the update workspace. --- src/client/src/lib/services/materials.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/client/src/lib/services/materials.ts b/src/client/src/lib/services/materials.ts index 22c59e7f..db2c9d91 100644 --- a/src/client/src/lib/services/materials.ts +++ b/src/client/src/lib/services/materials.ts @@ -2,7 +2,7 @@ import axios from 'axios'; export async function materials(type: boolean, workspace_id: string, lecturer_id: string, title: string, description: string, file_path: string) { try { - const response = await axios.post('http://localhost:3000/student/module/study/material', { + const response = await axios.post('http://localhost:3000/materials', { type: type, workspace_id: workspace_id, lecturer_id: lecturer_id, @@ -19,9 +19,29 @@ export async function materials(type: boolean, workspace_id: string, lecturer_id export async function getMaterial(id: string ): Promise { try { - const response = await axios.get(`http://localhost:3000/study/material/${id}`); + const response = await axios.get(`http://localhost:3000/materials/${id}`); return response.data; } catch (error) { throw new Error('Get Material Failed'); } +} + +export async function updateWorkspace( + id: string, + name: string, + organisationID: string, + users: string[], + image: string +): Promise { + try { + const response = await axios.put(`http://localhost:3000/materials/${id}`, { + name: name, + organisationID: organisationID, + users: users, + image: image + }); + return response.data; + } catch (error) { + throw new Error('Update Material Failed'); + } } \ No newline at end of file From c78998013e67a7acbe2931b1ccce9c7e3b8f440b Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 17:06:20 +0200 Subject: [PATCH 10/12] Updated Material Integration Includes the Delete Material Code --- src/client/src/lib/services/materials.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/client/src/lib/services/materials.ts b/src/client/src/lib/services/materials.ts index db2c9d91..1260cd71 100644 --- a/src/client/src/lib/services/materials.ts +++ b/src/client/src/lib/services/materials.ts @@ -44,4 +44,13 @@ export async function updateWorkspace( } catch (error) { throw new Error('Update Material Failed'); } +} + +export async function deleteMaterial(id: string): Promise { + try { + const response = await axios.delete(`http://localhost:3000/materials/${id}`); + return response.data.message; + } catch (error) { + throw new Error('Delete Material Failed'); + } } \ No newline at end of file From a542250a80c659cf0f47cbaa174f983f7b0a621e Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 17:11:45 +0200 Subject: [PATCH 11/12] Updated Material Integration Includes List All Material Code --- src/client/src/lib/services/materials.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/client/src/lib/services/materials.ts b/src/client/src/lib/services/materials.ts index 1260cd71..3cece935 100644 --- a/src/client/src/lib/services/materials.ts +++ b/src/client/src/lib/services/materials.ts @@ -53,4 +53,13 @@ export async function deleteMaterial(id: string): Promise { } catch (error) { throw new Error('Delete Material Failed'); } +} + +export async function listAllMaterial() { + try { + const response = await axios.get(`http://localhost:3000/materials`); + return response.data; + } catch (error) { + throw new Error('List All Material Failed'); + } } \ No newline at end of file From 0c1e2e220884f30b2b66937aa1a348dae4040afb Mon Sep 17 00:00:00 2001 From: Joshua Wereley Date: Sat, 22 Jun 2024 19:56:53 +0200 Subject: [PATCH 12/12] Modified Code To Match Linting Standards --- .../admin/modals/add/+AddWorkspace.svelte | 6 +- .../universal/auth/+SignInForm.svelte | 4 +- src/client/src/lib/services/materials.ts | 107 ++++++++++-------- src/client/src/lib/services/workspaces.ts | 90 ++++++++------- .../routes/admin/workspaces/+page.server.ts | 6 +- src/client/src/routes/student/+page.ts | 26 ++--- .../src/routes/student/module/study/+page.ts | 30 ++--- src/server/workspace/src/auth/auth.service.ts | 2 +- .../workspace/src/user/user.controller.ts | 2 +- src/server/workspace/src/user/user.service.ts | 5 +- 10 files changed, 146 insertions(+), 132 deletions(-) diff --git a/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte b/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte index 26678712..5485edce 100644 --- a/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte +++ b/src/client/src/lib/components/admin/modals/add/+AddWorkspace.svelte @@ -12,8 +12,8 @@ const organisationId = localStorage.getItem('organisationID') || 'non-existent'; const createdBy = localStorage.getItem('userID') || 'non-existent'; - - if(organisationId !== 'non-existent'){ + + if (organisationId !== 'non-existent') { formData.append('organisationId', organisationId); formData.append('createdBy', createdBy); const response = await fetch('/admin/workspaces?/add', { @@ -22,7 +22,7 @@ }); console.log(response); formModal = false; - }else{ + } else { const errorMessage = 'You need to be part of an organisation to create a workspace'; alert(errorMessage); } diff --git a/src/client/src/lib/components/universal/auth/+SignInForm.svelte b/src/client/src/lib/components/universal/auth/+SignInForm.svelte index a9e37e04..8da5c6ea 100644 --- a/src/client/src/lib/components/universal/auth/+SignInForm.svelte +++ b/src/client/src/lib/components/universal/auth/+SignInForm.svelte @@ -13,7 +13,7 @@ localStorage.setItem('accessToken', token); localStorage.setItem('userID', id); localStorage.setItem('organisationID', organisationID); - + console.log('This is the ID', id); console.log('User ID stored:', localStorage.getItem('userID')); @@ -41,7 +41,7 @@ console.log('Response:', response); if (response && response.accessToken && response.organisations[0]) { - storeAccessToken(response.accessToken, response.sub , response.organisations[0]); + storeAccessToken(response.accessToken, response.sub, response.organisations[0]); } goto('/student'); } catch (error) { diff --git a/src/client/src/lib/services/materials.ts b/src/client/src/lib/services/materials.ts index 3cece935..ed441eb3 100644 --- a/src/client/src/lib/services/materials.ts +++ b/src/client/src/lib/services/materials.ts @@ -1,65 +1,72 @@ import axios from 'axios'; -export async function materials(type: boolean, workspace_id: string, lecturer_id: string, title: string, description: string, file_path: string) { - try { - const response = await axios.post('http://localhost:3000/materials', { - type: type, - workspace_id: workspace_id, - lecturer_id: lecturer_id, - title: title, - description: description, - file_path: file_path - }); +export async function materials( + type: boolean, + workspace_id: string, + lecturer_id: string, + title: string, + description: string, + file_path: string +) { + try { + const response = await axios.post('http://localhost:3000/materials', { + type: type, + workspace_id: workspace_id, + lecturer_id: lecturer_id, + title: title, + description: description, + file_path: file_path + }); - return response.data; - } catch (error) { - throw new Error('Create Material Failed'); - } + return response.data; + } catch (error) { + throw new Error('Create Material Failed'); + } } -export async function getMaterial(id: string ): Promise { - try { - const response = await axios.get(`http://localhost:3000/materials/${id}`); - return response.data; - } catch (error) { - throw new Error('Get Material Failed'); - } +export async function getMaterial(id: string): Promise { + try { + const response = await axios.get(`http://localhost:3000/materials/${id}`); + return response.data; + } catch (error) { + throw new Error('Get Material Failed'); + } } export async function updateWorkspace( - id: string, - name: string, - organisationID: string, - users: string[], - image: string + id: string, + name: string, + organisationID: string, + users: string[], + image: string ): Promise { - try { - const response = await axios.put(`http://localhost:3000/materials/${id}`, { - name: name, - organisationID: organisationID, - users: users, - image: image - }); - return response.data; - } catch (error) { - throw new Error('Update Material Failed'); - } + try { + const response = await axios.put(`http://localhost:3000/materials/${id}`, { + name: name, + organisationID: organisationID, + users: users, + image: image + }); + return response.data; + } catch (error) { + throw new Error('Update Material Failed'); + } } export async function deleteMaterial(id: string): Promise { - try { - const response = await axios.delete(`http://localhost:3000/materials/${id}`); - return response.data.message; - } catch (error) { - throw new Error('Delete Material Failed'); - } + try { + const response = await axios.delete(`http://localhost:3000/materials/${id}`); + return response.data.message; + } catch (error) { + throw new Error('Delete Material Failed'); + } } export async function listAllMaterial() { - try { - const response = await axios.get(`http://localhost:3000/materials`); - return response.data; - } catch (error) { - throw new Error('List All Material Failed'); - } -} \ No newline at end of file + try { + const response = await axios.get(`http://localhost:3000/materials`); + return response.data; + } catch (error) { + throw new Error('List All Material Failed'); + } +} diff --git a/src/client/src/lib/services/workspaces.ts b/src/client/src/lib/services/workspaces.ts index 224c4dd3..8d37174f 100644 --- a/src/client/src/lib/services/workspaces.ts +++ b/src/client/src/lib/services/workspaces.ts @@ -1,57 +1,63 @@ import axios from 'axios'; // create workspace POST -export async function workspaces(name: string, organisationID: string, createdBy: string, users: string[], image: string): Promise { - try { - const response = await axios.post('http://localhost:3000/workspaces', { - name: name, - organisationID: organisationID, - createdBy: createdBy, - users: users, - image: image - }); +export async function workspaces( + name: string, + organisationID: string, + createdBy: string, + users: string[], + image: string +): Promise { + try { + const response = await axios.post('http://localhost:3000/workspaces', { + name: name, + organisationID: organisationID, + createdBy: createdBy, + users: users, + image: image + }); - return response.data; - } catch (error) { - throw new Error('Create Workspace Failed'); - } + return response.data; + } catch (error) { + throw new Error('Create Workspace Failed'); + } } // get Workspace GET export async function getWorkspace(id: string): Promise { - try { - const response = await axios.get(`http://localhost:3000/workspaces/${id}`); - return response.data; - } catch (error) { - throw new Error('Get Workspace Failed'); - } + try { + const response = await axios.get(`http://localhost:3000/workspaces/${id}`); + return response.data; + } catch (error) { + throw new Error('Get Workspace Failed'); + } } export async function updateWorkspace( - id: string, - name: string, - organisationID: string, - users: string[], - image: string + id: string, + name: string, + organisationID: string, + users: string[], + image: string ): Promise { - try { - const response = await axios.put(`http://localhost:3000/workspaces/${id}`, { - name: name, - organisationID: organisationID, - users: users, - image: image - }); - return response.data; - } catch (error) { - throw new Error('Update Workspace Failed'); - } + try { + const response = await axios.put(`http://localhost:3000/workspaces/${id}`, { + name: name, + organisationID: organisationID, + users: users, + image: image + }); + return response.data; + } catch (error) { + throw new Error('Update Workspace Failed'); + } } export async function deleteWorkspace(id: string): Promise { - try { - const response = await axios.delete(`http://localhost:3000/workspaces/${id}`); - return response.data.message; - } catch (error) { - throw new Error('Delete Workspace Failed'); - } -} \ No newline at end of file + try { + const response = await axios.delete(`http://localhost:3000/workspaces/${id}`); + return response.data.message; + } catch (error) { + throw new Error('Delete Workspace Failed'); + } +} diff --git a/src/client/src/routes/admin/workspaces/+page.server.ts b/src/client/src/routes/admin/workspaces/+page.server.ts index 1f448f5b..90b76056 100644 --- a/src/client/src/routes/admin/workspaces/+page.server.ts +++ b/src/client/src/routes/admin/workspaces/+page.server.ts @@ -7,14 +7,13 @@ async function addDetails(name, email, role) { console.log(role); } -async function addWorkspace(name, email, createdBy, image){ +async function addWorkspace(name, email, createdBy, image) { console.log(name); console.log(email); console.log(createdBy); console.log(image); //TODO: Based on the api contract you now have all the infomation to create a work space now just make the call; - } async function editDetails(name, email, role) { @@ -64,12 +63,11 @@ export const actions = { return { status: 200 }; - } catch (error) { console.log(error); return { status: 500 - } + }; } }, edit: async ({ request }) => { diff --git a/src/client/src/routes/student/+page.ts b/src/client/src/routes/student/+page.ts index c5effe1f..bb82e294 100644 --- a/src/client/src/routes/student/+page.ts +++ b/src/client/src/routes/student/+page.ts @@ -8,7 +8,7 @@ export function load() { /** * Note to intergration: * now once the user logs in and the user details are stored in the store - * they should be as follows according to the api contract + * they should be as follows according to the api contract * { * "id": "60d21b4667d0d8992e610c85", * "username": "a24125634", @@ -24,9 +24,9 @@ export function load() { * "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" * } * - * Now what your job if is to take the workspaces array, "workspaces": ["60d21b4c67d0d8992e610c87"], - * and fectch the details if of every a workspace a student is apart of according to the contact this - * should be the infomation on the workspaces you get + * Now what your job if is to take the workspaces array, "workspaces": ["60d21b4c67d0d8992e610c87"], + * and fectch the details if of every a workspace a student is apart of according to the contact this + * should be the infomation on the workspaces you get * { * "id": "60d21b4c67d0d8992e610c87", * "name": "Development", @@ -37,7 +37,7 @@ export function load() { * "createdAt": "2023-01-01T00:00:00.000Z", * "updatedAt": "2023-01-01T00:00:00.000Z" * } - * + * * now we only look to capture the name and id of the workspace and store it in and array as follows * { * modules: [ @@ -45,19 +45,19 @@ export function load() { * module_name: 'Computer Graphics', * module_id: '789123456' * }, - * + * * { * module_name: 'Programming Languages', * module_id: '789456123' * } - * ] + * ] * } - * - * please make sure that the how the return object is returned is not - * altered as it is used in later stages, this return object should then be stored in a store named - * module_details, it is advised that you console log the - * current respose just to see what it look s like then you make sure that your respose is the exact same - * + * + * please make sure that the how the return object is returned is not + * altered as it is used in later stages, this return object should then be stored in a store named + * module_details, it is advised that you console log the + * current respose just to see what it look s like then you make sure that your respose is the exact same + * */ return { modules: [ diff --git a/src/client/src/routes/student/module/study/+page.ts b/src/client/src/routes/student/module/study/+page.ts index 3d171b91..d0143b66 100644 --- a/src/client/src/routes/student/module/study/+page.ts +++ b/src/client/src/routes/student/module/study/+page.ts @@ -7,7 +7,7 @@ export function load() { /** * Note to intergration: * in the previous step you captured the module details and the user details are still as below - * + * * { * "id": "60d21b4667d0d8992e610c85", * "username": "a24125634", @@ -24,26 +24,26 @@ export function load() { * } * * the module details are as follows: - * + * * { * modules: [ * { * module_name: 'Computer Graphics', * module_id: '789123456' * }, - * + * * { * module_name: 'Programming Languages', * module_id: '789456123' * } - * ] + * ] * } - * + * * the infomation above is only true if the the previos steps have be correctly followed - * - * - * Now what your job if is to take the modules array, and get all the study material stored in the workspace/module :additional note WORKSPACE === MODULE - * + * + * + * Now what your job if is to take the modules array, and get all the study material stored in the workspace/module :additional note WORKSPACE === MODULE + * * now we only look to capture the title, descrtiption and link of the study material and store it in and array as follows * { * materials: [ @@ -59,13 +59,13 @@ export function load() { * 'An in-depth exploration of advanced networking topics such as routing algorithms, network security, and wireless networks. (COS 332)', * link: two * }, - * ] + * ] * } - * - * please make sure that the how the return object is returned is not - * altered as it is used in later stages, it is advised that you console log the - * current respose just to see what it look s like then you make sure that your respose is the exact same - * + * + * please make sure that the how the return object is returned is not + * altered as it is used in later stages, it is advised that you console log the + * current respose just to see what it look s like then you make sure that your respose is the exact same + * */ return { materials: [ diff --git a/src/server/workspace/src/auth/auth.service.ts b/src/server/workspace/src/auth/auth.service.ts index 32e1e077..e0c22b31 100644 --- a/src/server/workspace/src/auth/auth.service.ts +++ b/src/server/workspace/src/auth/auth.service.ts @@ -28,7 +28,7 @@ export class AuthService { username: findUser.username, }), }; - + return user; } else { return null; diff --git a/src/server/workspace/src/user/user.controller.ts b/src/server/workspace/src/user/user.controller.ts index 02e188ba..88723d63 100644 --- a/src/server/workspace/src/user/user.controller.ts +++ b/src/server/workspace/src/user/user.controller.ts @@ -28,7 +28,7 @@ export class UserController { @Get() async getUsers(@Query() query: Partial) { - return await this.userService.findMany({...query}); + return await this.userService.findMany({ ...query }); } @Put(':id') diff --git a/src/server/workspace/src/user/user.service.ts b/src/server/workspace/src/user/user.service.ts index cf2f3fe0..d5209cc6 100644 --- a/src/server/workspace/src/user/user.service.ts +++ b/src/server/workspace/src/user/user.service.ts @@ -48,7 +48,10 @@ export class UserService { } async findMany(filter: Partial): Promise { - const users = await this.userModel.find(filter).sort({ createdAt: -1 }).exec(); + const users = await this.userModel + .find(filter) + .sort({ createdAt: -1 }) + .exec(); return users; }