diff --git a/handlers/user/ProfilePictureHandlers.js b/handlers/user/ProfilePictureHandlers.js index 6e78a04..d58073b 100644 --- a/handlers/user/ProfilePictureHandlers.js +++ b/handlers/user/ProfilePictureHandlers.js @@ -1,4 +1,4 @@ -import randomImageGenerator from '../../utils/helper/randomImageGenerator.js' +import randomImageGenerator from "../../utils/helper/randomImageGenerator.js"; /** * Retrieves the profile picture URL for the current user and sends a JSON response. * @param {Object} req - The request object. @@ -6,16 +6,16 @@ import randomImageGenerator from '../../utils/helper/randomImageGenerator.js' * @returns {Object} - JSON response with the user's profile picture URL. */ const getProfilePicture = async (req, res) => { - const { auth, storage, uid } = req - let url = NaN - url = await storage.getDownloadURL(`pfp/${uid}`) + const { auth, storage, uid } = req; + let url = NaN; + url = await storage.getDownloadURL(`pfp/${uid}`); if (url[0] === false) { - url = await auth.getUser(uid) + url = await auth.getUser(uid); } return res.json({ - response: url[1] - }) -} + response: url[1], + }); +}; /** * Uploads a new profile picture for the current user and updates the user's photo URL in the database. @@ -25,17 +25,17 @@ const getProfilePicture = async (req, res) => { */ const uploadProfilePicture = async (req, res) => { - const { body, storage, auth, uid } = req - let { imageBase64, reqUrl } = body + const { body, storage, auth, uid } = req; + let { imageBase64, reqUrl } = body; if (imageBase64) { - const response = storage.uploadByte8Array(path, imageBase64) - reqUrl = response[response.length - 1] + const response = storage.uploadByte8Array(path, imageBase64); + reqUrl = response[response.length - 1]; } - reqUrl = await auth.updateUser(uid, { photoURL: reqUrl }) + reqUrl = await auth.updateUser(uid, { photoURL: reqUrl }); return res.json({ - response: reqUrl[1].photoURL - }) -} + response: reqUrl[1].photoURL, + }); +}; /** * Deletes the profile picture for the current user and updates the user's photo URL in the database to NaN. @@ -44,17 +44,17 @@ const uploadProfilePicture = async (req, res) => { * @returns {Object} - JSON response with the profile picture deletion status. */ const deleteProfilePicture = async (req, res) => { - const { storage, auth, uid } = req - let del = NaN - del = await storage.deleteFile(`pfp/${uid}`) + const { storage, auth, uid } = req; + let del = NaN; + del = await storage.deleteFile(`pfp/${uid}`); if (del[0] === false) { - del = await auth.updateUser(uid, { photoURL: randomImageGenerator() }) + del = await auth.updateUser(uid, { photoURL: randomImageGenerator() }); } // "https://www.pngfind.com/pngs/m/676-6764065_default-profile-picture-transparent-hd-png-download.png" return res.json({ - response: 'User was Deleted' - }) -} + response: "User was Deleted", + }); +}; -export { getProfilePicture, uploadProfilePicture, deleteProfilePicture } -randomImageGenerator +export { getProfilePicture, uploadProfilePicture, deleteProfilePicture }; +randomImageGenerator; diff --git a/models/community/InitiativeModel.js b/models/community/InitiativeModel.js index 4bac4af..329a57f 100644 --- a/models/community/InitiativeModel.js +++ b/models/community/InitiativeModel.js @@ -1,8 +1,8 @@ // Importing necessary modules -import Firestore from '../../firebaseCP/firestore.js' -import updateData from '../../utils/firestore/updateData.js' -import EndeavorEntity from './EndeavorEntity.js' -import { admin } from '../../config/firebase.js' +import Firestore from "../../firebaseCP/firestore.js"; +import updateData from "../../utils/firestore/updateData.js"; +import EndeavorEntity from "./EndeavorEntity.js"; +import { admin } from "../../config/firebase.js"; /** * Class representing an Initiative. @@ -18,7 +18,7 @@ export default class Initiative extends EndeavorEntity { * @param {string} introductory_video_URL - The URL of the introductory video. * @param {Array} projects - The projects of the initiative. */ - constructor ( + constructor( name, organizations, volunteers, @@ -31,7 +31,7 @@ export default class Initiative extends EndeavorEntity { introductory_video_URL, projects, communityUID, - initiativeUID + initiativeUID, ) { super( name, @@ -45,29 +45,29 @@ export default class Initiative extends EndeavorEntity { objectives, introductory_video_URL, projects, - communityUID - ) - this.name = name - this.organizations = organizations - this.volunteers = volunteers - this.started_date = started_date - this.expected_completing_date = expected_completing_date - this.initiated_organization = initiated_organization - this.slogun = slogun - this.mission = mission - this.objectives = objectives - this.introductory_video_URL = introductory_video_URL - this.projects = projects - this.communityUID = communityUID - this.initiativeUID = initiativeUID - this.fs = new Firestore(this.collectionName, this.initiativeID, []) + communityUID, + ); + this.name = name; + this.organizations = organizations; + this.volunteers = volunteers; + this.started_date = started_date; + this.expected_completing_date = expected_completing_date; + this.initiated_organization = initiated_organization; + this.slogun = slogun; + this.mission = mission; + this.objectives = objectives; + this.introductory_video_URL = introductory_video_URL; + this.projects = projects; + this.communityUID = communityUID; + this.initiativeUID = initiativeUID; + this.fs = new Firestore(this.collectionName, this.initiativeID, []); } /** * Create a new initiative. * @return {Promise} A promise that resolves with the created initiative. */ - create () { + create() { const initiativeData = { name: this.name, organizations: this.organizations, @@ -80,31 +80,31 @@ export default class Initiative extends EndeavorEntity { objectives: this.objectives, introductory_video_URL: this.introductory_video_URL, projects: this.projects, - communityUID: this.communityUID - } - return this.fs.create(initiativeData) + communityUID: this.communityUID, + }; + return this.fs.create(initiativeData); } /** * Update an existing initiative. * @return {Promise} A promise that resolves with the updated initiative. */ - update () { - const record = this.read() + update() { + const record = this.read(); const updatedData = updateData( [ - 'name', - 'organizations', - 'volunteers', - 'started_date', - 'expected_completing_date', - 'initiated_organization', - 'slogun', - 'mission', - 'objectives', - 'introductory_video_URL', - 'projects', - 'communityUID' + "name", + "organizations", + "volunteers", + "started_date", + "expected_completing_date", + "initiated_organization", + "slogun", + "mission", + "objectives", + "introductory_video_URL", + "projects", + "communityUID", ], [ this.name, @@ -118,10 +118,10 @@ export default class Initiative extends EndeavorEntity { this.objectives, this.introductory_video_URL, this.projects, - this.communityUID + this.communityUID, ], - record - ) - return this.fs.update(updatedData) + record, + ); + return this.fs.update(updatedData); } } diff --git a/models/organization/MemebershipRequestModel.js b/models/organization/MemebershipRequestModel.js index ca305ca..6445b5e 100644 --- a/models/organization/MemebershipRequestModel.js +++ b/models/organization/MemebershipRequestModel.js @@ -1,10 +1,10 @@ -import { Authentication } from '../../firebaseCP/authentication.js' -import Firestore from '../../firebaseCP/firestore.js' -import FirestoreAbstract from '../../utils/firestore/FirestoreAbstract.js' -import updateData from '../../utils/firestore/updateData.js' +import { Authentication } from "../../firebaseCP/authentication.js"; +import Firestore from "../../firebaseCP/firestore.js"; +import FirestoreAbstract from "../../utils/firestore/FirestoreAbstract.js"; +import updateData from "../../utils/firestore/updateData.js"; export default class MembershipRequestModel extends FirestoreAbstract { - constructor ( + constructor( registrationCertificateUrl, annualReportUrl, legalDocumentsUrl, @@ -12,9 +12,9 @@ export default class MembershipRequestModel extends FirestoreAbstract { email, password, description, - requestID = false + requestID = false, ) { - super() + super(); this.createStructure = { name, description, @@ -23,21 +23,21 @@ export default class MembershipRequestModel extends FirestoreAbstract { registrationCertificateUrl, annualReportUrl, legalDocumentsUrl, - creationDate: Date.now() - } - this.fs = new Firestore('organizationsRequests', this.requestID) - const currentRecord = this.read() + creationDate: Date.now(), + }; + this.fs = new Firestore("organizationsRequests", this.requestID); + const currentRecord = this.read(); this.updateStructure = updateData( [ - 'name', - 'description', - 'email', - 'password', - 'registrationCertificateUrl', - 'annualReportUrl', - 'legalDocumentsUrl', - 'creationDate', - 'accepted' + "name", + "description", + "email", + "password", + "registrationCertificateUrl", + "annualReportUrl", + "legalDocumentsUrl", + "creationDate", + "accepted", ], [ name, @@ -48,31 +48,31 @@ export default class MembershipRequestModel extends FirestoreAbstract { annualReportUrl, legalDocumentsUrl, Date.now(), - false + false, ], - currentRecord - ) - this.requestID = requestID + currentRecord, + ); + this.requestID = requestID; } - approve () { - const record = this.fs.read() - this.fs.delete() - this.fs = new Firestore('organizations', this.requestID) - const orgID = this.fs.create(record)[1] - this.auth = new Authentication() - this.auth.createUser({ email: record.email, password: record.password }) - this.authFS = new Firestore('users', orgID) + approve() { + const record = this.fs.read(); + this.fs.delete(); + this.fs = new Firestore("organizations", this.requestID); + const orgID = this.fs.create(record)[1]; + this.auth = new Authentication(); + this.auth.createUser({ email: record.email, password: record.password }); + this.authFS = new Firestore("users", orgID); this.authFS.create({ orgID, - role: 'Organization', - level: 0 - }) - return orgID + role: "Organization", + level: 0, + }); + return orgID; } - decline () { - this.fs.delete() - return true + decline() { + this.fs.delete(); + return true; } } diff --git a/utils/firestore/updateData.js b/utils/firestore/updateData.js index 6139081..5c7df80 100644 --- a/utils/firestore/updateData.js +++ b/utils/firestore/updateData.js @@ -1,15 +1,15 @@ -import isArray from '../validation/isArray.js' +import isArray from "../validation/isArray.js"; const updateData = (fields, data, alreadyData) => { - const updateStructure = {} + const updateStructure = {}; fields.forEach((field, index) => { - console.log(updateStructure) + console.log(updateStructure); if (Array.isArray(alreadyData[field])) { - updateStructure[field] = isArray(data[index], alreadyData[field]) + updateStructure[field] = isArray(data[index], alreadyData[field]); } - updateStructure[field] = data[index] ?? alreadyData[field] - console.log(updateStructure) - }) - return updateStructure -} -export default updateData + updateStructure[field] = data[index] ?? alreadyData[field]; + console.log(updateStructure); + }); + return updateStructure; +}; +export default updateData;