forked from UKSOURCE/cms.lams
feat(admin): implement unified submission and newsletter management
Introduce a centralized system to manage all website form submissions and newsletter subscriptions. - Add `Submission` and `NewsletterSubscription` models with MongoDB schema validation - Implement `submissionController` and `newsletterSubscriptionController` for CRUD operations and filtering - Create a unified admin UI for reviewing submissions across different sources (home, request, contact, partnership, newsletter) - Add database migration scripts for creating collections and indexes - Refactor partnership inquiry forms to use a fixed field structure - Update admin navigation and server CORS settings to support PATCH requests
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const STATUSES = ["subscribed", "unsubscribed"];
|
||||
const emailPattern = /^\S+@\S+\.\S+$/;
|
||||
|
||||
const newsletterSubscriptionSchema = new mongoose.Schema(
|
||||
{
|
||||
email: {
|
||||
type: String,
|
||||
required: [true, "Email is required"],
|
||||
trim: true,
|
||||
lowercase: true,
|
||||
validate: {
|
||||
validator(value) {
|
||||
return emailPattern.test(value);
|
||||
},
|
||||
message: "Please enter a valid email",
|
||||
},
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
enum: STATUSES,
|
||||
default: "subscribed",
|
||||
},
|
||||
pageUrl: {
|
||||
type: String,
|
||||
trim: true,
|
||||
default: "",
|
||||
},
|
||||
ipAddress: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
userAgent: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
internalNote: {
|
||||
type: String,
|
||||
trim: true,
|
||||
default: "",
|
||||
maxlength: [2000, "Internal note cannot exceed 2000 characters"],
|
||||
},
|
||||
},
|
||||
{
|
||||
collection: "newsletter_subscriptions",
|
||||
timestamps: true,
|
||||
autoCreate: false,
|
||||
autoIndex: false,
|
||||
},
|
||||
);
|
||||
|
||||
newsletterSubscriptionSchema.statics.STATUSES = STATUSES;
|
||||
|
||||
module.exports = mongoose.model(
|
||||
"NewsletterSubscription",
|
||||
newsletterSubscriptionSchema,
|
||||
);
|
||||
Reference in New Issue
Block a user