From c19133c045eb6f3fdf40612635cb4bca81d9f542 Mon Sep 17 00:00:00 2001 From: Fadhli Date: Tue, 20 Aug 2024 00:12:10 +0800 Subject: [PATCH 1/3] SCRUM-52 Added CRUD Endpoints for Accounts Affective --- backend/dist/app.js | 2 + .../accountsAffectiveController.js | 95 +++++++++++++++ backend/dist/models/accountsAffectiveModel.js | 29 +++++ backend/dist/models/accountsCognitiveModel.js | 29 +++++ .../dist/models/accountsDemographicsModel.js | 33 ++++++ backend/dist/models/accountsSocialModel.js | 25 ++++ .../dist/routes/accountsAffectiveRouter.js | 37 ++++++ .../dist/services/accountsAffectiveService.js | 108 ++++++++++++++++++ backend/src/app.ts | 2 + .../accountsAffectiveController.ts | 63 ++++++++++ backend/src/models/accountsAffectiveModel.ts | 42 +++++++ backend/src/models/accountsCognitiveModel.ts | 42 +++++++ .../src/models/accountsDemographicsModel.ts | 48 ++++++++ backend/src/models/accountsSocialModel.ts | 36 ++++++ backend/src/routes/accountsAffectiveRouter.ts | 18 +++ .../src/services/accountsAffectiveService.ts | 99 ++++++++++++++++ 16 files changed, 708 insertions(+) create mode 100644 backend/dist/controllers/accountsAffectiveController.js create mode 100644 backend/dist/models/accountsAffectiveModel.js create mode 100644 backend/dist/models/accountsCognitiveModel.js create mode 100644 backend/dist/models/accountsDemographicsModel.js create mode 100644 backend/dist/models/accountsSocialModel.js create mode 100644 backend/dist/routes/accountsAffectiveRouter.js create mode 100644 backend/dist/services/accountsAffectiveService.js create mode 100644 backend/src/controllers/accountsAffectiveController.ts create mode 100644 backend/src/models/accountsAffectiveModel.ts create mode 100644 backend/src/models/accountsCognitiveModel.ts create mode 100644 backend/src/models/accountsDemographicsModel.ts create mode 100644 backend/src/models/accountsSocialModel.ts create mode 100644 backend/src/routes/accountsAffectiveRouter.ts create mode 100644 backend/src/services/accountsAffectiveService.ts diff --git a/backend/dist/app.js b/backend/dist/app.js index 22060e3..56f6699 100644 --- a/backend/dist/app.js +++ b/backend/dist/app.js @@ -6,12 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); const cors_1 = __importDefault(require("cors")); const accountsRouter_1 = __importDefault(require("./routes/accountsRouter")); +const accountsAffectiveRouter_1 = __importDefault(require("./routes/accountsAffectiveRouter")); const app = (0, express_1.default)(); app.use((0, cors_1.default)()); const port = 3000; app.use(express_1.default.json()); // app.use(accountsRouter); app.use('/accounts', accountsRouter_1.default); +app.use('/accountsaffective', accountsAffectiveRouter_1.default); app.listen(port, () => { console.log(`Server is running on port ${port}`); }); diff --git a/backend/dist/controllers/accountsAffectiveController.js b/backend/dist/controllers/accountsAffectiveController.js new file mode 100644 index 0000000..14145e6 --- /dev/null +++ b/backend/dist/controllers/accountsAffectiveController.js @@ -0,0 +1,95 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAccountAffective = exports.updateAccountAffective = exports.getAccountById = exports.createAccountAffective = void 0; +const accountsAffectiveService = __importStar(require("../services/accountsAffectiveService")); +/* CREATE */ +const createAccountAffective = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const accountBody = req.body; + try { + const account = yield accountsAffectiveService.createAccountAffective(accountBody); + res.status(201).json({ + userID: account[0].userID, + status: 201, + statusText: "Created", + }); + } + catch (error) { + res.status(500).json({ + error: `Failed to create ${accountBody.role} account`, + }); + } +}); +exports.createAccountAffective = createAccountAffective; +/* READ */ +const getAccountById = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const account = yield accountsAffectiveService.getAccountAffectiveById(req.params.id); + res.status(200).json(account); + } + catch (error) { + res.status(500).json({ error: "Failed to retrieve account" }); + } +}); +exports.getAccountById = getAccountById; +/* UPDATE */ +const updateAccountAffective = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const account = req.body; + try { + const response = yield accountsAffectiveService.updateAccountAffective(account); + res.status(200).json({ + status: 200, + statusText: "Account Affective Updated Successfully", + }); + } + catch (error) { + res.status(500).json({ error: "Failed to update account" }); + } +}); +exports.updateAccountAffective = updateAccountAffective; +/* DELETE */ +const deleteAccountAffective = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const response = yield accountsAffectiveService.deleteAccountAffective(req.params.id); + // response body will be empty + res.status(200).json({ + status: 200, + statusText: "Account Affective Deleted Successfully", + }); + } + catch (error) { + res.status(500).json({ error: "Failed to delete account" }); + } +}); +exports.deleteAccountAffective = deleteAccountAffective; diff --git a/backend/dist/models/accountsAffectiveModel.js b/backend/dist/models/accountsAffectiveModel.js new file mode 100644 index 0000000..6e3dbb3 --- /dev/null +++ b/backend/dist/models/accountsAffectiveModel.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AccountsAffective = void 0; +class AccountsAffective { + constructor(userID, attitude, barriers, motivationalLevel, personality, reasons) { + this.userID = userID; + this.attitude = attitude; + this.barriers = barriers; + this.motivationalLevel = motivationalLevel; + this.personality = personality; + this.reasons = reasons; + } + getAttitude() { + return this.attitude; + } + getBarriers() { + return this.barriers; + } + getMotivationalLevel() { + return this.motivationalLevel; + } + getPersonality() { + return this.personality; + } + getReasons() { + return this.reasons; + } +} +exports.AccountsAffective = AccountsAffective; diff --git a/backend/dist/models/accountsCognitiveModel.js b/backend/dist/models/accountsCognitiveModel.js new file mode 100644 index 0000000..f646d94 --- /dev/null +++ b/backend/dist/models/accountsCognitiveModel.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AccountsCognitive = void 0; +class AccountsCognitive { + constructor(userID, educationalLevel, languageAbilities, learningPreferences, litNumProficiency, priorKnowledge) { + this.userID = userID; + this.educationalLevel = educationalLevel; + this.languageAbilities = languageAbilities; + this.learningPreferences = learningPreferences; + this.litNumProficiency = litNumProficiency; + this.priorKnowledge = priorKnowledge; + } + getEducationalLevel() { + return this.educationalLevel; + } + getLanguageAbilities() { + return this.languageAbilities; + } + getLearningPreferences() { + return this.learningPreferences; + } + getLitNumProficiency() { + return this.litNumProficiency; + } + getPriorKnowledge() { + return this.priorKnowledge; + } +} +exports.AccountsCognitive = AccountsCognitive; diff --git a/backend/dist/models/accountsDemographicsModel.js b/backend/dist/models/accountsDemographicsModel.js new file mode 100644 index 0000000..7b34fea --- /dev/null +++ b/backend/dist/models/accountsDemographicsModel.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AccountsDemographics = void 0; +class AccountsDemographics { + constructor(userID, careerStage, ethnicGroup, jobCategory, lifeStage, race, specialNeeds) { + this.userID = userID; + this.careerStage = careerStage; + this.ethnicGroup = ethnicGroup; + this.jobCategory = jobCategory; + this.lifeStage = lifeStage; + this.race = race; + this.specialNeeds = specialNeeds; + } + getCareerStage() { + return this.careerStage; + } + getEthnicGroup() { + return this.ethnicGroup; + } + getJobCategory() { + return this.jobCategory; + } + getLifeStage() { + return this.lifeStage; + } + getRace() { + return this.race; + } + getSpecialNeeds() { + return this.specialNeeds; + } +} +exports.AccountsDemographics = AccountsDemographics; diff --git a/backend/dist/models/accountsSocialModel.js b/backend/dist/models/accountsSocialModel.js new file mode 100644 index 0000000..54b1f10 --- /dev/null +++ b/backend/dist/models/accountsSocialModel.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AccountsSocial = void 0; +class AccountsSocial { + constructor(userID, compLiteracy, relationshipToPeers, socialBackground, tendency) { + this.userID = userID; + this.compLiteracy = compLiteracy; + this.relationshipToPeers = relationshipToPeers; + this.socialBackground = socialBackground; + this.tendency = tendency; + } + getCompLiteracy() { + return this.compLiteracy; + } + getRelationshipToPeers() { + return this.relationshipToPeers; + } + getSocialBackground() { + return this.socialBackground; + } + getTendency() { + return this.tendency; + } +} +exports.AccountsSocial = AccountsSocial; diff --git a/backend/dist/routes/accountsAffectiveRouter.js b/backend/dist/routes/accountsAffectiveRouter.js new file mode 100644 index 0000000..da3670f --- /dev/null +++ b/backend/dist/routes/accountsAffectiveRouter.js @@ -0,0 +1,37 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = require("express"); +const accountsAffectiveController = __importStar(require("../controllers/accountsAffectiveController")); +const router = (0, express_1.Router)(); +/* CREATE */ +router.post("/createaccountaffective", accountsAffectiveController.createAccountAffective); +/* READ */ +router.get('/getaccountaffectivebyid/:id', accountsAffectiveController.getAccountById); +/* UPDATE */ +router.patch('/updateaccountaffective', accountsAffectiveController.updateAccountAffective); +/* DELETE */ +router.delete('/deleteaccountaffective/:id', accountsAffectiveController.deleteAccountAffective); +exports.default = router; diff --git a/backend/dist/services/accountsAffectiveService.js b/backend/dist/services/accountsAffectiveService.js new file mode 100644 index 0000000..247e58d --- /dev/null +++ b/backend/dist/services/accountsAffectiveService.js @@ -0,0 +1,108 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createAccountAffective = createAccountAffective; +exports.getAccountAffectiveById = getAccountAffectiveById; +exports.updateAccountAffective = updateAccountAffective; +exports.deleteAccountAffective = deleteAccountAffective; +const supabaseConfig_1 = __importDefault(require("../config/supabaseConfig")); +const accountsAffectiveModel_1 = require("../models/accountsAffectiveModel"); +/* CREATE */ +function createAccountAffective(accountAffective) { + return __awaiter(this, void 0, void 0, function* () { + const { userID, attitude, barriers, motivationalLevel, personality, reasons } = accountAffective; + const { data, error } = yield supabaseConfig_1.default + .from("accountsaffective") + .insert({ + userID, + attitude, + barriers, + motivationalLevel, + personality, + reasons + }) + .select(); + if (error) { + console.error(error); + throw error; + } + else { + return data; + } + }); +} +/* READ */ +function getAccountAffectiveById(userID) { + return __awaiter(this, void 0, void 0, function* () { + const { data, error } = yield supabaseConfig_1.default + .from("accountsaffective") + .select("*") + .eq("userID", userID) + .single(); + if (error) { + console.error(error); + throw error; + } + else { + return new accountsAffectiveModel_1.AccountsAffective(data.userID, data.attitude, data.barriers, data.motivationalLevel, data.personality, data.reasons); + } + }); +} +/* UPDATE */ +function updateAccountAffective(accountAffective) { + return __awaiter(this, void 0, void 0, function* () { + const { userID, attitude, barriers, motivationalLevel, personality, reasons } = accountAffective; + const updateFields = {}; + if (attitude) + updateFields.attitude = attitude; + if (barriers) + updateFields.barriers = barriers; + if (motivationalLevel) + updateFields.motivationalLevel = motivationalLevel; + if (personality) + updateFields.personality = personality; + if (reasons) + updateFields.reasons = reasons; + if (Object.keys(updateFields).length === 0) { + throw new Error("No fields to update"); + } + const { status, statusText, error } = yield supabaseConfig_1.default + .from("accountsaffective") + .update(updateFields) + .eq("userID", userID); + if (error) { + console.error(error); + throw error; + } + else { + return { status, statusText }; + } + }); +} +/* DELETE */ +function deleteAccountAffective(userID) { + return __awaiter(this, void 0, void 0, function* () { + const { status, statusText, error } = yield supabaseConfig_1.default + .from("accountsaffective") + .delete() + .eq("userID", userID); + if (error) { + console.error(error); + throw error; + } + else { + return { status, statusText }; + } + }); +} diff --git a/backend/src/app.ts b/backend/src/app.ts index ea64f42..cc37c89 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -1,6 +1,7 @@ import express from 'express'; import cors from 'cors'; import accountsRouter from './routes/accountsRouter'; +import accountsAffectiveRouter from './routes/accountsAffectiveRouter'; const app = express(); app.use(cors()); @@ -10,6 +11,7 @@ app.use(express.json()); // app.use(accountsRouter); app.use('/accounts', accountsRouter); +app.use('/accountsaffective', accountsAffectiveRouter); app.listen(port, () => { console.log(`Server is running on port ${port}`); diff --git a/backend/src/controllers/accountsAffectiveController.ts b/backend/src/controllers/accountsAffectiveController.ts new file mode 100644 index 0000000..2f9034d --- /dev/null +++ b/backend/src/controllers/accountsAffectiveController.ts @@ -0,0 +1,63 @@ +import { Request, Response } from "express"; +import * as accountsAffectiveService from "../services/accountsAffectiveService"; + +/* CREATE */ + +export const createAccountAffective = async (req: Request, res: Response) => { + const accountBody = req.body; + + try { + const account = await accountsAffectiveService.createAccountAffective(accountBody); + res.status(201).json({ + userID: account[0].userID, + status: 201, + statusText: "Created", + }); + } catch (error) { + res.status(500).json({ + error: `Failed to create ${accountBody.role} account`, + }); + } +}; + +/* READ */ + +export const getAccountById = async (req: Request, res: Response) => { + try { + const account = await accountsAffectiveService.getAccountAffectiveById(req.params.id); + res.status(200).json(account); + } catch (error) { + res.status(500).json({ error: "Failed to retrieve account" }); + } +}; + +/* UPDATE */ + +export const updateAccountAffective = async (req: Request, res: Response) => { + const account = req.body; + + try { + const response = await accountsAffectiveService.updateAccountAffective(account); + res.status(200).json({ + status: 200, + statusText: "Account Affective Updated Successfully", + }); + } catch (error) { + res.status(500).json({ error: "Failed to update account" }); + } +}; + +/* DELETE */ + +export const deleteAccountAffective = async (req: Request, res: Response) => { + try { + const response = await accountsAffectiveService.deleteAccountAffective(req.params.id); + // response body will be empty + res.status(200).json({ + status: 200, + statusText: "Account Affective Deleted Successfully", + }); + } catch (error) { + res.status(500).json({ error: "Failed to delete account" }); + } +}; diff --git a/backend/src/models/accountsAffectiveModel.ts b/backend/src/models/accountsAffectiveModel.ts new file mode 100644 index 0000000..2ae6b5a --- /dev/null +++ b/backend/src/models/accountsAffectiveModel.ts @@ -0,0 +1,42 @@ +import { Enums } from "../config/database.types"; + +export class AccountsAffective { + userID: string; + attitude: Enums<"attitude_towards_learning_type">; + barriers: Enums<"barriers_to_learning_interests_type">[]; + motivationalLevel: Enums<"motivational_level_type">; + personality: Enums<"personality_type">; + reasons: Enums<"reasons_for_attending_section_type">[]; + + constructor( + userID: string, + attitude: Enums<"attitude_towards_learning_type">, + barriers: Enums<"barriers_to_learning_interests_type">[], + motivationalLevel: Enums<"motivational_level_type">, + personality: Enums<"personality_type">, + reasons: Enums<"reasons_for_attending_section_type">[] + ) { + this.userID = userID; + this.attitude = attitude; + this.barriers = barriers; + this.motivationalLevel = motivationalLevel; + this.personality = personality; + this.reasons = reasons; + } + + getAttitude(): Enums<"attitude_towards_learning_type"> { + return this.attitude; + } + getBarriers(): Enums<"barriers_to_learning_interests_type">[] { + return this.barriers; + } + getMotivationalLevel(): Enums<"motivational_level_type"> { + return this.motivationalLevel; + } + getPersonality(): Enums<"personality_type"> { + return this.personality; + } + getReasons(): Enums<"reasons_for_attending_section_type">[] { + return this.reasons; + } +} diff --git a/backend/src/models/accountsCognitiveModel.ts b/backend/src/models/accountsCognitiveModel.ts new file mode 100644 index 0000000..e955289 --- /dev/null +++ b/backend/src/models/accountsCognitiveModel.ts @@ -0,0 +1,42 @@ +import { Enums } from "../config/database.types"; + +export class AccountsCognitive { + userID: string; + educationalLevel: Enums<"educational_level_type">; + languageAbilities: Enums<"language_abilities_type">; + learningPreferences: Enums<"learning_preferences_type">; + litNumProficiency: Enums<"literacy_numeracy_proficiency_type">; + priorKnowledge: Enums<"prior_knowledge_skills_type">; + + constructor( + userID: string, + educationalLevel: Enums<"educational_level_type">, + languageAbilities: Enums<"language_abilities_type">, + learningPreferences: Enums<"learning_preferences_type">, + litNumProficiency: Enums<"literacy_numeracy_proficiency_type">, + priorKnowledge: Enums<"prior_knowledge_skills_type"> + ) { + this.userID = userID; + this.educationalLevel = educationalLevel; + this.languageAbilities = languageAbilities; + this.learningPreferences = learningPreferences; + this.litNumProficiency = litNumProficiency; + this.priorKnowledge = priorKnowledge; + } + + getEducationalLevel(): Enums<"educational_level_type"> { + return this.educationalLevel; + } + getLanguageAbilities(): Enums<"language_abilities_type"> { + return this.languageAbilities; + } + getLearningPreferences(): Enums<"learning_preferences_type"> { + return this.learningPreferences; + } + getLitNumProficiency(): Enums<"literacy_numeracy_proficiency_type"> { + return this.litNumProficiency; + } + getPriorKnowledge(): Enums<"prior_knowledge_skills_type"> { + return this.priorKnowledge; + } +} diff --git a/backend/src/models/accountsDemographicsModel.ts b/backend/src/models/accountsDemographicsModel.ts new file mode 100644 index 0000000..4ae571f --- /dev/null +++ b/backend/src/models/accountsDemographicsModel.ts @@ -0,0 +1,48 @@ +import { Enums } from "../config/database.types"; + +export class AccountsDemographics { + userID: string; + careerStage: Enums<"career_stage_type">; + ethnicGroup: string; + jobCategory: Enums<"job_category_type">; + lifeStage: Enums<"life_stage_type">; + race: Enums<"race_type">; + specialNeeds: Enums<"special_needs_type">; + + constructor( + userID: string, + careerStage: Enums<"career_stage_type">, + ethnicGroup: string, + jobCategory: Enums<"job_category_type">, + lifeStage: Enums<"life_stage_type">, + race: Enums<"race_type">, + specialNeeds: Enums<"special_needs_type"> + ) { + this.userID = userID; + this.careerStage = careerStage; + this.ethnicGroup = ethnicGroup; + this.jobCategory = jobCategory; + this.lifeStage = lifeStage; + this.race = race; + this.specialNeeds = specialNeeds; + } + + getCareerStage(): Enums<"career_stage_type"> { + return this.careerStage; + } + getEthnicGroup(): string { + return this.ethnicGroup; + } + getJobCategory(): Enums<"job_category_type"> { + return this.jobCategory; + } + getLifeStage(): Enums<"life_stage_type"> { + return this.lifeStage; + } + getRace(): Enums<"race_type"> { + return this.race; + } + getSpecialNeeds(): Enums<"special_needs_type"> { + return this.specialNeeds; + } +} diff --git a/backend/src/models/accountsSocialModel.ts b/backend/src/models/accountsSocialModel.ts new file mode 100644 index 0000000..fa3f672 --- /dev/null +++ b/backend/src/models/accountsSocialModel.ts @@ -0,0 +1,36 @@ +import { Enums } from "../config/database.types"; + +export class AccountsSocial { + userID: string; + compLiteracy: Enums<"computer_literacy_type">; + relationshipToPeers: Enums<"relationship_to_peers_type">; + socialBackground: Enums<"social_background_type">; + tendency: Enums<"tendency_to_compete_or_cooperate_type">; + + constructor( + userID: string, + compLiteracy: Enums<"computer_literacy_type">, + relationshipToPeers: Enums<"relationship_to_peers_type">, + socialBackground: Enums<"social_background_type">, + tendency: Enums<"tendency_to_compete_or_cooperate_type"> + ) { + this.userID = userID; + this.compLiteracy = compLiteracy; + this.relationshipToPeers = relationshipToPeers; + this.socialBackground = socialBackground; + this.tendency = tendency; + } + + getCompLiteracy(): Enums<"computer_literacy_type"> { + return this.compLiteracy; + } + getRelationshipToPeers(): Enums<"relationship_to_peers_type"> { + return this.relationshipToPeers; + } + getSocialBackground(): Enums<"social_background_type"> { + return this.socialBackground; + } + getTendency(): Enums<"tendency_to_compete_or_cooperate_type"> { + return this.tendency; + } +} diff --git a/backend/src/routes/accountsAffectiveRouter.ts b/backend/src/routes/accountsAffectiveRouter.ts new file mode 100644 index 0000000..f1e17b1 --- /dev/null +++ b/backend/src/routes/accountsAffectiveRouter.ts @@ -0,0 +1,18 @@ +import { Router } from 'express'; +import * as accountsAffectiveController from '../controllers/accountsAffectiveController'; + +const router = Router(); + +/* CREATE */ +router.post("/createaccountaffective", accountsAffectiveController.createAccountAffective); + +/* READ */ +router.get('/getaccountaffectivebyid/:id', accountsAffectiveController.getAccountById); + +/* UPDATE */ +router.patch('/updateaccountaffective', accountsAffectiveController.updateAccountAffective); + +/* DELETE */ +router.delete('/deleteaccountaffective/:id', accountsAffectiveController.deleteAccountAffective); + +export default router; \ No newline at end of file diff --git a/backend/src/services/accountsAffectiveService.ts b/backend/src/services/accountsAffectiveService.ts new file mode 100644 index 0000000..ee3c745 --- /dev/null +++ b/backend/src/services/accountsAffectiveService.ts @@ -0,0 +1,99 @@ +import supabase from "../config/supabaseConfig"; +import { + AccountsAffective +} from "../models/accountsAffectiveModel"; + +/* CREATE */ + +export async function createAccountAffective(accountAffective: AccountsAffective) { + const { userID, attitude, barriers, motivationalLevel, personality, reasons } = accountAffective; + + const { data, error } = await supabase + .from("accountsaffective") + .insert({ + userID, + attitude, + barriers, + motivationalLevel, + personality, + reasons + }) + .select(); + + if (error) { + console.error(error); + throw error; + } else { + return data; + } +} + +/* READ */ + +export async function getAccountAffectiveById(userID: string): Promise { + const { data, error } = await supabase + .from("accountsaffective") + .select("*") + .eq("userID", userID) + .single(); + + if (error) { + console.error(error); + throw error; + } else { + return new AccountsAffective( + data.userID, + data.attitude, + data.barriers, + data.motivationalLevel, + data.personality, + data.reasons, + ); + } +} + +/* UPDATE */ + +export async function updateAccountAffective(accountAffective: AccountsAffective) { + const { userID, attitude, barriers, motivationalLevel, personality, reasons } = accountAffective; + + const updateFields: { [key: string]: any } = {}; + + if (attitude) updateFields.attitude = attitude; + if (barriers) updateFields.barriers = barriers; + if (motivationalLevel) updateFields.motivationalLevel = motivationalLevel; + if (personality) updateFields.personality = personality; + if (reasons) updateFields.reasons = reasons; + + if (Object.keys(updateFields).length === 0) { + throw new Error("No fields to update"); + } + + const { status, statusText, error } = await supabase + .from("accountsaffective") + .update(updateFields) + .eq("userID", userID); + + if (error) { + console.error(error); + throw error; + } else { + return { status, statusText }; + } +} + +/* DELETE */ + +export async function deleteAccountAffective(userID: string) { + const { status, statusText, error } = await supabase + .from("accountsaffective") + .delete() + .eq("userID", userID); + + if (error) { + console.error(error); + throw error; + } else { + return { status, statusText }; + } +} \ No newline at end of file From 218851ac1654590208de1c153e6054fed7739e4a Mon Sep 17 00:00:00 2001 From: Fadhli Date: Tue, 20 Aug 2024 00:42:01 +0800 Subject: [PATCH 2/3] SCRUM-52 added accountsCognitive, accountsDemographics, accountsSocial endpoints --- backend/dist/app.js | 6 + .../accountsCognitiveController.js | 95 +++++++++++++++ .../accountsDemographicsController.js | 95 +++++++++++++++ .../controllers/accountsSocialController.js | 95 +++++++++++++++ .../dist/routes/accountsCognitiveRouter.js | 37 ++++++ .../dist/routes/accountsDemographicsRouter.js | 37 ++++++ backend/dist/routes/accountsSocialRouter.js | 37 ++++++ .../dist/services/accountsCognitiveService.js | 108 +++++++++++++++++ .../services/accountsDemographicsService.js | 111 ++++++++++++++++++ .../dist/services/accountsSocialService.js | 105 +++++++++++++++++ backend/src/app.ts | 6 + .../accountsCognitiveController.ts | 63 ++++++++++ .../accountsDemographicsController.ts | 63 ++++++++++ .../controllers/accountsSocialController.ts | 63 ++++++++++ backend/src/routes/accountsCognitiveRouter.ts | 18 +++ .../src/routes/accountsDemographicsRouter.ts | 18 +++ backend/src/routes/accountsSocialRouter.ts | 18 +++ .../src/services/accountsCognitiveService.ts | 99 ++++++++++++++++ .../services/accountsDemographicsService.ts | 102 ++++++++++++++++ backend/src/services/accountsSocialService.ts | 96 +++++++++++++++ 20 files changed, 1272 insertions(+) create mode 100644 backend/dist/controllers/accountsCognitiveController.js create mode 100644 backend/dist/controllers/accountsDemographicsController.js create mode 100644 backend/dist/controllers/accountsSocialController.js create mode 100644 backend/dist/routes/accountsCognitiveRouter.js create mode 100644 backend/dist/routes/accountsDemographicsRouter.js create mode 100644 backend/dist/routes/accountsSocialRouter.js create mode 100644 backend/dist/services/accountsCognitiveService.js create mode 100644 backend/dist/services/accountsDemographicsService.js create mode 100644 backend/dist/services/accountsSocialService.js create mode 100644 backend/src/controllers/accountsCognitiveController.ts create mode 100644 backend/src/controllers/accountsDemographicsController.ts create mode 100644 backend/src/controllers/accountsSocialController.ts create mode 100644 backend/src/routes/accountsCognitiveRouter.ts create mode 100644 backend/src/routes/accountsDemographicsRouter.ts create mode 100644 backend/src/routes/accountsSocialRouter.ts create mode 100644 backend/src/services/accountsCognitiveService.ts create mode 100644 backend/src/services/accountsDemographicsService.ts create mode 100644 backend/src/services/accountsSocialService.ts diff --git a/backend/dist/app.js b/backend/dist/app.js index 56f6699..0278e88 100644 --- a/backend/dist/app.js +++ b/backend/dist/app.js @@ -7,6 +7,9 @@ const express_1 = __importDefault(require("express")); const cors_1 = __importDefault(require("cors")); const accountsRouter_1 = __importDefault(require("./routes/accountsRouter")); const accountsAffectiveRouter_1 = __importDefault(require("./routes/accountsAffectiveRouter")); +const accountsCognitiveRouter_1 = __importDefault(require("./routes/accountsCognitiveRouter")); +const accountsDemographicsRouter_1 = __importDefault(require("./routes/accountsDemographicsRouter")); +const accountsSocialRouter_1 = __importDefault(require("./routes/accountsSocialRouter")); const app = (0, express_1.default)(); app.use((0, cors_1.default)()); const port = 3000; @@ -14,6 +17,9 @@ app.use(express_1.default.json()); // app.use(accountsRouter); app.use('/accounts', accountsRouter_1.default); app.use('/accountsaffective', accountsAffectiveRouter_1.default); +app.use('/accountscognitive', accountsCognitiveRouter_1.default); +app.use('/accountsdemographics', accountsDemographicsRouter_1.default); +app.use('/accountssocial', accountsSocialRouter_1.default); app.listen(port, () => { console.log(`Server is running on port ${port}`); }); diff --git a/backend/dist/controllers/accountsCognitiveController.js b/backend/dist/controllers/accountsCognitiveController.js new file mode 100644 index 0000000..bd6daf0 --- /dev/null +++ b/backend/dist/controllers/accountsCognitiveController.js @@ -0,0 +1,95 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAccountCognitive = exports.updateAccountCognitive = exports.getAccountCognitiveById = exports.createAccountCognitive = void 0; +const accountsCognitiveService = __importStar(require("../services/accountsCognitiveService")); +/* CREATE */ +const createAccountCognitive = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const accountBody = req.body; + try { + const account = yield accountsCognitiveService.createAccountCognitive(accountBody); + res.status(201).json({ + userID: account[0].userID, + status: 201, + statusText: "Created", + }); + } + catch (error) { + res.status(500).json({ + error: `Failed to create ${accountBody.role} account`, + }); + } +}); +exports.createAccountCognitive = createAccountCognitive; +/* READ */ +const getAccountCognitiveById = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const account = yield accountsCognitiveService.getAccountCognitiveById(req.params.id); + res.status(200).json(account); + } + catch (error) { + res.status(500).json({ error: "Failed to retrieve Account Cognitive" }); + } +}); +exports.getAccountCognitiveById = getAccountCognitiveById; +/* UPDATE */ +const updateAccountCognitive = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const account = req.body; + try { + const response = yield accountsCognitiveService.updateAccountCognitive(account); + res.status(200).json({ + status: 200, + statusText: "Account Cognitive Updated Successfully", + }); + } + catch (error) { + res.status(500).json({ error: "Failed to update account" }); + } +}); +exports.updateAccountCognitive = updateAccountCognitive; +/* DELETE */ +const deleteAccountCognitive = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const response = yield accountsCognitiveService.deleteAccountCognitive(req.params.id); + // response body will be empty + res.status(200).json({ + status: 200, + statusText: "Account Cognitive Deleted Successfully", + }); + } + catch (error) { + res.status(500).json({ error: "Failed to delete account" }); + } +}); +exports.deleteAccountCognitive = deleteAccountCognitive; diff --git a/backend/dist/controllers/accountsDemographicsController.js b/backend/dist/controllers/accountsDemographicsController.js new file mode 100644 index 0000000..20ef14f --- /dev/null +++ b/backend/dist/controllers/accountsDemographicsController.js @@ -0,0 +1,95 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAccountDemographics = exports.updateAccountDemographics = exports.getAccountDemographicsById = exports.createAccountDemographics = void 0; +const accountsDemographicsService = __importStar(require("../services/accountsDemographicsService")); +/* CREATE */ +const createAccountDemographics = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const accountBody = req.body; + try { + const account = yield accountsDemographicsService.createAccountDemographics(accountBody); + res.status(201).json({ + userID: account[0].userID, + status: 201, + statusText: "Created", + }); + } + catch (error) { + res.status(500).json({ + error: `Failed to create ${accountBody.role} account`, + }); + } +}); +exports.createAccountDemographics = createAccountDemographics; +/* READ */ +const getAccountDemographicsById = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const account = yield accountsDemographicsService.getAccountDemographicsById(req.params.id); + res.status(200).json(account); + } + catch (error) { + res.status(500).json({ error: "Failed to retrieve account" }); + } +}); +exports.getAccountDemographicsById = getAccountDemographicsById; +/* UPDATE */ +const updateAccountDemographics = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const account = req.body; + try { + const response = yield accountsDemographicsService.updateAccountCognitive(account); + res.status(200).json({ + status: 200, + statusText: "Account Demographics Updated Successfully", + }); + } + catch (error) { + res.status(500).json({ error: "Failed to update account" }); + } +}); +exports.updateAccountDemographics = updateAccountDemographics; +/* DELETE */ +const deleteAccountDemographics = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const response = yield accountsDemographicsService.deleteAccountDemographics(req.params.id); + // response body will be empty + res.status(200).json({ + status: 200, + statusText: "Account Demographics Deleted Successfully", + }); + } + catch (error) { + res.status(500).json({ error: "Failed to delete account" }); + } +}); +exports.deleteAccountDemographics = deleteAccountDemographics; diff --git a/backend/dist/controllers/accountsSocialController.js b/backend/dist/controllers/accountsSocialController.js new file mode 100644 index 0000000..0eb22c2 --- /dev/null +++ b/backend/dist/controllers/accountsSocialController.js @@ -0,0 +1,95 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAccountSocial = exports.updateAccountSocial = exports.getAccountSocialById = exports.createAccountSocial = void 0; +const accountsSocialService = __importStar(require("../services/accountsSocialService")); +/* CREATE */ +const createAccountSocial = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const accountBody = req.body; + try { + const account = yield accountsSocialService.createAccountSocial(accountBody); + res.status(201).json({ + userID: account[0].userID, + status: 201, + statusText: "Created", + }); + } + catch (error) { + res.status(500).json({ + error: `Failed to create ${accountBody.role} account`, + }); + } +}); +exports.createAccountSocial = createAccountSocial; +/* READ */ +const getAccountSocialById = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const account = yield accountsSocialService.getAccountSocialById(req.params.id); + res.status(200).json(account); + } + catch (error) { + res.status(500).json({ error: "Failed to retrieve account" }); + } +}); +exports.getAccountSocialById = getAccountSocialById; +/* UPDATE */ +const updateAccountSocial = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const account = req.body; + try { + const response = yield accountsSocialService.updateAccountSocial(account); + res.status(200).json({ + status: 200, + statusText: "Account Social Updated Successfully", + }); + } + catch (error) { + res.status(500).json({ error: "Failed to update account" }); + } +}); +exports.updateAccountSocial = updateAccountSocial; +/* DELETE */ +const deleteAccountSocial = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + try { + const response = yield accountsSocialService.deleteAccountSocial(req.params.id); + // response body will be empty + res.status(200).json({ + status: 200, + statusText: "Account Social Deleted Successfully", + }); + } + catch (error) { + res.status(500).json({ error: "Failed to delete account" }); + } +}); +exports.deleteAccountSocial = deleteAccountSocial; diff --git a/backend/dist/routes/accountsCognitiveRouter.js b/backend/dist/routes/accountsCognitiveRouter.js new file mode 100644 index 0000000..61dee7f --- /dev/null +++ b/backend/dist/routes/accountsCognitiveRouter.js @@ -0,0 +1,37 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = require("express"); +const accountsCognitiveController = __importStar(require("../controllers/accountsCognitiveController")); +const router = (0, express_1.Router)(); +/* CREATE */ +router.post("/createaccountcognitive", accountsCognitiveController.createAccountCognitive); +/* READ */ +router.get('/getaccountcognitivebyid/:id', accountsCognitiveController.getAccountCognitiveById); +/* UPDATE */ +router.patch('/updateaccountcognitive', accountsCognitiveController.updateAccountCognitive); +/* DELETE */ +router.delete('/deleteaccountcognitive/:id', accountsCognitiveController.deleteAccountCognitive); +exports.default = router; diff --git a/backend/dist/routes/accountsDemographicsRouter.js b/backend/dist/routes/accountsDemographicsRouter.js new file mode 100644 index 0000000..620d504 --- /dev/null +++ b/backend/dist/routes/accountsDemographicsRouter.js @@ -0,0 +1,37 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = require("express"); +const accountsDemographicsController = __importStar(require("../controllers/accountsDemographicsController")); +const router = (0, express_1.Router)(); +/* CREATE */ +router.post("/createaccountdemographics", accountsDemographicsController.createAccountDemographics); +/* READ */ +router.get('/getaccountdemographicsbyid/:id', accountsDemographicsController.getAccountDemographicsById); +/* UPDATE */ +router.patch('/updateaccountdemographics', accountsDemographicsController.updateAccountDemographics); +/* DELETE */ +router.delete('/deleteaccountdemographics/:id', accountsDemographicsController.deleteAccountDemographics); +exports.default = router; diff --git a/backend/dist/routes/accountsSocialRouter.js b/backend/dist/routes/accountsSocialRouter.js new file mode 100644 index 0000000..1f28212 --- /dev/null +++ b/backend/dist/routes/accountsSocialRouter.js @@ -0,0 +1,37 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const express_1 = require("express"); +const accountsSocialController = __importStar(require("../controllers/accountsSocialController")); +const router = (0, express_1.Router)(); +/* CREATE */ +router.post("/createaccountsocial", accountsSocialController.createAccountSocial); +/* READ */ +router.get('/getaccountsocialbyid/:id', accountsSocialController.getAccountSocialById); +/* UPDATE */ +router.patch('/updateaccountsocial', accountsSocialController.updateAccountSocial); +/* DELETE */ +router.delete('/deleteaccountsocial/:id', accountsSocialController.deleteAccountSocial); +exports.default = router; diff --git a/backend/dist/services/accountsCognitiveService.js b/backend/dist/services/accountsCognitiveService.js new file mode 100644 index 0000000..aa4e13a --- /dev/null +++ b/backend/dist/services/accountsCognitiveService.js @@ -0,0 +1,108 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createAccountCognitive = createAccountCognitive; +exports.getAccountCognitiveById = getAccountCognitiveById; +exports.updateAccountCognitive = updateAccountCognitive; +exports.deleteAccountCognitive = deleteAccountCognitive; +const supabaseConfig_1 = __importDefault(require("../config/supabaseConfig")); +const accountsCognitiveModel_1 = require("../models/accountsCognitiveModel"); +/* CREATE */ +function createAccountCognitive(accountCognitive) { + return __awaiter(this, void 0, void 0, function* () { + const { userID, educationalLevel, languageAbilities, learningPreferences, litNumProficiency, priorKnowledge } = accountCognitive; + const { data, error } = yield supabaseConfig_1.default + .from("accountscognitive") + .insert({ + userID, + educationalLevel, + languageAbilities, + learningPreferences, + litNumProficiency, + priorKnowledge + }) + .select(); + if (error) { + console.error(error); + throw error; + } + else { + return data; + } + }); +} +/* READ */ +function getAccountCognitiveById(userID) { + return __awaiter(this, void 0, void 0, function* () { + const { data, error } = yield supabaseConfig_1.default + .from("accountscognitive") + .select("*") + .eq("userID", userID) + .single(); + if (error) { + console.error(error); + throw error; + } + else { + return new accountsCognitiveModel_1.AccountsCognitive(data.userID, data.educationalLevel, data.languageAbilities, data.learningPreferences, data.litNumProficiency, data.priorKnowledge); + } + }); +} +/* UPDATE */ +function updateAccountCognitive(accountCognitive) { + return __awaiter(this, void 0, void 0, function* () { + const { userID, educationalLevel, languageAbilities, learningPreferences, litNumProficiency, priorKnowledge } = accountCognitive; + const updateFields = {}; + if (educationalLevel) + updateFields.educationalLevel = educationalLevel; + if (languageAbilities) + updateFields.languageAbilities = languageAbilities; + if (learningPreferences) + updateFields.learningPreferences = learningPreferences; + if (litNumProficiency) + updateFields.litNumProficiency = litNumProficiency; + if (priorKnowledge) + updateFields.priorKnowledge = priorKnowledge; + if (Object.keys(updateFields).length === 0) { + throw new Error("No fields to update"); + } + const { status, statusText, error } = yield supabaseConfig_1.default + .from("accountscognitive") + .update(updateFields) + .eq("userID", userID); + if (error) { + console.error(error); + throw error; + } + else { + return { status, statusText }; + } + }); +} +/* DELETE */ +function deleteAccountCognitive(userID) { + return __awaiter(this, void 0, void 0, function* () { + const { status, statusText, error } = yield supabaseConfig_1.default + .from("accountscognitive") + .delete() + .eq("userID", userID); + if (error) { + console.error(error); + throw error; + } + else { + return { status, statusText }; + } + }); +} diff --git a/backend/dist/services/accountsDemographicsService.js b/backend/dist/services/accountsDemographicsService.js new file mode 100644 index 0000000..4576fcf --- /dev/null +++ b/backend/dist/services/accountsDemographicsService.js @@ -0,0 +1,111 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createAccountDemographics = createAccountDemographics; +exports.getAccountDemographicsById = getAccountDemographicsById; +exports.updateAccountCognitive = updateAccountCognitive; +exports.deleteAccountDemographics = deleteAccountDemographics; +const supabaseConfig_1 = __importDefault(require("../config/supabaseConfig")); +const accountsDemographicsModel_1 = require("../models/accountsDemographicsModel"); +/* CREATE */ +function createAccountDemographics(accountDemographics) { + return __awaiter(this, void 0, void 0, function* () { + const { userID, careerStage, ethnicGroup, jobCategory, lifeStage, race, specialNeeds } = accountDemographics; + const { data, error } = yield supabaseConfig_1.default + .from("accountsdemographics") + .insert({ + userID, + careerStage, + ethnicGroup, + jobCategory, + lifeStage, + race, + specialNeeds + }) + .select(); + if (error) { + console.error(error); + throw error; + } + else { + return data; + } + }); +} +/* READ */ +function getAccountDemographicsById(userID) { + return __awaiter(this, void 0, void 0, function* () { + const { data, error } = yield supabaseConfig_1.default + .from("accountsdemographics") + .select("*") + .eq("userID", userID) + .single(); + if (error) { + console.error(error); + throw error; + } + else { + return new accountsDemographicsModel_1.AccountsDemographics(data.userID, data.careerStage, data.ethnicGroup, data.jobCategory, data.lifeStage, data.race, data.specialNeeds); + } + }); +} +/* UPDATE */ +function updateAccountCognitive(accountDemographics) { + return __awaiter(this, void 0, void 0, function* () { + const { userID, careerStage, ethnicGroup, jobCategory, lifeStage, race, specialNeeds } = accountDemographics; + const updateFields = {}; + if (careerStage) + updateFields.careerStage = careerStage; + if (ethnicGroup) + updateFields.ethnicGroup = ethnicGroup; + if (jobCategory) + updateFields.jobCategory = jobCategory; + if (lifeStage) + updateFields.lifeStage = lifeStage; + if (race) + updateFields.race = race; + if (specialNeeds) + updateFields.specialNeeds = specialNeeds; + if (Object.keys(updateFields).length === 0) { + throw new Error("No fields to update"); + } + const { status, statusText, error } = yield supabaseConfig_1.default + .from("accountsdemographics") + .update(updateFields) + .eq("userID", userID); + if (error) { + console.error(error); + throw error; + } + else { + return { status, statusText }; + } + }); +} +/* DELETE */ +function deleteAccountDemographics(userID) { + return __awaiter(this, void 0, void 0, function* () { + const { status, statusText, error } = yield supabaseConfig_1.default + .from("accountsdemographics") + .delete() + .eq("userID", userID); + if (error) { + console.error(error); + throw error; + } + else { + return { status, statusText }; + } + }); +} diff --git a/backend/dist/services/accountsSocialService.js b/backend/dist/services/accountsSocialService.js new file mode 100644 index 0000000..fe71036 --- /dev/null +++ b/backend/dist/services/accountsSocialService.js @@ -0,0 +1,105 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createAccountSocial = createAccountSocial; +exports.getAccountSocialById = getAccountSocialById; +exports.updateAccountSocial = updateAccountSocial; +exports.deleteAccountSocial = deleteAccountSocial; +const supabaseConfig_1 = __importDefault(require("../config/supabaseConfig")); +const accountsSocialModel_1 = require("../models/accountsSocialModel"); +/* CREATE */ +function createAccountSocial(accountSocial) { + return __awaiter(this, void 0, void 0, function* () { + const { userID, compLiteracy, relationshipToPeers, socialBackground, tendency } = accountSocial; + const { data, error } = yield supabaseConfig_1.default + .from("accountssocial") + .insert({ + userID, + compLiteracy, + relationshipToPeers, + socialBackground, + tendency, + }) + .select(); + if (error) { + console.error(error); + throw error; + } + else { + return data; + } + }); +} +/* READ */ +function getAccountSocialById(userID) { + return __awaiter(this, void 0, void 0, function* () { + const { data, error } = yield supabaseConfig_1.default + .from("accountssocial") + .select("*") + .eq("userID", userID) + .single(); + if (error) { + console.error(error); + throw error; + } + else { + return new accountsSocialModel_1.AccountsSocial(data.userID, data.compLiteracy, data.relationshipToPeers, data.socialBackground, data.tendency); + } + }); +} +/* UPDATE */ +function updateAccountSocial(accountSocial) { + return __awaiter(this, void 0, void 0, function* () { + const { userID, compLiteracy, relationshipToPeers, socialBackground, tendency } = accountSocial; + const updateFields = {}; + if (compLiteracy) + updateFields.compLiteracy = compLiteracy; + if (relationshipToPeers) + updateFields.relationshipToPeers = relationshipToPeers; + if (socialBackground) + updateFields.socialBackground = socialBackground; + if (tendency) + updateFields.tendency = tendency; + if (Object.keys(updateFields).length === 0) { + throw new Error("No fields to update"); + } + const { status, statusText, error } = yield supabaseConfig_1.default + .from("accountssocial") + .update(updateFields) + .eq("userID", userID); + if (error) { + console.error(error); + throw error; + } + else { + return { status, statusText }; + } + }); +} +/* DELETE */ +function deleteAccountSocial(userID) { + return __awaiter(this, void 0, void 0, function* () { + const { status, statusText, error } = yield supabaseConfig_1.default + .from("accountssocial") + .delete() + .eq("userID", userID); + if (error) { + console.error(error); + throw error; + } + else { + return { status, statusText }; + } + }); +} diff --git a/backend/src/app.ts b/backend/src/app.ts index cc37c89..70c0bb7 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -2,6 +2,9 @@ import express from 'express'; import cors from 'cors'; import accountsRouter from './routes/accountsRouter'; import accountsAffectiveRouter from './routes/accountsAffectiveRouter'; +import accountsCognitiveRouter from './routes/accountsCognitiveRouter'; +import accountsDemographicsRouter from './routes/accountsDemographicsRouter'; +import accountsSocialRouter from './routes/accountsSocialRouter'; const app = express(); app.use(cors()); @@ -12,6 +15,9 @@ app.use(express.json()); // app.use(accountsRouter); app.use('/accounts', accountsRouter); app.use('/accountsaffective', accountsAffectiveRouter); +app.use('/accountscognitive', accountsCognitiveRouter); +app.use('/accountsdemographics', accountsDemographicsRouter); +app.use('/accountssocial', accountsSocialRouter); app.listen(port, () => { console.log(`Server is running on port ${port}`); diff --git a/backend/src/controllers/accountsCognitiveController.ts b/backend/src/controllers/accountsCognitiveController.ts new file mode 100644 index 0000000..06f67d8 --- /dev/null +++ b/backend/src/controllers/accountsCognitiveController.ts @@ -0,0 +1,63 @@ +import { Request, Response } from "express"; +import * as accountsCognitiveService from "../services/accountsCognitiveService"; + +/* CREATE */ + +export const createAccountCognitive = async (req: Request, res: Response) => { + const accountBody = req.body; + + try { + const account = await accountsCognitiveService.createAccountCognitive(accountBody); + res.status(201).json({ + userID: account[0].userID, + status: 201, + statusText: "Created", + }); + } catch (error) { + res.status(500).json({ + error: `Failed to create ${accountBody.role} account`, + }); + } +}; + +/* READ */ + +export const getAccountCognitiveById = async (req: Request, res: Response) => { + try { + const account = await accountsCognitiveService.getAccountCognitiveById(req.params.id); + res.status(200).json(account); + } catch (error) { + res.status(500).json({ error: "Failed to retrieve Account Cognitive" }); + } +}; + +/* UPDATE */ + +export const updateAccountCognitive = async (req: Request, res: Response) => { + const account = req.body; + + try { + const response = await accountsCognitiveService.updateAccountCognitive(account); + res.status(200).json({ + status: 200, + statusText: "Account Cognitive Updated Successfully", + }); + } catch (error) { + res.status(500).json({ error: "Failed to update account" }); + } +}; + +/* DELETE */ + +export const deleteAccountCognitive = async (req: Request, res: Response) => { + try { + const response = await accountsCognitiveService.deleteAccountCognitive(req.params.id); + // response body will be empty + res.status(200).json({ + status: 200, + statusText: "Account Cognitive Deleted Successfully", + }); + } catch (error) { + res.status(500).json({ error: "Failed to delete account" }); + } +}; diff --git a/backend/src/controllers/accountsDemographicsController.ts b/backend/src/controllers/accountsDemographicsController.ts new file mode 100644 index 0000000..93c1dbc --- /dev/null +++ b/backend/src/controllers/accountsDemographicsController.ts @@ -0,0 +1,63 @@ +import { Request, Response } from "express"; +import * as accountsDemographicsService from "../services/accountsDemographicsService"; + +/* CREATE */ + +export const createAccountDemographics = async (req: Request, res: Response) => { + const accountBody = req.body; + + try { + const account = await accountsDemographicsService.createAccountDemographics(accountBody); + res.status(201).json({ + userID: account[0].userID, + status: 201, + statusText: "Created", + }); + } catch (error) { + res.status(500).json({ + error: `Failed to create ${accountBody.role} account`, + }); + } +}; + +/* READ */ + +export const getAccountDemographicsById = async (req: Request, res: Response) => { + try { + const account = await accountsDemographicsService.getAccountDemographicsById(req.params.id); + res.status(200).json(account); + } catch (error) { + res.status(500).json({ error: "Failed to retrieve account" }); + } +}; + +/* UPDATE */ + +export const updateAccountDemographics = async (req: Request, res: Response) => { + const account = req.body; + + try { + const response = await accountsDemographicsService.updateAccountCognitive(account); + res.status(200).json({ + status: 200, + statusText: "Account Demographics Updated Successfully", + }); + } catch (error) { + res.status(500).json({ error: "Failed to update account" }); + } +}; + +/* DELETE */ + +export const deleteAccountDemographics = async (req: Request, res: Response) => { + try { + const response = await accountsDemographicsService.deleteAccountDemographics(req.params.id); + // response body will be empty + res.status(200).json({ + status: 200, + statusText: "Account Demographics Deleted Successfully", + }); + } catch (error) { + res.status(500).json({ error: "Failed to delete account" }); + } +}; diff --git a/backend/src/controllers/accountsSocialController.ts b/backend/src/controllers/accountsSocialController.ts new file mode 100644 index 0000000..7f3c2aa --- /dev/null +++ b/backend/src/controllers/accountsSocialController.ts @@ -0,0 +1,63 @@ +import { Request, Response } from "express"; +import * as accountsSocialService from "../services/accountsSocialService"; + +/* CREATE */ + +export const createAccountSocial = async (req: Request, res: Response) => { + const accountBody = req.body; + + try { + const account = await accountsSocialService.createAccountSocial(accountBody); + res.status(201).json({ + userID: account[0].userID, + status: 201, + statusText: "Created", + }); + } catch (error) { + res.status(500).json({ + error: `Failed to create ${accountBody.role} account`, + }); + } +}; + +/* READ */ + +export const getAccountSocialById = async (req: Request, res: Response) => { + try { + const account = await accountsSocialService.getAccountSocialById(req.params.id); + res.status(200).json(account); + } catch (error) { + res.status(500).json({ error: "Failed to retrieve account" }); + } +}; + +/* UPDATE */ + +export const updateAccountSocial = async (req: Request, res: Response) => { + const account = req.body; + + try { + const response = await accountsSocialService.updateAccountSocial(account); + res.status(200).json({ + status: 200, + statusText: "Account Social Updated Successfully", + }); + } catch (error) { + res.status(500).json({ error: "Failed to update account" }); + } +}; + +/* DELETE */ + +export const deleteAccountSocial = async (req: Request, res: Response) => { + try { + const response = await accountsSocialService.deleteAccountSocial(req.params.id); + // response body will be empty + res.status(200).json({ + status: 200, + statusText: "Account Social Deleted Successfully", + }); + } catch (error) { + res.status(500).json({ error: "Failed to delete account" }); + } +}; diff --git a/backend/src/routes/accountsCognitiveRouter.ts b/backend/src/routes/accountsCognitiveRouter.ts new file mode 100644 index 0000000..bd8423e --- /dev/null +++ b/backend/src/routes/accountsCognitiveRouter.ts @@ -0,0 +1,18 @@ +import { Router } from 'express'; +import * as accountsCognitiveController from '../controllers/accountsCognitiveController'; + +const router = Router(); + +/* CREATE */ +router.post("/createaccountcognitive", accountsCognitiveController.createAccountCognitive); + +/* READ */ +router.get('/getaccountcognitivebyid/:id', accountsCognitiveController.getAccountCognitiveById); + +/* UPDATE */ +router.patch('/updateaccountcognitive', accountsCognitiveController.updateAccountCognitive); + +/* DELETE */ +router.delete('/deleteaccountcognitive/:id', accountsCognitiveController.deleteAccountCognitive); + +export default router; \ No newline at end of file diff --git a/backend/src/routes/accountsDemographicsRouter.ts b/backend/src/routes/accountsDemographicsRouter.ts new file mode 100644 index 0000000..83ad7ff --- /dev/null +++ b/backend/src/routes/accountsDemographicsRouter.ts @@ -0,0 +1,18 @@ +import { Router } from 'express'; +import * as accountsDemographicsController from '../controllers/accountsDemographicsController'; + +const router = Router(); + +/* CREATE */ +router.post("/createaccountdemographics", accountsDemographicsController.createAccountDemographics); + +/* READ */ +router.get('/getaccountdemographicsbyid/:id', accountsDemographicsController.getAccountDemographicsById); + +/* UPDATE */ +router.patch('/updateaccountdemographics', accountsDemographicsController.updateAccountDemographics); + +/* DELETE */ +router.delete('/deleteaccountdemographics/:id', accountsDemographicsController.deleteAccountDemographics); + +export default router; \ No newline at end of file diff --git a/backend/src/routes/accountsSocialRouter.ts b/backend/src/routes/accountsSocialRouter.ts new file mode 100644 index 0000000..481061d --- /dev/null +++ b/backend/src/routes/accountsSocialRouter.ts @@ -0,0 +1,18 @@ +import { Router } from 'express'; +import * as accountsSocialController from '../controllers/accountsSocialController'; + +const router = Router(); + +/* CREATE */ +router.post("/createaccountsocial", accountsSocialController.createAccountSocial); + +/* READ */ +router.get('/getaccountsocialbyid/:id', accountsSocialController.getAccountSocialById); + +/* UPDATE */ +router.patch('/updateaccountsocial', accountsSocialController.updateAccountSocial); + +/* DELETE */ +router.delete('/deleteaccountsocial/:id', accountsSocialController.deleteAccountSocial); + +export default router; \ No newline at end of file diff --git a/backend/src/services/accountsCognitiveService.ts b/backend/src/services/accountsCognitiveService.ts new file mode 100644 index 0000000..5028c04 --- /dev/null +++ b/backend/src/services/accountsCognitiveService.ts @@ -0,0 +1,99 @@ +import supabase from "../config/supabaseConfig"; +import { + AccountsCognitive +} from "../models/accountsCognitiveModel"; + +/* CREATE */ + +export async function createAccountCognitive(accountCognitive: AccountsCognitive) { + const { userID, educationalLevel, languageAbilities, learningPreferences, litNumProficiency, priorKnowledge } = accountCognitive; + + const { data, error } = await supabase + .from("accountscognitive") + .insert({ + userID, + educationalLevel, + languageAbilities, + learningPreferences, + litNumProficiency, + priorKnowledge + }) + .select(); + + if (error) { + console.error(error); + throw error; + } else { + return data; + } +} + +/* READ */ + +export async function getAccountCognitiveById(userID: string): Promise { + const { data, error } = await supabase + .from("accountscognitive") + .select("*") + .eq("userID", userID) + .single(); + + if (error) { + console.error(error); + throw error; + } else { + return new AccountsCognitive( + data.userID, + data.educationalLevel, + data.languageAbilities, + data.learningPreferences, + data.litNumProficiency, + data.priorKnowledge, + ); + } +} + +/* UPDATE */ + +export async function updateAccountCognitive(accountCognitive: AccountsCognitive) { + const { userID, educationalLevel, languageAbilities, learningPreferences, litNumProficiency, priorKnowledge } = accountCognitive; + + const updateFields: { [key: string]: any } = {}; + + if (educationalLevel) updateFields.educationalLevel = educationalLevel; + if (languageAbilities) updateFields.languageAbilities = languageAbilities; + if (learningPreferences) updateFields.learningPreferences = learningPreferences; + if (litNumProficiency) updateFields.litNumProficiency = litNumProficiency; + if (priorKnowledge) updateFields.priorKnowledge = priorKnowledge; + + if (Object.keys(updateFields).length === 0) { + throw new Error("No fields to update"); + } + + const { status, statusText, error } = await supabase + .from("accountscognitive") + .update(updateFields) + .eq("userID", userID); + + if (error) { + console.error(error); + throw error; + } else { + return { status, statusText }; + } +} + +/* DELETE */ + +export async function deleteAccountCognitive(userID: string) { + const { status, statusText, error } = await supabase + .from("accountscognitive") + .delete() + .eq("userID", userID); + + if (error) { + console.error(error); + throw error; + } else { + return { status, statusText }; + } +} \ No newline at end of file diff --git a/backend/src/services/accountsDemographicsService.ts b/backend/src/services/accountsDemographicsService.ts new file mode 100644 index 0000000..47cc239 --- /dev/null +++ b/backend/src/services/accountsDemographicsService.ts @@ -0,0 +1,102 @@ +import supabase from "../config/supabaseConfig"; +import { + AccountsDemographics +} from "../models/accountsDemographicsModel"; + +/* CREATE */ + +export async function createAccountDemographics(accountDemographics: AccountsDemographics) { + const { userID, careerStage, ethnicGroup, jobCategory, lifeStage, race, specialNeeds } = accountDemographics; + + const { data, error } = await supabase + .from("accountsdemographics") + .insert({ + userID, + careerStage, + ethnicGroup, + jobCategory, + lifeStage, + race, + specialNeeds + }) + .select(); + + if (error) { + console.error(error); + throw error; + } else { + return data; + } +} + +/* READ */ + +export async function getAccountDemographicsById(userID: string): Promise { + const { data, error } = await supabase + .from("accountsdemographics") + .select("*") + .eq("userID", userID) + .single(); + + if (error) { + console.error(error); + throw error; + } else { + return new AccountsDemographics( + data.userID, + data.careerStage, + data.ethnicGroup, + data.jobCategory, + data.lifeStage, + data.race, + data.specialNeeds + ); + } +} + +/* UPDATE */ + +export async function updateAccountCognitive(accountDemographics: AccountsDemographics) { + const { userID, careerStage, ethnicGroup, jobCategory, lifeStage, race, specialNeeds } = accountDemographics; + + const updateFields: { [key: string]: any } = {}; + + if (careerStage) updateFields.careerStage = careerStage; + if (ethnicGroup) updateFields.ethnicGroup = ethnicGroup; + if (jobCategory) updateFields.jobCategory = jobCategory; + if (lifeStage) updateFields.lifeStage = lifeStage; + if (race) updateFields.race = race; + if (specialNeeds) updateFields.specialNeeds = specialNeeds; + + if (Object.keys(updateFields).length === 0) { + throw new Error("No fields to update"); + } + + const { status, statusText, error } = await supabase + .from("accountsdemographics") + .update(updateFields) + .eq("userID", userID); + + if (error) { + console.error(error); + throw error; + } else { + return { status, statusText }; + } +} + +/* DELETE */ + +export async function deleteAccountDemographics(userID: string) { + const { status, statusText, error } = await supabase + .from("accountsdemographics") + .delete() + .eq("userID", userID); + + if (error) { + console.error(error); + throw error; + } else { + return { status, statusText }; + } +} \ No newline at end of file diff --git a/backend/src/services/accountsSocialService.ts b/backend/src/services/accountsSocialService.ts new file mode 100644 index 0000000..f4be5b9 --- /dev/null +++ b/backend/src/services/accountsSocialService.ts @@ -0,0 +1,96 @@ +import supabase from "../config/supabaseConfig"; +import { + AccountsSocial +} from "../models/accountsSocialModel"; + +/* CREATE */ + +export async function createAccountSocial(accountSocial: AccountsSocial) { + const { userID, compLiteracy, relationshipToPeers, socialBackground, tendency } = accountSocial; + + const { data, error } = await supabase + .from("accountssocial") + .insert({ + userID, + compLiteracy, + relationshipToPeers, + socialBackground, + tendency, + }) + .select(); + + if (error) { + console.error(error); + throw error; + } else { + return data; + } +} + +/* READ */ + +export async function getAccountSocialById(userID: string): Promise { + const { data, error } = await supabase + .from("accountssocial") + .select("*") + .eq("userID", userID) + .single(); + + if (error) { + console.error(error); + throw error; + } else { + return new AccountsSocial( + data.userID, + data.compLiteracy, + data.relationshipToPeers, + data.socialBackground, + data.tendency, + ); + } +} + +/* UPDATE */ + +export async function updateAccountSocial(accountSocial: AccountsSocial) { + const { userID, compLiteracy, relationshipToPeers, socialBackground, tendency } = accountSocial; + + const updateFields: { [key: string]: any } = {}; + + if (compLiteracy) updateFields.compLiteracy = compLiteracy; + if (relationshipToPeers) updateFields.relationshipToPeers = relationshipToPeers; + if (socialBackground) updateFields.socialBackground = socialBackground; + if (tendency) updateFields.tendency = tendency; + + if (Object.keys(updateFields).length === 0) { + throw new Error("No fields to update"); + } + + const { status, statusText, error } = await supabase + .from("accountssocial") + .update(updateFields) + .eq("userID", userID); + + if (error) { + console.error(error); + throw error; + } else { + return { status, statusText }; + } +} + +/* DELETE */ + +export async function deleteAccountSocial(userID: string) { + const { status, statusText, error } = await supabase + .from("accountssocial") + .delete() + .eq("userID", userID); + + if (error) { + console.error(error); + throw error; + } else { + return { status, statusText }; + } +} \ No newline at end of file From b7291a24957005cb9eab0f44b2fbf0171cba0d1e Mon Sep 17 00:00:00 2001 From: Fadhli Date: Tue, 20 Aug 2024 11:48:12 +0800 Subject: [PATCH 3/3] SCRUM-52 Updated error messages for each controller --- backend/src/controllers/accountsAffectiveController.ts | 10 +++++----- backend/src/controllers/accountsCognitiveController.ts | 6 +++--- .../src/controllers/accountsDemographicsController.ts | 8 ++++---- backend/src/controllers/accountsSocialController.ts | 8 ++++---- backend/src/routes/accountsAffectiveRouter.ts | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/backend/src/controllers/accountsAffectiveController.ts b/backend/src/controllers/accountsAffectiveController.ts index 2f9034d..7b8b6b5 100644 --- a/backend/src/controllers/accountsAffectiveController.ts +++ b/backend/src/controllers/accountsAffectiveController.ts @@ -15,19 +15,19 @@ export const createAccountAffective = async (req: Request, res: Response) => { }); } catch (error) { res.status(500).json({ - error: `Failed to create ${accountBody.role} account`, + error: `Failed to create Account Affective`, }); } }; /* READ */ -export const getAccountById = async (req: Request, res: Response) => { +export const getAccountAffectiveById = async (req: Request, res: Response) => { try { const account = await accountsAffectiveService.getAccountAffectiveById(req.params.id); res.status(200).json(account); } catch (error) { - res.status(500).json({ error: "Failed to retrieve account" }); + res.status(500).json({ error: "Failed to retrieve Account Affective" }); } }; @@ -43,7 +43,7 @@ export const updateAccountAffective = async (req: Request, res: Response) => { statusText: "Account Affective Updated Successfully", }); } catch (error) { - res.status(500).json({ error: "Failed to update account" }); + res.status(500).json({ error: "Failed to update Account Affective" }); } }; @@ -58,6 +58,6 @@ export const deleteAccountAffective = async (req: Request, res: Response) => { statusText: "Account Affective Deleted Successfully", }); } catch (error) { - res.status(500).json({ error: "Failed to delete account" }); + res.status(500).json({ error: "Failed to delete Account Affective" }); } }; diff --git a/backend/src/controllers/accountsCognitiveController.ts b/backend/src/controllers/accountsCognitiveController.ts index 06f67d8..ed5b0d7 100644 --- a/backend/src/controllers/accountsCognitiveController.ts +++ b/backend/src/controllers/accountsCognitiveController.ts @@ -15,7 +15,7 @@ export const createAccountCognitive = async (req: Request, res: Response) => { }); } catch (error) { res.status(500).json({ - error: `Failed to create ${accountBody.role} account`, + error: `Failed to create Account Cognitive`, }); } }; @@ -43,7 +43,7 @@ export const updateAccountCognitive = async (req: Request, res: Response) => { statusText: "Account Cognitive Updated Successfully", }); } catch (error) { - res.status(500).json({ error: "Failed to update account" }); + res.status(500).json({ error: "Failed to update Account Cognitive" }); } }; @@ -58,6 +58,6 @@ export const deleteAccountCognitive = async (req: Request, res: Response) => { statusText: "Account Cognitive Deleted Successfully", }); } catch (error) { - res.status(500).json({ error: "Failed to delete account" }); + res.status(500).json({ error: "Failed to delete Account Cognitive" }); } }; diff --git a/backend/src/controllers/accountsDemographicsController.ts b/backend/src/controllers/accountsDemographicsController.ts index 93c1dbc..bad2545 100644 --- a/backend/src/controllers/accountsDemographicsController.ts +++ b/backend/src/controllers/accountsDemographicsController.ts @@ -15,7 +15,7 @@ export const createAccountDemographics = async (req: Request, res: Response) => }); } catch (error) { res.status(500).json({ - error: `Failed to create ${accountBody.role} account`, + error: `Failed to create Account Demographics`, }); } }; @@ -27,7 +27,7 @@ export const getAccountDemographicsById = async (req: Request, res: Response) => const account = await accountsDemographicsService.getAccountDemographicsById(req.params.id); res.status(200).json(account); } catch (error) { - res.status(500).json({ error: "Failed to retrieve account" }); + res.status(500).json({ error: "Failed to retrieve Account Demographics" }); } }; @@ -43,7 +43,7 @@ export const updateAccountDemographics = async (req: Request, res: Response) => statusText: "Account Demographics Updated Successfully", }); } catch (error) { - res.status(500).json({ error: "Failed to update account" }); + res.status(500).json({ error: "Failed to update Account Demographics" }); } }; @@ -58,6 +58,6 @@ export const deleteAccountDemographics = async (req: Request, res: Response) => statusText: "Account Demographics Deleted Successfully", }); } catch (error) { - res.status(500).json({ error: "Failed to delete account" }); + res.status(500).json({ error: "Failed to delete Account Demographics" }); } }; diff --git a/backend/src/controllers/accountsSocialController.ts b/backend/src/controllers/accountsSocialController.ts index 7f3c2aa..89e977e 100644 --- a/backend/src/controllers/accountsSocialController.ts +++ b/backend/src/controllers/accountsSocialController.ts @@ -15,7 +15,7 @@ export const createAccountSocial = async (req: Request, res: Response) => { }); } catch (error) { res.status(500).json({ - error: `Failed to create ${accountBody.role} account`, + error: `Failed to create Account Social`, }); } }; @@ -27,7 +27,7 @@ export const getAccountSocialById = async (req: Request, res: Response) => { const account = await accountsSocialService.getAccountSocialById(req.params.id); res.status(200).json(account); } catch (error) { - res.status(500).json({ error: "Failed to retrieve account" }); + res.status(500).json({ error: "Failed to retrieve Account Social" }); } }; @@ -43,7 +43,7 @@ export const updateAccountSocial = async (req: Request, res: Response) => { statusText: "Account Social Updated Successfully", }); } catch (error) { - res.status(500).json({ error: "Failed to update account" }); + res.status(500).json({ error: "Failed to update Account Social" }); } }; @@ -58,6 +58,6 @@ export const deleteAccountSocial = async (req: Request, res: Response) => { statusText: "Account Social Deleted Successfully", }); } catch (error) { - res.status(500).json({ error: "Failed to delete account" }); + res.status(500).json({ error: "Failed to delete Account Social" }); } }; diff --git a/backend/src/routes/accountsAffectiveRouter.ts b/backend/src/routes/accountsAffectiveRouter.ts index f1e17b1..3d4d963 100644 --- a/backend/src/routes/accountsAffectiveRouter.ts +++ b/backend/src/routes/accountsAffectiveRouter.ts @@ -7,7 +7,7 @@ const router = Router(); router.post("/createaccountaffective", accountsAffectiveController.createAccountAffective); /* READ */ -router.get('/getaccountaffectivebyid/:id', accountsAffectiveController.getAccountById); +router.get('/getaccountaffectivebyid/:id', accountsAffectiveController.getAccountAffectiveById); /* UPDATE */ router.patch('/updateaccountaffective', accountsAffectiveController.updateAccountAffective);