Skip to content

style: format code with Prettier and StandardJS #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions handlers/user/ProfilePictureHandlers.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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.
* @param {Object} res - The response object.
* @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.
Expand All @@ -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.
Expand All @@ -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;
88 changes: 44 additions & 44 deletions models/community/InitiativeModel.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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,
Expand All @@ -31,7 +31,7 @@ export default class Initiative extends EndeavorEntity {
introductory_video_URL,
projects,
communityUID,
initiativeUID
initiativeUID,
) {
super(
name,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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);
}
}
78 changes: 39 additions & 39 deletions models/organization/MemebershipRequestModel.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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,
name,
email,
password,
description,
requestID = false
requestID = false,
) {
super()
super();
this.createStructure = {
name,
description,
Expand All @@ -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,
Expand All @@ -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;
}
}
20 changes: 10 additions & 10 deletions utils/firestore/updateData.js
Original file line number Diff line number Diff line change
@@ -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;
Loading