Skip to main content

Overview

The CardPlan model stores customer submissions for pre-defined pricing card plans. It captures customer information and their selected plan tier (Budget, Business, or Professional).

Schema Definition

The CardPlan schema is defined using Mongoose and includes the following structure:
import mongoose from 'mongoose';

const cardPlanSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true
    },
    phone: {
        type: String,
        required: true
    },
    websiteType: {
        type: String,
        required: true
    },
    planType: {
        type: String,
        required: true,
        enum: ['Budget', 'Business', 'Professional']
    },
    planPrice: {
        type: Number,
        required: true
    },
    budget: {
        type: Number,
        required: true,
        default: 0  // 0 indicates uncapped/no budget
    },
    createdAt: {
        type: Date,
        default: Date.now
    }
});

Schema Fields

name
String
required
Customer’s full name
email
String
required
Customer’s email address for communication
phone
String
required
Customer’s phone number
websiteType
String
required
Type of website being requested (e.g., “E-commerce”, “Portfolio”, “Business”)
planType
String
required
Selected pricing tier. Must be one of:
  • Budget - Entry-level plan
  • Business - Mid-tier plan
  • Professional - Premium plan
This field uses Mongoose enum validation to ensure only valid plan types are accepted.
planPrice
Number
required
Price of the selected plan in Rands
budget
Number
default:"0"
required
Customer’s budget for the project in Rands. A value of 0 indicates an uncapped or no budget constraint.
createdAt
Date
default:"Date.now"
Timestamp when the plan was submitted. Automatically set to current date/time if not provided

Example Document

{
  "_id": "65f8a1b2c3d4e5f6a7b8c9d1",
  "name": "Sarah Johnson",
  "email": "[email protected]",
  "phone": "+27 21 987 6543",
  "websiteType": "Portfolio",
  "planType": "Business",
  "planPrice": 7500,
  "budget": 10000,
  "createdAt": "2024-03-15T14:20:00.000Z",
  "__v": 0
}

Validators

Plan Type Enum Validation

The planType field uses Mongoose’s built-in enum validator to ensure only valid plan types are accepted:
planType: {
    type: String,
    required: true,
    enum: ['Budget', 'Business', 'Professional']
}
Attempting to save a document with an invalid plan type will result in a validation error:
// This will throw a validation error
const invalidPlan = new CardPlan({
    planType: 'Enterprise',  // Not in enum
    // ... other fields
});

Usage in API

The CardPlan model is primarily used in the /api/card-plan endpoint:

Creating a Card Plan

import CardPlan from '../server/models/CardPlan.js';

// Create a new card plan submission
const cardPlan = new CardPlan({
    name: req.body.name,
    email: req.body.email,
    phone: req.body.phone,
    websiteType: req.body.websiteType,
    planType: req.body.planType,
    planPrice: req.body.planPrice,
    budget: req.body.budget,
    date: new Date()
});

// Save to database
const savedPlan = await cardPlan.save();

Request Example

curl -X POST https://api.devaurva.com/api/card-plan \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Sarah Johnson",
    "email": "[email protected]",
    "phone": "+27 21 987 6543",
    "websiteType": "Portfolio",
    "planType": "Business",
    "planPrice": 7500,
    "budget": 10000
  }'

Response Example

{
  "success": true,
  "message": "Card plan submitted successfully",
  "plan": {
    "_id": "65f8a1b2c3d4e5f6a7b8c9d1",
    "name": "Sarah Johnson",
    "email": "[email protected]",
    "phone": "+27 21 987 6543",
    "websiteType": "Portfolio",
    "planType": "Business",
    "planPrice": 7500,
    "budget": 10000,
    "createdAt": "2024-03-15T14:20:00.000Z",
    "__v": 0
  }
}

Model Location

Source file: /server/models/CardPlan.js

Plan Types

Budget Plan

Entry-level plan suitable for basic websites with essential features.

Business Plan

Mid-tier plan for growing businesses requiring additional functionality and customization.

Professional Plan

Premium plan offering comprehensive features and advanced capabilities.

Notes

  • The model includes strict enum validation for planType to prevent invalid plan selections
  • When a card plan is submitted, an email notification is automatically sent to the configured recipient
  • All prices are stored in South African Rands (R)
  • The budget field defaults to 0, which represents an uncapped budget
  • The model uses createdAt instead of date for timestamp tracking
  • Unlike CustomPlan, this model does not use the mongoose.models.CardPlan check pattern

Build docs developers (and LLMs) love