-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/membership system #214
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4d5ea63
Add membership class, balance, and expiration fields to UserSettings …
DarinHajou dce51d2
Add endpoints for membership status, upgrade, and mappi usage
DarinHajou a660f43
Implement controller logic for fetching membership status, upgrading …
DarinHajou 4b93235
Include membership class, mappi balance, and membership expiration to…
DarinHajou 2048cee
Added service functions to retrieve membership status, upgrade member…
DarinHajou 0950e2a
Update UserPreferences schema to include membership fields
DarinHajou a5d4ca7
Add Tier mongoose model
DarinHajou cf9660e
Add script for populating tier data to the DB
DarinHajou d5926cd
Define the MembershipType enum
DarinHajou 172f115
Fix indentation issue
DarinHajou 9c7a4e6
Refactor user preference controller to use req.currentUser instead of…
DarinHajou c23045d
Validate mappi_balance and durationWeeks in 'upgradeMembership' and r…
DarinHajou bd6e12a
Add tierController with endpoints to retrieve all tiers or a specific…
DarinHajou 5d179f0
Add tier service with methods to fetch all tiers or a single tier by …
DarinHajou f9eb814
Add routes for retrieving all tiers or a single tier by class
DarinHajou 65b1cdd
Add tier routes to app
DarinHajou 0096abe
Merge branch 'dev' into feature/membership-system
DarinHajou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Request, Response } from "express"; | ||
import { fetchAllTiers, fetchTierByClass } from "../services/tier.service"; | ||
|
||
export const getAllTiers = async (req: Request, res: Response) => { | ||
try { | ||
const tiers = await fetchAllTiers(); | ||
res.status(200).json(tiers); | ||
} catch (error) { | ||
console.error("Error fetching tiers:", error); | ||
res.status(500).json({ message: "Failed to fetch tiers, please try again later." }); | ||
} | ||
}; | ||
|
||
export const getTierByClass = async (req: Request, res: Response) => { | ||
|
||
const { membershipClass } = req.params; | ||
console.log("Received membershipClass:", membershipClass); | ||
try { | ||
const tier = await fetchTierByClass(membershipClass); | ||
console.log("Fetched tier from database:", tier); | ||
if (!tier) { | ||
return res.status(404).json({ message: "Membership tier not found" }); | ||
} | ||
res.status(200).json(tier); | ||
} catch (error) { | ||
console.error("Error fetching tier:", error); | ||
res.status(500).json({ message: "Failed to fetch tier, please try again later." }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import mongoose, { Schema, Document } from "mongoose"; | ||
import { MembershipType } from "../models/enums/membershipTypes"; | ||
|
||
export interface ITier extends Document { | ||
class: MembershipType; // Use the MembershipType enum here | ||
mappiAllowance: number; | ||
durationWeeks: number; | ||
cost: number; | ||
badge: string; | ||
priorityLevel: number; | ||
} | ||
|
||
const tierSchema: Schema = new Schema( | ||
{ | ||
class: { type: String, enum: Object.values(MembershipType), required: true, unique: true }, | ||
mappiAllowance: { type: Number, required: true }, | ||
durationWeeks: { type: Number, required: true }, | ||
cost: { type: Number, required: true }, | ||
badge: { type: String, required: true }, | ||
priorityLevel: { type: Number, required: true }, | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
const Tier = mongoose.model<ITier>("Tier", tierSchema); | ||
|
||
export default Tier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,8 +54,26 @@ const userSettingsSchema = new Schema<IUserSettings>( | |
required: false, | ||
default: [0, 0] | ||
}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why didn't we just create a separate Membership model? 🤔 |
||
// Membership fields | ||
membership_class: { | ||
type: String, | ||
required: true, | ||
default: "Casual", | ||
enum: ["Triple Gold", "Double Gold", "Gold", "Green", "Member", "Casual"] | ||
}, | ||
mappi_balance: { | ||
type: Number, | ||
required: true, | ||
default: 0 | ||
}, | ||
membership_expiration: { | ||
type: Date, | ||
required: false, // Optional for casual users | ||
default: null | ||
} | ||
} | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
// use GeoJSON format to store geographical data i.e., points using '2dsphere' index. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export enum MembershipType { | ||
CASUAL = "Casual", | ||
MEMBER = "Member", | ||
GREEN = "Green", | ||
GOLD = "Gold", | ||
DOUBLE_GOLD = "Double Gold", | ||
TRIPLE_GOLD = "Triple Gold", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Router } from "express"; | ||
import { getAllTiers, getTierByClass } from "../controllers/tierController"; | ||
import { verifyToken } from "../middlewares/verifyToken"; | ||
|
||
/** | ||
* @swagger | ||
* /api/v1/tiers: | ||
* get: | ||
* tags: | ||
* - Tiers | ||
* summary: Get all membership tiers | ||
* responses: | ||
* 200: | ||
* description: Successful response | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: array | ||
* items: | ||
* $ref: '#/components/schemas/Tier' | ||
* 500: | ||
* description: Internal server error | ||
*/ | ||
const tierRoutes = Router(); | ||
|
||
// Endpoint to get all tiers | ||
tierRoutes.get("/tiers", verifyToken, getAllTiers); | ||
|
||
/** | ||
* @swagger | ||
* /api/v1/tiers/{membershipClass}: | ||
* get: | ||
* tags: | ||
* - Tiers | ||
* summary: Get a tier by membership class | ||
* parameters: | ||
* - name: membershipClass | ||
* in: path | ||
* required: true | ||
* schema: | ||
* type: string | ||
* description: Membership class to fetch details for | ||
* responses: | ||
* 200: | ||
* description: Successful response | ||
* content: | ||
* application/json: | ||
* schema: | ||
* $ref: '#/components/schemas/Tier' | ||
* 404: | ||
* description: Tier not found | ||
* 500: | ||
* description: Internal server error | ||
*/ | ||
tierRoutes.get("/tiers/:membershipClass", verifyToken, getTierByClass); | ||
|
||
export default tierRoutes; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify if this Tiers model is intended solely for informational purposes? If so, I don't anticipate the data needing to be changed very much and find the BE addition unnecessary overhead. Thoughts about treating the data as static content and presented on the FE.. perhaps in a JSON file?